mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:17:36 +00:00
LibJS: Parse "if" statements
This patch implements basic parsing of "if" statements. We don't yet support parsing "else", so I added a FIXME about that.
This commit is contained in:
parent
55c845713a
commit
7c48c3c8e1
4 changed files with 26 additions and 7 deletions
|
@ -91,8 +91,11 @@ Value IfStatement::execute(Interpreter& interpreter) const
|
|||
|
||||
if (predicate_result.to_boolean())
|
||||
return interpreter.run(*m_consequent);
|
||||
else
|
||||
|
||||
if (m_alternate)
|
||||
return interpreter.run(*m_alternate);
|
||||
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
Value WhileStatement::execute(Interpreter& interpreter) const
|
||||
|
@ -427,9 +430,11 @@ void IfStatement::dump(int indent) const
|
|||
printf("If\n");
|
||||
predicate().dump(indent + 1);
|
||||
consequent().dump(indent + 1);
|
||||
print_indent(indent);
|
||||
printf("Else\n");
|
||||
alternate().dump(indent + 1);
|
||||
if (alternate()) {
|
||||
print_indent(indent);
|
||||
printf("Else\n");
|
||||
alternate()->dump(indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void WhileStatement::dump(int indent) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue