diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-04-29 09:55:49 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-05-01 09:08:52 +0000 |
commit | 1650377af7dfb01a0641d4e21bf1ba33e6a7320f (patch) | |
tree | 3a4d704484b49905149d0f26d0937af6e14e39e9 /tests | |
parent | 3b0cb49ef0cff2e7ae4ba295d035b87f09fdea4f (diff) |
Fix crash when trying to call a property of the scope or context object
For calls on properties of the scope or context object the thisObject parameter
in the callData is a reference to the QmlContext, not a real object - therefore
the toString conversion fails.
Task-number: QTBUG-52340
Change-Id: I08d01cc5c05920c2fac46ddd40fa41e630bcade3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml new file mode 100644 index 0000000000..03f90c15c8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_52340.qml @@ -0,0 +1,13 @@ +import QtQml 2.0 + +QtObject { + property bool someProperty: true + function testCall() { + try { + someProperty(); // should throw + return false + } catch (e) { + return true + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 60fc8d0b90..08ebfbbbcf 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -327,6 +327,7 @@ private slots: void writeUnregisteredQObjectProperty(); void switchExpression(); void qtbug_46022(); + void qtbug_52340(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -7910,6 +7911,17 @@ void tst_qqmlecmascript::qtbug_46022() QCOMPARE(obj->property("test2").toBool(), true); } +void tst_qqmlecmascript::qtbug_52340() +{ + QQmlComponent component(&engine, testFileUrl("qtbug_52340.qml")); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QVariant returnValue; + QVERIFY(QMetaObject::invokeMethod(object.data(), "testCall", Q_RETURN_ARG(QVariant, returnValue))); + QVERIFY(returnValue.isValid()); + QVERIFY(returnValue.toBool()); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" |