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:
parent
87e063db65
commit
12c6692611
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/12c6692611 Pull-request: https://github.com/SerenityOS/serenity/pull/21202
1 changed files with 4 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue