1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #ifndef QJSCONVERTER_P_H
43 #define QJSCONVERTER_P_H
45 #include "qjsvalue_p.h"
46 #include <QtCore/qglobal.h>
47 #include <QtCore/qnumeric.h>
48 #include <QtCore/qstring.h>
49 #include <QtCore/qstringlist.h>
50 #include <QtCore/qvarlengtharray.h>
51 #include <QtCore/qregexp.h>
52 #include <QtCore/qdatetime.h>
54 #include <private/qv8_p.h>
61 QJSValue and QJSEngine helper class. This class's responsibility is to convert values
62 between JS values and Qt/C++ values.
64 This is a nice way to inline these functions in both QJSValue and QJSEngine.
68 static inline quint32 toArrayIndex(const QString& string);
70 static inline QString toString(v8::Handle<v8::String> jsString);
71 static inline v8::Local<v8::String> toString(const QString& string);
72 static inline QString toString(double value);
75 PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum,
77 // return a mask of v8::PropertyAttribute that may also contains QScriptValue::PropertyGetter or QScriptValue::PropertySetter
78 static inline uint toPropertyAttributes(const QFlags<QJSValuePrivate::PropertyFlag>& flags);
80 // Converts a JS RegExp to a QRegExp.
81 // The conversion is not 100% exact since ECMA regexp and QRegExp
82 // have different semantics/flags, but we try to do our best.
83 static inline QRegExp toRegExp(v8::Handle<v8::RegExp> jsRegExp);
85 // Converts a QRegExp to a JS RegExp.
86 // The conversion is not 100% exact since ECMA regexp and QRegExp
87 // have different semantics/flags, but we try to do our best.
88 static inline v8::Local<v8::RegExp> toRegExp(const QRegExp &re);
90 // Converts a QStringList to JS.
91 // The result is a new Array object with length equal to the length
92 // of the QStringList, and the elements being the QStringList's
93 // elements converted to JS Strings.
94 static inline v8::Local<v8::Array> toStringList(const QStringList &lst);
96 // Converts a JS Array object to a QStringList.
97 // The result is a QStringList with length equal to the length
98 // of the JS Array, and elements being the JS Array's elements
99 // converted to QStrings.
100 static inline QStringList toStringList(v8::Handle<v8::Array> jsArray);
102 // Converts a JS Date to a QDateTime.
103 static inline QDateTime toDateTime(v8::Handle<v8::Date> jsDate);
105 // Converts a QDateTime to a JS Date.
106 static inline v8::Local<v8::Value> toDateTime(const QDateTime &dt);