mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +00:00
LibJS: Add a PropertyName class that represents a string or a number
Now that we have two separate storages for Object properties depending on what kind of index they have, it's nice to have an abstraction that still allows us to say "here's a property name". We use PropertyName to always choose the optimal storage path directly while interpreting the AST. :^)
This commit is contained in:
@@ -855,13 +855,17 @@ void MemberExpression::dump(int indent) const
|
||||
m_property->dump(indent + 1);
|
||||
}
|
||||
|
||||
FlyString MemberExpression::computed_property_name(Interpreter& interpreter) const
|
||||
PropertyName MemberExpression::computed_property_name(Interpreter& interpreter) const
|
||||
{
|
||||
if (!is_computed()) {
|
||||
ASSERT(m_property->is_identifier());
|
||||
return static_cast<const Identifier&>(*m_property).string();
|
||||
return PropertyName(static_cast<const Identifier&>(*m_property).string());
|
||||
}
|
||||
return m_property->execute(interpreter).to_string();
|
||||
auto index = m_property->execute(interpreter);
|
||||
// FIXME: What about non-integer numbers tho.
|
||||
if (index.is_number())
|
||||
return PropertyName(index.to_i32());
|
||||
return PropertyName(index.to_string());
|
||||
}
|
||||
|
||||
Value MemberExpression::execute(Interpreter& interpreter) const
|
||||
|
||||
Reference in New Issue
Block a user