diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-04-10 12:58:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-17 07:09:54 +0200 |
commit | 37e4975e5f43a85e81109b115bfe10d371d0bf89 (patch) | |
tree | be5d98fa38a782ae91f2798c1a89a381e23e26d9 /tests | |
parent | 6572d4e50d73ac60a8974d07de74c27a7f99ebef (diff) |
Refine fix for dynamic properties on QObjects wrapped in JavaScript
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 <jedrzej.nowacki@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
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 <qstandarditemmodel.h> #include <QtCore/qnumeric.h> #include <qqmlengine.h> +#include <qqmlcomponent.h> #include <stdlib.h> #include <private/qv4alloca_p.h> @@ -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<QObject*>(root->property("subObject")); + QVERIFY(subObject); + QVERIFY(qmlContext(subObject)); + + wrapper = qmlEngine.newQObject(subObject); + wrapper.setProperty("someRandomProperty", 42); + QVERIFY(!wrapper.hasProperty("someRandomProperty")); + } } QTEST_MAIN(tst_QJSEngine) |