mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +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:
parent
1570e67881
commit
e6d920d87d
7 changed files with 121 additions and 16 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue