mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
LibJS: Implement "else" parsing
We can now handle scripts with if/else in LibJS. Most of the changes are about fixing IfStatement to store the consequent and alternate node as Statements. Interpreter now also runs Statements, rather than running ScopeNodes.
This commit is contained in:
@@ -50,16 +50,20 @@ Interpreter::~Interpreter()
|
||||
{
|
||||
}
|
||||
|
||||
Value Interpreter::run(const ScopeNode& scope_node, Vector<Argument> arguments, ScopeType scope_type)
|
||||
Value Interpreter::run(const Statement& statement, Vector<Argument> arguments, ScopeType scope_type)
|
||||
{
|
||||
enter_scope(scope_node, move(arguments), scope_type);
|
||||
if (!statement.is_scope_node())
|
||||
return statement.execute(*this);
|
||||
|
||||
auto& block = static_cast<const BlockStatement&>(statement);
|
||||
enter_scope(block, move(arguments), scope_type);
|
||||
|
||||
Value last_value = js_undefined();
|
||||
for (auto& node : scope_node.children()) {
|
||||
for (auto& node : block.children()) {
|
||||
last_value = node.execute(*this);
|
||||
}
|
||||
|
||||
exit_scope(scope_node);
|
||||
exit_scope(block);
|
||||
return last_value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user