Fix tst_qqmlecmascripts::importScripts with private imports
authorSimon Hausmann <simon.hausmann@digia.com>
Sun, 23 Jun 2013 13:08:13 +0000 (15:08 +0200)
committerLars Knoll <lars.knoll@digia.com>
Sun, 23 Jun 2013 19:38:12 +0000 (21:38 +0200)
* In QQmlContextWrapper::get we must check the calling context before
  allowing the get, just like in the Getter() in qv8contextwrapper.cpp
* When trying to call a method on undefined/null, throw a readable error message,
  as expected by the test.

Change-Id: Ie39e8ae82a108deef264e4044e12e7b15959caf9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/v4/qv4runtime.cpp

index 9ceb460..6a3fd15 100644 (file)
@@ -136,6 +136,9 @@ Value QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
     if (resource->isNullWrapper)
         return Object::get(m, name, hasProperty);
 
+    if (QV4::QmlContextWrapper::callingContext(v4) != resource->context)
+        return Object::get(m, name, hasProperty);
+
     bool hasProp;
     Value result = Object::get(m, name, &hasProp);
     if (hasProp) {
index beef790..481c1b5 100644 (file)
@@ -815,6 +815,11 @@ void __qmljs_call_property(ExecutionContext *context, Value *result, const Value
     Value thisObject = thatObject;
     Managed *baseObject = thisObject.asManaged();
     if (!baseObject) {
+        if (thisObject.isNull() || thisObject.isUndefined()) {
+            QString message = QStringLiteral("Cannot call method '%1' of %2").arg(name->toQString()).arg(thisObject.toQString());
+            context->throwTypeError(message);
+        }
+
         baseObject = __qmljs_convert_to_object(context, thisObject);
         thisObject = Value::fromObject(static_cast<Object *>(baseObject));
     }