diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-11-18 16:36:10 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-11-24 13:07:04 +0100 |
commit | 9bfb585cc6029c915d60004b71c681921e61aa19 (patch) | |
tree | c4feec3db87cc55a42b70425773018b1bea97e20 | |
parent | 39aba03d4c4bf80a54dbf5b6735b81854dd99220 (diff) |
QtQml: Recognize JavaScript null as equivalent to nullptr QObject*
Otherwise we can go into infinite recursion there.
Fixes: QTBUG-108651
Change-Id: I73a7c524b28d0eacb151f2090e3dce6afbc029d1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit c58d2e5229c39e8007ce5b93822c66af5e765a50)
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/nullIsNull.qml | 28 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 12 |
3 files changed, 41 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0cc26fe0fb..710aadda45 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -896,7 +896,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * QObject *arg = *reinterpret_cast<QObject **>(a[0]); if (const auto *wrap = sv->as<QV4::QObjectWrapper>()) needActivate = wrap->object() != arg; - else + else if (arg != nullptr || !sv->isNull()) needActivate = true; if (needActivate) writeProperty(id, arg); diff --git a/tests/auto/qml/qqmllanguage/data/nullIsNull.qml b/tests/auto/qml/qqmllanguage/data/nullIsNull.qml new file mode 100644 index 0000000000..a6cbbee0bf --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/nullIsNull.qml @@ -0,0 +1,28 @@ +import QtQml + +QtObject { + id: root + property alias someProperty: internal.someProperty + + property Timer t: Timer { + interval: 1 + running: true + onTriggered: root.someProperty = null + } + + property QtObject a: QtObject { + id: someObjectInstance + } + + property QtObject b: QtObject { + id: internal + property QtObject someProperty: someObjectInstance ? someObjectInstance : null + } + + property Connections c: Connections { + target: internal + function onSomePropertyChanged() { + internal.someProperty = null + } + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 0380456781..409c56d504 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -391,6 +391,7 @@ private slots: void badGroupedProperty(); void bindableOnly(); void signalInlineComponentArg(); + void nullIsNull(); private: QQmlEngine engine; @@ -7421,6 +7422,17 @@ void tst_qqmllanguage::signalInlineComponentArg() } } +void tst_qqmllanguage::nullIsNull() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("nullIsNull.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + QVERIFY(o->property("someProperty").value<QObject*>() != nullptr); + QTRY_COMPARE(o->property("someProperty").value<QObject*>(), nullptr); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |