1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 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 |
|
---|
42 | QT_BEGIN_NAMESPACE
|
---|
43 |
|
---|
44 | class QScriptObjectDelegate;
|
---|
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
|
---|
53 | QScriptObjectDelegate *delegate;
|
---|
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 | bool checkDontDelete = true);
|
---|
72 | virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&,
|
---|
73 | unsigned&) const;
|
---|
74 | virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
|
---|
75 | bool includeNonEnumerable = false);
|
---|
76 | virtual void markChildren(JSC::MarkStack& markStack);
|
---|
77 | virtual JSC::CallType getCallData(JSC::CallData&);
|
---|
78 | virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
|
---|
79 | virtual bool hasInstance(JSC::ExecState*, JSC::JSValue value, JSC::JSValue proto);
|
---|
80 | virtual bool compareToObject(JSC::ExecState*, JSC::JSObject*);
|
---|
81 |
|
---|
82 | virtual const JSC::ClassInfo* classInfo() const { return &info; }
|
---|
83 | static const JSC::ClassInfo info;
|
---|
84 |
|
---|
85 | static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
|
---|
86 | {
|
---|
87 | return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance | JSC::OverridesHasInstance));
|
---|
88 | }
|
---|
89 |
|
---|
90 | inline JSC::JSValue data() const;
|
---|
91 | inline void setData(JSC::JSValue data);
|
---|
92 |
|
---|
93 | inline QScriptObjectDelegate *delegate() const;
|
---|
94 | inline void setDelegate(QScriptObjectDelegate *delegate);
|
---|
95 |
|
---|
96 | protected:
|
---|
97 | Data *d;
|
---|
98 | };
|
---|
99 |
|
---|
100 | class QScriptObjectPrototype : public QScriptObject
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | QScriptObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
|
---|
104 | JSC::Structure* prototypeFunctionStructure);
|
---|
105 | };
|
---|
106 |
|
---|
107 | class QScriptObjectDelegate
|
---|
108 | {
|
---|
109 | public:
|
---|
110 | enum Type {
|
---|
111 | QtObject,
|
---|
112 | Variant,
|
---|
113 | ClassObject,
|
---|
114 | DeclarativeClassObject
|
---|
115 | };
|
---|
116 |
|
---|
117 | QScriptObjectDelegate();
|
---|
118 | virtual ~QScriptObjectDelegate();
|
---|
119 |
|
---|
120 | virtual Type type() const = 0;
|
---|
121 |
|
---|
122 | virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*,
|
---|
123 | const JSC::Identifier& propertyName,
|
---|
124 | JSC::PropertySlot&);
|
---|
125 | virtual bool getOwnPropertyDescriptor(QScriptObject*, JSC::ExecState*,
|
---|
126 | const JSC::Identifier& propertyName,
|
---|
127 | JSC::PropertyDescriptor&);
|
---|
128 | virtual void put(QScriptObject*, JSC::ExecState* exec, const JSC::Identifier& propertyName,
|
---|
129 | JSC::JSValue, JSC::PutPropertySlot&);
|
---|
130 | virtual bool deleteProperty(QScriptObject*, JSC::ExecState*,
|
---|
131 | const JSC::Identifier& propertyName,
|
---|
132 | bool checkDontDelete = true);
|
---|
133 | virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*,
|
---|
134 | const JSC::Identifier&, unsigned&) const;
|
---|
135 | virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*, JSC::PropertyNameArray&,
|
---|
136 | bool includeNonEnumerable = false);
|
---|
137 | virtual void markChildren(QScriptObject*, JSC::MarkStack& markStack);
|
---|
138 | virtual JSC::CallType getCallData(QScriptObject*, JSC::CallData&);
|
---|
139 | virtual JSC::ConstructType getConstructData(QScriptObject*, JSC::ConstructData&);
|
---|
140 | virtual bool hasInstance(QScriptObject*, JSC::ExecState*,
|
---|
141 | JSC::JSValue value, JSC::JSValue proto);
|
---|
142 | virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
|
---|
143 |
|
---|
144 | private:
|
---|
145 | Q_DISABLE_COPY(QScriptObjectDelegate)
|
---|
146 | };
|
---|
147 |
|
---|
148 | inline JSC::JSValue QScriptObject::data() const
|
---|
149 | {
|
---|
150 | if (!d)
|
---|
151 | return JSC::JSValue();
|
---|
152 | return d->data;
|
---|
153 | }
|
---|
154 |
|
---|
155 | inline void QScriptObject::setData(JSC::JSValue data)
|
---|
156 | {
|
---|
157 | if (!d)
|
---|
158 | d = new Data();
|
---|
159 | d->data = data;
|
---|
160 | }
|
---|
161 |
|
---|
162 | inline QScriptObjectDelegate *QScriptObject::delegate() const
|
---|
163 | {
|
---|
164 | if (!d)
|
---|
165 | return 0;
|
---|
166 | return d->delegate;
|
---|
167 | }
|
---|
168 |
|
---|
169 | inline void QScriptObject::setDelegate(QScriptObjectDelegate *delegate)
|
---|
170 | {
|
---|
171 | if (!d)
|
---|
172 | d = new Data();
|
---|
173 | else
|
---|
174 | delete d->delegate;
|
---|
175 | d->delegate = delegate;
|
---|
176 | }
|
---|
177 |
|
---|
178 | QT_END_NAMESPACE
|
---|
179 |
|
---|
180 | #endif
|
---|