source: trunk/src/script/bridge/qscriptobject_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: 5.9 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 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
42QT_BEGIN_NAMESPACE
43
44class QScriptObjectDelegate;
45
46class QScriptObject : public JSC::JSObject
47{
48public:
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 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
93protected:
94 static const unsigned StructureFlags = JSC::ImplementsHasInstance | JSC::OverridesHasInstance | JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSObject::StructureFlags;
95
96 Data *d;
97};
98
99class QScriptObjectPrototype : public QScriptObject
100{
101public:
102 QScriptObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
103 JSC::Structure* prototypeFunctionStructure);
104};
105
106class QScriptObjectDelegate
107{
108public:
109 enum Type {
110 QtObject,
111 Variant,
112 ClassObject,
113 DeclarativeClassObject
114 };
115
116 QScriptObjectDelegate();
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
140private:
141 Q_DISABLE_COPY(QScriptObjectDelegate)
142};
143
144inline JSC::JSValue QScriptObject::data() const
145{
146 if (!d)
147 return JSC::JSValue();
148 return d->data;
149}
150
151inline void QScriptObject::setData(JSC::JSValue data)
152{
153 if (!d)
154 d = new Data();
155 d->data = data;
156}
157
158inline QScriptObjectDelegate *QScriptObject::delegate() const
159{
160 if (!d)
161 return 0;
162 return d->delegate;
163}
164
165inline void QScriptObject::setDelegate(QScriptObjectDelegate *delegate)
166{
167 if (!d)
168 d = new Data();
169 else
170 delete d->delegate;
171 d->delegate = delegate;
172}
173
174QT_END_NAMESPACE
175
176#endif
Note: See TracBrowser for help on using the repository browser.