diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-16 10:57:25 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-17 11:06:12 +0000 |
commit | f43c1d902d908c6cd523b0174338ac0c98a30647 (patch) | |
tree | 50fa2c720dd86aa073efcb935e22bb967e01b5de /tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | |
parent | 29275ef53ec8e1edb7aad66af94058786c7d1e2f (diff) |
Add support for importing ES modules in .qml files
This is a straight-forward hook into the module implementation in
QV4::ExecutionEngine. Modules are pre-compiled in the QML type loader
thread. That thread keeps track of all pending loading scripts through
the type loader's m_scriptCache. Once a module is compiled, it's
thread-safely registered with the execution engine.
Script instantiation and evaluation is done solely in the QQmlEngine's
thread.
ES Modules are identified in imports as well as qmldir files by the .mjs
extension.
Change-Id: Ie9c59785118afcb49f43a1e176a9f7db00f09428
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp')
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index f98233f153..97727c1794 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -39,6 +39,7 @@ #include <QQmlFileSelector> #include <QFileSelector> #include <QEasingCurve> +#include <QScopeGuard> #include <private/qqmlproperty_p.h> #include <private/qqmlmetatype_p.h> @@ -182,6 +183,8 @@ private slots: void importIncorrectCase(); void importJs_data(); void importJs(); + void importJsModule_data(); + void importJsModule(); void explicitSelfImport(); void importInternalType(); @@ -3125,6 +3128,36 @@ void tst_qqmllanguage::importJs() engine.setImportPathList(defaultImportPathList); } +void tst_qqmllanguage::importJsModule_data() +{ + QTest::addColumn<QString>("file"); + + QTest::newRow("plainImport") + << "importJsModule.1.qml"; + + QTest::newRow("ImportQmlStyle") + << "importJsModule.2.qml"; + + QTest::newRow("plainImportWithCycle") + << "importJsModule.3.qml"; +} + +void tst_qqmllanguage::importJsModule() +{ + QFETCH(QString, file); + + engine.setImportPathList(QStringList(defaultImportPathList) << testFile("lib")); + auto importPathGuard = qScopeGuard([this]{ + engine.setImportPathList(defaultImportPathList); + }); + + QQmlComponent component(&engine, testFileUrl(file)); + QVERIFY2(!component.isError(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + QVERIFY(object != nullptr); + QCOMPARE(object->property("test").toBool(),true); +} + void tst_qqmllanguage::explicitSelfImport() { engine.setImportPathList(QStringList(defaultImportPathList) << testFile("lib")); |