Fix ownership of JS value returned by QJSEngine::newQObject
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 13 Jun 2013 15:10:35 +0000 (17:10 +0200)
committerLars Knoll <lars.knoll@digia.com>
Thu, 13 Jun 2013 15:51:14 +0000 (17:51 +0200)
As documented, the ownership should be JavaScriptOwned, which means:
Keep the QObject alive if there's a parent or some other JS object is
referencing it.

Fixes three QJSEngine auto-tests

Change-Id: I75503273b34e78355b08526da591b8d307a1c6e6
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v8/qjsengine.cpp

index d072c3a..9a3b7f2 100644 (file)
@@ -65,6 +65,7 @@
 #include <qmutex.h>
 #include <qwaitcondition.h>
 #include <private/qqmlglobal_p.h>
+#include <qqmlengine.h>
 
 #undef Q_D
 #undef Q_Q
@@ -319,6 +320,7 @@ QJSValue QJSEngine::newQObject(QObject *object)
 {
     Q_D(QJSEngine);
     QV4::ExecutionEngine *v4 = QV8Engine::getV4(d);
+    QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership);
     return new QJSValuePrivate(v4, QV4::QObjectWrapper::wrap(v4, object));
 }