1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtScript module of the Qt Toolkit.
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.
18 ** If you have questions regarding the use of this file, please contact
19 ** Nokia at qt-info@nokia.com.
22 ****************************************************************************/
27 #include <QtCore/qstring.h>
29 #include <QtCore/qlist.h>
30 #include <QtCore/qsharedpointer.h>
31 #include <QtCore/qshareddata.h>
46 typedef QList<QJSValue> QJSValueList;
48 class QJSValuePrivate;
49 struct QScriptValuePrivatePointerDeleter;
50 template <class T> class QScriptPassPointer;
52 class Q_DECLARATIVE_EXPORT QJSValue
56 ReadOnly = 0x00000001,
57 Undeletable = 0x00000002,
58 SkipInEnumeration = 0x00000004
60 Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
70 QJSValue(const QJSValue &other);
71 QJSValue(QJSEngine *engine, SpecialValue val);
72 QJSValue(QJSEngine *engine, bool val);
73 QJSValue(QJSEngine *engine, int val);
74 QJSValue(QJSEngine *engine, uint val);
75 QJSValue(QJSEngine *engine, double val);
76 QJSValue(QJSEngine *engine, const QString &val);
78 QJSValue(SpecialValue value);
82 QJSValue(double value);
83 QJSValue(const QString &value);
84 QJSValue(const QLatin1String &value);
85 #ifndef QT_NO_CAST_FROM_ASCII
86 QT_ASCII_CAST_WARN_CONSTRUCTOR QJSValue(const char *str);
89 QJSValue &operator=(const QJSValue &other);
91 QJSEngine *engine() const;
94 bool isNumber() const;
95 bool isFunction() const;
97 bool isString() const;
98 bool isUndefined() const;
99 bool isVariant() const;
100 bool isQObject() const;
101 bool isObject() const;
103 bool isRegExp() const;
104 bool isArray() const;
105 bool isError() const;
107 QString toString() const;
108 double toNumber() const;
109 qint32 toInt() const;
110 quint32 toUInt() const;
112 double toInteger() const;
113 qint32 toInt32() const;
114 quint32 toUInt32() const;
115 quint16 toUInt16() const;
116 QVariant toVariant() const;
117 QObject *toQObject() const;
118 QJSValue toObject() const;
119 QDateTime toDateTime() const;
120 QRegExp toRegExp() const;
122 bool instanceOf(const QJSValue &other) const;
124 bool equals(const QJSValue &other) const;
125 bool strictlyEquals(const QJSValue &other) const;
127 QJSValue prototype() const;
128 void setPrototype(const QJSValue &prototype);
130 QJSValue property(const QString &name) const;
131 void setProperty(const QString &name, const QJSValue &value);
133 bool hasProperty(const QString &name) const;
134 bool hasOwnProperty(const QString &name) const;
136 QJSValue property(quint32 arrayIndex) const;
137 void setProperty(quint32 arrayIndex, const QJSValue &value);
139 bool deleteProperty(const QString &name);
141 QJSValue::PropertyFlags propertyFlags(const QString &name) const;
143 bool isCallable() const;
144 QJSValue call(const QJSValueList &args);
145 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
146 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
147 QJSValue call(const QJSValue &thisObject = QJSValue(),
148 const QJSValueList &args = QJSValueList());
149 QJSValue construct(const QJSValueList &args = QJSValueList());
152 // force compile error, prevent QJSValue(bool) to be called
154 // force compile error, prevent QJSValue(QScriptEngine*, bool) to be called
155 QJSValue(QJSEngine *, void *);
156 QJSValue(QJSEngine *, const char *);
158 QJSValue(QJSValuePrivate*);
159 QJSValue(QScriptPassPointer<QJSValuePrivate>);
162 QExplicitlySharedDataPointer<QJSValuePrivate> d_ptr;
164 Q_DECLARE_PRIVATE(QJSValue)
167 Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValue::PropertyFlags)