diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-04-27 16:12:09 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-04 03:41:33 +0200 |
commit | c31026c9ca7ff0c745dba577f9ac2c14d1ef68c5 (patch) | |
tree | dd3150dd95af2fa9759852d61d9c87b86322852a /src/qml/qml/qqmlcontext.cpp | |
parent | 6318560eca7e3247a63620ce24d2d7e291dd5d84 (diff) |
Emit Component.onDestruction before context is invalidated
When a component no longer has any live references, emit the
destruction signal immediately so that handlers are run before the
associated V8 resources are invalidated. Also, when the root
context of the engine is destroyed, emit the destruction signal
before destroying any resources needed to process the resulting
binding invocations.
Change-Id: I722dd6e4b60c499b533fc45e33b61e95bca6187f
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlcontext.cpp')
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index cbb8430f40..7e15993a65 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -513,7 +513,8 @@ QObject *QQmlContextPrivate::context_at(QQmlListProperty<QObject> *prop, int ind QQmlContextData::QQmlContextData() : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), - isPragmaLibraryContext(false), unresolvedNames(false), publicContext(0), activeVMEData(0), + isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), + publicContext(0), activeVMEData(0), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0), componentAttached(0), v4bindings(0), v8bindings(0) @@ -522,25 +523,45 @@ QQmlContextData::QQmlContextData() QQmlContextData::QQmlContextData(QQmlContext *ctxt) : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), - isPragmaLibraryContext(false), unresolvedNames(false), publicContext(ctxt), activeVMEData(0), + isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), + publicContext(ctxt), activeVMEData(0), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0), componentAttached(0), v4bindings(0), v8bindings(0) { } -void QQmlContextData::invalidate() +void QQmlContextData::emitDestruction() { - while (componentAttached) { - QQmlComponentAttached *a = componentAttached; - componentAttached = a->next; - if (componentAttached) componentAttached->prev = &componentAttached; + if (!hasEmittedDestruction) { + hasEmittedDestruction = true; + + // Emit the destruction signal - must be emitted before invalidate so that the + // context is still valid if bindings or resultant expression evaluation requires it + if (engine) { + while (componentAttached) { + QQmlComponentAttached *a = componentAttached; + componentAttached = a->next; + if (componentAttached) componentAttached->prev = &componentAttached; - a->next = 0; - a->prev = 0; + a->next = 0; + a->prev = 0; + + emit a->destruction(); + } - emit a->destruction(); + QQmlContextData * child = childContexts; + while (child) { + child->emitDestruction(); + child = child->nextChild; + } + } } +} + +void QQmlContextData::invalidate() +{ + emitDestruction(); while (childContexts) { if (childContexts->ownedByParent) { @@ -563,18 +584,7 @@ void QQmlContextData::invalidate() void QQmlContextData::clearContext() { - if (engine) { - while (componentAttached) { - QQmlComponentAttached *a = componentAttached; - componentAttached = a->next; - if (componentAttached) componentAttached->prev = &componentAttached; - - a->next = 0; - a->prev = 0; - - emit a->destruction(); - } - } + emitDestruction(); QQmlAbstractExpression *expression = expressions; while (expression) { |