From 12c66926118cded6c1a7abd4cbeb9b3fbf31971e Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sat, 23 Sep 2023 13:47:16 +0200 Subject: [PATCH] LibJS: Defer GC during cell construction This stops us from trying to collect not fully constructed Cells, which's vtables are not fully initialized, which would cause issues during GC. --- Userland/Libraries/LibJS/Heap/Heap.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 1a97a1e7d4..77880c9b7a 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -39,7 +39,9 @@ public: NonnullGCPtr allocate_without_realm(Args&&... args) { auto* memory = allocate_cell(sizeof(T)); + defer_gc(); new (memory) T(forward(args)...); + undefer_gc(); return *static_cast(memory); } @@ -47,7 +49,9 @@ public: NonnullGCPtr allocate(Realm& realm, Args&&... args) { auto* memory = allocate_cell(sizeof(T)); + defer_gc(); new (memory) T(forward(args)...); + undefer_gc(); auto* cell = static_cast(memory); memory->initialize(realm); return *cell;