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 ****************************************************************************/
45 #include <QtQml/qtqmlglobal.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qlist.h>
48 #include <QtCore/qsharedpointer.h>
49 #include <QtCore/qshareddata.h>
63 typedef QList<QJSValue> QJSValueList;
65 class QJSValuePrivate;
66 struct QScriptValuePrivatePointerDeleter;
67 template <class T> class QScriptPassPointer;
69 class Q_QML_EXPORT QJSValue
78 QJSValue(SpecialValue value = UndefinedValue);
80 QJSValue(const QJSValue &other);
85 QJSValue(double value);
86 QJSValue(const QString &value);
87 QJSValue(const QLatin1String &value);
88 #ifndef QT_NO_CAST_FROM_ASCII
89 QT_ASCII_CAST_WARN QJSValue(const char *str);
92 QJSValue &operator=(const QJSValue &other);
95 bool isNumber() 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 QVariant toVariant() const;
113 QObject *toQObject() const;
114 QDateTime toDateTime() const;
116 bool equals(const QJSValue &other) const;
117 bool strictlyEquals(const QJSValue &other) const;
119 QJSValue prototype() const;
120 void setPrototype(const QJSValue &prototype);
122 QJSValue property(const QString &name) const;
123 void setProperty(const QString &name, const QJSValue &value);
125 bool hasProperty(const QString &name) const;
126 bool hasOwnProperty(const QString &name) const;
128 QJSValue property(quint32 arrayIndex) const;
129 void setProperty(quint32 arrayIndex, const QJSValue &value);
131 bool deleteProperty(const QString &name);
133 bool isCallable() const;
134 QJSValue call(const QJSValueList &args = QJSValueList());
135 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
136 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
139 QT_DEPRECATED QJSEngine *engine() const;
143 // force compile error, prevent QJSValue(bool) to be called
145 QJSValue(void *) Q_DECL_EQ_DELETE;
147 QJSValue(QJSValuePrivate*);
148 QJSValue(QScriptPassPointer<QJSValuePrivate>);
151 QExplicitlySharedDataPointer<QJSValuePrivate> d_ptr;
153 Q_DECLARE_PRIVATE(QJSValue)