diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-16 13:06:22 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-17 11:06:18 +0000 |
commit | 4b2b1fc12137450d34e8324c0dbe2af1e90b9e6a (patch) | |
tree | 9e397602b5f584032cdc29354c0fcf485766cce2 /tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | |
parent | 29e4b97bad6511ebd6aa009a47594395957c0e8e (diff) |
Add support for compiling ES modules ahead of time
This is also pretty straight-forward by adding .mjs as supported
extension in the qmake and cmake support.
This also tweaks qv4engine.cpp to share the same module compilation
function across all code paths.
Change-Id: Ia0e23c78a794f2330ecf8f991ee6ea948f4ac89d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp')
-rw-r--r-- | tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 17c12b87e8..6c399f6874 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -59,6 +59,7 @@ private slots: void qrcScriptImport(); void fsScriptImport(); + void moduleScriptImport(); void enums(); @@ -538,6 +539,36 @@ void tst_qmlcachegen::fsScriptImport() QCOMPARE(obj->property("value").toInt(), 42); } +void tst_qmlcachegen::moduleScriptImport() +{ + QQmlEngine engine; + CleanlyLoadingComponent component(&engine, QUrl("qrc:///jsmoduleimport.qml")); + QVERIFY2(!component.isError(), qPrintable(component.errorString())); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QTRY_VERIFY(obj->property("ok").toBool()); + + QVERIFY(QFile::exists(":/script.mjs")); + QCOMPARE(QFileInfo(":/script.mjs").size(), 0); + + { + auto componentPrivate = QQmlComponentPrivate::get(&component); + QVERIFY(componentPrivate); + auto compilationUnit = componentPrivate->compilationUnit->dependentScripts.first()->compilationUnit(); + QVERIFY(compilationUnit); + auto unitData = compilationUnit->unitData(); + QVERIFY(unitData); + QVERIFY(unitData->flags & QV4::CompiledData::Unit::StaticData); + QVERIFY(unitData->flags & QV4::CompiledData::Unit::IsESModule); + + QQmlMetaType::CachedUnitLookupError error = QQmlMetaType::CachedUnitLookupError::NoError; + const QV4::CompiledData::Unit *unitFromResources = QQmlMetaType::findCachedCompilationUnit(QUrl("qrc:/script.mjs"), &error); + QVERIFY(unitFromResources); + + QCOMPARE(unitFromResources, compilationUnit->unitData()); + } +} + void tst_qmlcachegen::enums() { QQmlEngine engine; |