diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-22 14:45:04 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-01-02 21:50:34 +0100 |
commit | 3fd3a2a9d06505d549cc4a7c18819a17c6622dfd (patch) | |
tree | aa266f8c45a9f81537a3820223f04387e57ddeb1 /src/qml/qml/qqmlirloader.cpp | |
parent | e39b4572c272f8a0a7be048a24808cb028480e82 (diff) |
QObjectWrapper: Fix calling attached methods on different objects
You can generally store a method in a value and call it on a different
object. However, since we've ignored the thisObject basically forever,
we cannot just accept it right away. Add an opt-in mechanism via a
pragma that allows you to pass (implicitly via context or explicitly via
call()) specific thisObjects to QObject methods.
Fixes: QTBUG-109585
Pick-to: 6.5
Change-Id: I4c81b8ecf6317af55104ac9ebb62d98862ff24e7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlirloader.cpp')
-rw-r--r-- | src/qml/qml/qqmlirloader.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlirloader.cpp b/src/qml/qml/qqmlirloader.cpp index 59853a85e5..c80f9b4bd1 100644 --- a/src/qml/qml/qqmlirloader.cpp +++ b/src/qml/qml/qqmlirloader.cpp @@ -49,6 +49,12 @@ void QQmlIRLoader::load() createPragma(type)->functionSignatureBehavior = value; }; + const auto createNativeMethodPragma = [&]( + Pragma::PragmaType type, + Pragma::NativeMethodBehaviorValue value) { + createPragma(type)->nativeMethodBehavior = value; + }; + if (unit->flags & QV4::CompiledData::Unit::IsSingleton) createPragma(Pragma::Singleton); if (unit->flags & QV4::CompiledData::Unit::IsStrict) @@ -65,6 +71,9 @@ void QQmlIRLoader::load() if (unit->flags & QV4::CompiledData::Unit::FunctionSignaturesEnforced) createFunctionSignaturePragma(Pragma::FunctionSignatureBehavior, Pragma::Enforced); + if (unit->flags & QV4::CompiledData::Unit::NativeMethodsAcceptThisObject) + createNativeMethodPragma(Pragma::NativeMethodBehavior, Pragma::AcceptThisObject); + for (uint i = 0; i < qmlUnit->nObjects; ++i) { const QV4::CompiledData::Object *serializedObject = qmlUnit->objectAt(i); QmlIR::Object *object = loadObject(serializedObject); |