From 4c953b1592956b712eca60eec070868a567c04c1 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 20 Sep 2013 12:09:04 +0200 Subject: [PATCH] [new compiler] Fix scope object for binding expressions in signal handlers of attached objects In populateInstance the QObject instance to populate with properties, etc. may not necessarily be the scope object (in qml lookup terms), so it needs to be provided as a separate parameter. Change-Id: I05db123c249e8582469bcfb76f56eb3f7bfbc4a2 Reviewed-by: Lars Knoll --- src/qml/qml/qqmlobjectcreator.cpp | 13 ++++++++----- src/qml/qml/qqmlobjectcreator_p.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 7b539b3..4e6c82c 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -970,7 +970,7 @@ bool QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, int bindingI const int id = attachedType->attachedPropertiesId(); QObject *qmlObject = qmlAttachedPropertiesObjectById(id, _qobject); QQmlRefPointer cache = QQmlEnginePrivate::get(engine)->cache(qmlObject); - if (!populateInstance(binding->value.objectIndex, qmlObject, cache)) + if (!populateInstance(binding->value.objectIndex, qmlObject, cache, _qobject)) return false; return true; } @@ -1002,7 +1002,7 @@ bool QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, int bindingI valueType->read(_qobject, property->coreIndex); QQmlRefPointer cache = QQmlEnginePrivate::get(engine)->cache(valueType); - if (!populateInstance(binding->value.objectIndex, valueType, cache)) + if (!populateInstance(binding->value.objectIndex, valueType, cache, _qobject)) return false; valueType->write(_qobject, property->coreIndex, QQmlPropertyPrivate::BypassInterceptor); @@ -1187,7 +1187,7 @@ QObject *QmlObjectCreator::createInstance(int index, QObject *parent) QQmlRefPointer cache = propertyCaches.value(index); Q_ASSERT(!cache.isNull()); - if (!populateInstance(index, instance, cache)) + if (!populateInstance(index, instance, cache, _qobject)) return 0; } @@ -1239,10 +1239,13 @@ void QmlObjectCreator::finalize() } } -bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPointer cache) +bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPointer cache, QObject *scopeObjectForJavaScript) { const QV4::CompiledData::Object *obj = qmlUnit->objectAt(index); + if (!scopeObjectForJavaScript) + scopeObjectForJavaScript = instance; + QQmlData *declarativeData = QQmlData::get(instance, /*create*/true); qSwap(_propertyCache, cache); @@ -1273,7 +1276,7 @@ bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPoi QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); QV4::Scope valueScope(v4); - QV4::ScopedValue scopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _qobject)); + QV4::ScopedValue scopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, scopeObjectForJavaScript)); QV4::QmlBindingWrapper *qmlBindingWrapper = new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, scopeObject->asObject()); QV4::ScopedValue qmlScopeFunction(valueScope, QV4::Value::fromObject(qmlBindingWrapper)); QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context(); diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 78e33cc..4b29295 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -118,7 +118,7 @@ public: private: QObject *createInstance(int index, QObject *parent = 0); - bool populateInstance(int index, QObject *instance, QQmlRefPointer cache); + bool populateInstance(int index, QObject *instance, QQmlRefPointer cache, QObject *scopeObjectForJavaScript); void setupBindings(); bool setPropertyValue(QQmlPropertyData *property, int index, const QV4::CompiledData::Binding *binding); -- 2.7.4