aboutsummaryrefslogtreecommitdiffstats
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
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>
-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
-rw-r--r--src/qml/jsruntime/qv4script.cpp5
-rw-r--r--src/qml/jsruntime/qv4script_p.h3
-rw-r--r--src/qml/qml/qqmltypeloader.cpp2
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp2
8 files changed, 17 insertions, 13 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) {
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 070c048c8f..951675b468 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -174,7 +174,8 @@ Function *Script::function()
QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile(QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine, Compiler::JSUnitGenerator *unitGenerator,
const QString &fileName, const QString &finalUrl, const QString &source,
- QList<QQmlError> *reportedErrors)
+ QList<QQmlError> *reportedErrors,
+ QV4::Compiler::ContextType contextType)
{
using namespace QV4::Compiler;
using namespace QQmlJS::AST;
@@ -201,7 +202,7 @@ 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::Global);
+ cg.generateFromProgram(fileName, finalUrl, source, program, module, contextType);
errors = cg.qmlErrors();
if (!errors.isEmpty()) {
if (reportedErrors)
diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h
index e7189664e2..c138e4a538 100644
--- a/src/qml/jsruntime/qv4script_p.h
+++ b/src/qml/jsruntime/qv4script_p.h
@@ -103,7 +103,8 @@ struct Q_QML_EXPORT Script {
static QQmlRefPointer<CompiledData::CompilationUnit> precompile(QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine, Compiler::JSUnitGenerator *unitGenerator,
const QString &fileName, const QString &finalUrl, const QString &source,
- QList<QQmlError> *reportedErrors = nullptr);
+ QList<QQmlError> *reportedErrors = nullptr,
+ QV4::Compiler::ContextType contextType = QV4::Compiler::ContextType::Global);
static Script *createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error);
static ReturnedValue evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext);
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 0047b20346..89b023c164 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -3084,7 +3084,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data)
QList<QQmlError> errors;
unit = QV4::Script::precompile(
&irUnit.jsModule, &irUnit.jsParserEngine, &irUnit.jsGenerator, urlString(), finalUrlString(),
- source, &errors);
+ source, &errors, QV4::Compiler::ContextType::ScriptImportedByQML);
// No need to addref on unit, it's initial refcount is 1
source.clear();
if (!errors.isEmpty()) {
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index 762f6e7221..1805dde5d2 100644
--- a/tools/qmlcachegen/qmlcachegen.cpp
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -319,7 +319,7 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile
&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::Global);
+ &irDocument.jsModule, QV4::Compiler::ContextType::ScriptImportedByQML);
QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
if (!jsErrors.isEmpty()) {
error->appendDiagnostics(inputFileName, jsErrors);