aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compileddata.cpp
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-10-12 16:56:14 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2018-11-02 16:44:11 +0000
commit627226520a2bbb977ce32a21bdffd2004cb28796 (patch)
treee3989c73887505a179e875baf2984be10fcbdda8 /src/qml/compiler/qv4compileddata.cpp
parentf20839aed0f2e4fe9134a239adda4853d7bd204a (diff)
Expose let/const variables from imported JS scripts
This patch allows QML to access let/const variables defined in JS files. Detailed changes: - The recently added ContextType::ScriptImportedByQML is changed to avoid creating Push/PopScriptContext instructions, similar to ContextType::ESModule. - QV4::Module is changed to also work with CompilationUnits which are not ESModules. In this case QV4::Module will behave as if all lexically scoped variables were exported. - CompilationUnit is changed to support instantiating and evaluating QV4::Modules for non-ESModules as well. - QQmlTypeLoader is changed to always create QV4::Modules for evaluating scripts. For the non-ESModule case, the QV4::Module is evaluated inside a QV4::QmlContext, as before. - A pointer to the QV4::Module is added to QV4::QQmlContextWrapper, and used in virtualGet to access the let/const variables in the CallContext. Access is read-only. Fixes: QTBUG-69408 Change-Id: I6f299363fdf5e1c5a4a0f1d9e655b4dc5112dd00 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compileddata.cpp')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 244e762faf..39f48f67f8 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -381,13 +381,20 @@ QStringList CompilationUnit::moduleRequests() const
Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
{
- if (m_module)
+ if (isESModule() && m_module)
return m_module;
+ if (data->indexOfRootFunction < 0)
+ return nullptr;
+
if (!this->engine)
linkToEngine(engine);
- m_module = engine->memoryManager->allocate<Module>(engine, this);
+ Scope scope(engine);
+ Scoped<Module> module(scope, engine->memoryManager->allocate<Module>(engine, this));
+
+ if (isESModule())
+ m_module = module->d();
for (const QString &request: moduleRequests()) {
auto dependentModuleUnit = engine->loadModule(QUrl(request), this);
@@ -396,7 +403,6 @@ Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
dependentModuleUnit->instantiate(engine);
}
- Scope scope(engine);
ScopedString importName(scope);
const uint importCount = data->importEntryTableSize;
@@ -431,7 +437,7 @@ Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
}
}
- return m_module;
+ return module->d();
}
const Value *CompilationUnit::resolveExport(QV4::String *exportName)
@@ -556,10 +562,13 @@ void CompilationUnit::getExportedNamesRecursively(QStringList *names, QVector<co
void CompilationUnit::evaluate()
{
- if (m_moduleEvaluated)
- return;
- m_moduleEvaluated = true;
+ QV4::Scope scope(engine);
+ QV4::Scoped<Module> module(scope, m_module);
+ module->evaluate();
+}
+void CompilationUnit::evaluateModuleRequests()
+{
for (const QString &request: moduleRequests()) {
auto dependentModuleUnit = engine->loadModule(QUrl(request), this);
if (engine->hasException)
@@ -568,19 +577,6 @@ void CompilationUnit::evaluate()
if (engine->hasException)
return;
}
-
- QV4::Function *moduleFunction = runtimeFunctions[data->indexOfRootFunction];
- CppStackFrame frame;
- frame.init(engine, moduleFunction, nullptr, 0);
- frame.setupJSFrame(engine->jsStackTop, Value::undefinedValue(), m_module->scope,
- Value::undefinedValue(), Value::undefinedValue());
-
- frame.push();
- engine->jsStackTop += frame.requiredJSStackFrameSize();
- auto frameCleanup = qScopeGuard([&frame]() {
- frame.pop();
- });
- Moth::VME::exec(&frame, engine);
}
bool CompilationUnit::loadFromDisk(const QUrl &url, const QDateTime &sourceTimeStamp, QString *errorString)