From ad0e3c0e548070554f92367721303ac1dc16dbfc Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 9 Jun 2021 18:01:06 +0300 Subject: [PATCH] LibJS: Mark heap cell values stored in Set instances This makes sure they dont get garbage collected while stored in a Set. --- Userland/Libraries/LibJS/Runtime/Set.cpp | 7 +++++++ Userland/Libraries/LibJS/Runtime/Set.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp index f0cc7be8031..4cb42f215ff 100644 --- a/Userland/Libraries/LibJS/Runtime/Set.cpp +++ b/Userland/Libraries/LibJS/Runtime/Set.cpp @@ -34,4 +34,11 @@ Set* Set::typed_this(VM& vm, GlobalObject& global_object) return static_cast(this_object); } +void Set::visit_edges(Cell::Visitor& visitor) +{ + Object::visit_edges(visitor); + for (auto& value : m_values) + visitor.visit(value); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/Set.h b/Userland/Libraries/LibJS/Runtime/Set.h index 289d361c036..59ac8ace4cf 100644 --- a/Userland/Libraries/LibJS/Runtime/Set.h +++ b/Userland/Libraries/LibJS/Runtime/Set.h @@ -47,6 +47,8 @@ public: HashTable& values() { return m_values; }; private: + virtual void visit_edges(Visitor& visitor) override; + HashTable m_values; // FIXME: Replace with a HashTable that maintains a linked list of insertion order for correct iteration order };