aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-03-22 14:03:26 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2019-03-25 10:26:11 +0000
commit516523750dbae4fdabed5b09281fdb2da843941e (patch)
treee12c6b22dc7c5b0b347a082d36af45b2ee3b5e47
parent42ed40cf0abd0155d6e6d1ef01faf9bded065588 (diff)
Enable lookups for imported scripts and worker scripts
This is straight-forward to enable, with the minor adjustment that we need to handle the case where a global lookup is done without a calling qml context (worker script). We don't know at compile time whether a script will be imported directly or used as a worker script, so we have to generate the global qml lookup instruction regardless and handle it at run-time. Change-Id: Ia033afa214d919d906c676498dd3eceb1c5639d8 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/compiler/qv4compilercontext.cpp2
-rw-r--r--src/qml/jsruntime/qv4qmlcontext.cpp19
-rw-r--r--src/qml/jsruntime/qv4script.cpp1
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp1
4 files changed, 17 insertions, 6 deletions
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp
index 84c5d67e8d..d1a5fee92b 100644
--- a/src/qml/compiler/qv4compilercontext.cpp
+++ b/src/qml/compiler/qv4compilercontext.cpp
@@ -190,7 +190,7 @@ Context::ResolvedName Context::resolveName(const QString &name, const QQmlJS::AS
if (c->contextType == ContextType::Eval)
return result;
- if (c->contextType == ContextType::Binding)
+ if (c->contextType == ContextType::Binding || c->contextType == ContextType::ScriptImportedByQML)
result.type = ResolvedName::QmlGlobal;
else
result.type = ResolvedName::Global;
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp
index a2c8e3916f..12ada7ee70 100644
--- a/src/qml/jsruntime/qv4qmlcontext.cpp
+++ b/src/qml/jsruntime/qv4qmlcontext.cpp
@@ -465,10 +465,23 @@ ReturnedValue QQmlContextWrapper::resolveQmlContextPropertyLookupGetter(Lookup *
return static_cast<Heap::CallContext*>(ctx.d())->locals[index].asReturnedValue();
}
- Scoped<QQmlContextWrapper> qmlContext(scope, engine->qmlContext()->qml());
bool hasProperty = false;
- ScopedValue result(scope, QQmlContextWrapper::getPropertyAndBase(qmlContext, name, /*receiver*/nullptr,
- &hasProperty, base, l));
+ ScopedValue result(scope);
+
+ Scoped<QmlContext> callingQmlContext(scope, engine->qmlContext());
+ if (callingQmlContext) {
+ Scoped<QQmlContextWrapper> qmlContextWrapper(scope, callingQmlContext->d()->qml());
+ result = QQmlContextWrapper::getPropertyAndBase(qmlContextWrapper, name, /*receiver*/nullptr, &hasProperty,
+ base, l);
+ } else {
+ // Code path typical to worker scripts, compiled with lookups but no qml context.
+ result = l->resolveGlobalGetter(engine);
+ if (l->globalGetter != Lookup::globalGetterGeneric) {
+ hasProperty = true;
+ l->qmlContextGlobalLookup.getterTrampoline = l->globalGetter;
+ l->qmlContextPropertyGetter = QQmlContextWrapper::lookupInGlobalObject;
+ }
+ }
if (!hasProperty)
return engine->throwReferenceError(name.toQString());
return result->asReturnedValue();
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 7bbef3335e..6cb2e95cdc 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -201,7 +201,6 @@ QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile(QV4::Compi
}
Codegen cg(unitGenerator, /*strict mode*/false);
- cg.setUseFastLookups(false);
cg.generateFromProgram(fileName, finalUrl, source, program, module, contextType);
errors = cg.qmlErrors();
if (!errors.isEmpty()) {
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index d6fae446a1..b6b80a4461 100644
--- a/tools/qmlcachegen/qmlcachegen.cpp
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -301,7 +301,6 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile
QmlIR::JSCodeGen v4CodeGen(irDocument.code, &irDocument.jsGenerator,
&irDocument.jsModule, &irDocument.jsParserEngine,
irDocument.program, &irDocument.jsGenerator.stringTable, illegalNames);
- v4CodeGen.setUseFastLookups(false); // Disable lookups in non-standalone (aka QML) mode
v4CodeGen.generateFromProgram(inputFileName, inputFileUrl, sourceCode, program,
&irDocument.jsModule, QV4::Compiler::ContextType::ScriptImportedByQML);
QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();