1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QV8QOBJECTWRAPPER_P_H
43 #define QV8QOBJECTWRAPPER_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qmetatype.h>
58 #include <QtCore/qpair.h>
59 #include <QtCore/qhash.h>
60 #include <private/qv8_p.h>
61 #include <private/qhashedstring_p.h>
62 #include <private/qdeclarativedata_p.h>
63 #include <private/qdeclarativepropertycache_p.h>
69 class QDeclarativeData;
70 class QV8ObjectResource;
71 class QV8QObjectInstance;
72 class QV8QObjectConnectionList;
73 class QDeclarativePropertyCache;
74 class Q_DECLARATIVE_EXPORT QV8QObjectWrapper
80 void init(QV8Engine *);
83 v8::Handle<v8::Value> newQObject(QObject *object);
84 bool isQObject(v8::Handle<v8::Object>);
85 QObject *toQObject(v8::Handle<v8::Object>);
86 static QObject *toQObject(QV8ObjectResource *);
88 enum RevisionMode { IgnoreRevision, CheckRevision };
89 inline v8::Handle<v8::Value> getProperty(QObject *, const QHashedV8String &, RevisionMode);
90 inline bool setProperty(QObject *, const QHashedV8String &, v8::Handle<v8::Value>, RevisionMode);
93 friend class QDeclarativePropertyCache;
94 friend class QV8QObjectConnectionList;
95 friend class QV8QObjectInstance;
97 v8::Local<v8::Object> newQObject(QObject *, QDeclarativeData *, QV8Engine *);
98 static v8::Handle<v8::Value> GetProperty(QV8Engine *, QObject *, v8::Handle<v8::Value> *,
99 const QHashedV8String &, QV8QObjectWrapper::RevisionMode);
100 static bool SetProperty(QV8Engine *, QObject *, const QHashedV8String &,
101 v8::Handle<v8::Value>, QV8QObjectWrapper::RevisionMode);
102 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
103 const v8::AccessorInfo &info);
104 static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
105 v8::Local<v8::Value> value,
106 const v8::AccessorInfo &info);
107 static v8::Handle<v8::Integer> Query(v8::Local<v8::String> property,
108 const v8::AccessorInfo &info);
109 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info);
110 static v8::Handle<v8::Value> Connect(const v8::Arguments &args);
111 static v8::Handle<v8::Value> Disconnect(const v8::Arguments &args);
112 static v8::Handle<v8::Value> Invoke(const v8::Arguments &args);
113 static QPair<QObject *, int> ExtractQtMethod(QV8Engine *, v8::Handle<v8::Function>);
114 static QPair<QObject *, int> ExtractQtSignal(QV8Engine *, v8::Handle<v8::Object>);
118 v8::Persistent<v8::Function> m_constructor;
119 v8::Persistent<v8::Function> m_methodConstructor;
120 v8::Persistent<v8::Function> m_signalHandlerConstructor;
121 v8::Persistent<v8::String> m_toStringSymbol;
122 v8::Persistent<v8::String> m_destroySymbol;
123 QHashedV8String m_toStringString;
124 QHashedV8String m_destroyString;
125 v8::Persistent<v8::Object> m_hiddenObject;
126 QHash<QObject *, QV8QObjectConnectionList *> m_connections;
127 typedef QHash<QObject *, QV8QObjectInstance *> TaintedHash;
128 TaintedHash m_taintedObjects;
131 v8::Handle<v8::Value> QV8QObjectWrapper::getProperty(QObject *object, const QHashedV8String &string,
134 QDeclarativeData *dd = QDeclarativeData::get(object, false);
135 if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
136 dd->propertyCache->property(string)) {
137 return GetProperty(m_engine, object, 0, string, mode);
139 return v8::Handle<v8::Value>();
143 bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV8String &string,
144 v8::Handle<v8::Value> value, RevisionMode mode)
146 QDeclarativeData *dd = QDeclarativeData::get(object, false);
147 if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
148 dd->propertyCache->property(string)) {
149 return SetProperty(m_engine, object, string, value, mode);
157 #endif // QV8QOBJECTWRAPPER_P_H