Get rid of qjsconverter*
authorLars Knoll <lars.knoll@digia.com>
Thu, 2 May 2013 20:33:47 +0000 (22:33 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 2 May 2013 20:42:43 +0000 (22:42 +0200)
Replace the conversion methods by better API directly in the v8
objects.

Change-Id: I9d39b1db38def9aa6d1ef8673e7b1bf36e5b830a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
18 files changed:
src/qml/debugger/qv8debugservice.cpp
src/qml/debugger/qv8profilerservice.cpp
src/qml/qml/qqmllocale.cpp
src/qml/qml/v4/qv4dateobject.cpp
src/qml/qml/v4/qv4dateobject_p.h
src/qml/qml/v4/qv4engine.cpp
src/qml/qml/v4/qv4engine_p.h
src/qml/qml/v4/qv4object.cpp
src/qml/qml/v4/qv4object_p.h
src/qml/qml/v4/qv4regexpobject.cpp
src/qml/qml/v4/qv4regexpobject_p.h
src/qml/qml/v8/qjsconverter_impl_p.h [deleted file]
src/qml/qml/v8/qjsconverter_p.h [deleted file]
src/qml/qml/v8/qjsvalue.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
src/qml/qml/v8/qv4jsonwrapper.cpp
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/script.pri

index 11d5af2..5b692f8 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "qv8debugservice_p.h"
 #include "qqmldebugservice_p_p.h"
-#include <private/qjsconverter_p.h>
 #include <private/qv8engine_p.h>
 
 #include <QtCore/QHash>
index 4e24a73..7f5c486 100644 (file)
@@ -41,8 +41,8 @@
 
 #include "qv8profilerservice_p.h"
 #include "qqmldebugservice_p_p.h"
-#include "private/qjsconverter_p.h"
 #include <private/qv8profiler_p.h>
+#include <private/qv8_p.h>
 
 #include <QtCore/QHash>
 #include <QtCore/QMutex>
index 4115bcb..04750b1 100644 (file)
@@ -289,11 +289,12 @@ v8::Handle<v8::Value> QQmlDateExtension::toLocaleDateString(const v8::Arguments&
 
 v8::Handle<v8::Value> QQmlDateExtension::fromLocaleString(const v8::Arguments& args)
 {
+    QV4::ExecutionEngine *engine = args.GetIsolate()->GetEngine();
     if (args.Length() == 1 && args[0]->IsString()) {
         QLocale locale;
-        QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
+        QString dateString = args[0]->v4Value().toString(engine->current)->toQString();
         QDateTime dt = locale.toDateTime(dateString);
-        return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
+        return QV4::Value::fromObject(engine->newDateObject(dt));
     }
 
     if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
@@ -319,18 +320,20 @@ v8::Handle<v8::Value> QQmlDateExtension::fromLocaleString(const v8::Arguments& a
         dt = r->locale.toDateTime(dateString, enumFormat);
     }
 
-    return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
+    return QV4::Value::fromObject(engine->newDateObject(dt));
 }
 
 v8::Handle<v8::Value> QQmlDateExtension::fromLocaleTimeString(const v8::Arguments& args)
 {
+    QV4::ExecutionEngine *engine = args.GetIsolate()->GetEngine();
+
     if (args.Length() == 1 && args[0]->IsString()) {
         QLocale locale;
-        QString timeString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
+        QString timeString = args[0]->v4Value().toString(engine->current)->toQString();
         QTime time = locale.toTime(timeString);
         QDateTime dt = QDateTime::currentDateTime();
         dt.setTime(time);
-        return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
+        return QV4::Value::fromObject(engine->newDateObject(dt));
     }
 
     if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
@@ -359,16 +362,18 @@ v8::Handle<v8::Value> QQmlDateExtension::fromLocaleTimeString(const v8::Argument
     QDateTime dt = QDateTime::currentDateTime();
     dt.setTime(tm);
 
-    return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
+    return QV4::Value::fromObject(engine->newDateObject(dt));
 }
 
 v8::Handle<v8::Value> QQmlDateExtension::fromLocaleDateString(const v8::Arguments& args)
 {
+    QV4::ExecutionEngine *engine = args.GetIsolate()->GetEngine();
+
     if (args.Length() == 1 && args[0]->IsString()) {
         QLocale locale;
-        QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
+        QString dateString = args[0]->v4Value().toString(engine->current)->toQString();
         QDate date = locale.toDate(dateString);
-        return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(date)));
+        return QV4::Value::fromObject(engine->newDateObject(QDateTime(date)));
     }
 
     if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
@@ -394,7 +399,7 @@ v8::Handle<v8::Value> QQmlDateExtension::fromLocaleDateString(const v8::Argument
         dt = r->locale.toDate(dateString, enumFormat);
     }
 
-    return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(dt)));
+    return QV4::Value::fromObject(engine->newDateObject(QDateTime(dt)));
 }
 
 v8::Handle<v8::Value> QQmlDateExtension::timeZoneUpdated(const v8::Arguments& args)
index 1d6ba4b..f2fa8d7 100644 (file)
@@ -657,6 +657,17 @@ static double getLocalTZA()
 #endif
 }
 
+DateObject::DateObject(ExecutionEngine *engine, const QDateTime &date)
+    : Object(engine)
+{
+    value = Value::fromDouble(FromDateTime(date));
+}
+
+QDateTime DateObject::toQDateTime() const
+{
+    return ToDateTime(value.asDouble(), Qt::LocalTime);
+}
+
 DEFINE_MANAGED_VTABLE(DateCtor);
 
 DateCtor::DateCtor(ExecutionContext *scope)
@@ -768,16 +779,6 @@ void DatePrototype::init(ExecutionContext *ctx, const Value &ctor)
     defineDefaultProperty(ctx, QStringLiteral("toJSON"), method_toJSON, 1);
 }
 
-double DatePrototype::toJSDate(const QDateTime &dateTime)
-{
-    return FromDateTime(dateTime);
-}
-
-QDateTime DatePrototype::toQDateTime(double d)
-{
-    return ToDateTime(d, Qt::LocalTime);
-}
-
 double DatePrototype::getThisDate(ExecutionContext *ctx)
 {
     if (DateObject *thisObject = ctx->thisObject.asDateObject())
index 729e146..629dfa5 100644 (file)
@@ -54,6 +54,9 @@ namespace QV4 {
 struct DateObject: Object {
     Value value;
     DateObject(ExecutionEngine *engine, const Value &value): Object(engine), value(value) { type = Type_DateObject; }
+    DateObject(ExecutionEngine *engine, const QDateTime &value);
+
+    QDateTime toQDateTime() const;
 };
 
 struct DateCtor: FunctionObject
@@ -72,9 +75,6 @@ struct DatePrototype: DateObject
     DatePrototype(ExecutionEngine *engine): DateObject(engine, Value::fromDouble(qSNaN())) {}
     void init(ExecutionContext *ctx, const Value &ctor);
 
-    static double toJSDate(const QDateTime &dateTime);
-    static QDateTime toQDateTime(double d);
-
     static double getThisDate(ExecutionContext *ctx);
 
     static Value method_parse(SimpleCallContext *ctx);
index d9a3260..8fa6b53 100644 (file)
@@ -401,16 +401,16 @@ Object *ExecutionEngine::newBooleanObject(const Value &value)
     return object;
 }
 
-Object *ExecutionEngine::newFunctionObject(ExecutionContext *scope)
+ArrayObject *ExecutionEngine::newArrayObject()
 {
-    Object *object = new (memoryManager) FunctionObject(scope);
-    object->prototype = functionPrototype;
+    ArrayObject *object = new (memoryManager) ArrayObject(this);
+    object->prototype = arrayPrototype;
     return object;
 }
 
-ArrayObject *ExecutionEngine::newArrayObject()
+ArrayObject *ExecutionEngine::newArrayObject(const QStringList &list)
 {
-    ArrayObject *object = new (memoryManager) ArrayObject(this);
+    ArrayObject *object = new (memoryManager) ArrayObject(this, list);
     object->prototype = arrayPrototype;
     return object;
 }
@@ -422,6 +422,13 @@ DateObject *ExecutionEngine::newDateObject(const Value &value)
     return object;
 }
 
+DateObject *ExecutionEngine::newDateObject(const QDateTime &dt)
+{
+    DateObject *object = new (memoryManager) DateObject(this, dt);
+    object->prototype = datePrototype;
+    return object;
+}
+
 RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
 {
     bool global = (flags & QQmlJS::V4IR::RegExp::RegExp_Global);
@@ -442,6 +449,13 @@ RegExpObject *ExecutionEngine::newRegExpObject(RegExp* re, bool global)
     return object;
 }
 
+RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re)
+{
+    RegExpObject *object = new (memoryManager) RegExpObject(this, re);
+    object->prototype = regExpPrototype;
+    return object;
+}
+
 Object *ExecutionEngine::newErrorObject(const Value &value)
 {
     ErrorObject *object = new (memoryManager) ErrorObject(this, value);
index 9474b44..9f5a04b 100644 (file)
@@ -224,14 +224,16 @@ struct Q_QML_EXPORT ExecutionEngine
     Object *newStringObject(const Value &value);
     Object *newNumberObject(const Value &value);
     Object *newBooleanObject(const Value &value);
-    Object *newFunctionObject(ExecutionContext *scope);
 
     ArrayObject *newArrayObject();
+    ArrayObject *newArrayObject(const QStringList &list);
 
     DateObject *newDateObject(const Value &value);
+    DateObject *newDateObject(const QDateTime &dt);
 
     RegExpObject *newRegExpObject(const QString &pattern, int flags);
     RegExpObject *newRegExpObject(RegExp* re, bool global);
+    RegExpObject *newRegExpObject(const QRegExp &re);
 
     Object *newErrorObject(const Value &value);
     Object *newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message);
index d5cbf56..f5462b6 100644 (file)
@@ -1245,6 +1245,20 @@ void Object::markArrayObjects() const
     }
 }
 
+ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list)
+    : Object(engine)
+{
+    // Converts a QStringList to JS.
+    // The result is a new Array object with length equal to the length
+    // of the QStringList, and the elements being the QStringList's
+    // elements converted to JS Strings.
+    int len = list.count();
+    arrayReserve(len);
+    for (int ii = 0; ii < len; ++ii)
+        arrayData[ii].value = Value::fromString(engine->newString(list.at(ii)));
+    setArrayLengthUnchecked(len);
+}
+
 void ArrayObject::init(ExecutionEngine *engine)
 {
     type = Type_ArrayObject;
@@ -1254,6 +1268,18 @@ void ArrayObject::init(ExecutionEngine *engine)
     memberData[LengthPropertyIndex].value = Value::fromInt32(0);
 }
 
+QStringList ArrayObject::toQStringList() const
+{
+    QStringList result;
+
+    QV4::ExecutionEngine *engine = internalClass->engine;
+
+    uint32_t length = arrayLength();
+    for (uint32_t i = 0; i < length; ++i)
+        result.append(const_cast<ArrayObject *>(this)->getIndexed(engine->current, i).toString(engine->current)->toQString());
+    return result;
+}
+
 
 DEFINE_MANAGED_VTABLE(ForEachIteratorObject);
 
index fc70d6b..aef9367 100644 (file)
@@ -391,7 +391,10 @@ struct ArrayObject: Object {
     };
 
     ArrayObject(ExecutionEngine *engine) : Object(engine) { init(engine); }
+    ArrayObject(ExecutionEngine *engine, const QStringList &list);
     void init(ExecutionEngine *engine);
+
+    QStringList toQStringList() const;
 };
 
 inline uint Object::arrayLength() const
index 6183315..00f3ce3 100644 (file)
 
 #include <QtCore/qmath.h>
 #include <QtCore/QDebug>
+#include <QtCore/qregexp.h>
 #include <cassert>
 #include <typeinfo>
 #include <iostream>
 #include "qv4alloca_p.h"
 
+Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
+
 using namespace QV4;
 
 DEFINE_MANAGED_VTABLE(RegExpObject);
@@ -84,6 +87,54 @@ RegExpObject::RegExpObject(ExecutionEngine *engine, RegExp* value, bool global)
     defineReadonlyProperty(engine->newIdentifier(QStringLiteral("multiline")), Value::fromBoolean(this->value->multiLine()));
 }
 
+// Converts a QRegExp to a JS RegExp.
+// The conversion is not 100% exact since ECMA regexp and QRegExp
+// have different semantics/flags, but we try to do our best.
+RegExpObject::RegExpObject(ExecutionEngine *engine, const QRegExp &re)
+    : Object(engine)
+    , value(0)
+    , global(false)
+{
+    // Convert the pattern to a ECMAScript pattern.
+    QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
+    if (re.isMinimal()) {
+        QString ecmaPattern;
+        int len = pattern.length();
+        ecmaPattern.reserve(len);
+        int i = 0;
+        const QChar *wc = pattern.unicode();
+        bool inBracket = false;
+        while (i < len) {
+            QChar c = wc[i++];
+            ecmaPattern += c;
+            switch (c.unicode()) {
+            case '?':
+            case '+':
+            case '*':
+            case '}':
+                if (!inBracket)
+                    ecmaPattern += QLatin1Char('?');
+                break;
+            case '\\':
+                if (i < len)
+                    ecmaPattern += wc[i++];
+                break;
+            case '[':
+                inBracket = true;
+                break;
+            case ']':
+                inBracket = false;
+                break;
+            default:
+                break;
+            }
+        }
+        pattern = ecmaPattern;
+    }
+
+    value = RegExp::create(engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false);
+}
+
 void RegExpObject::destroy(Managed *that)
 {
     static_cast<RegExpObject *>(that)->~RegExpObject();
@@ -103,6 +154,16 @@ Property *RegExpObject::lastIndexProperty(ExecutionContext *ctx)
     return &memberData[0];
 }
 
+// Converts a JS RegExp to a QRegExp.
+// The conversion is not 100% exact since ECMA regexp and QRegExp
+// have different semantics/flags, but we try to do our best.
+QRegExp RegExpObject::toQRegExp() const
+{
+    Qt::CaseSensitivity caseSensitivity = value->ignoreCase() ? Qt::CaseInsensitive : Qt::CaseSensitive;
+    return QRegExp(value->pattern(), caseSensitivity, QRegExp::RegExp2);
+}
+
+
 DEFINE_MANAGED_VTABLE(RegExpCtor);
 
 RegExpCtor::RegExpCtor(ExecutionContext *scope)
index 27ef2c8..67f0877 100644 (file)
@@ -69,8 +69,11 @@ struct RegExpObject: Object {
     Property *lastIndexProperty(ExecutionContext *ctx);
     bool global;
     RegExpObject(ExecutionEngine *engine, RegExp* value, bool global);
+    RegExpObject(ExecutionEngine *engine, const QRegExp &re);
     ~RegExpObject() {}
 
+    QRegExp toQRegExp() const;
+
 protected:
     static const ManagedVTable static_vtbl;
     static void destroy(Managed *that);
diff --git a/src/qml/qml/v8/qjsconverter_impl_p.h b/src/qml/qml/v8/qjsconverter_impl_p.h
deleted file mode 100644 (file)
index 99a34cc..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qjsconverter_p.h"
-#include <stdlib.h>
-
-#include <private/qv4jsir_p.h>
-#include <private/qv4regexpobject_p.h>
-#include <private/qv4dateobject_p.h>
-
-#ifndef QJSCONVERTER_IMPL_P_H
-#define QJSCONVERTER_IMPL_P_H
-
-#ifdef Q_OS_QNX
-#include <malloc.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-extern char *qdtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str);
-Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
-
-// Converts a JS RegExp to a QRegExp.
-// The conversion is not 100% exact since ECMA regexp and QRegExp
-// have different semantics/flags, but we try to do our best.
-QRegExp QJSConverter::toRegExp(const QV4::RegExpObject *jsRegExp)
-{
-    QV4::RegExp *re = jsRegExp->value;
-    QString pattern = re->pattern();
-    Qt::CaseSensitivity caseSensitivity = re->ignoreCase() ? Qt::CaseInsensitive : Qt::CaseSensitive;
-    return QRegExp(pattern, caseSensitivity, QRegExp::RegExp2);
-}
-
-// Converts a QRegExp to a JS RegExp.
-// The conversion is not 100% exact since ECMA regexp and QRegExp
-// have different semantics/flags, but we try to do our best.
-QV4::RegExpObject *QJSConverter::toRegExp(const QRegExp &re)
-{
-    // Convert the pattern to a ECMAScript pattern.
-    QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
-    if (re.isMinimal()) {
-        QString ecmaPattern;
-        int len = pattern.length();
-        ecmaPattern.reserve(len);
-        int i = 0;
-        const QChar *wc = pattern.unicode();
-        bool inBracket = false;
-        while (i < len) {
-            QChar c = wc[i++];
-            ecmaPattern += c;
-            switch (c.unicode()) {
-            case '?':
-            case '+':
-            case '*':
-            case '}':
-                if (!inBracket)
-                    ecmaPattern += QLatin1Char('?');
-                break;
-            case '\\':
-                if (i < len)
-                    ecmaPattern += wc[i++];
-                break;
-            case '[':
-                inBracket = true;
-                break;
-            case ']':
-                inBracket = false;
-                break;
-            default:
-                break;
-            }
-        }
-        pattern = ecmaPattern;
-    }
-
-    int flags = 0;
-    if (re.caseSensitivity() == Qt::CaseInsensitive)
-        flags |= QQmlJS::V4IR::RegExp::RegExp_IgnoreCase;
-
-    QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
-    return e->newRegExpObject(pattern, flags);
-}
-
-// Converts a QStringList to JS.
-// The result is a new Array object with length equal to the length
-// of the QStringList, and the elements being the QStringList's
-// elements converted to JS Strings.
-QV4::Value QJSConverter::toStringList(const QStringList &list)
-{
-    QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
-    QV4::ArrayObject *a = e->newArrayObject();
-    int len = list.count();
-    a->arrayReserve(len);
-    for (int ii = 0; ii < len; ++ii)
-        a->arrayData[ii].value = QV4::Value::fromString(e->newString(list.at(ii)));
-    a->setArrayLengthUnchecked(len);
-    return QV4::Value::fromObject(a);
-}
-
-// Converts a JS Array object to a QStringList.
-// The result is a QStringList with length equal to the length
-// of the JS Array, and elements being the JS Array's elements
-// converted to QStrings.
-QStringList QJSConverter::toStringList(const QV4::Value &jsArray)
-{
-    QStringList result;
-
-    QV4::ArrayObject *a = jsArray.asArrayObject();
-    if (!a)
-        return result;
-    QV4::ExecutionEngine *e = a->internalClass->engine;
-
-    uint32_t length = a->arrayLength();
-    for (uint32_t i = 0; i < length; ++i)
-        result.append(a->getIndexed(e->current, i).toString(e->current)->toQString());
-    return result;
-}
-
-
-// Converts a JS Date to a QDateTime.
-QDateTime QJSConverter::toDateTime(QV4::DateObject *jsDate)
-{
-    return QDateTime::fromMSecsSinceEpoch(jsDate->value.doubleValue());
-}
-
-// Converts a QDateTime to a JS Date.
-QV4::DateObject *QJSConverter::toDateTime(const QDateTime &dt)
-{
-    double date;
-    if (!dt.isValid())
-        date = qSNaN();
-    else
-        date = dt.toMSecsSinceEpoch();
-    QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
-    return e->newDateObject(QV4::Value::fromDouble(date));
-}
-
-QT_END_NAMESPACE
-
-#endif // QJSCONVERTER_IMPL_P_H
diff --git a/src/qml/qml/v8/qjsconverter_p.h b/src/qml/qml/v8/qjsconverter_p.h
deleted file mode 100644 (file)
index 88c2754..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QJSCONVERTER_P_H
-#define QJSCONVERTER_P_H
-
-#include "qjsvalue_p.h"
-#include <QtCore/qglobal.h>
-#include <QtCore/qnumeric.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qregexp.h>
-#include <QtCore/qdatetime.h>
-
-#include <private/qv8_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace QV4 {
-struct RegExpObject;
-struct DateObject;
-struct Value;
-}
-
-/*
-  \internal
-  \class QJSConverter
-  QJSValue and QJSEngine helper class. This class's responsibility is to convert values
-  between JS values and Qt/C++ values.
-
-  This is a nice way to inline these functions in both QJSValue and QJSEngine.
-*/
-class QJSConverter {
-public:
-    // Converts a JS RegExp to a QRegExp.
-    // The conversion is not 100% exact since ECMA regexp and QRegExp
-    // have different semantics/flags, but we try to do our best.
-    static QRegExp toRegExp(const QV4::RegExpObject *jsRegExp);
-
-    // Converts a QRegExp to a JS RegExp.
-    // The conversion is not 100% exact since ECMA regexp and QRegExp
-    // have different semantics/flags, but we try to do our best.
-    static QV4::RegExpObject *toRegExp(const QRegExp &re);
-
-    // Converts a QStringList to JS.
-    // The result is a new Array object with length equal to the length
-    // of the QStringList, and the elements being the QStringList's
-    // elements converted to JS Strings.
-    static QV4::Value toStringList(const QStringList &list);
-
-    // Converts a JS Array object to a QStringList.
-    // The result is a QStringList with length equal to the length
-    // of the JS Array, and elements being the JS Array's elements
-    // converted to QStrings.
-    static QStringList toStringList(const QV4::Value &jsArray);
-
-    // Converts a JS Date to a QDateTime.
-    static QDateTime toDateTime(QV4::DateObject *jsDate);
-
-    // Converts a QDateTime to a JS Date.
-    static QV4::DateObject *toDateTime(const QDateTime &dt);
-};
-
-QT_END_NAMESPACE
-
-#endif
index fe77382..8a965f8 100644 (file)
@@ -924,7 +924,7 @@ QDateTime QJSValue::toDateTime() const
     QV4::DateObject *date = d->value.asDateObject();
     if (!date)
         return QDateTime();
-    return QV4::DatePrototype::toQDateTime(date->value.toNumber());
+    return date->toQDateTime();
 }
 
 /*!
index a31c75b..f08a06f 100644 (file)
@@ -47,7 +47,6 @@
 #include <private/qqmlstringconverters_p.h>
 #include <private/qqmllocale_p.h>
 #include <private/qv8engine_p.h>
-#include <private/qjsconverter_p.h>
 
 #include <private/qv8profilerservice_p.h>
 #include <private/qqmlprofilerservice_p.h>
index 7aee1fd..d20592c 100644 (file)
@@ -43,7 +43,6 @@
 #include "private/qv4engine_p.h"
 #include "private/qv4object_p.h"
 #include "private/qv4objectiterator_p.h"
-#include "qjsconverter_p.h"
 
 QT_BEGIN_NAMESPACE
 
index cd2e096..c6165ce 100644 (file)
@@ -55,7 +55,7 @@
 #include <private/qqmlglobal_p.h>
 #include <private/qqmlmemoryprofiler_p.h>
 #include <private/qqmlplatform_p.h>
-#include <private/qjsconverter_p.h>
+#include <private/qjsvalue_p.h>
 
 #include "qv4domerrors_p.h"
 #include "qv4sqlerrors_p.h"
@@ -353,13 +353,13 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant)
             case QMetaType::QChar:
                 return QV4::Value::fromInt32((*reinterpret_cast<const QChar*>(ptr)).unicode());
             case QMetaType::QDateTime:
-                return QV4::Value::fromObject(QJSConverter::toDateTime(*reinterpret_cast<const QDateTime *>(ptr)));
+                return QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(ptr)));
             case QMetaType::QDate:
-                return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(*reinterpret_cast<const QDate *>(ptr))));
+                return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(ptr))));
             case QMetaType::QTime:
-            return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr))));
+            return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr))));
             case QMetaType::QRegExp:
-                return QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(ptr)));
+                return QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(ptr)));
             case QMetaType::QObjectStar:
                 return newQObject(*reinterpret_cast<QObject* const *>(ptr));
             case QMetaType::QStringList:
@@ -527,7 +527,7 @@ QVariant QV8Engine::toBasicVariant(const QV4::Value &value)
     Q_ASSERT(value.isObject());
 
     if (QV4::RegExpObject *re = value.asRegExpObject())
-        return QJSConverter::toRegExp(re);
+        return re->toQRegExp();
     if (QV4::ArrayObject *a = value.asArrayObject()) {
         QVariantList rv;
 
@@ -1031,7 +1031,7 @@ QV4::Value QV8Engine::metaTypeToJS(int type, const void *data)
     case QMetaType::QChar:
         return QV4::Value::fromUInt32((*reinterpret_cast<const QChar*>(data)).unicode());
     case QMetaType::QStringList:
-        result = QJSConverter::toStringList(*reinterpret_cast<const QStringList *>(data));
+        result = QV4::Value::fromObject(m_v4Engine->newArrayObject(*reinterpret_cast<const QStringList *>(data)));
         break;
     case QMetaType::QVariantList:
         result = variantListToJS(*reinterpret_cast<const QVariantList *>(data));
@@ -1040,13 +1040,13 @@ QV4::Value QV8Engine::metaTypeToJS(int type, const void *data)
         result = variantMapToJS(*reinterpret_cast<const QVariantMap *>(data));
         break;
     case QMetaType::QDateTime:
-        result = QV4::Value::fromObject(QJSConverter::toDateTime(*reinterpret_cast<const QDateTime *>(data)));
+        result = QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(data)));
         break;
     case QMetaType::QDate:
-        result = QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(*reinterpret_cast<const QDate *>(data))));
+        result = QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(data))));
         break;
     case QMetaType::QRegExp:
-        result = QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(data)));
+        result = QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(data)));
         break;
     case QMetaType::QObjectStar:
         result = newQObject(*reinterpret_cast<QObject* const *>(data));
@@ -1134,17 +1134,17 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
         return true;
     case QMetaType::QDateTime:
         if (QV4::DateObject *d = value.asDateObject()) {
-            *reinterpret_cast<QDateTime *>(data) = QV4::DatePrototype::toQDateTime(d->value.doubleValue());
+            *reinterpret_cast<QDateTime *>(data) = d->toQDateTime();
             return true;
         } break;
     case QMetaType::QDate:
         if (QV4::DateObject *d = value.asDateObject()) {
-            *reinterpret_cast<QDate *>(data) = QV4::DatePrototype::toQDateTime(d->value.doubleValue()).date();
+            *reinterpret_cast<QDate *>(data) = d->toQDateTime().date();
             return true;
         } break;
     case QMetaType::QRegExp:
         if (QV4::RegExpObject *r = value.asRegExpObject()) {
-            *reinterpret_cast<QRegExp *>(data) = QJSConverter::toRegExp(r);
+            *reinterpret_cast<QRegExp *>(data) = r->toQRegExp();
             return true;
         } break;
     case QMetaType::QObjectStar: {
@@ -1155,7 +1155,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
     }
     case QMetaType::QStringList:
         if (QV4::ArrayObject *a = value.asArrayObject()) {
-            *reinterpret_cast<QStringList *>(data) = QJSConverter::toStringList(value);
+            *reinterpret_cast<QStringList *>(data) = a->toQStringList();
             return true;
         } break;
     case QMetaType::QVariantList:
@@ -1287,9 +1287,9 @@ QVariant QV8Engine::variantFromJS(const QV4::Value &value,
     if (QV4::ArrayObject *a = value.asArrayObject())
         return variantListFromJS(a, visitedObjects);
     if (QV4::DateObject *d = value.asDateObject())
-        return QJSConverter::toDateTime(d);
+        return d->toQDateTime();
     if (QV4::RegExpObject *re = value.asRegExpObject())
-        return QJSConverter::toRegExp(re);
+        return re->toQRegExp();
     if (isVariant(value))
         return variantWrapper()->variantValue(v8::Value::fromV4Value(value));
     if (isQObject(value))
index f7d9e92..bb8a2aa 100644 (file)
@@ -9,7 +9,5 @@ HEADERS += \
     $$PWD/qjsvalue.h \
     $$PWD/qjsvalue_p.h \
     $$PWD/qjsvalueiterator.h \
-    $$PWD/qjsconverter_p.h \
-    $$PWD/qjsconverter_impl_p.h \
     $$PWD/qscriptisolate_p.h \
     $$PWD/qjsvalueiterator_p.h