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;