From 37e4975e5f43a85e81109b115bfe10d371d0bf89 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 10 Apr 2014 12:58:15 +0200 Subject: Refine fix for dynamic properties on QObjects wrapped in JavaScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an ammendment to commit 60730cbb5e5475b5db6a15641211aa6958a93197 to further restrict the ability to set dynamic properties on JS wrapped QObjects only on those that are associated with a qml context. Only one such association comes with the static property lookup rules of QML and therefore only those should be prohibited from dynamic properties. The previous implementation on using the "compiledData" field to detect QML association or not is not strong and reliable enough. Change-Id: I10c0e6e58a2727c01a6cb56fdf912bf250333e1f Reviewed-by: Jędrzej Nowacki --- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp') diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 0a56c2f6d0..64c6754aa7 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -2964,11 +2965,34 @@ void tst_QJSEngine::prototypeChainGc() void tst_QJSEngine::dynamicProperties() { - QJSEngine engine; - QObject *obj = new QObject; - QJSValue wrapper = engine.newQObject(obj); - wrapper.setProperty("someRandomProperty", 42); - QCOMPARE(wrapper.property("someRandomProperty").toInt(), 42); + { + QJSEngine engine; + QObject *obj = new QObject; + QJSValue wrapper = engine.newQObject(obj); + wrapper.setProperty("someRandomProperty", 42); + QCOMPARE(wrapper.property("someRandomProperty").toInt(), 42); + QVERIFY(!qmlContext(obj)); + } + { + QQmlEngine qmlEngine; + QQmlComponent component(&qmlEngine); + component.setData("import QtQml 2.0; QtObject { property QtObject subObject: QtObject {} }", QUrl()); + QObject *root = component.create(0); + QVERIFY(root); + QVERIFY(qmlContext(root)); + + QJSValue wrapper = qmlEngine.newQObject(root); + wrapper.setProperty("someRandomProperty", 42); + QVERIFY(!wrapper.hasProperty("someRandomProperty")); + + QObject *subObject = qvariant_cast(root->property("subObject")); + QVERIFY(subObject); + QVERIFY(qmlContext(subObject)); + + wrapper = qmlEngine.newQObject(subObject); + wrapper.setProperty("someRandomProperty", 42); + QVERIFY(!wrapper.hasProperty("someRandomProperty")); + } } QTEST_MAIN(tst_QJSEngine) -- cgit v1.2.3