From 0dc3be1bdf3ca9da44b96ac4d674e4b3e36c5120 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 30 Apr 2013 23:02:33 +0200 Subject: [PATCH] Convert qjsconverter to v4 based API Longer term the whole class should go, but for now this'll do. Change-Id: I17b13848a07d415633606faa1c93ff3a9f54a45a Reviewed-by: Simon Hausmann --- src/qml/qml/qqmllocale.cpp | 36 ++++---- src/qml/qml/v4/qv4engine.cpp | 4 +- src/qml/qml/v4/qv4engine_p.h | 2 +- src/qml/qml/v8/qjsconverter_impl_p.h | 150 ++++++++------------------------ src/qml/qml/v8/qjsconverter_p.h | 28 +++--- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 4 +- src/qml/qml/v8/qv8engine.cpp | 35 ++++---- src/qml/qml/v8/qv8engine_p.h | 2 +- 8 files changed, 91 insertions(+), 170 deletions(-) diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 54d4f36..4115bcb 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -49,6 +49,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QV8LocaleDataResource : public QV8ObjectResource @@ -173,7 +175,7 @@ v8::Handle QQmlDateExtension::toLocaleString(const v8::Arguments& arg if (args.Length() == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return QJSConverter::toString(locale.toString(dt)); + return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(dt))); } if (!isLocaleObject(args[0])) @@ -215,7 +217,7 @@ v8::Handle QQmlDateExtension::toLocaleTimeString(const v8::Arguments& if (args.Length() == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return QJSConverter::toString(locale.toString(time)); + return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(time))); } if (!isLocaleObject(args[0])) @@ -257,7 +259,7 @@ v8::Handle QQmlDateExtension::toLocaleDateString(const v8::Arguments& if (args.Length() == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return QJSConverter::toString(locale.toString(date)); + return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(date))); } if (!isLocaleObject(args[0])) @@ -289,9 +291,9 @@ v8::Handle QQmlDateExtension::fromLocaleString(const v8::Arguments& a { if (args.Length() == 1 && args[0]->IsString()) { QLocale locale; - QString dateString = QJSConverter::toString(args[0]->ToString()); + QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString(); QDateTime dt = locale.toDateTime(dateString); - return QJSConverter::toDateTime(dt); + return QV4::Value::fromObject(QJSConverter::toDateTime(dt)); } if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0])) @@ -317,18 +319,18 @@ v8::Handle QQmlDateExtension::fromLocaleString(const v8::Arguments& a dt = r->locale.toDateTime(dateString, enumFormat); } - return QJSConverter::toDateTime(dt); + return QV4::Value::fromObject(QJSConverter::toDateTime(dt)); } v8::Handle QQmlDateExtension::fromLocaleTimeString(const v8::Arguments& args) { if (args.Length() == 1 && args[0]->IsString()) { QLocale locale; - QString timeString = QJSConverter::toString(args[0]->ToString()); + QString timeString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString(); QTime time = locale.toTime(timeString); QDateTime dt = QDateTime::currentDateTime(); dt.setTime(time); - return QJSConverter::toDateTime(dt); + return QV4::Value::fromObject(QJSConverter::toDateTime(dt)); } if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0])) @@ -357,16 +359,16 @@ v8::Handle QQmlDateExtension::fromLocaleTimeString(const v8::Argument QDateTime dt = QDateTime::currentDateTime(); dt.setTime(tm); - return QJSConverter::toDateTime(dt); + return QV4::Value::fromObject(QJSConverter::toDateTime(dt)); } v8::Handle QQmlDateExtension::fromLocaleDateString(const v8::Arguments& args) { if (args.Length() == 1 && args[0]->IsString()) { QLocale locale; - QString dateString = QJSConverter::toString(args[0]->ToString()); + QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString(); QDate date = locale.toDate(dateString); - return QJSConverter::toDateTime(QDateTime(date)); + return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(date))); } if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0])) @@ -392,7 +394,7 @@ v8::Handle QQmlDateExtension::fromLocaleDateString(const v8::Argument dt = r->locale.toDate(dateString, enumFormat); } - return QJSConverter::toDateTime(QDateTime(dt)); + return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(dt))); } v8::Handle QQmlDateExtension::timeZoneUpdated(const v8::Arguments& args) @@ -451,7 +453,7 @@ v8::Handle QQmlNumberExtension::toLocaleString(const v8::Arguments& a if (args.Length() == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return QJSConverter::toString(locale.toString(number)); + return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(number))); } if (!isLocaleObject(args[0])) @@ -490,7 +492,7 @@ v8::Handle QQmlNumberExtension::toLocaleCurrencyString(const v8::Argu if (args.Length() == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return QJSConverter::toString(locale.toString(number)); + return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(number))); } if (!isLocaleObject(args[0])) @@ -531,7 +533,7 @@ v8::Handle QQmlNumberExtension::fromLocaleString(const v8::Arguments& return v8::Number::New(Q_QNAN); bool ok = false; - double val = locale.toDouble(QJSConverter::toString(ns), &ok); + double val = locale.toDouble(ns->v4Value().asString()->toQString(), &ok); if (!ok) V8THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format") @@ -906,8 +908,8 @@ v8::Handle QQmlLocale::localeCompare(const v8::Arguments &args) if (!args.This()->IsString() && !args.This()->IsStringObject()) return v8::Undefined(); - QString thisString = QJSConverter::toString(args.This()->ToString()); - QString thatString = QJSConverter::toString(args[0]->ToString()); + QString thisString = args.This()->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString(); + QString thatString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString(); return v8::Integer::New(QString::localeAwareCompare(thisString, thatString)); } diff --git a/src/qml/qml/v4/qv4engine.cpp b/src/qml/qml/v4/qv4engine.cpp index ac28069..4fcde52 100644 --- a/src/qml/qml/v4/qv4engine.cpp +++ b/src/qml/qml/v4/qv4engine.cpp @@ -415,9 +415,9 @@ ArrayObject *ExecutionEngine::newArrayObject(ExecutionContext *ctx) return object; } -Object *ExecutionEngine::newDateObject(const Value &value) +DateObject *ExecutionEngine::newDateObject(const Value &value) { - Object *object = new (memoryManager) DateObject(this, value); + DateObject *object = new (memoryManager) DateObject(this, value); object->prototype = datePrototype; return object; } diff --git a/src/qml/qml/v4/qv4engine_p.h b/src/qml/qml/v4/qv4engine_p.h index dc9783f..de894a5 100644 --- a/src/qml/qml/v4/qv4engine_p.h +++ b/src/qml/qml/v4/qv4engine_p.h @@ -228,7 +228,7 @@ struct Q_QML_EXPORT ExecutionEngine ArrayObject *newArrayObject(ExecutionContext *ctx); - Object *newDateObject(const Value &value); + DateObject *newDateObject(const Value &value); RegExpObject *newRegExpObject(const QString &pattern, int flags); RegExpObject *newRegExpObject(RegExp* re, bool global); diff --git a/src/qml/qml/v8/qjsconverter_impl_p.h b/src/qml/qml/v8/qjsconverter_impl_p.h index 165373c..16bd330 100644 --- a/src/qml/qml/v8/qjsconverter_impl_p.h +++ b/src/qml/qml/v8/qjsconverter_impl_p.h @@ -42,6 +42,10 @@ #include "qjsconverter_p.h" #include +#include +#include +#include + #ifndef QJSCONVERTER_IMPL_P_H #define QJSCONVERTER_IMPL_P_H @@ -54,115 +58,21 @@ 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); - -quint32 QJSConverter::toArrayIndex(const QString& string) -{ - // FIXME this function should be exported by JSC C API. - bool ok; - quint32 idx = string.toUInt(&ok); - if (!ok || toString(idx) != string) - idx = 0xffffffff; - - return idx; -} - -QString QJSConverter::toString(v8::Handle jsString) -{ - if (jsString.IsEmpty()) - return QString(); - QString qstr; - qstr.resize(jsString->Length()); - jsString->Write(reinterpret_cast(qstr.data())); - return qstr; -} - -v8::Local QJSConverter::toString(const QString& string) -{ - return v8::String::New(reinterpret_cast(string.data()), string.size()); -} - -QString QJSConverter::toString(double value) -{ - // FIXME this should be easier. The ideal fix is to create - // a new function in V8 API which could cover the functionality. - - if (qIsNaN(value)) - return QString::fromLatin1("NaN"); - if (qIsInf(value)) - return QString::fromLatin1(value < 0 ? "-Infinity" : "Infinity"); - if (!value) - return QString::fromLatin1("0"); - - QVarLengthArray buf; - int decpt; - int sign; - char* result = 0; - char* endresult; - (void)qdtoa(value, 0, 0, &decpt, &sign, &endresult, &result); - - if (!result) - return QString(); - - int resultLen = endresult - result; - if (decpt <= 0 && decpt > -6) { - buf.resize(-decpt + 2 + sign); - memset(buf.data(), '0', -decpt + 2 + sign); - if (sign) // fix the sign. - buf[0] = '-'; - buf[sign + 1] = '.'; - buf.append(result, resultLen); - } else { - if (sign) - buf.append('-'); - int length = buf.size() - sign + resultLen; - if (decpt <= 21 && decpt > 0) { - if (length <= decpt) { - const char* zeros = "0000000000000000000000000"; - buf.append(result, resultLen); - buf.append(zeros, decpt - length); - } else { - buf.append(result, decpt); - buf.append('.'); - buf.append(result + decpt, resultLen - decpt); - } - } else if (result[0] >= '0' && result[0] <= '9') { - if (length > 1) { - buf.append(result, 1); - buf.append('.'); - buf.append(result + 1, resultLen - 1); - } else - buf.append(result, resultLen); - buf.append('e'); - buf.append(decpt >= 0 ? '+' : '-'); - int e = qAbs(decpt - 1); - if (e >= 100) - buf.append('0' + e / 100); - if (e >= 10) - buf.append('0' + (e % 100) / 10); - buf.append('0' + e % 10); - } - } - free(result); - buf.append(0); - return QString::fromLatin1(buf.constData()); -} - // 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(v8::Handle jsRegExp) +QRegExp QJSConverter::toRegExp(const QV4::RegExpObject *jsRegExp) { - QString pattern = QJSConverter::toString(jsRegExp->GetSource()); - Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive; - if (jsRegExp->GetFlags() & v8::RegExp::kIgnoreCase) - caseSensitivity = Qt::CaseInsensitive; + 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. -v8::Local QJSConverter::toRegExp(const QRegExp &re) +QV4::RegExpObject *QJSConverter::toRegExp(const QRegExp &re) { // Convert the pattern to a ECMAScript pattern. QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax()); @@ -201,54 +111,66 @@ v8::Local QJSConverter::toRegExp(const QRegExp &re) pattern = ecmaPattern; } - int flags = v8::RegExp::kNone; + int flags = 0; if (re.caseSensitivity() == Qt::CaseInsensitive) - flags |= v8::RegExp::kIgnoreCase; + flags |= QQmlJS::V4IR::RegExp::RegExp_IgnoreCase; - return v8::RegExp::New(QJSConverter::toString(pattern), static_cast(flags)); + 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. -v8::Local QJSConverter::toStringList(const QStringList &lst) +QV4::Value QJSConverter::toStringList(const QStringList &list) { - v8::Local result = v8::Array::New(lst.size()); - for (int i = 0; i < lst.size(); ++i) - result->Set(i, toString(lst.at(i))); - return result; + QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine(); + QV4::ArrayObject *a = e->newArrayObject(e->current); + 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(v8::Handle jsArray) +QStringList QJSConverter::toStringList(const QV4::Value &jsArray) { QStringList result; - uint32_t length = jsArray->Length(); + + 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(toString(jsArray->Get(i)->ToString())); + result.append(a->getIndexed(e->current, i).toString(e->current)->toQString()); return result; } // Converts a JS Date to a QDateTime. -QDateTime QJSConverter::toDateTime(v8::Handle jsDate) +QDateTime QJSConverter::toDateTime(QV4::DateObject *jsDate) { - return QDateTime::fromMSecsSinceEpoch(jsDate->NumberValue()); + return QDateTime::fromMSecsSinceEpoch(jsDate->value.doubleValue()); } // Converts a QDateTime to a JS Date. -v8::Local QJSConverter::toDateTime(const QDateTime &dt) +QV4::DateObject *QJSConverter::toDateTime(const QDateTime &dt) { double date; if (!dt.isValid()) date = qSNaN(); else date = dt.toMSecsSinceEpoch(); - return v8::Date::New(date); + QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine(); + return e->newDateObject(QV4::Value::fromDouble(date)); } QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qjsconverter_p.h b/src/qml/qml/v8/qjsconverter_p.h index 3522b38..88c2754 100644 --- a/src/qml/qml/v8/qjsconverter_p.h +++ b/src/qml/qml/v8/qjsconverter_p.h @@ -55,6 +55,12 @@ QT_BEGIN_NAMESPACE +namespace QV4 { +struct RegExpObject; +struct DateObject; +struct Value; +} + /* \internal \class QJSConverter @@ -65,43 +71,33 @@ QT_BEGIN_NAMESPACE */ class QJSConverter { public: - static quint32 toArrayIndex(const QString& string); - - static QString toString(v8::Handle jsString); - static v8::Local toString(const QString& string); - static QString toString(double value); - - enum { - PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum, - }; - // 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(v8::Handle jsRegExp); + 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 v8::Local toRegExp(const QRegExp &re); + 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 v8::Local toStringList(const QStringList &lst); + 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(v8::Handle jsArray); + static QStringList toStringList(const QV4::Value &jsArray); // Converts a JS Date to a QDateTime. - static QDateTime toDateTime(v8::Handle jsDate); + static QDateTime toDateTime(QV4::DateObject *jsDate); // Converts a QDateTime to a JS Date. - static v8::Local toDateTime(const QDateTime &dt); + static QV4::DateObject *toDateTime(const QDateTime &dt); }; QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 9ab2ac8..a31c75b 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -99,8 +99,8 @@ static QString jsStack() { int columnNumber = frame->GetColumn(); QString stackFrame = - QString::fromLatin1("%1 (%2:%3:%4)").arg(QJSConverter::toString(function), - QJSConverter::toString(script), + QString::fromLatin1("%1 (%2:%3:%4)").arg(function->v4Value().asString()->toQString(), + script->v4Value().asString()->toQString(), QString::number(lineNumber), QString::number(columnNumber)); stackFrames.append(stackFrame); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 2d3f1f5..c5f022e 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -71,6 +71,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(QList) @@ -361,7 +362,7 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) return QV4::Value::fromObject(m_v4Engine->newDateObject(QV4::Value::fromDouble( qtDateTimeToJsDate(QDateTime(QDate(1970,1,1), *reinterpret_cast(ptr)))))); case QMetaType::QRegExp: - return QJSConverter::toRegExp(*reinterpret_cast(ptr))->v4Value(); + return QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast(ptr))); case QMetaType::QObjectStar: return newQObject(*reinterpret_cast(ptr)); case QMetaType::QStringList: @@ -439,8 +440,8 @@ v8::Local QV8Engine::qmlModeCompile(const QString &source, const QString &fileName, quint16 lineNumber) { - v8::Local v8source = QJSConverter::toString(source); - v8::Local v8fileName = QJSConverter::toString(fileName); + v8::Handle v8source = QV4::Value::fromString(m_v4Engine->newString(source)); + v8::Handle v8fileName = QV4::Value::fromString(m_v4Engine->newString(fileName)); v8::ScriptOrigin origin(v8fileName, v8::Integer::New(lineNumber - 1)); @@ -459,8 +460,8 @@ v8::Local QV8Engine::qmlModeCompile(const char *source, int sourceLe if (sourceLength == -1) sourceLength = int(strlen(source)); - v8::Local v8source = v8::String::New(source, sourceLength); - v8::Local v8fileName = QJSConverter::toString(fileName); + v8::Handle v8source = QV4::Value::fromString(m_v4Engine->newString(QString::fromUtf8(source, sourceLength))); + v8::Handle v8fileName = QV4::Value::fromString(m_v4Engine->newString(fileName)); v8::ScriptOrigin origin(v8fileName, v8::Integer::New(lineNumber - 1)); @@ -529,7 +530,7 @@ QVariant QV8Engine::toBasicVariant(v8::Handle value) if (value->IsRegExp()) { v8::Context::Scope scope(context()); - return QJSConverter::toRegExp(v8::Handle::Cast(value)); + return QJSConverter::toRegExp(value->v4Value().asRegExpObject()); } if (value->IsArray()) { v8::Context::Scope scope(context()); @@ -1048,7 +1049,7 @@ QV4::Value QV8Engine::metaTypeToJS(int type, const void *data) case QMetaType::QChar: return QV4::Value::fromUInt32((*reinterpret_cast(data)).unicode()); case QMetaType::QStringList: - result = QJSConverter::toStringList(*reinterpret_cast(data))->v4Value(); + result = QJSConverter::toStringList(*reinterpret_cast(data)); break; case QMetaType::QVariantList: result = variantListToJS(*reinterpret_cast(data)); @@ -1057,13 +1058,13 @@ QV4::Value QV8Engine::metaTypeToJS(int type, const void *data) result = variantMapToJS(*reinterpret_cast(data)); break; case QMetaType::QDateTime: - result = QJSConverter::toDateTime(*reinterpret_cast(data))->v4Value(); + result = QV4::Value::fromObject(QJSConverter::toDateTime(*reinterpret_cast(data))); break; case QMetaType::QDate: - result = QJSConverter::toDateTime(QDateTime(*reinterpret_cast(data)))->v4Value(); + result = QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(*reinterpret_cast(data)))); break; case QMetaType::QRegExp: - result = QJSConverter::toRegExp(*reinterpret_cast(data))->v4Value(); + result = QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast(data))); break; case QMetaType::QObjectStar: result = newQObject(*reinterpret_cast(data)); @@ -1161,7 +1162,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) { } break; case QMetaType::QRegExp: if (QV4::RegExpObject *r = value.asRegExpObject()) { - *reinterpret_cast(data) = QJSConverter::toRegExp(v8::Handle::Cast(v8::Value::fromV4Value(value))); + *reinterpret_cast(data) = QJSConverter::toRegExp(r); return true; } break; case QMetaType::QObjectStar: { @@ -1172,7 +1173,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) { } case QMetaType::QStringList: if (QV4::ArrayObject *a = value.asArrayObject()) { - *reinterpret_cast(data) = QJSConverter::toStringList(v8::Handle::Cast(v8::Value::fromV4Value(value))); + *reinterpret_cast(data) = QJSConverter::toStringList(value); return true; } break; case QMetaType::QVariantList: @@ -1304,9 +1305,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(v8::Handle::Cast(v8::Value::fromV4Value(value))); - if (value.asRegExpObject()) - return QJSConverter::toRegExp(v8::Handle::Cast(v8::Value::fromV4Value(value))); + return QJSConverter::toDateTime(d); + if (QV4::RegExpObject *re = value.asRegExpObject()) + return QJSConverter::toRegExp(re); if (isVariant(v8::Value::fromV4Value(value))) return variantWrapper()->variantValue(v8::Value::fromV4Value(value)); if (isQObject(value)) @@ -1521,9 +1522,9 @@ QV8Engine::ThreadData::~ThreadData() } } -v8::Local QV8Engine::toString(const QString &string) +QV4::Value QV8Engine::toString(const QString &string) { - return QJSConverter::toString(string); + return QV4::Value::fromString(m_v4Engine->newString(string)); } diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 7e9f809..87b430b 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -328,7 +328,7 @@ public: inline QObject *toQObject(const QV4::Value &value); // Return a JS string for the given QString \a string - v8::Local toString(const QString &string); + QV4::Value toString(const QString &string); // Create a new value type object inline QV4::Value newValueType(QObject *, int coreIndex, QQmlValueType *); -- 2.7.4