2cb32f9ba08a0ba523148274ad12e3e64f69c25a
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qjsvalue.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file.  Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
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
45 typedef QList<QJSValue> QJSValueList;
46
47 class QJSValuePrivate;
48 struct QScriptValuePrivatePointerDeleter;
49 template <class T> class QScriptPassPointer;
50
51 class Q_DECLARATIVE_EXPORT QJSValue
52 {
53 public:
54     enum SpecialValue {
55         NullValue,
56         UndefinedValue
57     };
58
59 public:
60     QJSValue(SpecialValue value = UndefinedValue);
61     ~QJSValue();
62     QJSValue(const QJSValue &other);
63
64     QJSValue(bool value);
65     QJSValue(int value);
66     QJSValue(uint value);
67     QJSValue(double value);
68     QJSValue(const QString &value);
69     QJSValue(const QLatin1String &value);
70 #ifndef QT_NO_CAST_FROM_ASCII
71     QT_ASCII_CAST_WARN_CONSTRUCTOR QJSValue(const char *str);
72 #endif
73
74     QJSValue &operator=(const QJSValue &other);
75
76     bool isBool() const;
77     bool isNumber() const;
78     bool isNull() const;
79     bool isString() const;
80     bool isUndefined() const;
81     bool isVariant() const;
82     bool isQObject() const;
83     bool isObject() const;
84     bool isDate() const;
85     bool isRegExp() const;
86     bool isArray() const;
87     bool isError() const;
88
89     QString toString() const;
90     double toNumber() const;
91     qint32 toInt() const;
92     quint32 toUInt() const;
93     bool toBool() const;
94     QVariant toVariant() const;
95     QObject *toQObject() const;
96     QDateTime toDateTime() const;
97
98     bool equals(const QJSValue &other) const;
99     bool strictlyEquals(const QJSValue &other) const;
100
101     QJSValue prototype() const;
102     void setPrototype(const QJSValue &prototype);
103
104     QJSValue property(const QString &name) const;
105     void setProperty(const QString &name, const QJSValue &value);
106
107     bool hasProperty(const QString &name) const;
108     bool hasOwnProperty(const QString &name) const;
109
110     QJSValue property(quint32 arrayIndex) const;
111     void setProperty(quint32 arrayIndex, const QJSValue &value);
112
113     bool deleteProperty(const QString &name);
114
115     bool isCallable() const;
116     QJSValue call(const QJSValueList &args);
117     QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
118     QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
119
120 #ifdef QT_DEPRECATED
121     QT_DEPRECATED QJSEngine *engine() const;
122
123     QT_DEPRECATED bool isFunction() const;
124     QT_DEPRECATED qint32 toInt32() const;
125     QT_DEPRECATED quint32 toUInt32() const;
126
127     QT_DEPRECATED QJSValue call(const QJSValue &thisObject = QJSValue(),
128                       const QJSValueList &args = QJSValueList());
129     QT_DEPRECATED QJSValue construct(const QJSValueList &args = QJSValueList());
130 #endif
131
132 private:
133     // force compile error, prevent QJSValue(bool) to be called
134     QJSValue(void *);
135
136     QJSValue(QJSValuePrivate*);
137     QJSValue(QScriptPassPointer<QJSValuePrivate>);
138
139 private:
140     QExplicitlySharedDataPointer<QJSValuePrivate> d_ptr;
141
142     Q_DECLARE_PRIVATE(QJSValue)
143 };
144
145 QT_END_NAMESPACE
146
147 QT_END_HEADER
148
149 #endif