From 61902215393c27041739d4cd8544e502ca7f8270 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 20 May 2013 18:55:49 +0200 Subject: [PATCH] Move QQmlJavascriptExression::evaluate over to v4 Change-Id: Ic4093dc5413f43af55a74a0e0f8c316ac1c6d974 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlboundsignal.cpp | 4 +-- src/qml/qml/qqmljavascriptexpression.cpp | 49 ++++++++++++++++++-------------- src/qml/qml/qqmljavascriptexpression_p.h | 6 ++-- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 44c1c52..761636a 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -225,7 +225,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) int *argsTypes = QQmlPropertyCache::methodParameterTypes(m_target, methodIndex, dummy, 0); int argCount = argsTypes ? m_parameterCountForJS : 0; - QVarLengthArray, 9> args(argCount); + QVarLengthArray args(argCount); for (int ii = 0; ii < argCount; ++ii) { int type = argsTypes[ii + 1]; @@ -236,7 +236,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) args[ii] = engine->fromVariant(*((QVariant *)a[ii + 1])); } else if (type == QMetaType::Int) { //### optimization. Can go away if we switch to metaTypeToJS, or be expanded otherwise - args[ii] = v8::Integer::New(*reinterpret_cast(a[ii + 1])); + args[ii] = QV4::Value::fromInt32(*reinterpret_cast(a[ii + 1])); } else if (type == qMetaTypeId()) { args[ii] = reinterpret_cast(a[ii + 1])->toValue(); } else if (ep->isQObject(type)) { diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 759955f..3c0e8d8 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -43,6 +43,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -120,22 +121,23 @@ void QQmlJavaScriptExpression::resetNotifyOnValueChanged() v8::Handle QQmlJavaScriptExpression::evaluate(QQmlContextData *context, - v8::Handle function, bool *isUndefined) + const QV4::Value &function, bool *isUndefined) { return evaluate(context, function, 0, 0, isUndefined); } v8::Handle QQmlJavaScriptExpression::evaluate(QQmlContextData *context, - v8::Handle function, - int argc, v8::Handle args[], + const QV4::Value &function, + int argc, QV4::Value *args, bool *isUndefined) { Q_ASSERT(context && context->engine); - if (function.IsEmpty() || function->IsUndefined()) { - if (isUndefined) *isUndefined = true; - return v8::Handle(); + if (function.isEmpty() || function.isUndefined()) { + if (isUndefined) + *isUndefined = true; + return QV4::Value::emptyValue(); } QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context->engine); @@ -166,30 +168,35 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, ep->sharedScope = scopeObject(); } - v8::Handle result; - { - v8::TryCatch try_catch; - v8::Handle This = v8::Value::fromV4Value(ep->v8engine()->global()); + QV4::Value result; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); + QV4::ExecutionContext *ctx = v4->current; + try { + QV4::Value This = ep->v8engine()->global(); if (scopeObject() && requiresThisObject()) { - v8::Handle value = ep->v8engine()->newQObject(scopeObject()); - if (value->IsObject()) This = v8::Handle::Cast(value); + QV4::Value value = ep->v8engine()->newQObject(scopeObject()); + if (value.isObject()) + This = value; } - result = function->Call(This, argc, args); + result = function.asFunctionObject()->call(ctx, This, args, argc); if (isUndefined) - *isUndefined = try_catch.HasCaught() || result->IsUndefined(); + *isUndefined = result.isUndefined(); - if (watcher.wasDeleted()) { - } else if (try_catch.HasCaught()) { - v8::Handle message = try_catch.Message(); - if (!message.IsEmpty()) { - delayedError()->setMessage(message); + if (!watcher.wasDeleted() && hasDelayedError()) + delayedError()->clearError(); + } catch (QV4::Exception &e) { + e.accept(ctx); + if (isUndefined) + *isUndefined = true; + if (!watcher.wasDeleted()) { + if (!e.value().isEmpty()) { + // ### line number + delayedError()->setErrorDescription(e.value().toQString()); } else { if (hasDelayedError()) delayedError()->clearError(); } - } else { - if (hasDelayedError()) delayedError()->clearError(); } } diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index cfdb5b0..b9ce495 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -110,10 +110,10 @@ public: QQmlJavaScriptExpression(VTable *vtable); - v8::Handle evaluate(QQmlContextData *, v8::Handle, + v8::Handle evaluate(QQmlContextData *, const QV4::Value &function, bool *isUndefined); - v8::Handle evaluate(QQmlContextData *, v8::Handle, - int argc, v8::Handle args[], + v8::Handle evaluate(QQmlContextData *, const QV4::Value &function, + int argc, QV4::Value *args, bool *isUndefined); inline bool requiresThisObject() const; -- 2.7.4