1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 ** us via http://www.qt-project.org/.
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
57 ReadOnly = 0x00000001,
58 Undeletable = 0x00000002,
59 SkipInEnumeration = 0x00000004
61 Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
72 QJSValue(const QJSValue &other);
74 QJSValue(SpecialValue value);
78 QJSValue(double value);
79 QJSValue(const QString &value);
80 QJSValue(const QLatin1String &value);
81 #ifndef QT_NO_CAST_FROM_ASCII
82 QT_ASCII_CAST_WARN_CONSTRUCTOR QJSValue(const char *str);
85 QJSValue &operator=(const QJSValue &other);
88 bool isNumber() const;
90 bool isString() const;
91 bool isUndefined() const;
92 bool isVariant() const;
93 bool isQObject() const;
94 bool isObject() const;
96 bool isRegExp() const;
100 QString toString() const;
101 double toNumber() const;
102 qint32 toInt() const;
103 quint32 toUInt() const;
105 QVariant toVariant() const;
106 QObject *toQObject() const;
107 QDateTime toDateTime() const;
109 bool equals(const QJSValue &other) const;
110 bool strictlyEquals(const QJSValue &other) const;
112 QJSValue prototype() const;
113 void setPrototype(const QJSValue &prototype);
115 QJSValue property(const QString &name) const;
116 void setProperty(const QString &name, const QJSValue &value);
118 bool hasProperty(const QString &name) const;
119 bool hasOwnProperty(const QString &name) const;
121 QJSValue property(quint32 arrayIndex) const;
122 void setProperty(quint32 arrayIndex, const QJSValue &value);
124 bool deleteProperty(const QString &name);
126 bool isCallable() const;
127 QJSValue call(const QJSValueList &args);
128 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
129 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
132 QT_DEPRECATED QJSValue(QJSEngine *engine, SpecialValue val);
133 QT_DEPRECATED QJSValue(QJSEngine *engine, bool val);
134 QT_DEPRECATED QJSValue(QJSEngine *engine, int val);
135 QT_DEPRECATED QJSValue(QJSEngine *engine, uint val);
136 QT_DEPRECATED QJSValue(QJSEngine *engine, double val);
137 QT_DEPRECATED QJSValue(QJSEngine *engine, const QString &val);
139 QT_DEPRECATED QJSEngine *engine() const;
141 QT_DEPRECATED bool isValid() const;
142 QT_DEPRECATED bool isFunction() const;
143 QT_DEPRECATED double toInteger() const;
144 QT_DEPRECATED qint32 toInt32() const;
145 QT_DEPRECATED quint32 toUInt32() const;
146 QT_DEPRECATED quint16 toUInt16() const;
147 QT_DEPRECATED QJSValue toObject() const;
148 QT_DEPRECATED QRegExp toRegExp() const;
150 QT_DEPRECATED bool instanceOf(const QJSValue &other) const;
152 QT_DEPRECATED QJSValue::PropertyFlags propertyFlags(const QString &name) const;
154 QT_DEPRECATED QJSValue call(const QJSValue &thisObject = QJSValue(),
155 const QJSValueList &args = QJSValueList());
156 QT_DEPRECATED QJSValue construct(const QJSValueList &args = QJSValueList());
160 // force compile error, prevent QJSValue(bool) to be called
163 // force compile error, prevent QJSValue(QScriptEngine*, bool) to be called
164 QJSValue(QJSEngine *, void *);
165 QJSValue(QJSEngine *, const char *);
168 QJSValue(QJSValuePrivate*);
169 QJSValue(QScriptPassPointer<QJSValuePrivate>);
172 QExplicitlySharedDataPointer<QJSValuePrivate> d_ptr;
174 Q_DECLARE_PRIVATE(QJSValue)
178 Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValue::PropertyFlags)