aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvaluetypewrapper.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-09-30 15:32:14 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-10-14 22:05:42 +0200
commit1aa0b1c3989eebcbdca6655648e397937c11fc24 (patch)
tree4a93ccc4480ccf7013e02a160456cdaee498ac60 /src/qml/qml/qqmlvaluetypewrapper.cpp
parent700dfe7cb6705a79fa7ad3a6499787bcac9d5b31 (diff)
QML: Track statement locations in sequence and value types
With this in place we can enforce that reference objects we add in the future can only be written back in the same statement as they were created. Task-number: QTBUG-99766 Change-Id: I1c74bd239caa1bb5febd1a3705d8ee29a8fc4249 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/qml/qqmlvaluetypewrapper.cpp')
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 2e7eaf23f8..721917bb6d 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -109,12 +109,13 @@ void *Heap::QQmlValueTypeWrapper::storagePointer()
bool Heap::QQmlValueTypeWrapper::readReference()
{
- return QV4::ReferenceObject::readReference(this);
+ // If locations are enforced we only read once
+ return enforcesLocation() || QV4::ReferenceObject::readReference(this);
}
bool Heap::QQmlValueTypeWrapper::writeBack()
{
- return QV4::ReferenceObject::writeBack(this);
+ return isAttachedToProperty() && QV4::ReferenceObject::writeBack(this);
}
ReturnedValue QQmlValueTypeWrapper::create(
@@ -130,6 +131,7 @@ ReturnedValue QQmlValueTypeWrapper::create(
r->d()->setMetaObject(cloneFrom->metaObject());
r->d()->setValueType(cloneFrom->valueType());
r->d()->setGadgetPtr(nullptr);
+ r->d()->setLocation(cloneFrom->function(), cloneFrom->statementIndex());
return r->asReturnedValue();
}
@@ -160,6 +162,8 @@ ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, QObject *obj
}
r->d()->setValueType(valueType);
r->d()->setGadgetPtr(nullptr);
+ if (CppStackFrame *frame = engine->currentStackFrame)
+ r->d()->setLocation(frame->v4Function, frame->statementNumber());
return r->asReturnedValue();
}