|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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-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 qt-info@nokia.com. |
|
20 ** $QT_END_LICENSE$ |
|
21 ** |
|
22 ****************************************************************************/ |
|
23 |
|
24 #ifndef QSCRIPTVALUE_P_H |
|
25 #define QSCRIPTVALUE_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 "wtf/Platform.h" |
|
41 #include "JSValue.h" |
|
42 |
|
43 QT_BEGIN_NAMESPACE |
|
44 |
|
45 class QString; |
|
46 class QScriptEnginePrivate; |
|
47 |
|
48 class QScriptValue; |
|
49 class QScriptValuePrivate |
|
50 { |
|
51 Q_DISABLE_COPY(QScriptValuePrivate) |
|
52 public: |
|
53 inline void* operator new(size_t, QScriptEnginePrivate*); |
|
54 inline void operator delete(void*); |
|
55 |
|
56 enum Type { |
|
57 JavaScriptCore, |
|
58 Number, |
|
59 String |
|
60 }; |
|
61 |
|
62 inline QScriptValuePrivate(QScriptEnginePrivate*); |
|
63 inline ~QScriptValuePrivate(); |
|
64 |
|
65 inline void initFrom(JSC::JSValue value); |
|
66 inline void initFrom(qsreal value); |
|
67 inline void initFrom(const QString &value); |
|
68 |
|
69 inline bool isJSC() const; |
|
70 inline bool isObject() const; |
|
71 |
|
72 QVariant &variantValue() const; |
|
73 void setVariantValue(const QVariant &value); |
|
74 |
|
75 static inline QScriptValuePrivate *get(const QScriptValue &q) |
|
76 { |
|
77 return q.d_ptr.data(); |
|
78 } |
|
79 |
|
80 static inline QScriptValue toPublic(QScriptValuePrivate *d) |
|
81 { |
|
82 return QScriptValue(d); |
|
83 } |
|
84 |
|
85 static inline QScriptEnginePrivate *getEngine(const QScriptValue &q) |
|
86 { |
|
87 if (!q.d_ptr) |
|
88 return 0; |
|
89 return q.d_ptr->engine; |
|
90 } |
|
91 |
|
92 inline QScriptValue property(const JSC::Identifier &id, int resolveMode) const; |
|
93 QScriptValue propertyHelper(const JSC::Identifier &id, int resolveMode) const; |
|
94 inline QScriptValue property(quint32 index, int resolveMode) const; |
|
95 QScriptValue propertyHelper(quint32, int resolveMode) const; |
|
96 inline QScriptValue property(const QString &, int resolveMode) const; |
|
97 void setProperty(const JSC::Identifier &id, const QScriptValue &value, |
|
98 const QScriptValue::PropertyFlags &flags); |
|
99 QScriptValue::PropertyFlags propertyFlags( |
|
100 const JSC::Identifier &id, const QScriptValue::ResolveFlags &mode) const; |
|
101 |
|
102 void detachFromEngine(); |
|
103 |
|
104 qint64 objectId() |
|
105 { |
|
106 if ( (type == JavaScriptCore) && (engine) ) |
|
107 return (qint64)jscValue.asCell(); |
|
108 else |
|
109 return -1; |
|
110 } |
|
111 |
|
112 static inline void saveException(JSC::ExecState*, JSC::JSValue*); |
|
113 static inline void restoreException(JSC::ExecState*, JSC::JSValue); |
|
114 |
|
115 QScriptEnginePrivate *engine; |
|
116 Type type; |
|
117 JSC::JSValue jscValue; |
|
118 qsreal numberValue; |
|
119 QString stringValue; |
|
120 |
|
121 // linked list of engine's script values |
|
122 QScriptValuePrivate *prev; |
|
123 QScriptValuePrivate *next; |
|
124 |
|
125 QBasicAtomicInt ref; |
|
126 }; |
|
127 |
|
128 inline QScriptValuePrivate::QScriptValuePrivate(QScriptEnginePrivate *e) |
|
129 : engine(e), prev(0), next(0) |
|
130 { |
|
131 ref = 0; |
|
132 } |
|
133 |
|
134 inline bool QScriptValuePrivate::isJSC() const |
|
135 { |
|
136 return (type == JavaScriptCore); |
|
137 } |
|
138 |
|
139 inline bool QScriptValuePrivate::isObject() const |
|
140 { |
|
141 return isJSC() && jscValue && jscValue.isObject(); |
|
142 } |
|
143 |
|
144 // Rest of inline functions implemented in qscriptengine_p.h |
|
145 |
|
146 QT_END_NAMESPACE |
|
147 |
|
148 #endif |