aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcachegen
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-16 13:06:22 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-17 11:06:18 +0000
commit4b2b1fc12137450d34e8324c0dbe2af1e90b9e6a (patch)
tree9e397602b5f584032cdc29354c0fcf485766cce2 /tests/auto/qml/qmlcachegen
parent29e4b97bad6511ebd6aa009a47594395957c0e8e (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')
-rw-r--r--tests/auto/qml/qmlcachegen/jsmoduleimport.qml6
-rw-r--r--tests/auto/qml/qmlcachegen/qmlcachegen.pro2
-rw-r--r--tests/auto/qml/qmlcachegen/script.mjs4
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp31
4 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcachegen/jsmoduleimport.qml b/tests/auto/qml/qmlcachegen/jsmoduleimport.qml
new file mode 100644
index 0000000000..c1fad7fee2
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/jsmoduleimport.qml
@@ -0,0 +1,6 @@
+import QtQml 2.0
+import "script.mjs" as Script
+
+QtObject {
+ property bool ok: Script.ok()
+}
diff --git a/tests/auto/qml/qmlcachegen/qmlcachegen.pro b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
index 6dee2a0454..7f7b3128cf 100644
--- a/tests/auto/qml/qmlcachegen/qmlcachegen.pro
+++ b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
@@ -19,4 +19,6 @@ RESOURCES += Enums.qml
# QTBUG-46375
!win32: RESOURCES += trickypaths_umlaut.qrc
+RESOURCES += jsmoduleimport.qml script.mjs
+
QT += core-private qml-private testlib
diff --git a/tests/auto/qml/qmlcachegen/script.mjs b/tests/auto/qml/qmlcachegen/script.mjs
new file mode 100644
index 0000000000..459c336125
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/script.mjs
@@ -0,0 +1,4 @@
+
+export function ok() {
+ return true
+}
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;