summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-06 17:08:23 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-06 18:09:26 +0200
commitbe019f28caa5400db817ef00ac6bd727c7252d0f (patch)
tree701df2bd5f17d3f5dbe585204f3c871db7ec0000 /Libraries/LibJS/AST.cpp
parent90ba0145f6baec96bee41d2d0aa63253a42f4101 (diff)
downloadserenity-be019f28caa5400db817ef00ac6bd727c7252d0f.zip
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. :^)
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r--Libraries/LibJS/AST.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index be00893918..e52f7f00ad 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -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