aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine.cpp
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-02-08 15:42:59 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2021-02-12 12:00:09 +0100
commitf3281ca869420df83d618c255aa7d62e63a102d5 (patch)
tree4c990b4253313c3826dfb840cf427e8efa15b341 /src/qml/jsruntime/qv4engine.cpp
parent9c282fe2e90eec05e160241069c219c7f09f4078 (diff)
Support runtime functions evaluation by index through QQmlEngine
Add execution function that can evaluate runtime functions available in the compilation unit. Private API for now as it's unclear what would be a comprehensive solution to support all existing use cases Task-number: QTBUG-84368 Task-number: QTBUG-91039 Change-Id: Icf755b53484587d7983eaae4821c1aa0111d5c05 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 7ae281fb1a..ee35ad2586 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -93,6 +93,7 @@
#include "qv4stackframe_p.h"
#include "qv4atomics_p.h"
#include "qv4urlobject_p.h"
+#include "qv4jscall_p.h"
#if QT_CONFIG(qml_sequence_object)
#include "qv4sequenceobject_p.h"
@@ -124,6 +125,8 @@
#include <qmetatype.h>
#include <qsequentialiterable.h>
+#include <private/qqmlengine_p.h>
+
#if USE(PTHREADS)
# include <pthread.h>
#if !defined(Q_OS_INTEGRITY)
@@ -2051,6 +2054,31 @@ bool ExecutionEngine::diskCacheEnabled() const
return (!disableDiskCache() && !debugger()) || forceDiskCache();
}
+ReturnedValue ExecutionEngine::callInContext(Function *function, QObject *self,
+ QQmlRefPointer<QQmlContextData> ctxtdata, void **args,
+ int *types)
+{
+ QV4::Scope scope(this);
+ ExecutionContext *ctx = currentStackFrame ? currentContext() : scriptContext();
+ QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(ctx, ctxtdata, self));
+ QV4::ScopedValue selfValue(scope, QV4::QObjectWrapper::wrap(this, self));
+
+ if (!args)
+ return function->call(selfValue, nullptr, 0, qmlContext);
+
+ if (!types) // both args and types must be present
+ return Encode::undefined();
+
+ // use JSCallData to pass arguments into the function call
+ QV4::JSCallData jsCall(scope, types[0]);
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_qmlEngine);
+ QV4::populateJSCallArguments(ep, this, jsCall, args, types);
+
+ QV4::CallData *callData = jsCall->callData();
+ return function->call(selfValue, callData->argValues<QV4::Value>(), callData->argc(),
+ qmlContext);
+}
+
void ExecutionEngine::initQmlGlobalObject()
{
initializeGlobal();