Fix toString lookups on QObject bindings (And thus qqmlecmascript::toObjectString)
authorSimon Hausmann <simon.hausmann@digia.com>
Wed, 12 Jun 2013 18:43:45 +0000 (20:43 +0200)
committerLars Knoll <lars.knoll@digia.com>
Thu, 13 Jun 2013 06:53:06 +0000 (08:53 +0200)
Change-Id: I20e5788e8810d9354ca51245ee05181c9f4648ae
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/qv4qobjectwrapper.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index bbdcbe9..f127a83 100644 (file)
@@ -330,18 +330,10 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextData *qml
     }
 
     if (name->isEqualTo(m_destroy) || name->isEqualTo(m_toString)) {
-        bool hasProp = false;
-        QV4::Value method = QV4::Object::get(this, ctx, name, &hasProp);
-
-        if (!hasProp) {
-            int index = name->isEqualTo(m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
-            method = QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, index);
-            QV4::Object::put(this, ctx, name, method);
-        }
-
+        int index = name->isEqualTo(m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
+        QV4::Value method = QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, index);
         if (hasProperty)
             *hasProperty = true;
-
         return method;
     }
 
index cfbd987..a9a63d5 100644 (file)
@@ -1795,7 +1795,9 @@ void tst_qqmlecmascript::functionErrors()
     object = componentTwo.create();
     QVERIFY(object != 0);
 
-    warning = url + QLatin1String(":16: TypeError: Property 'scarceResource' of object [object Object] is not a function");
+    QObject *resource = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+    warning = url + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
+    warning = warning.arg(QString::number((qintptr)resource, 16));
     QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); // we expect a meaningful warning to be printed.
     QMetaObject::invokeMethod(object, "retrieveScarceResource");
     delete object;
@@ -4112,7 +4114,8 @@ void tst_qqmlecmascript::scarceResources_other()
     QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
     eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
     QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
-    expectedWarning = varComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object [object Object] is not a function");
+    expectedWarning = varComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
+    expectedWarning = expectedWarning.arg(QString::number((qintptr)eo, 16));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
     QMetaObject::invokeMethod(object, "retrieveScarceResource");
     QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.
@@ -4184,7 +4187,8 @@ void tst_qqmlecmascript::scarceResources_other()
     QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
     eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
     QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
-    expectedWarning = variantComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object [object Object] is not a function");
+    expectedWarning = variantComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
+    expectedWarning = expectedWarning.arg(QString::number((qintptr)eo, 16));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
     QMetaObject::invokeMethod(object, "retrieveScarceResource");
     QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.