diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-07-07 11:13:35 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-07 22:22:27 +0000 |
commit | cefbda6006e21363e7b7f9bf643812dba5363945 (patch) | |
tree | 58b646034212ecf3428dd494170c2cd0f96c1564 /src/qml | |
parent | 5c5b8788d330f76ef601ea97fece15359f442732 (diff) |
QQmlValueTypeWrapper: readReferenceValue in virtualGetOwnProperty
Otherwise we may end up with a nullptr gadget.
Fixes: QTBUG-104803
Change-Id: Ia0c3741fdf0214f0c3d4b352006442747f635f5c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 0e48d9d9387aeb39c8289f61f75d9c6fcd6c753f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index c2bbd7f498..2cba0375e7 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -281,10 +281,27 @@ PropertyAttributes QQmlValueTypeWrapper::virtualGetOwnProperty(const Managed *m, { if (id.isString()) { const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m); - QQmlPropertyData result = r->dataForPropertyKey(id); - if (p && result.isValid()) - p->value = getGadgetProperty(r->engine(), r->d(), result.propType(), result.coreIndex(), result.isFunction(), result.isEnum()); - return result.isValid() ? Attr_Data : Attr_Invalid; + Q_ASSERT(r); + + const QQmlPropertyData result = r->dataForPropertyKey(id); + if (!result.isValid()) + return Attr_Invalid; // Property doesn't exist. Object shouldn't meddle with it. + + if (!p) + return Attr_Data; // Property exists, but we're not interested in the value + + const QQmlValueTypeReference *ref = r->as<const QQmlValueTypeReference>(); + if (!ref || ref->readReferenceValue()) { + // Property exists, and we can retrieve it + p->value = getGadgetProperty( + r->engine(), r->d(), result.propType(), result.coreIndex(), + result.isFunction(), result.isEnum()); + } else { + // Property exists, but we can't retrieve it. Make it undefined. + p->value = Encode::undefined(); + } + + return Attr_Data; } return QV4::Object::virtualGetOwnProperty(m, id, p); |