mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
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
1 changed files with 4 additions and 0 deletions
|
@ -39,7 +39,9 @@ public:
|
||||||
NonnullGCPtr<T> allocate_without_realm(Args&&... args)
|
NonnullGCPtr<T> allocate_without_realm(Args&&... args)
|
||||||
{
|
{
|
||||||
auto* memory = allocate_cell(sizeof(T));
|
auto* memory = allocate_cell(sizeof(T));
|
||||||
|
defer_gc();
|
||||||
new (memory) T(forward<Args>(args)...);
|
new (memory) T(forward<Args>(args)...);
|
||||||
|
undefer_gc();
|
||||||
return *static_cast<T*>(memory);
|
return *static_cast<T*>(memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +49,9 @@ public:
|
||||||
NonnullGCPtr<T> allocate(Realm& realm, Args&&... args)
|
NonnullGCPtr<T> allocate(Realm& realm, Args&&... args)
|
||||||
{
|
{
|
||||||
auto* memory = allocate_cell(sizeof(T));
|
auto* memory = allocate_cell(sizeof(T));
|
||||||
|
defer_gc();
|
||||||
new (memory) T(forward<Args>(args)...);
|
new (memory) T(forward<Args>(args)...);
|
||||||
|
undefer_gc();
|
||||||
auto* cell = static_cast<T*>(memory);
|
auto* cell = static_cast<T*>(memory);
|
||||||
memory->initialize(realm);
|
memory->initialize(realm);
|
||||||
return *cell;
|
return *cell;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue