aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4sequenceobject.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/jsruntime/qv4sequenceobject.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/jsruntime/qv4sequenceobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 2558e376b5..6aadf68c05 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -162,6 +162,8 @@ void Heap::Sequence::init(
QV4::Scope scope(internalClass->engine);
QV4::Scoped<QV4::Sequence> o(scope, this);
o->setArrayType(Heap::ArrayData::Custom);
+ if (CppStackFrame *frame = scope.engine->currentStackFrame)
+ setLocation(frame->v4Function, frame->statementNumber());
o->loadReference();
}
@@ -422,18 +424,19 @@ bool Sequence::sort(const FunctionObject *f, const Value *, const Value *argv, i
void *Sequence::getRawContainerPtr() const
{ return d()->storagePointer(); }
-void Sequence::loadReference() const
+bool Sequence::loadReference() const
{
Q_ASSERT(d()->object());
Q_ASSERT(d()->isReference());
- QV4::ReferenceObject::readReference(d());
+ // If locations are enforced we only read once
+ return d()->enforcesLocation() || QV4::ReferenceObject::readReference(d());
}
-void Sequence::storeReference()
+bool Sequence::storeReference()
{
Q_ASSERT(d()->object());
Q_ASSERT(d()->isReference());
- QV4::ReferenceObject::writeBack(d());
+ return d()->isAttachedToProperty() && QV4::ReferenceObject::writeBack(d());
}
ReturnedValue Sequence::virtualGet(const Managed *that, PropertyKey id, const Value *receiver, bool *hasProperty)