LibGC: Default-construct RootHashMap from the global heap

This commit is contained in:
Shannon Booth 2026-05-19 21:23:04 +02:00 committed by Shannon Booth
parent 78a4438cd8
commit a24af35ca1
5 changed files with 15 additions and 10 deletions

View file

@ -9,6 +9,11 @@
namespace GC {
RootHashMapBase::RootHashMapBase()
: RootHashMapBase(Heap::the())
{
}
RootHashMapBase::RootHashMapBase(Heap& heap)
: m_heap(&heap)
{

View file

@ -19,6 +19,7 @@ public:
virtual void gather_roots(HashMap<Cell*, GC::HeapRoot>&) const = 0;
protected:
RootHashMapBase();
explicit RootHashMapBase(Heap&);
~RootHashMapBase();
@ -39,8 +40,8 @@ class RootHashMap final
using HashMapBase = HashMap<K, V, KeyTraits, ValueTraits, IsOrdered>;
public:
explicit RootHashMap(Heap& heap)
: RootHashMapBase(heap)
RootHashMap()
: RootHashMapBase()
{
}

View file

@ -338,7 +338,7 @@ static void invalidate_style_of_elements_affected_by_pending_has_mutations(Style
++counters.has_ancestor_walk_invocations;
GC::RootHashTable<GC::Ref<DOM::Element>> elements_already_invalidated_for_has;
GC::OrderedRootHashMap<GC::Ref<DOM::Node>, PendingHasInvalidationMutationFeatures> pending_has_invalidations { style_scope.node().heap() };
GC::OrderedRootHashMap<GC::Ref<DOM::Node>, PendingHasInvalidationMutationFeatures> pending_has_invalidations;
for (auto& [node, features] : style_scope.m_pending_has_invalidations)
pending_has_invalidations.set(node, features);
bool should_scan_ancestor_siblings = style_scope.have_has_selectors_with_relative_selector_that_has_sibling_combinator();

View file

@ -23,7 +23,7 @@ void test_root_hash_map_non_gc_types(GC::Heap& heap)
{
// expected-error@*{{RootHashMap requires at least one of key or value types to be convertible to Cell const* or derive from NanBoxedValue}}
// expected-note@+1 {{in instantiation of member function}}
GC::RootHashMap<int, int> bad_map(heap);
GC::RootHashMap<int, int> bad_map;
}
// RootHashTable with a non-GC element type should fail.

View file

@ -90,7 +90,7 @@ TEST_CASE(root_vector_ptr_reports_roots)
TEST_CASE(root_hash_map_value_reports_roots)
{
auto& heap = test_heap();
GC::RootHashMap<int, GC::Ref<TestCell>> map(heap);
GC::RootHashMap<int, GC::Ref<TestCell>> map;
auto cell = heap.allocate<TestCell>();
map.set(42, cell);
@ -105,7 +105,7 @@ TEST_CASE(root_hash_map_value_reports_roots)
TEST_CASE(root_hash_map_key_reports_roots)
{
auto& heap = test_heap();
GC::RootHashMap<GC::Ref<TestCell>, int> map(heap);
GC::RootHashMap<GC::Ref<TestCell>, int> map;
auto cell = heap.allocate<TestCell>();
map.set(cell, 42);
@ -120,7 +120,7 @@ TEST_CASE(root_hash_map_key_reports_roots)
TEST_CASE(root_hash_map_key_and_value_reports_roots)
{
auto& heap = test_heap();
GC::RootHashMap<GC::Ref<TestCell>, GC::Ref<TestCell>> map(heap);
GC::RootHashMap<GC::Ref<TestCell>, GC::Ref<TestCell>> map;
auto key_cell = heap.allocate<TestCell>();
auto value_cell = heap.allocate<TestCell>();
@ -137,7 +137,7 @@ TEST_CASE(root_hash_map_key_and_value_reports_roots)
TEST_CASE(root_hash_map_non_gc_key_skipped)
{
auto& heap = test_heap();
GC::RootHashMap<int, GC::Ref<TestCell>> map(heap);
GC::RootHashMap<int, GC::Ref<TestCell>> map;
auto cell = heap.allocate<TestCell>();
map.set(42, cell);
@ -243,10 +243,9 @@ TEST_CASE(root_hash_table_reports_roots)
TEST_CASE(empty_containers_report_no_roots)
{
auto& heap = test_heap();
GC::RootVector<GC::Ref<TestCell>> vector;
GC::RootHashTable<GC::Ref<TestCell>> table;
GC::RootHashMap<int, GC::Ref<TestCell>> map(heap);
GC::RootHashMap<int, GC::Ref<TestCell>> map;
HashMap<GC::Cell*, GC::HeapRoot> roots;
vector.gather_roots(roots);