From 186a38c683cbec6a2a141245d5e428d85c073b8f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 Jan 2010 13:40:16 +1000 Subject: Mark function contexts as temporary QTBUG-5690 --- src/declarative/qml/qmlbindingoptimizations.cpp | 4 +++- src/declarative/qml/qmlcontext.cpp | 4 ++-- src/declarative/qml/qmlcontext_p.h | 2 ++ src/declarative/qml/qmlengine.cpp | 5 ++++- src/declarative/qml/qmlexpression.cpp | 7 ++++++- src/declarative/qml/qmlvmemetaobject.cpp | 1 + 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/declarative/qml/qmlbindingoptimizations.cpp b/src/declarative/qml/qmlbindingoptimizations.cpp index d7105b2..868440e 100644 --- a/src/declarative/qml/qmlbindingoptimizations.cpp +++ b/src/declarative/qml/qmlbindingoptimizations.cpp @@ -145,8 +145,10 @@ void QmlOptimizedBindings::run(Binding *binding) qWarning("ERROR: Circular binding"); QmlContext *context = QmlAbstractExpression::context(); - if (!context) + if (!context) { + qWarning("QmlOptimizedBindings: Attempted to evaluate an expression in an invalid context"); return; + } QmlContextPrivate *cp = QmlContextPrivate::get(context); if (binding->property & 0xFFFF0000) { diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 4467cce..e063981 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -57,8 +57,8 @@ QT_BEGIN_NAMESPACE QmlContextPrivate::QmlContextPrivate() -: parent(0), engine(0), isInternal(false), propertyNames(0), notifyIndex(-1), - highPriorityCount(0), imports(0), expressions(0), contextObjects(0), +: parent(0), engine(0), isInternal(false), isTemporary(false), propertyNames(0), + notifyIndex(-1), highPriorityCount(0), imports(0), expressions(0), contextObjects(0), idValues(0), idValueCount(0), optimizedBindings(0) { } diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index bc8c357..cb89474 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -86,7 +86,9 @@ public: QmlContext *parent; QmlEngine *engine; + bool isInternal; + bool isTemporary; QmlIntegerCache *propertyNames; QList propertyValues; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 0e9b7c4..d5e3884 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -648,7 +648,10 @@ QmlContext *QmlEnginePrivate::getContext(QScriptContext *ctxt) QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3); Q_ASSERT(scopeNode.isValid()); Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass); - return contextClass->contextFromValue(scopeNode); + QmlContext *context = contextClass->contextFromValue(scopeNode); + while (context && QmlContextPrivate::get(context)->isTemporary) + context = context->parentContext(); + return context; } QScriptValue QmlEnginePrivate::createComponent(QScriptContext *ctxt, diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index ab9f9ea..652c5f8 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -421,7 +421,12 @@ QVariant QmlExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) Q_Q(QmlExpression); QVariant rv; - if (!q->engine() || (!data->sse.isValid() && data->expression.isEmpty())) + if (!q->engine()) { + qWarning("QmlExpression: Attempted to evaluate an expression in an invalid context"); + return rv; + } + + if (!data->sse.isValid() && data->expression.isEmpty()) return rv; #ifdef Q_ENABLE_PERFORMANCE_LOG diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index 8588eff..3b1f068 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -273,6 +273,7 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) rv = expr.value(); } else { QmlContext newCtxt(ctxt); + QmlContextPrivate::get(&newCtxt)->isTemporary = true; QMetaMethod m = method(_id); QList names = m.parameterNames(); for (int ii = 0; ii < names.count(); ++ii) -- cgit v0.12