diff options
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 24 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine_p.h | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index aa30c08c19..5e108f6914 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2312,6 +2312,30 @@ bool QQmlEnginePrivate::isScriptLoaded(const QUrl &url) const return typeLoader.isScriptLoaded(url); } +QJSValue QQmlEnginePrivate::executeRuntimeFunction(const QUrl &url, qsizetype functionIndex, + QObject *thisObject, void **args, int *types) +{ + Q_Q(QQmlEngine); + if (const auto unit = typeLoader.getType(url)->compilationUnit()) { + Q_ASSERT(functionIndex >= 0); + Q_ASSERT(thisObject); + + if (!unit->engine) + unit->linkToEngine(q->handle()); + + if (unit->runtimeFunctions.length() <= functionIndex) + return QJSValue(); + + QQmlContext *ctx = q->contextForObject(thisObject); + if (!ctx) + ctx = q->rootContext(); + return QJSValuePrivate::fromReturnedValue( + q->handle()->callInContext(unit->runtimeFunctions[functionIndex], thisObject, + QQmlContextData::get(ctx), args, types)); + } + return QJSValue(); +} + #if defined(Q_OS_WIN) // Normalize a file name using Shell API. As opposed to converting it // to a short 8.3 name and back, this also works for drives where 8.3 notation diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index b7073ffcfd..4f1c5f26dd 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -300,6 +300,9 @@ public: return nullptr; } + QJSValue executeRuntimeFunction(const QUrl &url, qsizetype functionIndex, QObject *thisObject, + void **args = nullptr, int *types = nullptr); + private: class SingletonInstances : private QHash<QQmlType, QJSValue> { |