diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-18 12:13:23 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-18 13:20:12 +0100 |
commit | 65b88e61a5a67a0377b375b444fa4fb2a4c9f2b5 (patch) | |
tree | f16b86fb6edf20aa21a5e8eaef8222d498782f59 /tests/auto/qml | |
parent | 831efa14e91cfa358e57a32197578d41c2ae1b24 (diff) |
QML engine: Fix writing function to property through alias
We special case writing functions to properties, only allowing assigning
them to var properties and QJSValue properties.
This would however break when aliases are involved. This commit fixes
the issue by resolving the alias, and then checking and writing to the
resolved property.
Fixes: QTBUG-90373
Pick-to: 5.15 6.0
Change-Id: Ia09ebe92feeaf8359c99ff9aeadc676b9fcfaa07
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/assignFunctionThroughAliasToVarProperty.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 14 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/assignFunctionThroughAliasToVarProperty.qml b/tests/auto/qml/qqmlecmascript/data/assignFunctionThroughAliasToVarProperty.qml new file mode 100644 index 0000000000..96b55af9d4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignFunctionThroughAliasToVarProperty.qml @@ -0,0 +1,9 @@ +import QtQuick 2.15 + +Item { + id: root + property alias bar: root.foo + property var foo: function() { return false } + + Component.onCompleted: root.bar = function() { return true } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 73c2267dca..13b6ad7700 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -79,6 +79,7 @@ private slots: void assignBasicTypes(); void assignDate_data(); void assignDate(); + void assignFunctionThroughAliasToVarProperty(); void exportDate_data(); void exportDate(); void checkDate_data(); @@ -562,6 +563,19 @@ void tst_qqmlecmascript::assignDate() QCOMPARE(object->boolProperty(), true); } +void tst_qqmlecmascript::assignFunctionThroughAliasToVarProperty() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("assignFunctionThroughAliasToVarProperty.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + + QJSValue fooFunc = root->property("foo").value<QJSValue>(); + QVERIFY(fooFunc.isCallable()); + QJSValue callResult = fooFunc.call(); + QVERIFY(callResult.toBool()); +} + void tst_qqmlecmascript::exportDate_data() { QTest::addColumn<QUrl>("source"); |