mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +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:
parent
b2f005125d
commit
fbb9e1b715
5 changed files with 31 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue