author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtScript module of the Qt Toolkit. |
|
8 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:LGPL-ONLY$ |
0 | 10 |
** GNU Lesser General Public License Usage |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11 |
** This file may be used under the terms of the GNU Lesser |
0 | 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 qt-info@nokia.com. |
|
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 void put(QScriptObject*, JSC::ExecState* exec, |
|
82 |
const JSC::Identifier& propertyName, |
|
83 |
JSC::JSValue, JSC::PutPropertySlot&); |
|
84 |
virtual bool deleteProperty(QScriptObject*, JSC::ExecState*, |
|
85 |
const JSC::Identifier& propertyName, |
|
86 |
bool checkDontDelete = true); |
|
87 |
virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*, |
|
88 |
const JSC::Identifier&, |
|
89 |
unsigned&) const; |
|
90 |
virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*, |
|
91 |
JSC::PropertyNameArray&, |
|
92 |
bool includeNonEnumerable = false); |
|
93 |
virtual void markChildren(QScriptObject*, JSC::MarkStack& markStack); |
|
94 |
virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*); |
|
95 |
||
96 |
inline QObject *value() const { return data->value; } |
|
97 |
inline void setValue(QObject* value) { data->value = value; } |
|
98 |
||
99 |
inline QScriptEngine::ValueOwnership ownership() const |
|
100 |
{ return data->ownership; } |
|
101 |
inline void setOwnership(QScriptEngine::ValueOwnership ownership) |
|
102 |
{ data->ownership = ownership; } |
|
103 |
||
104 |
inline QScriptEngine::QObjectWrapOptions options() const |
|
105 |
{ return data->options; } |
|
106 |
inline void setOptions(QScriptEngine::QObjectWrapOptions options) |
|
107 |
{ data->options = options; } |
|
108 |
||
109 |
protected: |
|
110 |
Data *data; |
|
111 |
}; |
|
112 |
||
113 |
class QObjectPrototypeObject : public QObject |
|
114 |
{ |
|
115 |
Q_OBJECT |
|
116 |
public: |
|
117 |
QObjectPrototypeObject(QObject *parent = 0) |
|
118 |
: QObject(parent) { } |
|
119 |
~QObjectPrototypeObject() { } |
|
120 |
}; |
|
121 |
||
122 |
class QObjectPrototype : public QScriptObject |
|
123 |
{ |
|
124 |
public: |
|
125 |
QObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>, |
|
126 |
JSC::Structure* prototypeFunctionStructure); |
|
127 |
}; |
|
128 |
||
129 |
class QObjectConnectionManager; |
|
130 |
||
131 |
struct QObjectWrapperInfo |
|
132 |
{ |
|
133 |
QObjectWrapperInfo(QScriptObject *obj, |
|
134 |
QScriptEngine::ValueOwnership own, |
|
135 |
const QScriptEngine::QObjectWrapOptions &opt) |
|
136 |
: object(obj), ownership(own), options(opt) {} |
|
137 |
||
138 |
QScriptObject *object; |
|
139 |
QScriptEngine::ValueOwnership ownership; |
|
140 |
QScriptEngine::QObjectWrapOptions options; |
|
141 |
}; |
|
142 |
||
143 |
class QObjectData // : public QObjectUserData |
|
144 |
{ |
|
145 |
public: |
|
146 |
QObjectData(QScriptEnginePrivate *engine); |
|
147 |
~QObjectData(); |
|
148 |
||
149 |
bool addSignalHandler(QObject *sender, |
|
150 |
int signalIndex, |
|
151 |
JSC::JSValue receiver, |
|
152 |
JSC::JSValue slot, |
|
153 |
JSC::JSValue senderWrapper, |
|
154 |
Qt::ConnectionType type); |
|
155 |
bool removeSignalHandler(QObject *sender, |
|
156 |
int signalIndex, |
|
157 |
JSC::JSValue receiver, |
|
158 |
JSC::JSValue slot); |
|
159 |
||
160 |
QScriptObject *findWrapper(QScriptEngine::ValueOwnership ownership, |
|
161 |
const QScriptEngine::QObjectWrapOptions &options) const; |
|
162 |
void registerWrapper(QScriptObject *wrapper, |
|
163 |
QScriptEngine::ValueOwnership ownership, |
|
164 |
const QScriptEngine::QObjectWrapOptions &options); |
|
165 |
||
166 |
void mark(JSC::MarkStack&); |
|
167 |
||
168 |
private: |
|
169 |
QScriptEnginePrivate *engine; |
|
170 |
QScript::QObjectConnectionManager *connectionManager; |
|
171 |
QList<QScript::QObjectWrapperInfo> wrappers; |
|
172 |
}; |
|
173 |
||
174 |
class QtFunction: public JSC::InternalFunction |
|
175 |
{ |
|
176 |
public: |
|
177 |
// work around CELL_SIZE limitation |
|
178 |
struct Data |
|
179 |
{ |
|
180 |
JSC::JSValue object; |
|
181 |
int initialIndex; |
|
182 |
bool maybeOverloaded; |
|
183 |
||
184 |
Data(JSC::JSValue o, int ii, bool mo) |
|
185 |
: object(o), initialIndex(ii), maybeOverloaded(mo) {} |
|
186 |
}; |
|
187 |
||
188 |
QtFunction(JSC::JSValue object, int initialIndex, bool maybeOverloaded, |
|
189 |
JSC::JSGlobalData*, WTF::PassRefPtr<JSC::Structure>, const JSC::Identifier&); |
|
190 |
virtual ~QtFunction(); |
|
191 |
||
192 |
virtual JSC::CallType getCallData(JSC::CallData&); |
|
193 |
virtual void markChildren(JSC::MarkStack&); |
|
194 |
||
195 |
virtual const JSC::ClassInfo* classInfo() const { return &info; } |
|
196 |
static const JSC::ClassInfo info; |
|
197 |
||
198 |
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*, |
|
199 |
JSC::JSValue, const JSC::ArgList&); |
|
200 |
||
201 |
JSC::JSValue execute(JSC::ExecState *exec, JSC::JSValue thisValue, |
|
202 |
const JSC::ArgList &args); |
|
203 |
||
204 |
QScriptObject *wrapperObject() const; |
|
205 |
QObject *qobject() const; |
|
206 |
const QMetaObject *metaObject() const; |
|
207 |
int initialIndex() const; |
|
208 |
bool maybeOverloaded() const; |
|
209 |
int mostGeneralMethod(QMetaMethod *out = 0) const; |
|
210 |
QList<int> overloadedIndexes() const; |
|
211 |
QString functionName() const; |
|
212 |
||
213 |
private: |
|
214 |
Data *data; |
|
215 |
}; |
|
216 |
||
217 |
class QtPropertyFunction: public JSC::InternalFunction |
|
218 |
{ |
|
219 |
public: |
|
220 |
// work around CELL_SIZE limitation |
|
221 |
struct Data |
|
222 |
{ |
|
223 |
const QMetaObject *meta; |
|
224 |
int index; |
|
225 |
||
226 |
Data(const QMetaObject *m, int i) |
|
227 |
: meta(m), index(i) {} |
|
228 |
}; |
|
229 |
||
230 |
QtPropertyFunction(const QMetaObject *meta, int index, |
|
231 |
JSC::JSGlobalData*, WTF::PassRefPtr<JSC::Structure>, |
|
232 |
const JSC::Identifier&); |
|
233 |
virtual ~QtPropertyFunction(); |
|
234 |
||
235 |
virtual JSC::CallType getCallData(JSC::CallData&); |
|
236 |
||
237 |
virtual const JSC::ClassInfo* classInfo() const { return &info; } |
|
238 |
static const JSC::ClassInfo info; |
|
239 |
||
240 |
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*, |
|
241 |
JSC::JSValue, const JSC::ArgList&); |
|
242 |
||
243 |
JSC::JSValue execute(JSC::ExecState *exec, JSC::JSValue thisValue, |
|
244 |
const JSC::ArgList &args); |
|
245 |
||
246 |
const QMetaObject *metaObject() const; |
|
247 |
int propertyIndex() const; |
|
248 |
||
249 |
private: |
|
250 |
Data *data; |
|
251 |
}; |
|
252 |
||
253 |
class QMetaObjectWrapperObject : public JSC::JSObject |
|
254 |
{ |
|
255 |
public: |
|
256 |
// work around CELL_SIZE limitation |
|
257 |
struct Data |
|
258 |
{ |
|
259 |
const QMetaObject *value; |
|
260 |
JSC::JSValue ctor; |
|
261 |
JSC::JSValue prototype; |
|
262 |
||
263 |
Data(const QMetaObject *mo, JSC::JSValue c) |
|
264 |
: value(mo), ctor(c) {} |
|
265 |
}; |
|
266 |
||
267 |
explicit QMetaObjectWrapperObject( |
|
268 |
JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor, |
|
269 |
WTF::PassRefPtr<JSC::Structure> sid); |
|
270 |
~QMetaObjectWrapperObject(); |
|
271 |
||
272 |
virtual bool getOwnPropertySlot(JSC::ExecState*, |
|
273 |
const JSC::Identifier& propertyName, |
|
274 |
JSC::PropertySlot&); |
|
275 |
virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName, |
|
276 |
JSC::JSValue, JSC::PutPropertySlot&); |
|
277 |
virtual bool deleteProperty(JSC::ExecState*, |
|
278 |
const JSC::Identifier& propertyName, |
|
279 |
bool checkDontDelete = true); |
|
280 |
virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&, |
|
281 |
unsigned&) const; |
|
282 |
virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, |
|
283 |
bool includeNonEnumerable = false); |
|
284 |
virtual void markChildren(JSC::MarkStack& markStack); |
|
285 |
||
286 |
virtual JSC::CallType getCallData(JSC::CallData&); |
|
287 |
virtual JSC::ConstructType getConstructData(JSC::ConstructData&); |
|
288 |
||
289 |
virtual const JSC::ClassInfo* classInfo() const { return &info; } |
|
290 |
static const JSC::ClassInfo info; |
|
291 |
||
292 |
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*, |
|
293 |
JSC::JSValue, const JSC::ArgList&); |
|
294 |
static JSC::JSObject* construct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &); |
|
295 |
||
296 |
JSC::JSValue execute(JSC::ExecState *exec, const JSC::ArgList &args); |
|
297 |
||
298 |
inline const QMetaObject *value() const { return data->value; } |
|
299 |
inline void setValue(const QMetaObject* value) { data->value = value; } |
|
300 |
||
301 |
static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype) |
|
302 |
{ |
|
303 |
return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType)); |
|
304 |
} |
|
305 |
||
306 |
protected: |
|
307 |
Data *data; |
|
308 |
}; |
|
309 |
||
310 |
class QMetaObjectPrototype : public QMetaObjectWrapperObject |
|
311 |
{ |
|
312 |
public: |
|
313 |
QMetaObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>, |
|
314 |
JSC::Structure* prototypeFunctionStructure); |
|
315 |
}; |
|
316 |
||
317 |
} // namespace QScript |
|
318 |
||
319 |
QT_END_NAMESPACE |
|
320 |
||
321 |
#endif |