Qt 4.8
qscriptqobject_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
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 
46 
47 namespace QScript
48 {
49 
51  // ### Make sure there's no conflict with JSC::Attribute
53 };
54 
56 {
57 public:
58  struct Data
59  {
62  QScriptEngine::QObjectWrapOptions options;
63 
65 
67  QScriptEngine::QObjectWrapOptions opt)
68  : value(o), ownership(own), options(opt) {}
69  };
70 
73  const QScriptEngine::QObjectWrapOptions &options);
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 
100  { return data->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:
111 };
112 
114 {
115  Q_OBJECT
116 public:
118  : QObject(parent) { }
120 };
121 
123 {
124 public:
125  QObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
126  JSC::Structure* prototypeFunctionStructure);
127 };
128 
130 
132 {
135  const QScriptEngine::QObjectWrapOptions &opt)
136  : object(obj), ownership(own), options(opt) {}
137 
140  QScriptEngine::QObjectWrapOptions options;
141 };
142 
143 class QObjectData // : public QObjectUserData
144 {
145 public:
147  ~QObjectData();
148 
149  bool addSignalHandler(QObject *sender,
150  int signalIndex,
151  JSC::JSValue receiver,
152  JSC::JSValue slot,
153  JSC::JSValue senderWrapper,
155  bool removeSignalHandler(QObject *sender,
156  int signalIndex,
157  JSC::JSValue receiver,
158  JSC::JSValue slot);
159 
161  const QScriptEngine::QObjectWrapOptions &options) const;
162  void registerWrapper(QScriptObject *wrapper,
164  const QScriptEngine::QObjectWrapOptions &options);
165 
166  void mark(JSC::MarkStack&);
167 
168 private:
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;
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 
212 private:
214 };
215 
216 class QtPropertyFunction: public JSC::InternalFunction
217 {
218 public:
219  // work around CELL_SIZE limitation
220  struct Data
221  {
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 
248 private:
250 };
251 
252 class QMetaObjectWrapperObject : public JSC::JSObject
253 {
254 public:
255  // work around CELL_SIZE limitation
256  struct Data
257  {
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);
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 
305 protected:
306  static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::ImplementsHasInstance | JSObject::StructureFlags;
307 
309 };
310 
312 {
313 public:
314  QMetaObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
315  JSC::Structure* prototypeFunctionStructure);
316 };
317 
318 } // namespace QScript
319 
321 
322 #endif
static const JSC::ClassInfo info
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
Data(const QMetaObject *m, int i)
QScriptEngine::QObjectWrapOptions options() const
QList< QScript::QObjectWrapperInfo > wrappers
virtual JSC::ConstructType getConstructData(QScriptObject *, JSC::ConstructData &)
QScriptEnginePrivate * engine
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QObjectDelegate(QObject *object, QScriptEngine::ValueOwnership ownership, const QScriptEngine::QObjectWrapOptions &options)
virtual const JSC::ClassInfo * classInfo() const
static const JSC::ClassInfo info
virtual void markChildren(QScriptObject *, JSC::MarkStack &markStack)
virtual bool deleteProperty(QScriptObject *, JSC::ExecState *, const JSC::Identifier &propertyName)
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
QScriptEngine::ValueOwnership ownership() const
QObject * value() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Data(const QMetaObject *mo, JSC::JSValue c)
const QMetaObject * value() const
virtual bool getOwnPropertySlot(QScriptObject *, JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertySlot &)
ConnectionType
Definition: qnamespace.h:1469
void setOwnership(QScriptEngine::ValueOwnership ownership)
virtual void getOwnPropertyNames(QScriptObject *, JSC::ExecState *, JSC::PropertyNameArray &, JSC::EnumerationMode mode=JSC::ExcludeDontEnumProperties)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setValue(QObject *value)
virtual const JSC::ClassInfo * classInfo() const
QScriptEngine::ValueOwnership ownership
static WTF::PassRefPtr< JSC::Structure > createStructure(JSC::JSValue prototype)
QScript::QObjectConnectionManager * connectionManager
ValueOwnership
This enum specifies the ownership when wrapping a C++ value, e.
virtual void put(QScriptObject *, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue, JSC::PutPropertySlot &)
virtual bool getOwnPropertyDescriptor(QScriptObject *, JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &)
QHash< QByteArray, JSC::JSValue > cachedMembers
#define Q_OBJECT
Definition: qobjectdefs.h:157
QScriptEngine::ValueOwnership ownership
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
virtual Type type() const
virtual const JSC::ClassInfo * classInfo() const
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
QObjectWrapperInfo(QScriptObject *obj, QScriptEngine::ValueOwnership own, const QScriptEngine::QObjectWrapOptions &opt)
Data(JSC::JSValue o, int ii, bool mo)
Data(QObject *o, QScriptEngine::ValueOwnership own, QScriptEngine::QObjectWrapOptions opt)
quint16 index
QScriptEngine::QObjectWrapOptions options
virtual bool compareToObject(QScriptObject *, JSC::ExecState *, JSC::JSObject *)
QScriptEngine::QObjectWrapOptions options
void setValue(const QMetaObject *value)
void setOptions(QScriptEngine::QObjectWrapOptions options)
static const JSC::ClassInfo info
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual JSC::CallType getCallData(QScriptObject *, JSC::CallData &)
QObjectPrototypeObject(QObject *parent=0)