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.
This commit is contained in:
Hendiadyoin1 2023-09-23 13:47:16 +02:00 committed by Andreas Kling
parent 87e063db65
commit 12c6692611
Notes: sideshowbarker 2024-07-17 03:27:40 +09:00

View file

@ -39,7 +39,9 @@ public:
NonnullGCPtr<T> allocate_without_realm(Args&&... args)
{
auto* memory = allocate_cell(sizeof(T));
defer_gc();
new (memory) T(forward<Args>(args)...);
undefer_gc();
return *static_cast<T*>(memory);
}
@ -47,7 +49,9 @@ public:
NonnullGCPtr<T> allocate(Realm& realm, Args&&... args)
{
auto* memory = allocate_cell(sizeof(T));
defer_gc();
new (memory) T(forward<Args>(args)...);
undefer_gc();
auto* cell = static_cast<T*>(memory);
memory->initialize(realm);
return *cell;