From b297e8fccf262bb0d870b39a960f0b80193dcaf5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 25 Aug 2022 11:42:23 +0200 Subject: QML: Make modules imported with registerModule() available in QML So far, you could only use them from pure JavaScript programs. Also, fix re-exporting parts of native modules. Fixes: QTBUG-105901 Change-Id: I170017083284e6457b1aa0c6e606fd26227edae3 Reviewed-by: Fabian Kosmale --- src/qmlworkerscript/qquickworkerscript.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/qmlworkerscript/qquickworkerscript.cpp') diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index 336c3d5edb..0aa9b936c8 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -230,10 +230,12 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) script->source = url; if (fileName.endsWith(QLatin1String(".mjs"))) { - auto moduleUnit = engine->loadModule(url); - if (moduleUnit) { - if (moduleUnit->instantiate(engine)) - moduleUnit->evaluate(); + auto module = engine->loadModule(url); + if (module.compiled) { + if (module.compiled->instantiate(engine)) + module.compiled->evaluate(); + } else if (module.native) { + // Nothing to do. There is no global code in a native module. } else { engine->throwError(QStringLiteral("Could not load module file")); } -- cgit v1.2.3