mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibJS: Integrate Symbols into objects as valid keys
This allows objects properties to be created for symbol keys in addition to just plain strings/numbers
This commit is contained in:
parent
9783a4936c
commit
7a1d485b19
14 changed files with 424 additions and 154 deletions
|
@ -41,7 +41,7 @@ Shape* Shape::create_unique_clone() const
|
|||
return new_shape;
|
||||
}
|
||||
|
||||
Shape* Shape::create_put_transition(const FlyString& property_name, PropertyAttributes attributes)
|
||||
Shape* Shape::create_put_transition(const StringOrSymbol& property_name, PropertyAttributes attributes)
|
||||
{
|
||||
TransitionKey key { property_name, attributes };
|
||||
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
|
||||
|
@ -51,7 +51,7 @@ Shape* Shape::create_put_transition(const FlyString& property_name, PropertyAttr
|
|||
return new_shape;
|
||||
}
|
||||
|
||||
Shape* Shape::create_configure_transition(const FlyString& property_name, PropertyAttributes attributes)
|
||||
Shape* Shape::create_configure_transition(const StringOrSymbol& property_name, PropertyAttributes attributes)
|
||||
{
|
||||
TransitionKey key { property_name, attributes };
|
||||
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
|
||||
|
@ -71,7 +71,7 @@ Shape::Shape(GlobalObject& global_object)
|
|||
{
|
||||
}
|
||||
|
||||
Shape::Shape(Shape& previous_shape, const FlyString& property_name, PropertyAttributes attributes, TransitionType transition_type)
|
||||
Shape::Shape(Shape& previous_shape, const StringOrSymbol& property_name, PropertyAttributes attributes, TransitionType transition_type)
|
||||
: m_global_object(previous_shape.m_global_object)
|
||||
, m_previous(&previous_shape)
|
||||
, m_property_name(property_name)
|
||||
|
@ -99,11 +99,16 @@ void Shape::visit_children(Cell::Visitor& visitor)
|
|||
visitor.visit(&m_global_object);
|
||||
visitor.visit(m_prototype);
|
||||
visitor.visit(m_previous);
|
||||
m_property_name.visit_children(visitor);
|
||||
for (auto& it : m_forward_transitions)
|
||||
visitor.visit(it.value);
|
||||
|
||||
ensure_property_table();
|
||||
for (auto& it : *m_property_table)
|
||||
it.key.visit_children(visitor);
|
||||
}
|
||||
|
||||
Optional<PropertyMetadata> Shape::lookup(const FlyString& property_name) const
|
||||
Optional<PropertyMetadata> Shape::lookup(const StringOrSymbol& property_name) const
|
||||
{
|
||||
auto property = property_table().get(property_name);
|
||||
if (!property.has_value())
|
||||
|
@ -111,7 +116,7 @@ Optional<PropertyMetadata> Shape::lookup(const FlyString& property_name) const
|
|||
return property;
|
||||
}
|
||||
|
||||
const HashMap<FlyString, PropertyMetadata>& Shape::property_table() const
|
||||
const HashMap<StringOrSymbol, PropertyMetadata>& Shape::property_table() const
|
||||
{
|
||||
ensure_property_table();
|
||||
return *m_property_table;
|
||||
|
@ -138,7 +143,7 @@ void Shape::ensure_property_table() const
|
|||
{
|
||||
if (m_property_table)
|
||||
return;
|
||||
m_property_table = make<HashMap<FlyString, PropertyMetadata>>();
|
||||
m_property_table = make<HashMap<StringOrSymbol, PropertyMetadata>>();
|
||||
|
||||
// FIXME: We need to make sure the GC doesn't collect the transition chain as we're building it.
|
||||
// Maybe some kind of RAII "prevent GC for a moment" helper thingy?
|
||||
|
@ -151,7 +156,7 @@ void Shape::ensure_property_table() const
|
|||
u32 next_offset = 0;
|
||||
for (ssize_t i = transition_chain.size() - 1; i >= 0; --i) {
|
||||
auto* shape = transition_chain[i];
|
||||
if (shape->m_property_name.is_null()) {
|
||||
if (!shape->m_property_name.is_valid()) {
|
||||
// Ignore prototype transitions as they don't affect the key map.
|
||||
continue;
|
||||
}
|
||||
|
@ -165,7 +170,7 @@ void Shape::ensure_property_table() const
|
|||
}
|
||||
}
|
||||
|
||||
void Shape::add_property_to_unique_shape(const FlyString& property_name, PropertyAttributes attributes)
|
||||
void Shape::add_property_to_unique_shape(const StringOrSymbol& property_name, PropertyAttributes attributes)
|
||||
{
|
||||
ASSERT(is_unique());
|
||||
ASSERT(m_property_table);
|
||||
|
@ -173,7 +178,7 @@ void Shape::add_property_to_unique_shape(const FlyString& property_name, Propert
|
|||
m_property_table->set(property_name, { m_property_table->size(), attributes });
|
||||
}
|
||||
|
||||
void Shape::reconfigure_property_in_unique_shape(const FlyString& property_name, PropertyAttributes attributes)
|
||||
void Shape::reconfigure_property_in_unique_shape(const StringOrSymbol& property_name, PropertyAttributes attributes)
|
||||
{
|
||||
ASSERT(is_unique());
|
||||
ASSERT(m_property_table);
|
||||
|
@ -181,7 +186,7 @@ void Shape::reconfigure_property_in_unique_shape(const FlyString& property_name,
|
|||
m_property_table->set(property_name, { m_property_table->size(), attributes });
|
||||
}
|
||||
|
||||
void Shape::remove_property_from_unique_shape(const FlyString& property_name, size_t offset)
|
||||
void Shape::remove_property_from_unique_shape(const StringOrSymbol& property_name, size_t offset)
|
||||
{
|
||||
ASSERT(is_unique());
|
||||
ASSERT(m_property_table);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue