aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index e5661bd883..97fe099999 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -283,6 +283,7 @@ private slots:
void fallbackBindings();
void propertyOverride();
void concatenatedStringPropertyAccess();
+ void jsOwnedObjectsDeletedOnEngineDestroy();
private:
static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7294,6 +7295,38 @@ void tst_qqmlecmascript::concatenatedStringPropertyAccess()
delete object;
}
+void tst_qqmlecmascript::jsOwnedObjectsDeletedOnEngineDestroy()
+{
+ QQmlEngine *myEngine = new QQmlEngine;
+
+ MyDeleteObject deleteObject;
+ deleteObject.setObjectName("deleteObject");
+ QObject * const object1 = new QObject;
+ QObject * const object2 = new QObject;
+ object1->setObjectName("object1");
+ object2->setObjectName("object2");
+ deleteObject.setObject1(object1);
+ deleteObject.setObject2(object2);
+
+ // Objects returned by function calls get marked as destructible, but objects returned by
+ // property getters do not - therefore we explicitly set the object as destructible.
+ QQmlEngine::setObjectOwnership(object2, QQmlEngine::JavaScriptOwnership);
+
+ myEngine->rootContext()->setContextProperty("deleteObject", &deleteObject);
+ QQmlComponent component(myEngine, testFileUrl("jsOwnedObjectsDeletedOnEngineDestroy.qml"));
+ QObject *object = component.create();
+ QVERIFY(object);
+
+ // Destroying the engine should delete all JS owned QObjects
+ QSignalSpy spy1(object1, SIGNAL(destroyed()));
+ QSignalSpy spy2(object2, SIGNAL(destroyed()));
+ delete myEngine;
+ QCOMPARE(spy1.count(), 1);
+ QCOMPARE(spy2.count(), 1);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"