Add QJSValue::callAsConstructor() function
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qjsvalue.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtScript module of the Qt Toolkit.
8 **
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.
17 **
18 ** If you have questions regarding the use of this file, please contact
19 ** Nokia at qt-info@nokia.com.
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23
24 #ifndef QJSVALUE_H
25 #define QJSVALUE_H
26
27 #include <QtCore/qstring.h>
28
29 #include <QtCore/qlist.h>
30 #include <QtCore/qsharedpointer.h>
31 #include <QtCore/qshareddata.h>
32
33 QT_BEGIN_HEADER
34
35 QT_BEGIN_NAMESPACE
36
37
38 class QJSValue;
39 class QJSEngine;
40 class QVariant;
41 class QObject;
42 struct QMetaObject;
43 class QDateTime;
44 class QRegExp;
45
46 typedef QList<QJSValue> QJSValueList;
47
48 class QJSValuePrivate;
49 struct QScriptValuePrivatePointerDeleter;
50 template <class T> class QScriptPassPointer;
51
52 class Q_DECLARATIVE_EXPORT QJSValue
53 {
54 public:
55     enum PropertyFlag {
56         ReadOnly            = 0x00000001,
57         Undeletable         = 0x00000002,
58         SkipInEnumeration   = 0x00000004
59     };
60     Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
61
62     enum SpecialValue {
63         NullValue,
64         UndefinedValue
65     };
66
67 public:
68     QJSValue();
69     ~QJSValue();
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);
77
78     QJSValue(SpecialValue value);
79     QJSValue(bool value);
80     QJSValue(int value);
81     QJSValue(uint 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);
87 #endif
88
89     QJSValue &operator=(const QJSValue &other);
90
91     QJSEngine *engine() const;
92     bool isValid() const;
93     bool isBool() const;
94     bool isNumber() const;
95     bool isFunction() const;
96     bool isNull() const;
97     bool isString() const;
98     bool isUndefined() const;
99     bool isVariant() const;
100     bool isQObject() const;
101     bool isObject() const;
102     bool isDate() const;
103     bool isRegExp() const;
104     bool isArray() const;
105     bool isError() const;
106
107     QString toString() const;
108     double toNumber() const;
109     qint32 toInt() const;
110     quint32 toUInt() const;
111     bool toBool() 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;
121
122     bool instanceOf(const QJSValue &other) const;
123
124     bool equals(const QJSValue &other) const;
125     bool strictlyEquals(const QJSValue &other) const;
126
127     QJSValue prototype() const;
128     void setPrototype(const QJSValue &prototype);
129
130     QJSValue property(const QString &name) const;
131     void setProperty(const QString &name, const QJSValue &value);
132
133     bool hasProperty(const QString &name) const;
134     bool hasOwnProperty(const QString &name) const;
135
136     QJSValue property(quint32 arrayIndex) const;
137     void setProperty(quint32 arrayIndex, const QJSValue &value);
138
139     bool deleteProperty(const QString &name);
140
141     QJSValue::PropertyFlags propertyFlags(const QString &name) const;
142
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());
150
151 private:
152     // force compile error, prevent QJSValue(bool) to be called
153     QJSValue(void *);
154     // force compile error, prevent QJSValue(QScriptEngine*, bool) to be called
155     QJSValue(QJSEngine *, void *);
156     QJSValue(QJSEngine *, const char *);
157
158     QJSValue(QJSValuePrivate*);
159     QJSValue(QScriptPassPointer<QJSValuePrivate>);
160
161 private:
162     QExplicitlySharedDataPointer<QJSValuePrivate> d_ptr;
163
164     Q_DECLARE_PRIVATE(QJSValue)
165 };
166
167 Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValue::PropertyFlags)
168
169 QT_END_NAMESPACE
170
171 QT_END_HEADER
172
173 #endif