From de2d7cba76bcfbe0a29271df1178c176d00bf9b4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 23 Sep 2022 16:43:58 +0200 Subject: 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 --- src/qmlcompiler/qqmljsfunctioninitializer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/qmlcompiler/qqmljsfunctioninitializer.cpp') diff --git a/src/qmlcompiler/qqmljsfunctioninitializer.cpp b/src/qmlcompiler/qqmljsfunctioninitializer.cpp index 80ee8d0e74..54bef282ea 100644 --- a/src/qmlcompiler/qqmljsfunctioninitializer.cpp +++ b/src/qmlcompiler/qqmljsfunctioninitializer.cpp @@ -61,6 +61,12 @@ void QQmlJSFunctionInitializer::populateSignature( error->message = message; }; + if (!m_typeResolver->canCallJSFunctions()) { + signatureError(u"Ignoring type annotations as requested " + "by pragma FunctionSignatureBehavior"_s); + return; + } + QQmlJS::AST::BoundNames arguments; if (ast->formals) arguments = ast->formals->formals(); -- cgit v1.2.3