diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2012-04-03 12:37:29 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-03 16:22:04 +0200 |
commit | 7aa4c4164e0b7e09bfb0ea50d7f70203f7871bc6 (patch) | |
tree | 159697b3f94cb5cf591f46be4535253e9ad62ea3 /tests | |
parent | 411066bdf2d09a8f0071eb9d494287a6a95639fb (diff) |
Don't crash if calling a method on a QObject that has been gc()'d
As we don't actually delete an object immediately when it is collected,
it is possible to get into a situation where a method is called on an
object after the collector has marked it to be destroyed. This fixes
a crash in this case.
Change-Id: I131d4c5d7ed788a91aa52f6af2e5c089d9bf5e08
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml | 22 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 9 |
2 files changed, 30 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml b/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml new file mode 100644 index 0000000000..d1418e57a1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + property var fn + + property var c: Component { + MyQmlObject { + function go() { + try { methodNoArgs(); } catch(e) { } + } + } + } + + Component.onCompleted: { + var f = c.createObject().go; + + gc(); + + f(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 5842ab057e..ee9c7ee89d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -246,7 +246,7 @@ private slots: void invokableWithQObjectDerived(); void realTypePrecision(); void registeredFlagMethod(); - + void deleteLaterObjectMethodCall(); void automaticSemicolon(); void unaryExpression(); void switchStatement(); @@ -6001,6 +6001,13 @@ void tst_qqmlecmascript::dynamicString() QString::fromLatin1("string:Hello World false:0 true:1 uint32:100 int32:-100 double:3.14159 date:2011-02-11 05::30:50!")); } +void tst_qqmlecmascript::deleteLaterObjectMethodCall() +{ + QQmlComponent component(&engine, testFileUrl("deleteLaterObjectMethodCall.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); +} + void tst_qqmlecmascript::automaticSemicolon() { QQmlComponent component(&engine, testFileUrl("automaticSemicolon.qml")); |