1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtScript module of the Qt Toolkit.
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.
18 ** If you have questions regarding the use of this file, please contact
19 ** us via http://www.qt-project.org/.
22 ****************************************************************************/
24 #ifndef QJSCONVERTER_P_H
25 #define QJSCONVERTER_P_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>
36 #include <private/qv8_p.h>
43 QJSValue and QJSEngine helper class. This class's responsibility is to convert values
44 between JS values and Qt/C++ values.
46 This is a nice way to inline these functions in both QJSValue and QJSEngine.
50 static inline quint32 toArrayIndex(const QString& string);
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);
57 PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum,
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);
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);
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);
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);
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);
84 // Converts a JS Date to a QDateTime.
85 static inline QDateTime toDateTime(v8::Handle<v8::Date> jsDate);
87 // Converts a QDateTime to a JS Date.
88 static inline v8::Local<v8::Value> toDateTime(const QDateTime &dt);