aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4mapobject.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-06-04 14:49:37 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2024-06-05 09:35:51 +0200
commitd6a48c924a51af0e0681b05702e6389d3c05d1bc (patch)
tree8751dc469c2f6718517774caeed1ba441d6f516c /src/qml/jsruntime/qv4mapobject.cpp
parent828ac00990ed2a7920d59a0fb6ecac290696a842 (diff)
gc: fix marking for (Weak)(Map|Set)
Map and Set must hold on to their keys (and values in case of Map), which did not happen if we inserted values into an already marked Map or Set. A similar issue holds for weak maps and sets, except that for those we only want to mark them once we are past the FreeWeak(Maps|Sets) phase. Pick-to: 6.8 Change-Id: Ibc05be4a85172a9b726beebf0d008acde4479edf Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4mapobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4mapobject.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4mapobject.cpp b/src/qml/jsruntime/qv4mapobject.cpp
index b927efd685..94cac02556 100644
--- a/src/qml/jsruntime/qv4mapobject.cpp
+++ b/src/qml/jsruntime/qv4mapobject.cpp
@@ -214,6 +214,16 @@ ReturnedValue WeakMapPrototype::method_set(const FunctionObject *b, const Value
(!argc || !argv[0].isObject()))
return scope.engine->throwTypeError();
+ QV4::WriteBarrier::markCustom(scope.engine, [&](QV4::MarkStack *ms) {
+ if (scope.engine->memoryManager->gcStateMachine->state <= GCState::FreeWeakMaps)
+ return;
+ argv[0].heapObject()->mark(ms);
+ if (argc > 1) {
+ if (auto *h = argv[1].heapObject())
+ h->mark(ms);
+ }
+ });
+
that->d()->esTable->set(argv[0], argc > 1 ? argv[1] : Value::undefinedValue());
return that.asReturnedValue();
}
@@ -317,6 +327,14 @@ ReturnedValue MapPrototype::method_set(const FunctionObject *b, const Value *thi
if (!that || that->d()->isWeakMap)
return scope.engine->throwTypeError();
+ QV4::WriteBarrier::markCustom(scope.engine, [&](QV4::MarkStack *ms) {
+ argv[0].heapObject()->mark(ms);
+ if (argc > 1) {
+ if (auto *h = argv[1].heapObject())
+ h->mark(ms);
+ }
+ });
+
that->d()->esTable->set(argc ? argv[0] : Value::undefinedValue(), argc > 1 ? argv[1] : Value::undefinedValue());
return that.asReturnedValue();
}