diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-03-04 20:48:11 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-05 15:01:07 +0100 |
commit | c8889fbb5561d75a7a383b86daa89c1b264c6f6e (patch) | |
tree | 4393600dc118c8fa9bbd3b518d23ca12d75f67e9 /src/qml/qml/qqmlobjectcreator.cpp | |
parent | e4e4a7912b03499a20f25e261e1c515aab17e5a8 (diff) |
[new compiler] Add support for deferred properties
Change-Id: I592518444ef353cfcf153df0e6afa2fbac613560
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlobjectcreator.cpp')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 6ec8c2bea4..abca36c6aa 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -237,6 +237,59 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI return instance; } +bool QQmlObjectCreator::populateDeferredProperties(QObject *instance) +{ + QQmlData *declarativeData = QQmlData::get(instance); + context = declarativeData->deferredData->context; + const int objectIndex = declarativeData->deferredData->deferredIdx; + + const QV4::CompiledData::Object *obj = qmlUnit->objectAt(objectIndex); + QObject *bindingTarget = instance; + + QQmlRefPointer<QQmlPropertyCache> cache = declarativeData->propertyCache; + QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance); + + QObject *scopeObject = instance; + qSwap(_scopeObject, scopeObject); + + QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); + QV4::Scope valueScope(v4); + QV4::ScopedValue scopeObjectProtector(valueScope, declarativeData->jsWrapper.value()); + Q_UNUSED(scopeObjectProtector); + QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _scopeObject)); + QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, qmlScope)); + QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context(); + + qSwap(_qmlContext, qmlContext); + + qSwap(_propertyCache, cache); + qSwap(_qobject, instance); + qSwap(_compiledObject, obj); + qSwap(_ddata, declarativeData); + qSwap(_bindingTarget, bindingTarget); + qSwap(_vmeMetaObject, vmeMetaObject); + + QBitArray bindingSkipList = compiledData->deferredBindingsPerObject.value(objectIndex); + for (int i = 0; i < bindingSkipList.count(); ++i) + bindingSkipList.setBit(i, !bindingSkipList.testBit(i)); + + setupBindings(bindingSkipList); + + qSwap(_vmeMetaObject, vmeMetaObject); + qSwap(_bindingTarget, bindingTarget); + qSwap(_ddata, declarativeData); + qSwap(_compiledObject, obj); + qSwap(_qobject, instance); + qSwap(_propertyCache, cache); + + qSwap(_qmlContext, qmlContext); + qSwap(_scopeObject, scopeObject); + + phase = ObjectsCreated; + + return errors.isEmpty(); +} + void QQmlObjectCreator::setPropertyValue(QQmlPropertyData *property, const QV4::CompiledData::Binding *binding) { QQmlPropertyPrivate::WriteFlags propertyWriteFlags = QQmlPropertyPrivate::BypassInterceptor | @@ -1009,7 +1062,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent) customParser = type->customParser(); - if (sharedState->rootContext->isRootObjectInCreation) { + if (sharedState->rootContext && sharedState->rootContext->isRootObjectInCreation) { QQmlData *ddata = QQmlData::get(instance, /*create*/true); ddata->rootObjectInCreation = true; sharedState->rootContext->isRootObjectInCreation = false; @@ -1243,8 +1296,27 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPo QVector<QQmlAbstractBinding*> createdBindings(_compiledObject->nBindings, 0); + QBitArray bindingSkipList = bindingsToSkip; + { + QHash<int, QBitArray>::ConstIterator deferredBindings = compiledData->deferredBindingsPerObject.find(index); + if (deferredBindings != compiledData->deferredBindingsPerObject.constEnd()) { + if (bindingSkipList.isEmpty()) + bindingSkipList.resize(deferredBindings->count()); + + for (int i = 0; i < deferredBindings->count(); ++i) + if (deferredBindings->testBit(i)) + bindingSkipList.setBit(i); + QQmlData::DeferredData *deferData = new QQmlData::DeferredData; + deferData->deferredIdx = index; + deferData->compiledData = compiledData; + deferData->compiledData->addref(); + deferData->context = context; + _ddata->deferredData = deferData; + } + } + setupFunctions(); - setupBindings(bindingsToSkip); + setupBindings(bindingSkipList); qSwap(_vmeMetaObject, vmeMetaObject); qSwap(_bindingTarget, bindingTarget); |