aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2025-08-14 09:52:22 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2025-08-18 09:06:23 +0200
commit15e90d46382123778f8c4fbe0669f0a6d51eca8f (patch)
tree2d37b079c7f89d9d4c4d625f75fd5af923629caf /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent4434466383fc2b41e54efe8bd3d1899c76e32c80 (diff)
Compiler: Detect calls on partially deleted objects and throw
Component.onDestruction can be used to execute some code as an object is being destructed. The code may, however, reference objects that are no longer in a valid state because they themselves have already been destructed. We then throw an exeception. Commit a741271dd58b21728928684f1ef1efaa91e79ebf introduced the init step for calls in which the types of arguments are resolved. For object methods, we need to check that the object is still valid or throw an exception otherwise. This is made more complicated by the fact that, in some cases, the destruction of the object happens in a somewhat chaotic manner where, for instance, the object is still alive but its method and property storage has already been deleted. This inconsistent state is the cause of QTBUG-138516 and existing checks for invalid objects were not sufficient and we crashed when trying to use the function that we were unable to resolve. We can detect this particular problem by checking whether the ddata of the object still has its jsWrapper. Amends a741271dd58b21728928684f1ef1efaa91e79ebf Fixes: QTBUG-138516 Pick-to: 6.10 6.9 Change-Id: Ifdd7708d73ea6012d1e07aebed257b3f538183c1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index b13c3f0755..a3082d0d75 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -127,6 +127,7 @@ private slots:
void fromBoolValue();
void funcWithParams();
void functionArguments();
+ void functionCallInitCrash();
void functionCallOnNamespaced();
void functionLookup();
void functionReturningVoid();
@@ -2307,6 +2308,15 @@ void tst_QmlCppCodegen::functionArguments()
QCOMPARE(concatenated, u"foobar"_s);
}
+void tst_QmlCppCodegen::functionCallInitCrash()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/functionCallInitCrash.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+}
+
void tst_QmlCppCodegen::functionCallOnNamespaced()
{
QQmlEngine engine;