aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-08-25 11:42:23 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-09-02 15:33:31 +0200
commitb297e8fccf262bb0d870b39a960f0b80193dcaf5 (patch)
tree1f5bb9adf1e3fcbd4a8490c64995c064f3ce1f74 /src/qml/jsruntime/qv4engine_p.h
parent7c56dc7e980fc2b0814fb4aec1d5484d4cd3f286 (diff)
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine_p.h')
-rw-r--r--src/qml/jsruntime/qv4engine_p.h30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index d00495eff0..c4a966eb07 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -714,19 +714,18 @@ public:
QQmlRefPointer<ExecutableCompilationUnit> compileModule(
const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp);
- mutable QMutex moduleMutex;
- QHash<QUrl, QQmlRefPointer<ExecutableCompilationUnit>> modules;
+ void injectCompiledModule(const QQmlRefPointer<ExecutableCompilationUnit> &moduleUnit);
+ QV4::Value *registerNativeModule(const QUrl &url, const QV4::Value &module);
- // QV4::PersistentValue would be preferred, but using QHash will create copies,
- // and QV4::PersistentValue doesn't like creating copies.
- // Instead, we allocate a raw pointer using the same manual memory management
- // technique in QV4::PersistentValue.
- QHash<QUrl, QV4::Value*> nativeModules;
+ struct Module {
+ QQmlRefPointer<ExecutableCompilationUnit> compiled;
+
+ // We can pass a raw value pointer here, but nowhere else. See below.
+ Value *native = nullptr;
+ };
- void injectModule(const QQmlRefPointer<ExecutableCompilationUnit> &moduleUnit);
- QQmlRefPointer<ExecutableCompilationUnit> moduleForUrl(const QUrl &_url, const ExecutableCompilationUnit *referrer = nullptr) const;
- QQmlRefPointer<ExecutableCompilationUnit> loadModule(const QUrl &_url, const ExecutableCompilationUnit *referrer = nullptr);
- void registerModule(const QString &name, const QJSValue &module);
+ Module moduleForUrl(const QUrl &_url, const ExecutableCompilationUnit *referrer = nullptr) const;
+ Module loadModule(const QUrl &_url, const ExecutableCompilationUnit *referrer = nullptr);
bool diskCacheEnabled() const;
@@ -767,6 +766,15 @@ private:
QHash<QString, quint32> m_consoleCount;
QVector<Deletable *> m_extensionData;
+
+ mutable QMutex moduleMutex;
+ QHash<QUrl, QQmlRefPointer<ExecutableCompilationUnit>> modules;
+
+ // QV4::PersistentValue would be preferred, but using QHash will create copies,
+ // and QV4::PersistentValue doesn't like creating copies.
+ // Instead, we allocate a raw pointer using the same manual memory management
+ // technique in QV4::PersistentValue.
+ QHash<QUrl, Value *> nativeModules;
};
#define CHECK_STACK_LIMITS(v4) if ((v4)->checkStackLimits()) return Encode::undefined(); \