LibJS: Support empty values in array expression

This commit is contained in:
Linus Groh 2020-04-15 20:09:06 +01:00 committed by Andreas Kling
parent d30db07048
commit cea950fd70
Notes: sideshowbarker 2024-07-19 07:33:59 +09:00
4 changed files with 44 additions and 10 deletions

View file

@ -973,7 +973,12 @@ void ArrayExpression::dump(int indent) const
{
ASTNode::dump(indent);
for (auto& element : m_elements) {
element.dump(indent + 1);
if (element) {
element->dump(indent + 1);
} else {
print_indent(indent + 1);
printf("<empty>\n");
}
}
}
@ -981,9 +986,12 @@ Value ArrayExpression::execute(Interpreter& interpreter) const
{
auto* array = interpreter.heap().allocate<Array>();
for (auto& element : m_elements) {
auto value = element.execute(interpreter);
if (interpreter.exception())
return {};
auto value = Value();
if (element) {
value = element->execute(interpreter);
if (interpreter.exception())
return {};
}
array->elements().append(value);
}
return array;