diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-02-04 15:46:48 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-05 19:48:26 +0100 |
commit | 37019a96db01b99a76b67b9e655bc457e8edb5a1 (patch) | |
tree | a8979cda9124b77ad28211750612e2b31f4ad344 | |
parent | 1845ae01929cdaf6aa50ae096fe5c249f14b1f18 (diff) |
[new compiler] Fix propagation of imported scripts for anonymous components
We must take the imported scripts from the creation context. Fixes various
errors in Qt Quick Controls.
Change-Id: I336d8ffa0537cefd4eeac15f98bbf1b0a5c784af
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 9 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator_p.h | 3 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/jsimport/creationContext.qml | 24 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 15 |
6 files changed, 49 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 898a00a9bb..bf87a9dd2d 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -862,7 +862,7 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context) enginePriv->referenceScarceResources(); QObject *rv = 0; if (enginePriv->useNewCompiler) { - state.creator = new QmlObjectCreator(context, cc); + state.creator = new QmlObjectCreator(context, cc, creationContext); rv = state.creator->create(start); if (!rv) state.errors = state.creator->errors; @@ -1057,7 +1057,7 @@ void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, p->compiledData = d->cc; p->compiledData->addref(); if (enginePriv->useNewCompiler) { - p->creator.reset(new QmlObjectCreator(contextData, d->cc)); + p->creator.reset(new QmlObjectCreator(contextData, d->cc, d->creationContext)); p->subComponentToCreate = d->start; } else p->vme.init(contextData, d->cc, d->start, d->creationContext); diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index e2f1212e84..933242ba72 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -80,13 +80,14 @@ static void removeBindingOnProperty(QObject *o, int index) if (binding) binding->destroy(); } -QmlObjectCreator::QmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledData *compiledData, QQmlContextData *rootContext) +QmlObjectCreator::QmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledData *compiledData, QQmlContextData *creationContext, QQmlContextData *rootContext) : componentAttached(0) , url(compiledData->url) , engine(parentContext->engine) , qmlUnit(compiledData->qmlUnit) , jsUnit(compiledData->compilationUnit) , parentContext(parentContext) + , creationContext(creationContext) , context(0) , resolvedTypes(compiledData->resolvedTypes) , propertyCaches(compiledData->propertyCaches) @@ -153,8 +154,8 @@ QObject *QmlObjectCreator::create(int subComponentIndex, QObject *parent) QQmlScriptData *s = compiledData->scripts.at(i); scripts->putIndexed(i, s->scriptValueForContext(context)); } - } else if (parentContext) { - context->importedScripts = parentContext->importedScripts; + } else if (creationContext) { + context->importedScripts = creationContext->importedScripts; } QVector<QQmlParserStatus*> parserStatusCallbacks; @@ -942,7 +943,7 @@ QObject *QmlObjectCreator::createInstance(int index, QObject *parent) recordError(obj->location, tr("Composite Singleton Type %1 is not creatable").arg(stringAt(obj->inheritedTypeNameIndex))); return 0; } - QmlObjectCreator subCreator(context, typeRef->component, rootContext); + QmlObjectCreator subCreator(context, typeRef->component, creationContext, rootContext); instance = subCreator.create(); if (!instance) { errors += subCreator.errors; diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 424d2e55cd..e5fe4e3b81 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -57,7 +57,7 @@ class QmlObjectCreator { Q_DECLARE_TR_FUNCTIONS(QmlObjectCreator) public: - QmlObjectCreator(QQmlContextData *contextData, QQmlCompiledData *compiledData, QQmlContextData *rootContext = 0); + QmlObjectCreator(QQmlContextData *contextData, QQmlCompiledData *compiledData, QQmlContextData *creationContext, QQmlContextData *rootContext = 0); QObject *create(int subComponentIndex = -1, QObject *parent = 0); QQmlContextData *finalize(); @@ -85,6 +85,7 @@ private: const QV4::CompiledData::QmlUnit *qmlUnit; const QV4::CompiledData::CompilationUnit *jsUnit; QQmlContextData *parentContext; + QQmlContextData *creationContext; QQmlContextData *context; const QHash<int, QQmlCompiledData::TypeReference*> resolvedTypes; const QVector<QQmlPropertyCache *> propertyCaches; diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 5dbccefbde..5f0d26725c 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1873,7 +1873,7 @@ void QQmlDelegateModelItem::incubateObject( incubatorPriv->compiledData = componentPriv->cc; incubatorPriv->compiledData->addref(); if (enginePriv->useNewCompiler) { - incubatorPriv->creator.reset(new QmlObjectCreator(context, componentPriv->cc)); + incubatorPriv->creator.reset(new QmlObjectCreator(context, componentPriv->cc, componentPriv->creationContext)); incubatorPriv->subComponentToCreate = componentPriv->start; } else { incubatorPriv->vme.init( diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/creationContext.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/creationContext.qml new file mode 100644 index 0000000000..c4d0c7284c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/creationContext.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 +import "importFour.js" as SomeScript + +Item { + id: root + property bool success: false; + Component { + id: testComponent + Item { + property string valueFromScript: SomeScript.greetingString() + } + } + property Loader loader; + signal loaded + onLoaded: { + success = (loader.item.valueFromScript === SomeScript.greetingString()) + } + Component.onCompleted: { + loader = Qt.createQmlObject("import QtQuick 2.0; Loader {}", this, "dynamic loader") + loader.onLoaded.connect(loaded) + loader.sourceComponent = testComponent + } +} + diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index f9f3ac2d4c..6163628ab5 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -169,6 +169,7 @@ private slots: void singletonTypeResolution(); void importScripts_data(); void importScripts(); + void importCreationContext(); void scarceResources(); void scarceResources_data(); void scarceResources_other(); @@ -4210,6 +4211,20 @@ void tst_qqmlecmascript::importScripts() engine.setImportPathList(importPathList); } +void tst_qqmlecmascript::importCreationContext() +{ + QQmlComponent component(&engine, testFileUrl("jsimport/creationContext.qml")); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + bool success = object->property("success").toBool(); + if (!success) { + QSignalSpy readySpy(object.data(), SIGNAL(loaded())); + readySpy.wait(); + } + success = object->property("success").toBool(); + QVERIFY(success); +} + void tst_qqmlecmascript::scarceResources_other() { /* These tests require knowledge of state, since we test values after |