aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-03-14 12:00:40 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-30 04:37:59 +0200
commit47eb68ab0b8d9ffd357cbad2f74b63ee2cf00dad (patch)
tree5159737869c7b8981003ed519b8cd8541799728e /src/qml/qml/v8
parent7f8c243dec987018db47547c6ddea9cd8272e02a (diff)
Ensure that variant property references keep QObjects alive
Previously, only var property references could keep QObjects alive. This meant that the garbage collector would collect QObject data prematurely. This commit ensures that variant properties keep QObjects alive as required. Task-number: QTBUG-24767 Change-Id: Ic98a06863251a3e7d6384ba9256810a78fb23406 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r--src/qml/qml/v8/qv8engine.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 85a2f1b379..732a04d437 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -836,7 +836,7 @@ v8::Persistent<v8::Object> *QV8Engine::findOwnerAndStrength(QObject *object, boo
void QV8Engine::addRelationshipForGC(QObject *object, v8::Persistent<v8::Value> handle)
{
- if (handle.IsEmpty())
+ if (!object || handle.IsEmpty())
return;
bool handleShouldBeStrong = false;
@@ -850,14 +850,18 @@ void QV8Engine::addRelationshipForGC(QObject *object, v8::Persistent<v8::Value>
void QV8Engine::addRelationshipForGC(QObject *object, QObject *other)
{
+ if (!object || !other)
+ return;
+
bool handleShouldBeStrong = false;
v8::Persistent<v8::Object> *implicitOwner = findOwnerAndStrength(object, &handleShouldBeStrong);
v8::Persistent<v8::Value> handle = QQmlData::get(other, true)->v8object;
- if (handleShouldBeStrong) {
+ if (handle.IsEmpty()) // no JS data to keep alive.
+ return;
+ else if (handleShouldBeStrong)
v8::V8::AddImplicitReferences(m_strongReferencer, &handle, 1);
- } else if (!implicitOwner->IsEmpty()) {
+ else if (!implicitOwner->IsEmpty())
v8::V8::AddImplicitReferences(*implicitOwner, &handle, 1);
- }
}
static QThreadStorage<QV8Engine::ThreadData*> perThreadEngineData;