|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtScript module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QSCRIPTVALUE_P_H |
|
43 #define QSCRIPTVALUE_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists purely as an |
|
50 // implementation detail. This header file may change from version to |
|
51 // version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include <QtCore/qobjectdefs.h> |
|
57 |
|
58 #include "wtf/Platform.h" |
|
59 #include "JSValue.h" |
|
60 |
|
61 QT_BEGIN_NAMESPACE |
|
62 |
|
63 class QString; |
|
64 class QScriptEnginePrivate; |
|
65 |
|
66 class QScriptValue; |
|
67 class QScriptValuePrivate |
|
68 { |
|
69 Q_DISABLE_COPY(QScriptValuePrivate) |
|
70 public: |
|
71 inline void* operator new(size_t, QScriptEnginePrivate*); |
|
72 inline void operator delete(void*); |
|
73 |
|
74 enum Type { |
|
75 JavaScriptCore, |
|
76 Number, |
|
77 String |
|
78 }; |
|
79 |
|
80 inline QScriptValuePrivate(QScriptEnginePrivate*); |
|
81 inline ~QScriptValuePrivate(); |
|
82 |
|
83 inline void initFrom(JSC::JSValue value); |
|
84 inline void initFrom(qsreal value); |
|
85 inline void initFrom(const QString &value); |
|
86 |
|
87 inline bool isJSC() const; |
|
88 inline bool isObject() const; |
|
89 |
|
90 QVariant &variantValue() const; |
|
91 void setVariantValue(const QVariant &value); |
|
92 |
|
93 static inline QScriptValuePrivate *get(const QScriptValue &q) |
|
94 { |
|
95 return q.d_ptr.data(); |
|
96 } |
|
97 |
|
98 static inline QScriptValue toPublic(QScriptValuePrivate *d) |
|
99 { |
|
100 return QScriptValue(d); |
|
101 } |
|
102 |
|
103 static inline QScriptEnginePrivate *getEngine(const QScriptValue &q) |
|
104 { |
|
105 if (!q.d_ptr) |
|
106 return 0; |
|
107 return q.d_ptr->engine; |
|
108 } |
|
109 |
|
110 inline QScriptValue property(const JSC::Identifier &id, int resolveMode) const; |
|
111 QScriptValue propertyHelper(const JSC::Identifier &id, int resolveMode) const; |
|
112 inline QScriptValue property(quint32 index, int resolveMode) const; |
|
113 QScriptValue propertyHelper(quint32, int resolveMode) const; |
|
114 inline QScriptValue property(const QString &, int resolveMode) const; |
|
115 void setProperty(const JSC::Identifier &id, const QScriptValue &value, |
|
116 const QScriptValue::PropertyFlags &flags); |
|
117 QScriptValue::PropertyFlags propertyFlags( |
|
118 const JSC::Identifier &id, const QScriptValue::ResolveFlags &mode) const; |
|
119 |
|
120 void detachFromEngine(); |
|
121 |
|
122 qint64 objectId() |
|
123 { |
|
124 if ( (type == JavaScriptCore) && (engine) ) |
|
125 return (qint64)jscValue.asCell(); |
|
126 else |
|
127 return -1; |
|
128 } |
|
129 |
|
130 static inline void saveException(JSC::ExecState*, JSC::JSValue*); |
|
131 static inline void restoreException(JSC::ExecState*, JSC::JSValue); |
|
132 |
|
133 QScriptEnginePrivate *engine; |
|
134 Type type; |
|
135 JSC::JSValue jscValue; |
|
136 qsreal numberValue; |
|
137 QString stringValue; |
|
138 |
|
139 // linked list of engine's script values |
|
140 QScriptValuePrivate *prev; |
|
141 QScriptValuePrivate *next; |
|
142 |
|
143 QBasicAtomicInt ref; |
|
144 }; |
|
145 |
|
146 inline QScriptValuePrivate::QScriptValuePrivate(QScriptEnginePrivate *e) |
|
147 : engine(e), prev(0), next(0) |
|
148 { |
|
149 ref = 0; |
|
150 } |
|
151 |
|
152 inline bool QScriptValuePrivate::isJSC() const |
|
153 { |
|
154 return (type == JavaScriptCore); |
|
155 } |
|
156 |
|
157 inline bool QScriptValuePrivate::isObject() const |
|
158 { |
|
159 return isJSC() && jscValue && jscValue.isObject(); |
|
160 } |
|
161 |
|
162 // Rest of inline functions implemented in qscriptengine_p.h |
|
163 |
|
164 QT_END_NAMESPACE |
|
165 |
|
166 #endif |