Move QQmlJavascriptExression::evaluate over to v4
authorLars Knoll <lars.knoll@digia.com>
Mon, 20 May 2013 16:55:49 +0000 (18:55 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 21 May 2013 07:59:45 +0000 (09:59 +0200)
Change-Id: Ic4093dc5413f43af55a74a0e0f8c316ac1c6d974
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/qqmljavascriptexpression.cpp
src/qml/qml/qqmljavascriptexpression_p.h

index 44c1c52..761636a 100644 (file)
@@ -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<v8::Handle<v8::Value>, 9> args(argCount);
+            QVarLengthArray<QV4::Value, 9> 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<const int*>(a[ii + 1]));
+                    args[ii] = QV4::Value::fromInt32(*reinterpret_cast<const int*>(a[ii + 1]));
                 } else if (type == qMetaTypeId<QQmlV4Handle>()) {
                     args[ii] = reinterpret_cast<QQmlV4Handle *>(a[ii + 1])->toValue();
                 } else if (ep->isQObject(type)) {
index 759955f..3c0e8d8 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <private/qqmlexpression_p.h>
 #include <private/qv4value_p.h>
+#include <private/qv4functionobject_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -120,22 +121,23 @@ void QQmlJavaScriptExpression::resetNotifyOnValueChanged()
 
 v8::Handle<v8::Value>
 QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
-                                   v8::Handle<v8::Function> function, bool *isUndefined)
+                                   const QV4::Value &function, bool *isUndefined)
 {
     return evaluate(context, function, 0, 0, isUndefined);
 }
 
 v8::Handle<v8::Value>
 QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
-                                   v8::Handle<v8::Function> function,
-                                   int argc, v8::Handle<v8::Value> 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<v8::Value>();
+    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<v8::Value> result;
-    {
-        v8::TryCatch try_catch;
-        v8::Handle<v8::Object> 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<v8::Value> value = ep->v8engine()->newQObject(scopeObject());
-            if (value->IsObject()) This = v8::Handle<v8::Object>::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<v8::Message> 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();
         }
     }
 
index cfdb5b0..b9ce495 100644 (file)
@@ -110,10 +110,10 @@ public:
 
     QQmlJavaScriptExpression(VTable *vtable);
 
-    v8::Handle<v8::Value> evaluate(QQmlContextData *, v8::Handle<v8::Function>,
+    v8::Handle<v8::Value> evaluate(QQmlContextData *, const QV4::Value &function,
                                   bool *isUndefined);
-    v8::Handle<v8::Value> evaluate(QQmlContextData *, v8::Handle<v8::Function>,
-                                  int argc, v8::Handle<v8::Value> args[],
+    v8::Handle<v8::Value> evaluate(QQmlContextData *, const QV4::Value &function,
+                                  int argc, QV4::Value *args,
                                   bool *isUndefined);
 
     inline bool requiresThisObject() const;