Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / src / qml / qml / v8 / qjsconverter_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QJSCONVERTER_P_H
43 #define QJSCONVERTER_P_H
44
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>
53
54 #include <private/qv8_p.h>
55
56 QT_BEGIN_NAMESPACE
57
58 /*
59   \internal
60   \class QJSConverter
61   QJSValue and QJSEngine helper class. This class's responsibility is to convert values
62   between JS values and Qt/C++ values.
63
64   This is a nice way to inline these functions in both QJSValue and QJSEngine.
65 */
66 class QJSConverter {
67 public:
68     static inline quint32 toArrayIndex(const QString& string);
69
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);
73
74     enum {
75         PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum,
76     };
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);
79
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);
84
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);
89
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);
95
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);
101
102     // Converts a JS Date to a QDateTime.
103     static inline QDateTime toDateTime(v8::Handle<v8::Date> jsDate);
104
105     // Converts a QDateTime to a JS Date.
106     static inline v8::Local<v8::Value> toDateTime(const QDateTime &dt);
107 };
108
109 QT_END_NAMESPACE
110
111 #endif