From a24af35ca1b17c648880f78e28f616caac59c918 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 19 May 2026 21:23:04 +0200 Subject: [PATCH] LibGC: Default-construct RootHashMap from the global heap --- Libraries/LibGC/RootHashMap.cpp | 5 +++++ Libraries/LibGC/RootHashMap.h | 5 +++-- .../CSS/Invalidation/HasMutationInvalidator.cpp | 2 +- .../LibJSGCTests/root_container_non_gc_type.cpp | 2 +- Tests/LibGC/TestGCContainers.cpp | 11 +++++------ 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Libraries/LibGC/RootHashMap.cpp b/Libraries/LibGC/RootHashMap.cpp index 439d7e108b..dc47844300 100644 --- a/Libraries/LibGC/RootHashMap.cpp +++ b/Libraries/LibGC/RootHashMap.cpp @@ -9,6 +9,11 @@ namespace GC { +RootHashMapBase::RootHashMapBase() + : RootHashMapBase(Heap::the()) +{ +} + RootHashMapBase::RootHashMapBase(Heap& heap) : m_heap(&heap) { diff --git a/Libraries/LibGC/RootHashMap.h b/Libraries/LibGC/RootHashMap.h index 20a86a3ee3..2dcb8feb7d 100644 --- a/Libraries/LibGC/RootHashMap.h +++ b/Libraries/LibGC/RootHashMap.h @@ -19,6 +19,7 @@ public: virtual void gather_roots(HashMap&) const = 0; protected: + RootHashMapBase(); explicit RootHashMapBase(Heap&); ~RootHashMapBase(); @@ -39,8 +40,8 @@ class RootHashMap final using HashMapBase = HashMap; public: - explicit RootHashMap(Heap& heap) - : RootHashMapBase(heap) + RootHashMap() + : RootHashMapBase() { } diff --git a/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp b/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp index ce32bb2028..799b3a7385 100644 --- a/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp +++ b/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp @@ -338,7 +338,7 @@ static void invalidate_style_of_elements_affected_by_pending_has_mutations(Style ++counters.has_ancestor_walk_invocations; GC::RootHashTable> elements_already_invalidated_for_has; - GC::OrderedRootHashMap, PendingHasInvalidationMutationFeatures> pending_has_invalidations { style_scope.node().heap() }; + GC::OrderedRootHashMap, 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(); diff --git a/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp b/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp index e9656faf45..e1a054d2c3 100644 --- a/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp +++ b/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp @@ -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 bad_map(heap); + GC::RootHashMap bad_map; } // RootHashTable with a non-GC element type should fail. diff --git a/Tests/LibGC/TestGCContainers.cpp b/Tests/LibGC/TestGCContainers.cpp index d3ac905108..beca403aee 100644 --- a/Tests/LibGC/TestGCContainers.cpp +++ b/Tests/LibGC/TestGCContainers.cpp @@ -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> map(heap); + GC::RootHashMap> map; auto cell = heap.allocate(); 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, int> map(heap); + GC::RootHashMap, int> map; auto cell = heap.allocate(); 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> map(heap); + GC::RootHashMap, GC::Ref> map; auto key_cell = heap.allocate(); auto value_cell = heap.allocate(); @@ -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> map(heap); + GC::RootHashMap> map; auto cell = heap.allocate(); 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> vector; GC::RootHashTable> table; - GC::RootHashMap> map(heap); + GC::RootHashMap> map; HashMap roots; vector.gather_roots(roots);