diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-08 15:49:24 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-27 15:29:24 +0200 |
commit | b4d5b64359cc0e908fb68d4490df076475c899c3 (patch) | |
tree | 15045e1a90b00aef24488b466313b2d5b39ba5d6 /src/qml/jsruntime/qv4engine_p.h | |
parent | 52aaf0a4e78a197b1c12189db7d7bf5681946df5 (diff) |
Make QQmlEngine resolve closures when executing runtime functions
QML can create a function which holds a closure in the cases like:
onSignal: function() { ... }
If the left-hand side is a signal handler (or similar), we want to
execute the *inner* function when a signal is called, not the outer
one. However, under certain conditions (e.g. we use `this`), the
outer function must also be called beforehand to correctly setup the
calling scope for the inner function
Thus, make the QQmlEnginePrivate::executeRuntimeFunction() do that:
always call an outer function first and then the inner one if present.
This creates an overhead when dealing with certain signal handlers but
we could optimize it later if needed
Note that the case `property var prop: function() { return 42; }` where
a property contains a callable function is no longer supported by the
executeRuntimeFunction() routine (we always call the inner code now).
This is fine since qmltc (the main beneficiary of the routine) does not
rely on this functionality when dealing with property bindings
Given the change, qmltc can be simplified to only work with absolute
function indices, ignoring the nesting problem altogether
Change-Id: I61f61587b6fe700cb695b3b7a213d9cfab0eb746
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index b9f2633d91..6528802f19 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -766,8 +766,10 @@ public: bool diskCacheEnabled() const; - void callInContext(Function *function, QObject *self, QQmlRefPointer<QQmlContextData> ctxtdata, + void callInContext(QV4::Function *function, QObject *self, QV4::ExecutionContext *ctxt, int argc, void **args, QMetaType *types); + QV4::ReturnedValue callInContext(QV4::Function *function, QObject *self, + QV4::ExecutionContext *ctxt, int argc, const QV4::Value *argv); private: QV4::ReturnedValue fromData(QMetaType type, const void *ptr, const QVariant *variant = nullptr); |