1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
56 #include <private/qv8_p.h>
58 #include <QtCore/qbytearray.h>
59 #include <QtCore/qdatetime.h>
60 #include <QtCore/qmath.h>
61 #include <QtCore/qvarlengtharray.h>
64 #include <private/qintrusivelist_p.h>
65 #include "qscriptshareddata_p.h"
74 \class QJSValuePrivate
81 ReadOnly = 0x00000001,
82 Undeletable = 0x00000002,
83 SkipInEnumeration = 0x00000004
85 Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
87 inline static QJSValuePrivate* get(const QJSValue& q);
88 inline static QJSValue get(const QJSValuePrivate* d);
89 inline static QJSValue get(QJSValuePrivate* d);
90 inline static QJSValue get(QScriptPassPointer<QJSValuePrivate> d);
91 inline ~QJSValuePrivate();
93 inline QJSValuePrivate(bool value);
94 inline QJSValuePrivate(int value);
95 inline QJSValuePrivate(uint value);
96 inline QJSValuePrivate(double value);
97 inline QJSValuePrivate(const QString& value);
98 inline QJSValuePrivate(QJSValue::SpecialValue value = QJSValue::UndefinedValue);
100 inline QJSValuePrivate(QV8Engine *engine, bool value);
101 inline QJSValuePrivate(QV8Engine *engine, int value);
102 inline QJSValuePrivate(QV8Engine *engine, uint value);
103 inline QJSValuePrivate(QV8Engine *engine, double value);
104 inline QJSValuePrivate(QV8Engine *engine, const QString& value);
105 inline QJSValuePrivate(QV8Engine *engine, QJSValue::SpecialValue value = QJSValue::UndefinedValue);
106 inline QJSValuePrivate(QV8Engine *engine, v8::Handle<v8::Value>);
107 inline void invalidate();
109 inline bool toBool() const;
110 inline double toNumber() const;
111 inline QString toString() const;
112 inline double toInteger() const;
113 inline qint32 toInt32() const;
114 inline quint32 toUInt32() const;
115 inline quint16 toUInt16() const;
116 inline QDateTime toDataTime() const;
117 inline QObject *toQObject() const;
118 inline QVariant toVariant() const;
120 inline bool isArray() const;
121 inline bool isBool() const;
122 inline bool isCallable() const;
123 inline bool isError() const;
124 inline bool isFunction() const;
125 inline bool isNull() const;
126 inline bool isNumber() const;
127 inline bool isObject() const;
128 inline bool isString() const;
129 inline bool isUndefined() const;
130 inline bool isVariant() const;
131 inline bool isDate() const;
132 inline bool isRegExp() const;
133 inline bool isQObject() const;
135 inline bool equals(QJSValuePrivate* other);
136 inline bool strictlyEquals(QJSValuePrivate* other);
138 inline QScriptPassPointer<QJSValuePrivate> prototype() const;
139 inline void setPrototype(QJSValuePrivate* prototype);
141 inline void setProperty(const QString &name, QJSValuePrivate *value, uint attribs = 0);
142 inline void setProperty(v8::Handle<v8::String> name, QJSValuePrivate *value, uint attribs = 0);
143 inline void setProperty(quint32 index, QJSValuePrivate* value, uint attribs = 0);
144 inline QScriptPassPointer<QJSValuePrivate> property(const QString& name) const;
145 inline QScriptPassPointer<QJSValuePrivate> property(v8::Handle<v8::String> name) const;
146 inline QScriptPassPointer<QJSValuePrivate> property(quint32 index) const;
148 inline QScriptPassPointer<QJSValuePrivate> property(T name) const;
149 inline bool deleteProperty(const QString& name);
150 inline bool hasProperty(const QString &name) const;
151 inline bool hasOwnProperty(const QString &name) const;
152 inline PropertyFlags propertyFlags(const QString& name) const;
153 inline PropertyFlags propertyFlags(v8::Handle<v8::String> name) const;
155 inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValueList& args);
156 inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValue& arguments);
157 inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, int argc, v8::Handle< v8::Value >* argv);
158 inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(int argc, v8::Handle<v8::Value> *argv);
159 inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(const QJSValueList& args);
160 inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(const QJSValue& arguments);
162 inline bool assignEngine(QV8Engine *engine);
163 inline QV8Engine *engine() const;
165 inline operator v8::Handle<v8::Value>() const;
166 inline operator v8::Handle<v8::Object>() const;
167 inline v8::Handle<v8::Value> handle() const;
168 inline v8::Handle<v8::Value> asV8Value(QV8Engine *engine);
170 QIntrusiveListNode m_node;
173 // Please, update class documentation when you change the enum.
180 JSValue = 0x2000 // V8 values are equal or higher then this value.
190 CValue() : m_number(0) {}
191 CValue(bool value) : m_bool(value) {}
192 CValue(int number) : m_number(number) {}
193 CValue(uint number) : m_number(number) {}
194 CValue(double number) : m_number(number) {}
195 CValue(QString* string) : m_string(string) {}
197 // v8::Persistent is not a POD, so can't be part of the union.
198 v8::Persistent<v8::Value> m_value;
200 Q_DISABLE_COPY(QJSValuePrivate)
201 inline bool isJSBased() const;
202 inline bool isNumberBased() const;
203 inline bool isStringBased() const;
204 inline bool prepareArgumentsForCall(v8::Handle<v8::Value> argv[], const QJSValueList& arguments) const;
206 friend class QV8Engine;
209 Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValuePrivate::PropertyFlags)