1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibJS: Move native objects towards two-pass construction

To make sure that everything is set up correctly in objects before we
start adding properties to them, we split cell allocation into 3 steps:

1. Allocate a cell of appropriate size from the Heap
2. Call the C++ constructor on the cell
3. Call initialize() on the constructed object

The job of initialize() is to define all the initial properties.
Doing it in a second pass guarantees that the Object has a valid Shape
and can find its own GlobalObject.
This commit is contained in:
Andreas Kling 2020-06-20 15:40:48 +02:00
parent e4add19915
commit 64513f3c23
83 changed files with 295 additions and 167 deletions

View file

@ -32,7 +32,7 @@ namespace JS {
Shape* Shape::create_unique_clone() const
{
auto* new_shape = heap().allocate<Shape>(m_global_object);
auto* new_shape = heap().allocate<Shape>(m_global_object, m_global_object);
new_shape->m_unique = true;
new_shape->m_prototype = m_prototype;
ensure_property_table();
@ -46,7 +46,7 @@ Shape* Shape::create_put_transition(const FlyString& property_name, PropertyAttr
TransitionKey key { property_name, attributes };
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
return existing_shape;
auto* new_shape = heap().allocate<Shape>(*this, property_name, attributes, TransitionType::Put);
auto* new_shape = heap().allocate<Shape>(m_global_object, *this, property_name, attributes, TransitionType::Put);
m_forward_transitions.set(key, new_shape);
return new_shape;
}
@ -56,14 +56,14 @@ Shape* Shape::create_configure_transition(const FlyString& property_name, Proper
TransitionKey key { property_name, attributes };
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
return existing_shape;
auto* new_shape = heap().allocate<Shape>(*this, property_name, attributes, TransitionType::Configure);
auto* new_shape = heap().allocate<Shape>(m_global_object, *this, property_name, attributes, TransitionType::Configure);
m_forward_transitions.set(key, new_shape);
return new_shape;
}
Shape* Shape::create_prototype_transition(Object* new_prototype)
{
return heap().allocate<Shape>(*this, new_prototype);
return heap().allocate<Shape>(m_global_object, *this, new_prototype);
}
Shape::Shape(GlobalObject& global_object)