diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-05 00:22:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-05 00:22:42 +0200 |
commit | 9ebd066ac84d6a4b132299c4a927e2c4049a2f42 (patch) | |
tree | f88ed91b0c838b5cf5d95f994f3c1081418c8022 /Libraries/LibJS/AST.cpp | |
parent | e3b92caa6d9f00a25095d294601131e106b94c93 (diff) | |
download | serenity-9ebd066ac84d6a4b132299c4a927e2c4049a2f42.zip |
LibJS: Add support for "continue" inside "for" statements :^)
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 6dc50d51ae..52d8e007ff 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -215,6 +215,16 @@ Value ForStatement::execute(Interpreter& interpreter) const last_value = interpreter.run(*m_body); if (interpreter.exception()) return {}; + if (interpreter.should_unwind()) { + if (interpreter.should_unwind_until(ScopeType::Continuable)) { + interpreter.stop_unwind(); + } else if (interpreter.should_unwind_until(ScopeType::Breakable)) { + interpreter.stop_unwind(); + break; + } else { + return {}; + } + } if (m_update) { m_update->execute(interpreter); if (interpreter.exception()) @@ -226,6 +236,16 @@ Value ForStatement::execute(Interpreter& interpreter) const last_value = interpreter.run(*m_body); if (interpreter.exception()) return {}; + if (interpreter.should_unwind()) { + if (interpreter.should_unwind_until(ScopeType::Continuable)) { + interpreter.stop_unwind(); + } else if (interpreter.should_unwind_until(ScopeType::Breakable)) { + interpreter.stop_unwind(); + break; + } else { + return {}; + } + } if (m_update) { m_update->execute(interpreter); if (interpreter.exception()) @@ -759,7 +779,7 @@ Value VariableDeclaration::execute(Interpreter& interpreter) const return {}; } -Value VariableDeclarator::execute(Interpreter &) const +Value VariableDeclarator::execute(Interpreter&) const { // NOTE: This node is handled by VariableDeclaration. ASSERT_NOT_REACHED(); @@ -1005,6 +1025,12 @@ Value BreakStatement::execute(Interpreter& interpreter) const return {}; } +Value ContinueStatement::execute(Interpreter& interpreter) const +{ + interpreter.unwind(ScopeType::Continuable); + return {}; +} + void SwitchStatement::dump(int indent) const { ASTNode::dump(indent); |