mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +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:
parent
90ba0145f6
commit
be019f28ca
5 changed files with 91 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue