1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtScript module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL-ONLY$
|
---|
10 | ** GNU Lesser General Public License Usage
|
---|
11 | ** This file may be used under the terms of the GNU Lesser
|
---|
12 | ** General Public License version 2.1 as published by the Free Software
|
---|
13 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
14 | ** packaging of this file. Please review the following information to
|
---|
15 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
17 | **
|
---|
18 | ** If you have questions regarding the use of this file, please contact
|
---|
19 | ** Nokia at [email protected].
|
---|
20 | ** $QT_END_LICENSE$
|
---|
21 | **
|
---|
22 | ****************************************************************************/
|
---|
23 |
|
---|
24 | #ifndef QSCRIPTQOBJECT_P_H
|
---|
25 | #define QSCRIPTQOBJECT_P_H
|
---|
26 |
|
---|
27 | //
|
---|
28 | // W A R N I N G
|
---|
29 | // -------------
|
---|
30 | //
|
---|
31 | // This file is not part of the Qt API. It exists purely as an
|
---|
32 | // implementation detail. This header file may change from version to
|
---|
33 | // version without notice, or even be removed.
|
---|
34 | //
|
---|
35 | // We mean it.
|
---|
36 | //
|
---|
37 |
|
---|
38 | #include "qscriptobject_p.h"
|
---|
39 |
|
---|
40 | #include "qscriptengine.h"
|
---|
41 | #include <QtCore/qpointer.h>
|
---|
42 |
|
---|
43 | #include "InternalFunction.h"
|
---|
44 |
|
---|
45 | QT_BEGIN_NAMESPACE
|
---|
46 |
|
---|
47 | namespace QScript
|
---|
48 | {
|
---|
49 |
|
---|
50 | enum AttributeExtension {
|
---|
51 | // ### Make sure there's no conflict with JSC::Attribute
|
---|
52 | QObjectMemberAttribute = 1 << 12
|
---|
53 | };
|
---|
54 |
|
---|
55 | class QObjectDelegate : public QScriptObjectDelegate
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | struct Data
|
---|
59 | {
|
---|
60 | QPointer<QObject> value;
|
---|
61 | QScriptEngine::ValueOwnership ownership;
|
---|
62 | QScriptEngine::QObjectWrapOptions options;
|
---|
63 |
|
---|
64 | QHash<QByteArray, JSC::JSValue> cachedMembers;
|
---|
65 |
|
---|
66 | Data(QObject *o, QScriptEngine::ValueOwnership own,
|
---|
67 | QScriptEngine::QObjectWrapOptions opt)
|
---|
68 | : value(o), ownership(own), options(opt) {}
|
---|
69 | };
|
---|
70 |
|
---|
71 | QObjectDelegate(
|
---|
72 | QObject *object, QScriptEngine::ValueOwnership ownership,
|
---|
73 | const QScriptEngine::QObjectWrapOptions &options);
|
---|
74 | ~QObjectDelegate();
|
---|
75 |
|
---|
76 | virtual Type type() const;
|
---|
77 |
|
---|
78 | virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*,
|
---|
79 | const JSC::Identifier& propertyName,
|
---|
80 | JSC::PropertySlot&);
|
---|
81 | virtual bool getOwnPropertyDescriptor(QScriptObject*, JSC::ExecState*,
|
---|
82 | const JSC::Identifier& propertyName,
|
---|
83 | JSC::PropertyDescriptor&);
|
---|
84 |
|
---|
85 | virtual void put(QScriptObject*, JSC::ExecState* exec,
|
---|
86 | const JSC::Identifier& propertyName,
|
---|
87 | JSC::JSValue, JSC::PutPropertySlot&);
|
---|
88 | virtual bool deleteProperty(QScriptObject*, JSC::ExecState*,
|
---|
89 | const JSC::Identifier& propertyName,
|
---|
90 | bool checkDontDelete = true);
|
---|
91 | virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*,
|
---|
92 | const JSC::Identifier&,
|
---|
93 | unsigned&) const;
|
---|
94 | virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*,
|
---|
95 | JSC::PropertyNameArray&,
|
---|
96 | bool includeNonEnumerable = false);
|
---|
97 | virtual void markChildren(QScriptObject*, JSC::MarkStack& markStack);
|
---|
98 | virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
|
---|
99 |
|
---|
100 | inline QObject *value() const { return data->value; }
|
---|
101 | inline void setValue(QObject* value) { data->value = value; }
|
---|
102 |
|
---|
103 | inline QScriptEngine::ValueOwnership ownership() const
|
---|
104 | { return data->ownership; }
|
---|
105 | inline void setOwnership(QScriptEngine::ValueOwnership ownership)
|
---|
106 | { data->ownership = ownership; }
|
---|
107 |
|
---|
108 | inline QScriptEngine::QObjectWrapOptions options() const
|
---|
109 | { return data->options; }
|
---|
110 | inline void setOptions(QScriptEngine::QObjectWrapOptions options)
|
---|
111 | { data->options = options; }
|
---|
112 |
|
---|
113 | protected:
|
---|
114 | Data *data;
|
---|
115 | };
|
---|
116 |
|
---|
117 | class QObjectPrototypeObject : public QObject
|
---|
118 | {
|
---|
119 | Q_OBJECT
|
---|
120 | public:
|
---|
121 | QObjectPrototypeObject(QObject *parent = 0)
|
---|
122 | : QObject(parent) { }
|
---|
123 | ~QObjectPrototypeObject() { }
|
---|
124 | };
|
---|
125 |
|
---|
126 | class QObjectPrototype : public QScriptObject
|
---|
127 | {
|
---|
128 | public:
|
---|
129 | QObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
|
---|
130 | JSC::Structure* prototypeFunctionStructure);
|
---|
131 | };
|
---|
132 |
|
---|
133 | class QObjectConnectionManager;
|
---|
134 |
|
---|
135 | struct QObjectWrapperInfo
|
---|
136 | {
|
---|
137 | QObjectWrapperInfo(QScriptObject *obj,
|
---|
138 | QScriptEngine::ValueOwnership own,
|
---|
139 | const QScriptEngine::QObjectWrapOptions &opt)
|
---|
140 | : object(obj), ownership(own), options(opt) {}
|
---|
141 |
|
---|
142 | QScriptObject *object;
|
---|
143 | QScriptEngine::ValueOwnership ownership;
|
---|
144 | QScriptEngine::QObjectWrapOptions options;
|
---|
145 | };
|
---|
146 |
|
---|
147 | class QObjectData // : public QObjectUserData
|
---|
148 | {
|
---|
149 | public:
|
---|
150 | QObjectData(QScriptEnginePrivate *engine);
|
---|
151 | ~QObjectData();
|
---|
152 |
|
---|
153 | bool addSignalHandler(QObject *sender,
|
---|
154 | int signalIndex,
|
---|
155 | JSC::JSValue receiver,
|
---|
156 | JSC::JSValue slot,
|
---|
157 | JSC::JSValue senderWrapper,
|
---|
158 | Qt::ConnectionType type);
|
---|
159 | bool removeSignalHandler(QObject *sender,
|
---|
160 | int signalIndex,
|
---|
161 | JSC::JSValue receiver,
|
---|
162 | JSC::JSValue slot);
|
---|
163 |
|
---|
164 | QScriptObject *findWrapper(QScriptEngine::ValueOwnership ownership,
|
---|
165 | const QScriptEngine::QObjectWrapOptions &options) const;
|
---|
166 | void registerWrapper(QScriptObject *wrapper,
|
---|
167 | QScriptEngine::ValueOwnership ownership,
|
---|
168 | const QScriptEngine::QObjectWrapOptions &options);
|
---|
169 |
|
---|
170 | void mark(JSC::MarkStack&);
|
---|
171 |
|
---|
172 | private:
|
---|
173 | QScriptEnginePrivate *engine;
|
---|
174 | QScript::QObjectConnectionManager *connectionManager;
|
---|
175 | QList<QScript::QObjectWrapperInfo> wrappers;
|
---|
176 | };
|
---|
177 |
|
---|
178 | class QtFunction: public JSC::InternalFunction
|
---|
179 | {
|
---|
180 | public:
|
---|
181 | // work around CELL_SIZE limitation
|
---|
182 | struct Data
|
---|
183 | {
|
---|
184 | JSC::JSValue object;
|
---|
185 | int initialIndex;
|
---|
186 | bool maybeOverloaded;
|
---|
187 |
|
---|
188 | Data(JSC::JSValue o, int ii, bool mo)
|
---|
189 | : object(o), initialIndex(ii), maybeOverloaded(mo) {}
|
---|
190 | };
|
---|
191 |
|
---|
192 | QtFunction(JSC::JSValue object, int initialIndex, bool maybeOverloaded,
|
---|
193 | JSC::JSGlobalData*, WTF::PassRefPtr<JSC::Structure>, const JSC::Identifier&);
|
---|
194 | virtual ~QtFunction();
|
---|
195 |
|
---|
196 | virtual JSC::CallType getCallData(JSC::CallData&);
|
---|
197 | virtual void markChildren(JSC::MarkStack&);
|
---|
198 |
|
---|
199 | virtual const JSC::ClassInfo* classInfo() const { return &info; }
|
---|
200 | static const JSC::ClassInfo info;
|
---|
201 |
|
---|
202 | static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*,
|
---|
203 | JSC::JSValue, const JSC::ArgList&);
|
---|
204 |
|
---|
205 | JSC::JSValue execute(JSC::ExecState *exec, JSC::JSValue thisValue,
|
---|
206 | const JSC::ArgList &args);
|
---|
207 |
|
---|
208 | QScriptObject *wrapperObject() const;
|
---|
209 | QObject *qobject() const;
|
---|
210 | const QMetaObject *metaObject() const;
|
---|
211 | int initialIndex() const;
|
---|
212 | bool maybeOverloaded() const;
|
---|
213 | int mostGeneralMethod(QMetaMethod *out = 0) const;
|
---|
214 | QList<int> overloadedIndexes() const;
|
---|
215 | QString functionName() const;
|
---|
216 |
|
---|
217 | private:
|
---|
218 | Data *data;
|
---|
219 | };
|
---|
220 |
|
---|
221 | class QtPropertyFunction: public JSC::InternalFunction
|
---|
222 | {
|
---|
223 | public:
|
---|
224 | // work around CELL_SIZE limitation
|
---|
225 | struct Data
|
---|
226 | {
|
---|
227 | const QMetaObject *meta;
|
---|
228 | int index;
|
---|
229 |
|
---|
230 | Data(const QMetaObject *m, int i)
|
---|
231 | : meta(m), index(i) {}
|
---|
232 | };
|
---|
233 |
|
---|
234 | QtPropertyFunction(const QMetaObject *meta, int index,
|
---|
235 | JSC::JSGlobalData*, WTF::PassRefPtr<JSC::Structure>,
|
---|
236 | const JSC::Identifier&);
|
---|
237 | virtual ~QtPropertyFunction();
|
---|
238 |
|
---|
239 | virtual JSC::CallType getCallData(JSC::CallData&);
|
---|
240 |
|
---|
241 | virtual const JSC::ClassInfo* classInfo() const { return &info; }
|
---|
242 | static const JSC::ClassInfo info;
|
---|
243 |
|
---|
244 | static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*,
|
---|
245 | JSC::JSValue, const JSC::ArgList&);
|
---|
246 |
|
---|
247 | JSC::JSValue execute(JSC::ExecState *exec, JSC::JSValue thisValue,
|
---|
248 | const JSC::ArgList &args);
|
---|
249 |
|
---|
250 | const QMetaObject *metaObject() const;
|
---|
251 | int propertyIndex() const;
|
---|
252 |
|
---|
253 | private:
|
---|
254 | Data *data;
|
---|
255 | };
|
---|
256 |
|
---|
257 | class QMetaObjectWrapperObject : public JSC::JSObject
|
---|
258 | {
|
---|
259 | public:
|
---|
260 | // work around CELL_SIZE limitation
|
---|
261 | struct Data
|
---|
262 | {
|
---|
263 | const QMetaObject *value;
|
---|
264 | JSC::JSValue ctor;
|
---|
265 | JSC::JSValue prototype;
|
---|
266 |
|
---|
267 | Data(const QMetaObject *mo, JSC::JSValue c)
|
---|
268 | : value(mo), ctor(c) {}
|
---|
269 | };
|
---|
270 |
|
---|
271 | explicit QMetaObjectWrapperObject(
|
---|
272 | JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor,
|
---|
273 | WTF::PassRefPtr<JSC::Structure> sid);
|
---|
274 | ~QMetaObjectWrapperObject();
|
---|
275 |
|
---|
276 | virtual bool getOwnPropertySlot(JSC::ExecState*,
|
---|
277 | const JSC::Identifier& propertyName,
|
---|
278 | JSC::PropertySlot&);
|
---|
279 | virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
|
---|
280 | JSC::JSValue, JSC::PutPropertySlot&);
|
---|
281 | virtual bool deleteProperty(JSC::ExecState*,
|
---|
282 | const JSC::Identifier& propertyName,
|
---|
283 | bool checkDontDelete = true);
|
---|
284 | virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&,
|
---|
285 | unsigned&) const;
|
---|
286 | virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
|
---|
287 | bool includeNonEnumerable = false);
|
---|
288 | virtual void markChildren(JSC::MarkStack& markStack);
|
---|
289 |
|
---|
290 | virtual JSC::CallType getCallData(JSC::CallData&);
|
---|
291 | virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
|
---|
292 |
|
---|
293 | virtual const JSC::ClassInfo* classInfo() const { return &info; }
|
---|
294 | static const JSC::ClassInfo info;
|
---|
295 |
|
---|
296 | static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*,
|
---|
297 | JSC::JSValue, const JSC::ArgList&);
|
---|
298 | static JSC::JSObject* construct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &);
|
---|
299 |
|
---|
300 | JSC::JSValue execute(JSC::ExecState *exec, const JSC::ArgList &args);
|
---|
301 |
|
---|
302 | inline const QMetaObject *value() const { return data->value; }
|
---|
303 | inline void setValue(const QMetaObject* value) { data->value = value; }
|
---|
304 |
|
---|
305 | static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
|
---|
306 | {
|
---|
307 | return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType));
|
---|
308 | }
|
---|
309 |
|
---|
310 | protected:
|
---|
311 | Data *data;
|
---|
312 | };
|
---|
313 |
|
---|
314 | class QMetaObjectPrototype : public QMetaObjectWrapperObject
|
---|
315 | {
|
---|
316 | public:
|
---|
317 | QMetaObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
|
---|
318 | JSC::Structure* prototypeFunctionStructure);
|
---|
319 | };
|
---|
320 |
|
---|
321 | } // namespace QScript
|
---|
322 |
|
---|
323 | QT_END_NAMESPACE
|
---|
324 |
|
---|
325 | #endif
|
---|