Qt 4.8
qscriptobject_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 QSCRIPTOBJECT_P_H
25 #define QSCRIPTOBJECT_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 <QtCore/qobjectdefs.h>
39 
40 #include "JSObject.h"
41 
43 
45 
46 class QScriptObject : public JSC::JSObject
47 {
48 public:
49  // work around CELL_SIZE limitation
50  struct Data
51  {
52  JSC::JSValue data; // QScriptValue::data
54  bool isMarking; // recursion guard
55 
56  Data() : delegate(0), isMarking(false) {}
57  ~Data();
58  };
59 
60  explicit QScriptObject(WTF::PassRefPtr<JSC::Structure> sid);
61  virtual ~QScriptObject();
62 
63  virtual bool getOwnPropertySlot(JSC::ExecState*,
64  const JSC::Identifier& propertyName,
65  JSC::PropertySlot&);
66  virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
67  virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
68  JSC::JSValue, JSC::PutPropertySlot&);
69  virtual bool deleteProperty(JSC::ExecState*,
70  const JSC::Identifier& propertyName);
71  virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
72  JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
73  virtual void markChildren(JSC::MarkStack& markStack);
74  virtual JSC::CallType getCallData(JSC::CallData&);
75  virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
76  virtual bool hasInstance(JSC::ExecState*, JSC::JSValue value, JSC::JSValue proto);
77  virtual bool compareToObject(JSC::ExecState*, JSC::JSObject*);
78 
79  virtual const JSC::ClassInfo* classInfo() const { return &info; }
80  static const JSC::ClassInfo info;
81 
82  static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
83  {
84  return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
85  }
86 
87  inline JSC::JSValue data() const;
88  inline void setData(JSC::JSValue data);
89 
90  inline QScriptObjectDelegate *delegate() const;
91  inline void setDelegate(QScriptObjectDelegate *delegate);
92 
93 protected:
94  static const unsigned StructureFlags = JSC::ImplementsHasInstance | JSC::OverridesHasInstance | JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSObject::StructureFlags;
95 
96  Data *d;
97 };
98 
100 {
101 public:
102  QScriptObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
103  JSC::Structure* prototypeFunctionStructure);
104 };
105 
107 {
108 public:
109  enum Type {
113  DeclarativeClassObject
114  };
115 
117  virtual ~QScriptObjectDelegate();
118 
119  virtual Type type() const = 0;
120 
121  virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*,
122  const JSC::Identifier& propertyName,
123  JSC::PropertySlot&);
124  virtual bool getOwnPropertyDescriptor(QScriptObject*, JSC::ExecState*,
125  const JSC::Identifier& propertyName,
126  JSC::PropertyDescriptor&);
127  virtual void put(QScriptObject*, JSC::ExecState* exec, const JSC::Identifier& propertyName,
128  JSC::JSValue, JSC::PutPropertySlot&);
129  virtual bool deleteProperty(QScriptObject*, JSC::ExecState*,
130  const JSC::Identifier& propertyName);
131  virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*, JSC::PropertyNameArray&,
132  JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
133  virtual void markChildren(QScriptObject*, JSC::MarkStack& markStack);
134  virtual JSC::CallType getCallData(QScriptObject*, JSC::CallData&);
135  virtual JSC::ConstructType getConstructData(QScriptObject*, JSC::ConstructData&);
136  virtual bool hasInstance(QScriptObject*, JSC::ExecState*,
137  JSC::JSValue value, JSC::JSValue proto);
138  virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
139 
140 private:
142 };
143 
144 inline JSC::JSValue QScriptObject::data() const
145 {
146  if (!d)
147  return JSC::JSValue();
148  return d->data;
149 }
150 
151 inline void QScriptObject::setData(JSC::JSValue data)
152 {
153  if (!d)
154  d = new Data();
155  d->data = data;
156 }
157 
159 {
160  if (!d)
161  return 0;
162  return d->delegate;
163 }
164 
166 {
167  if (!d)
168  d = new Data();
169  else
170  delete d->delegate;
171  d->delegate = delegate;
172 }
173 
175 
176 #endif
int type
Definition: qmetatype.cpp:239
virtual bool getOwnPropertySlot(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertySlot &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
QScriptObjectDelegate * delegate() const
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
static const JSC::ClassInfo info
virtual bool deleteProperty(JSC::ExecState *, const JSC::Identifier &propertyName)
virtual bool getOwnPropertyDescriptor(JSC::ExecState *, const JSC::Identifier &, JSC::PropertyDescriptor &)
virtual bool hasInstance(JSC::ExecState *, JSC::JSValue value, JSC::JSValue proto)
virtual void getOwnPropertyNames(JSC::ExecState *, JSC::PropertyNameArray &, JSC::EnumerationMode mode=JSC::ExcludeDontEnumProperties)
virtual bool compareToObject(JSC::ExecState *, JSC::JSObject *)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
JSC::JSValue data() const
virtual void put(JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue, JSC::PutPropertySlot &)
void setData(JSC::JSValue data)
static WTF::PassRefPtr< JSC::Structure > createStructure(JSC::JSValue prototype)
virtual JSC::CallType getCallData(JSC::CallData &)
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
virtual const JSC::ClassInfo * classInfo() const
virtual ~QScriptObject()
QScriptObjectDelegate * delegate
QScriptObject(WTF::PassRefPtr< JSC::Structure > sid)
void setDelegate(QScriptObjectDelegate *delegate)
static const unsigned StructureFlags
virtual JSC::ConstructType getConstructData(JSC::ConstructData &)
virtual void markChildren(JSC::MarkStack &markStack)