diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:29:23 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:29:23 +0200 |
commit | f8393b80e302b80b20198ea53b3c29342faf4003 (patch) | |
tree | 9966d41098a022f64001756f4dc33bd42048c406 /Libraries/LibJS/AST.cpp | |
parent | da0715aba96b85a6df23854960ebb3382fa0cf1f (diff) | |
download | serenity-f8393b80e302b80b20198ea53b3c29342faf4003.zip |
LibJS: Add support for do..while statements
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 1b4cd0d76b..978ede3922 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -177,6 +177,20 @@ Value WhileStatement::execute(Interpreter& interpreter) const return last_value; } +Value DoWhileStatement::execute(Interpreter& interpreter) const +{ + Value last_value = js_undefined(); + do { + if (interpreter.exception()) + return {}; + last_value = interpreter.run(*m_body); + if (interpreter.exception()) + return {}; + } while (m_test->execute(interpreter).to_boolean()); + + return last_value; +} + Value ForStatement::execute(Interpreter& interpreter) const { RefPtr<BlockStatement> wrapper; @@ -568,6 +582,16 @@ void WhileStatement::dump(int indent) const body().dump(indent + 1); } +void DoWhileStatement::dump(int indent) const +{ + ASTNode::dump(indent); + + print_indent(indent); + printf("DoWhile\n"); + test().dump(indent + 1); + body().dump(indent + 1); +} + void ForStatement::dump(int indent) const { ASTNode::dump(indent); |