1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QJSVALUE_H
41#define QJSVALUE_H
42
43#include <QtQml/qtqmlglobal.h>
44#include <QtCore/qstring.h>
45#include <QtCore/qlist.h>
46#include <QtCore/qmetatype.h>
47
48QT_BEGIN_NAMESPACE
49
50class QJSValue;
51class QJSEngine;
52class QVariant;
53class QObject;
54struct QMetaObject;
55class QDateTime;
56
57typedef QList<QJSValue> QJSValueList;
58namespace QV4 {
59 struct ExecutionEngine;
60}
61
62class Q_QML_EXPORT QJSValue
63{
64public:
65 enum SpecialValue {
66 NullValue,
67 UndefinedValue
68 };
69
70 enum ErrorType {
71 NoError,
72 GenericError,
73 EvalError,
74 RangeError,
75 ReferenceError,
76 SyntaxError,
77 TypeError,
78 URIError
79 };
80
81public:
82 QJSValue(SpecialValue value = UndefinedValue);
83 ~QJSValue();
84 QJSValue(const QJSValue &other);
85
86#ifdef Q_COMPILER_RVALUE_REFS
87 inline QJSValue(QJSValue && other) : d(other.d) { other.d = 0; }
88 inline QJSValue &operator=(QJSValue &&other)
89 { qSwap(value1&: d, value2&: other.d); return *this; }
90#endif
91
92 QJSValue(bool value);
93 QJSValue(int value);
94 QJSValue(uint value);
95 QJSValue(double value);
96 QJSValue(const QString &value);
97 QJSValue(const QLatin1String &value);
98#ifndef QT_NO_CAST_FROM_ASCII
99 QT_ASCII_CAST_WARN QJSValue(const char *str);
100#endif
101
102 QJSValue &operator=(const QJSValue &other);
103
104 bool isBool() const;
105 bool isNumber() const;
106 bool isNull() const;
107 bool isString() const;
108 bool isUndefined() const;
109 bool isVariant() const;
110 bool isQObject() const;
111 bool isQMetaObject() const;
112 bool isObject() const;
113 bool isDate() const;
114 bool isRegExp() const;
115 bool isArray() const;
116 bool isError() const;
117
118 QString toString() const;
119 double toNumber() const;
120 qint32 toInt() const;
121 quint32 toUInt() const;
122 bool toBool() const;
123 QVariant toVariant() const;
124 QObject *toQObject() const;
125 const QMetaObject *toQMetaObject() const;
126 QDateTime toDateTime() const;
127
128 bool equals(const QJSValue &other) const;
129 bool strictlyEquals(const QJSValue &other) const;
130
131 QJSValue prototype() const;
132 void setPrototype(const QJSValue &prototype);
133
134 QJSValue property(const QString &name) const;
135 void setProperty(const QString &name, const QJSValue &value);
136
137 bool hasProperty(const QString &name) const;
138 bool hasOwnProperty(const QString &name) const;
139
140 QJSValue property(quint32 arrayIndex) const;
141 void setProperty(quint32 arrayIndex, const QJSValue &value);
142
143 bool deleteProperty(const QString &name);
144
145 bool isCallable() const;
146 QJSValue call(const QJSValueList &args = QJSValueList()); // ### Qt6: Make const
147 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList()); // ### Qt6: Make const
148 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList()); // ### Qt6: Make const
149
150 ErrorType errorType() const;
151#ifdef QT_DEPRECATED
152 QT_DEPRECATED QJSEngine *engine() const;
153#endif
154
155 QJSValue(QV4::ExecutionEngine *e, quint64 val);
156private:
157 friend class QJSValuePrivate;
158 // force compile error, prevent QJSValue(bool) to be called
159 QJSValue(void *) Q_DECL_EQ_DELETE;
160
161 mutable quintptr d;
162};
163
164QT_END_NAMESPACE
165
166Q_DECLARE_METATYPE(QJSValue)
167
168#endif
169

source code of qtdeclarative/src/qml/jsapi/qjsvalue.h