mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
LibJS: Add Object.defineProperty() and start caring about attributes
We now care (a little bit) about the "configurable" and "writable" property attributes. Property attributes are stored together with the property name in the Shape object. Forward transitions are not attribute-savvy and will cause poor Shape reuse in the case of multiple same-name properties with different attributes. Oh, and this patch also adds Object.getOwnPropertyDescriptor() :^)
This commit is contained in:
@@ -29,12 +29,12 @@
|
||||
|
||||
namespace JS {
|
||||
|
||||
Shape* Shape::create_put_transition(const FlyString& property_name, u8 property_attributes)
|
||||
Shape* Shape::create_put_transition(const FlyString& property_name, u8 attributes)
|
||||
{
|
||||
auto* new_shape = m_forward_transitions.get(property_name).value_or(nullptr);
|
||||
if (new_shape && new_shape->m_property_attributes == property_attributes)
|
||||
if (new_shape && new_shape->m_attributes == attributes)
|
||||
return new_shape;
|
||||
new_shape = heap().allocate<Shape>(this, property_name, property_attributes);
|
||||
new_shape = heap().allocate<Shape>(this, property_name, attributes);
|
||||
m_forward_transitions.set(property_name, new_shape);
|
||||
return new_shape;
|
||||
}
|
||||
@@ -48,10 +48,10 @@ Shape::Shape()
|
||||
{
|
||||
}
|
||||
|
||||
Shape::Shape(Shape* previous_shape, const FlyString& property_name, u8 property_attributes)
|
||||
Shape::Shape(Shape* previous_shape, const FlyString& property_name, u8 attributes)
|
||||
: m_previous(previous_shape)
|
||||
, m_property_name(property_name)
|
||||
, m_property_attributes(property_attributes)
|
||||
, m_attributes(attributes)
|
||||
, m_prototype(previous_shape->m_prototype)
|
||||
{
|
||||
}
|
||||
@@ -114,7 +114,7 @@ void Shape::ensure_property_table() const
|
||||
// Ignore prototype transitions as they don't affect the key map.
|
||||
continue;
|
||||
}
|
||||
m_property_table->set(shape->m_property_name, { next_offset++, shape->m_property_attributes });
|
||||
m_property_table->set(shape->m_property_name, { next_offset++, shape->m_attributes });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user