aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2022-09-23 16:43:58 +0200
committerUlf Hermann <[email protected]>2022-10-14 16:36:36 +0200
commitde2d7cba76bcfbe0a29271df1178c176d00bf9b4 (patch)
tree5d37fcfad0636975f8ed4292f07140fdecdd19f2 /src/qml/jsruntime/qv4functionobject.cpp
parentd45925b0fdbd8055b60afbf87324325465d89568 (diff)
Add option to enforce function signatures
By default, the QML engine does not enforce signatures given as type annotations to functions. By passing different types than the function declares, you can get different behavior between the interpreter/JIT and the AOT-compiled code. In addition, in interpreted or JIT'ed mode, we pass all non-primitive value types as references. This means, if you modify them within the called function, the modifications are propagated back to the place where the value was loaded from. Enforcing the signature prevents all of this, at a run time cost. Since we have to coerce all arguments to the desired types, the function call overhead grows. This change introduces a pragma "FunctionSignatureBehavior" which you can set to "Ignored" or "Enforced" to choose one way or the other as universal way of handling type annotations. Fixes: QTBUG-106819 Change-Id: I50e9b2bd6702907da44974cd9e05b48a96bb609e Reviewed-by: Fabian Kosmale <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 6cc2ca7ab0..84ba0cfcfb 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -507,17 +507,8 @@ void ArrowFunction::virtualCallWithMetaTypes(const FunctionObject *fo, QObject *
frame.pop(scope.engine);
}
-ReturnedValue ArrowFunction::virtualCall(const FunctionObject *fo, const Value *thisObject, const Value *argv, int argc)
+static ReturnedValue doCall(const FunctionObject *fo, const Value *thisObject, const Value *argv, int argc)
{
- Function *function = fo->function();
- if (function->kind == Function::AotCompiled) {
- return QV4::convertAndCall(
- fo->engine(), function->typedFunction, thisObject, argv, argc,
- [fo](QObject *thisObject, void **a, const QMetaType *types, int argc) {
- ArrowFunction::virtualCallWithMetaTypes(fo, thisObject, a, types, argc);
- });
- }
-
ExecutionEngine *engine = fo->engine();
JSTypesStackFrame frame;
frame.init(fo->function(), argv, argc, true);
@@ -540,6 +531,29 @@ ReturnedValue ArrowFunction::virtualCall(const FunctionObject *fo, const Value *
return result;
}
+ReturnedValue ArrowFunction::virtualCall(const FunctionObject *fo, const Value *thisObject, const Value *argv, int argc)
+{
+ Function *function = fo->function();
+ switch (function->kind) {
+ case Function::AotCompiled:
+ return QV4::convertAndCall(
+ fo->engine(), function->typedFunction, thisObject, argv, argc,
+ [fo](QObject *thisObject, void **a, const QMetaType *types, int argc) {
+ ArrowFunction::virtualCallWithMetaTypes(fo, thisObject, a, types, argc);
+ });
+ case Function::JsTyped:
+ return QV4::coerceAndCall(
+ fo->engine(), function->typedFunction, thisObject, argv, argc,
+ [fo](const Value *thisObject, const Value *argv, int argc) {
+ return doCall(fo, thisObject, argv, argc);
+ });
+ default:
+ break;
+ }
+
+ return doCall(fo, thisObject, argv, argc);
+}
+
void Heap::ArrowFunction::init(QV4::ExecutionContext *scope, Function *function, QV4::String *n)
{
FunctionObject::init();