mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 06:37:52 +00:00
LibJS: Do not allocate in Set's constructor
We are currently allocating in Set's constructor to create the set's underlying Map. This can cause GC to occur before the member is actually initialized, thus we will crash in Set::visit_edges trying to visit a member that does not exist. Instead, create the Map in Set::initialize, where we can allocate. Also change Map to be stored as a normal JS heap-allocated object, rather than as a stack variable.
This commit is contained in:
@@ -15,14 +15,18 @@ Set* Set::create(Realm& realm)
|
||||
|
||||
Set::Set(Object& prototype)
|
||||
: Object(prototype)
|
||||
, m_values(*prototype.shape().realm().intrinsics().map_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void Set::initialize(Realm& realm)
|
||||
{
|
||||
m_values = Map::create(realm);
|
||||
}
|
||||
|
||||
void Set::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
static_cast<Object&>(m_values).visit_edges(visitor);
|
||||
visitor.visit(m_values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user