mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibJS: Support "hello friends".length
The above snippet is a MemberExpression that necessitates the implicit construction of a StringObject wrapper around a PrimitiveString. We then do a property lookup (a "get") on the StringObject, where we find the "length" property. This is pretty neat! :^)
This commit is contained in:
parent
6ec6fa1a02
commit
542108421e
6 changed files with 100 additions and 11 deletions
|
@ -387,7 +387,6 @@ Value VariableDeclaration::execute(Interpreter& interpreter) const
|
|||
return js_undefined();
|
||||
}
|
||||
|
||||
|
||||
void VariableDeclaration::dump(int indent) const
|
||||
{
|
||||
ASTNode::dump(indent);
|
||||
|
@ -406,4 +405,26 @@ Value ObjectExpression::execute(Interpreter& interpreter) const
|
|||
return Value(interpreter.heap().allocate<Object>());
|
||||
}
|
||||
|
||||
void MemberExpression::dump(int indent) const
|
||||
{
|
||||
ASTNode::dump(indent);
|
||||
m_object->dump(indent + 1);
|
||||
m_property->dump(indent + 1);
|
||||
}
|
||||
|
||||
Value MemberExpression::execute(Interpreter& interpreter) const
|
||||
{
|
||||
auto object_result = m_object->execute(interpreter).to_object(interpreter.heap());
|
||||
ASSERT(object_result.is_object());
|
||||
|
||||
String property_name;
|
||||
if (m_property->is_identifier()) {
|
||||
property_name = static_cast<const Identifier&>(*m_property).string();
|
||||
} else {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
return object_result.as_object()->get(property_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue