source: trunk/src/script/bridge/qscriptqobject_p.h@ 1036

Last change on this file since 1036 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 10.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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
45QT_BEGIN_NAMESPACE
46
47namespace QScript
48{
49
50enum AttributeExtension {
51 // ### Make sure there's no conflict with JSC::Attribute
52 QObjectMemberAttribute = 1 << 12
53};
54
55class QObjectDelegate : public QScriptObjectDelegate
56{
57public:
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 virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*,
91 JSC::PropertyNameArray&,
92 JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
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
109protected:
110 Data *data;
111};
112
113class QObjectPrototypeObject : public QObject
114{
115 Q_OBJECT
116public:
117 QObjectPrototypeObject(QObject *parent = 0)
118 : QObject(parent) { }
119 ~QObjectPrototypeObject() { }
120};
121
122class QObjectPrototype : public QScriptObject
123{
124public:
125 QObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
126 JSC::Structure* prototypeFunctionStructure);
127};
128
129class QObjectConnectionManager;
130
131struct 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
143class QObjectData // : public QObjectUserData
144{
145public:
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
168private:
169 QScriptEnginePrivate *engine;
170 QScript::QObjectConnectionManager *connectionManager;
171 QList<QScript::QObjectWrapperInfo> wrappers;
172};
173
174class QtFunction: public JSC::InternalFunction
175{
176public:
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
212private:
213 Data *data;
214};
215
216class QtPropertyFunction: public JSC::InternalFunction
217{
218public:
219 // work around CELL_SIZE limitation
220 struct Data
221 {
222 const QMetaObject *meta;
223 int index;
224
225 Data(const QMetaObject *m, int i)
226 : meta(m), index(i) {}
227 };
228
229 QtPropertyFunction(const QMetaObject *meta, int index,
230 JSC::JSGlobalData*, WTF::PassRefPtr<JSC::Structure>,
231 const JSC::Identifier&);
232 virtual ~QtPropertyFunction();
233
234 virtual JSC::CallType getCallData(JSC::CallData&);
235
236 virtual const JSC::ClassInfo* classInfo() const { return &info; }
237 static const JSC::ClassInfo info;
238
239 static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*,
240 JSC::JSValue, const JSC::ArgList&);
241
242 JSC::JSValue execute(JSC::ExecState *exec, JSC::JSValue thisValue,
243 const JSC::ArgList &args);
244
245 const QMetaObject *metaObject() const;
246 int propertyIndex() const;
247
248private:
249 Data *data;
250};
251
252class QMetaObjectWrapperObject : public JSC::JSObject
253{
254public:
255 // work around CELL_SIZE limitation
256 struct Data
257 {
258 const QMetaObject *value;
259 JSC::JSValue ctor;
260 JSC::JSValue prototype;
261
262 Data(const QMetaObject *mo, JSC::JSValue c)
263 : value(mo), ctor(c) {}
264 };
265
266 explicit QMetaObjectWrapperObject(
267 JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor,
268 WTF::PassRefPtr<JSC::Structure> sid);
269 ~QMetaObjectWrapperObject();
270
271 virtual bool getOwnPropertySlot(JSC::ExecState*,
272 const JSC::Identifier& propertyName,
273 JSC::PropertySlot&);
274 virtual bool getOwnPropertyDescriptor(JSC::ExecState*,
275 const JSC::Identifier& propertyName,
276 JSC::PropertyDescriptor&);
277 virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
278 JSC::JSValue, JSC::PutPropertySlot&);
279 virtual bool deleteProperty(JSC::ExecState*,
280 const JSC::Identifier& propertyName);
281 virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
282 JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
283 virtual void markChildren(JSC::MarkStack& markStack);
284
285 virtual JSC::CallType getCallData(JSC::CallData&);
286 virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
287
288 virtual const JSC::ClassInfo* classInfo() const { return &info; }
289 static const JSC::ClassInfo info;
290
291 static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*,
292 JSC::JSValue, const JSC::ArgList&);
293 static JSC::JSObject* construct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &);
294
295 JSC::JSValue execute(JSC::ExecState *exec, const JSC::ArgList &args);
296
297 inline const QMetaObject *value() const { return data->value; }
298 inline void setValue(const QMetaObject* value) { data->value = value; }
299
300 static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
301 {
302 return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
303 }
304
305protected:
306 static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::ImplementsHasInstance | JSObject::StructureFlags;
307
308 Data *data;
309};
310
311class QMetaObjectPrototype : public QMetaObjectWrapperObject
312{
313public:
314 QMetaObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
315 JSC::Structure* prototypeFunctionStructure);
316};
317
318} // namespace QScript
319
320QT_END_NAMESPACE
321
322#endif
Note: See TracBrowser for help on using the repository browser.