aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4qmlcontext.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/jsruntime/qv4qmlcontext.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/jsruntime/qv4qmlcontext.cpp')
-rw-r--r--src/qml/jsruntime/qv4qmlcontext.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp
index cc0b0feeee..88b0822f42 100644
--- a/src/qml/jsruntime/qv4qmlcontext.cpp
+++ b/src/qml/jsruntime/qv4qmlcontext.cpp
@@ -54,6 +54,7 @@
#include <private/qqmljavascriptexpression_p.h>
#include <private/qjsvalue_p.h>
#include <private/qv4qobjectwrapper_p.h>
+#include <private/qv4module_p.h>
QT_BEGIN_NAMESPACE
@@ -87,8 +88,20 @@ ReturnedValue QQmlContextWrapper::virtualGet(const Managed *m, PropertyKey id, c
QV4::ExecutionEngine *v4 = resource->engine();
QV4::Scope scope(v4);
- if (v4->callingQmlContext() != *resource->d()->context)
+ if (v4->callingQmlContext() != *resource->d()->context) {
+ if (resource->d()->module) {
+ Scoped<Module> module(scope, resource->d()->module);
+ bool hasProp = false;
+ ScopedValue value(scope, module->get(id, receiver, &hasProp));
+ if (hasProp) {
+ if (hasProperty)
+ *hasProperty = hasProp;
+ return value->asReturnedValue();
+ }
+ }
+
return Object::virtualGet(m, id, receiver, hasProperty);
+ }
bool hasProp = false;
ScopedValue result(scope, Object::virtualGet(m, id, receiver, &hasProp));