diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-09-20 10:48:33 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-09-23 20:27:40 +0000 |
commit | 6146021eb72a0aca5cc635b577b5e43b60824bc8 (patch) | |
tree | bbca3e8d57d763692a5418f19a587c2a01baf4d9 /tests/auto/qml/qjsengine | |
parent | a97d118bf55e1c44ded9bbcd143b0f0725db8268 (diff) |
Fix use of lexically scoped variables in modules
Their use may trigger setting c->requiresExecutionContext on the module
context, which is correct. However, unlike functions, modules at
instantiation time always have their context created ahead of time (to
populate imports). Therefore we must not emit call context creating byte
code instructions where we'd end up storing exports in the wrong place.
Change-Id: Id1264f1cfa6a7f1cd94247ffe71938bc9c5c3ff9
Fixes: QTBUG-70632
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r-- | tests/auto/qml/qjsengine/modulewithlexicals.mjs | 9 | ||||
-rw-r--r-- | tests/auto/qml/qjsengine/qjsengine.pro | 2 | ||||
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 9 |
3 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/qml/qjsengine/modulewithlexicals.mjs b/tests/auto/qml/qjsengine/modulewithlexicals.mjs new file mode 100644 index 0000000000..c31cb5aef3 --- /dev/null +++ b/tests/auto/qml/qjsengine/modulewithlexicals.mjs @@ -0,0 +1,9 @@ +class Point { + constructor() {} +} + + +export function main() { + (new Point()); + return 10; +} diff --git a/tests/auto/qml/qjsengine/qjsengine.pro b/tests/auto/qml/qjsengine/qjsengine.pro index ea4d3ea464..1fb2d55b31 100644 --- a/tests/auto/qml/qjsengine/qjsengine.pro +++ b/tests/auto/qml/qjsengine/qjsengine.pro @@ -4,6 +4,6 @@ QT += qml qml-private widgets testlib gui-private macx:CONFIG -= app_bundle SOURCES += tst_qjsengine.cpp RESOURCES += qjsengine.qrc -RESOURCES += testmodule.mjs +RESOURCES += testmodule.mjs modulewithlexicals.mjs TESTDATA = script/* diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index f08d9a4798..92696c7e76 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -226,6 +226,7 @@ private slots: void importModule(); void importModuleRelative(); + void importModuleWithLexicallyScopedVars(); public: Q_INVOKABLE QJSValue throwingCppMethod(); @@ -4394,6 +4395,14 @@ void tst_QJSEngine::importModuleRelative() } } +void tst_QJSEngine::importModuleWithLexicallyScopedVars() +{ + QJSEngine engine; + QJSValue ns = engine.importModule(QStringLiteral(":/modulewithlexicals.mjs")); + QVERIFY2(!ns.isError(), qPrintable(ns.toString())); + QCOMPARE(ns.property("main").call().toInt(), 10); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |