diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-06-11 17:25:21 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-14 20:39:07 +0000 |
commit | 01b991ec1ea68b67589c2f93acf1f7704c516dd5 (patch) | |
tree | 66057c4043897fecaaf9b1428a34711e4b4febf0 | |
parent | 30e354f2b410f7c4d846ac31033b930221588960 (diff) |
Handle AOT functions returning QVariant in bindings
We need to write the inner data of the variant. Otherwise we create
double-wrapped objects.
Change-Id: Iacc7b341168c4328172a4e442c16cfbedc6c36c0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit c83249da39ed1ec33bfb35cd630f6b3c0facf7a3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 788d03b8e2..3212dc5604 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -259,15 +259,24 @@ protected: const QV4::Function *v4Function = function(); if (v4Function && v4Function->aotFunction && !hasBoundFunction()) { const auto returnType = v4Function->aotFunction->returnType; - const auto size = returnType.sizeOf(); - if (Q_LIKELY(size > 0)) { - Q_ALLOCA_VAR(void, result, size); + if (returnType == QMetaType::fromType<QVariant>()) { + // It expects uninitialized memory + Q_ALLOCA_VAR(QVariant, result, sizeof(QVariant)); const bool isUndefined = !evaluate(result, returnType); if (canWrite()) - error = !write(result, returnType, isUndefined, flags); - returnType.destruct(result); - } else if (canWrite()) { - error = !write(QV4::Encode::undefined(), true, flags); + error = !write(result->data(), result->metaType(), isUndefined, flags); + result->~QVariant(); + } else { + const auto size = returnType.sizeOf(); + if (Q_LIKELY(size > 0)) { + Q_ALLOCA_VAR(void, result, size); + const bool isUndefined = !evaluate(result, returnType); + if (canWrite()) + error = !write(result, returnType, isUndefined, flags); + returnType.destruct(result); + } else if (canWrite()) { + error = !write(QV4::Encode::undefined(), true, flags); + } } } else { bool isUndefined = false; |