95dee96f25859d10d77a784d82da0ca27c59de29
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qjsconverter_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 ** us via http://www.qt-project.org/.
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23
24 #ifndef QJSCONVERTER_P_H
25 #define QJSCONVERTER_P_H
26
27 #include "qjsvalue.h"
28 #include <QtCore/qglobal.h>
29 #include <QtCore/qnumeric.h>
30 #include <QtCore/qstring.h>
31 #include <QtCore/qstringlist.h>
32 #include <QtCore/qvarlengtharray.h>
33 #include <QtCore/qregexp.h>
34 #include <QtCore/qdatetime.h>
35
36 #include <private/qv8_p.h>
37
38 QT_BEGIN_NAMESPACE
39
40 /*
41   \internal
42   \class QJSConverter
43   QJSValue and QJSEngine helper class. This class's responsibility is to convert values
44   between JS values and Qt/C++ values.
45
46   This is a nice way to inline these functions in both QJSValue and QJSEngine.
47 */
48 class QJSConverter {
49 public:
50     static inline quint32 toArrayIndex(const QString& string);
51
52     static inline QString toString(v8::Handle<v8::String> jsString);
53     static inline v8::Local<v8::String> toString(const QString& string);
54     static inline QString toString(double value);
55
56     enum {
57         PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum,
58     };
59     // return a mask of v8::PropertyAttribute that may also contains QScriptValue::PropertyGetter or QScriptValue::PropertySetter
60     static inline uint toPropertyAttributes(const QFlags<QJSValue::PropertyFlag>& flags);
61
62     // Converts a JS RegExp to a QRegExp.
63     // The conversion is not 100% exact since ECMA regexp and QRegExp
64     // have different semantics/flags, but we try to do our best.
65     static inline QRegExp toRegExp(v8::Handle<v8::RegExp> jsRegExp);
66
67     // Converts a QRegExp to a JS RegExp.
68     // The conversion is not 100% exact since ECMA regexp and QRegExp
69     // have different semantics/flags, but we try to do our best.
70     static inline v8::Local<v8::RegExp> toRegExp(const QRegExp &re);
71
72     // Converts a QStringList to JS.
73     // The result is a new Array object with length equal to the length
74     // of the QStringList, and the elements being the QStringList's
75     // elements converted to JS Strings.
76     static inline v8::Local<v8::Array> toStringList(const QStringList &lst);
77
78     // Converts a JS Array object to a QStringList.
79     // The result is a QStringList with length equal to the length
80     // of the JS Array, and elements being the JS Array's elements
81     // converted to QStrings.
82     static inline QStringList toStringList(v8::Handle<v8::Array> jsArray);
83
84     // Converts a JS Date to a QDateTime.
85     static inline QDateTime toDateTime(v8::Handle<v8::Date> jsDate);
86
87     // Converts a QDateTime to a JS Date.
88     static inline v8::Local<v8::Value> toDateTime(const QDateTime &dt);
89 };
90
91 QT_END_NAMESPACE
92
93 #endif