aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-10-05 14:17:05 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2018-11-01 15:07:01 +0000
commit8b418d9be73dafd25c9c528127274a3573f1a7e1 (patch)
treef5901f8cf6e9a23caadbf5ba6fc4c3329b9823c7 /src/qml/compiler
parentfd3cf7a45ad5abf269aecc63dc164d9bd0f1b407 (diff)
Clone ContextType::Global as ContextType::ScriptImportedByQML
Add new enum value QV4::Compiler::ContextType::ScriptImportedByQML, which behaves exactly the same as ContextType::Global. A follow-up patch will change the behavior slightly. Task-number: QTBUG-69408 Change-Id: I20d27804fd1433f2229704546bcd78a0ac108c01 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r--src/qml/compiler/qv4codegen.cpp2
-rw-r--r--src/qml/compiler/qv4compilercontext.cpp9
-rw-r--r--src/qml/compiler/qv4compilercontext_p.h5
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp2
4 files changed, 10 insertions, 8 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index e55f4022d6..295ce08071 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -2992,7 +2992,7 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast,
ControlFlow *savedControlFlow = controlFlow;
controlFlow = nullptr;
- if (_context->contextType == ContextType::Global) {
+ if (_context->contextType == ContextType::Global || _context->contextType == ContextType::ScriptImportedByQML) {
_module->blocks.append(_context);
_context->blockIndex = _module->blocks.count() - 1;
}
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp
index b423dcf0b7..572f24f148 100644
--- a/src/qml/compiler/qv4compilercontext.cpp
+++ b/src/qml/compiler/qv4compilercontext.cpp
@@ -207,7 +207,7 @@ void Context::emitBlockHeader(Codegen *codegen)
blockIndex = codegen->module()->blocks.count() - 1;
}
- if (contextType == ContextType::Global) {
+ if (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML) {
Instruction::PushScriptContext scriptContext;
scriptContext.index = blockIndex;
bytecodeGenerator->addInstruction(scriptContext);
@@ -256,7 +256,7 @@ void Context::emitBlockHeader(Codegen *codegen)
r.storeConsumeAccumulator();
}
- if (contextType == ContextType::Global || (contextType == ContextType::Eval && !isStrict)) {
+ if (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML || (contextType == ContextType::Eval && !isStrict)) {
// variables in global code are properties of the global context object, not locals as with other functions.
for (Context::MemberMap::const_iterator it = members.constBegin(), cend = members.constEnd(); it != cend; ++it) {
if (it->isLexicallyScoped())
@@ -316,7 +316,7 @@ void Context::emitBlockFooter(Codegen *codegen)
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") // the loads below are empty structs.
- if (contextType == ContextType::Global)
+ if (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML)
bytecodeGenerator->addInstruction(Instruction::PopScriptContext());
else if (contextType != ContextType::ESModule)
bytecodeGenerator->addInstruction(Instruction::PopContext());
@@ -371,9 +371,10 @@ void Context::setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator)
break;
}
case ContextType::Global:
+ case ContextType::ScriptImportedByQML:
case ContextType::Eval:
for (Context::MemberMap::iterator it = members.begin(), end = members.end(); it != end; ++it) {
- if (!it->isLexicallyScoped() && (contextType == ContextType::Global || !isStrict))
+ if (!it->isLexicallyScoped() && (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML || !isStrict))
continue;
if (it->canEscape)
registerLocal(it);
diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h
index 796d5e274c..d36ef0f447 100644
--- a/src/qml/compiler/qv4compilercontext_p.h
+++ b/src/qml/compiler/qv4compilercontext_p.h
@@ -75,7 +75,8 @@ enum class ContextType {
// * return statements are allowed everywhere (like in FunctionCode)
// * variable declarations are treated as true locals (like in FunctionCode)
Block,
- ESModule
+ ESModule,
+ ScriptImportedByQML,
};
struct Context;
@@ -313,7 +314,7 @@ struct Context {
bool requiresImplicitReturnValue() const {
return contextType == ContextType::Binding ||
contextType == ContextType::Eval ||
- contextType == ContextType::Global;
+ contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML;
}
void addUsedVariable(const QString &name) {
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index 6a56b7d1a0..2026e64929 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -819,7 +819,7 @@ void ScanFunctions::calcEscapingVariables()
}
if (c->allVarsEscape && c->contextType == ContextType::Block && c->members.isEmpty())
c->allVarsEscape = false;
- if (c->contextType == ContextType::Global || (!c->isStrict && c->contextType == ContextType::Eval) || m->debugMode)
+ if (c->contextType == ContextType::Global || c->contextType == ContextType::ScriptImportedByQML || (!c->isStrict && c->contextType == ContextType::Eval) || m->debugMode)
c->allVarsEscape = true;
if (c->allVarsEscape) {
if (c->parent) {