From da79a51d955d701b458b410b80c2a7585f1333be Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 29 May 2013 12:18:31 +0200 Subject: Fix failing tst_qqmlecmascript::deleteRootObjectDuringCreation unit test Respect the rootObjectInCreation flag in QQmlData. Centralize the checking code for that through the places in the engine where it is checked, along with the indestructible flag. Change-Id: Ie977b34ac8d070f6dcd7bab11a95dd27ca25145e Reviewed-by: Lars Knoll --- src/qml/qml/qqmldata_p.h | 7 +++++++ src/qml/qml/v4/qv4mm.cpp | 4 ++-- src/qml/qml/v8/qv8qobjectwrapper.cpp | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h index 98407e53b5..568a43e36e 100644 --- a/src/qml/qml/qqmldata_p.h +++ b/src/qml/qml/qqmldata_p.h @@ -200,6 +200,13 @@ public: } } + static bool keepAliveDuringGarbageCollection(const QObject *object) { + QQmlData *ddata = get(object); + if (!ddata || ddata->indestructible || ddata->rootObjectInCreation) + return true; + return false; + } + bool hasExtendedData() const { return extendedData != 0; } QHash *attachedProperties() const; diff --git a/src/qml/qml/v4/qv4mm.cpp b/src/qml/qml/v4/qv4mm.cpp index aca838a515..fcc660e3db 100644 --- a/src/qml/qml/v4/qv4mm.cpp +++ b/src/qml/qml/v4/qv4mm.cpp @@ -303,14 +303,14 @@ void MemoryManager::mark() QObject *qobject = qobjectWrapper->object; if (!qobject) continue; - bool keepAlive = QQmlEngine::objectOwnership(qobject) == QQmlEngine::CppOwnership; + bool keepAlive = QQmlData::keepAliveDuringGarbageCollection(qobject); if (!keepAlive) { if (QObject *parent = qobject->parent()) { while (parent->parent()) parent = parent->parent(); - keepAlive = QQmlEngine::objectOwnership(parent) == QQmlEngine::CppOwnership; + keepAlive = QQmlData::keepAliveDuringGarbageCollection(parent); } } diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index fdf07389c2..8c884c492d 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -1964,8 +1964,7 @@ QV4::Value QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, Value *args { if (!m_object) return QV4::Value::undefinedValue(); - QQmlData *ddata = QQmlData::get(m_object, false); - if (!ddata || ddata->indestructible || ddata->rootObjectInCreation) + if (QQmlData::keepAliveDuringGarbageCollection(m_object)) ctx->throwError(QStringLiteral("Invalid attempt to destroy() an indestructible object")); int delay = 0; -- cgit v1.2.3