aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-07-07 11:13:35 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-08 11:29:06 +0000
commit53b4046cb8d97f84d1560ae3537553aa2eb7ec89 (patch)
tree7153da1495377dc7661baf8a75f78b900e8cb47e /src/qml
parent4419d9eed8d816674ceb074269ebd0c45315f97f (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.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 66e16dac74..53de4b6b2a 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);