From 627226520a2bbb977ce32a21bdffd2004cb28796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 12 Oct 2018 16:56:14 +0200 Subject: 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 --- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 2f110ed5a5..71c4e03812 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -8822,10 +8822,10 @@ void tst_qqmlecmascript::importLexicalVariables_data() QTest::newRow("script") << testFileUrl("importLexicalVariables_script.qml") - << QStringLiteral("0?? 1?? 2??"); + << QStringLiteral("000 100 210"); QTest::newRow("pragmaLibrary") << testFileUrl("importLexicalVariables_pragmaLibrary.qml") - << QStringLiteral("0?? 1?? 2??"); + << QStringLiteral("000 100 210"); QTest::newRow("module") << testFileUrl("importLexicalVariables_module.qml") << QStringLiteral("000 000 110"); -- cgit v1.2.3