Fix tst_qqmlecmascript::signalHandlers auto-test
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 3 Jun 2013 11:27:38 +0000 (13:27 +0200)
committerLars Knoll <lars.knoll@digia.com>
Mon, 3 Jun 2013 12:50:46 +0000 (14:50 +0200)
Provide a more elaborate error message when a type error is thrown as
the result of trying to call a property as function.

Change-Id: Ie4cd56e2f0d16b90060af1f596a48914a868244a
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/qv4context.cpp
src/qml/qml/v4/qv4context_p.h
src/qml/qml/v4/qv4runtime.cpp

index eb9a953..9a15c41 100644 (file)
@@ -532,8 +532,10 @@ Value ExecutionContext::getPropertyAndBase(String *name, Object **base)
             if (c->activation) {
                 bool hasProperty = false;
                 Value v = c->activation->get(c, name, &hasProperty);
-                if (hasProperty)
+                if (hasProperty) {
+                    *base = c->activation;
                     return v;
+                }
             }
             if (f->function && f->function->isNamedExpression
                 && name->isEqualTo(f->function->name))
@@ -583,6 +585,11 @@ void ExecutionContext::throwTypeError()
     throwError(Value::fromObject(engine->newTypeErrorObject(QStringLiteral("Type error"))));
 }
 
+void ExecutionContext::throwTypeError(const QString &message)
+{
+    throwError(Value::fromObject(engine->newTypeErrorObject(message)));
+}
+
 void ExecutionContext::throwUnimplemented(const QString &message)
 {
     Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message);
index fe0a788..0ed74a6 100644 (file)
@@ -131,6 +131,7 @@ struct Q_QML_EXPORT ExecutionContext
     void Q_NORETURN throwError(const QString &message);
     void Q_NORETURN throwSyntaxError(DiagnosticMessage *message);
     void Q_NORETURN throwTypeError();
+    void Q_NORETURN throwTypeError(const QString &message);
     void Q_NORETURN throwReferenceError(Value value);
     void Q_NORETURN throwRangeError(Value value);
     void Q_NORETURN throwURIError(Value msg);
index e559d68..47a41bd 100644 (file)
@@ -779,8 +779,13 @@ void __qmljs_call_activation_property(ExecutionContext *context, Value *result,
     Object *base;
     Value func = context->getPropertyAndBase(name, &base);
     FunctionObject *o = func.asFunctionObject();
-    if (!o)
-        context->throwTypeError();
+    if (!o) {
+        QString objectAsString = QStringLiteral("[null]");
+        if (base)
+            objectAsString = Value::fromObject(base).toQString();
+        QString msg = QStringLiteral("Property '%1' of object %2 is not a function").arg(name->toQString()).arg(objectAsString);
+        context->throwTypeError(msg);
+    }
 
     Value thisObject = base ? Value::fromObject(base) : Value::undefinedValue();