diff options
author | Linus Groh <mail@linusgroh.de> | 2020-10-18 17:44:55 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-18 19:08:52 +0200 |
commit | 8f54edb7a0846908266f66cc17a19908328d14d5 (patch) | |
tree | c074e16652b357b0fb0f73a319e35f2fcc976344 /Libraries/LibJS/AST.cpp | |
parent | 2c888b3c6e118fa4354aa21d5bed62e17bc045b4 (diff) | |
download | serenity-8f54edb7a0846908266f66cc17a19908328d14d5.zip |
LibJS: Handle return value in switch statement unwinding
Fixes #3790.
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 044f35bac5..098d4699dd 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -1469,7 +1469,7 @@ Value VariableDeclaration::execute(Interpreter& interpreter, GlobalObject& globa Value VariableDeclarator::execute(Interpreter&, GlobalObject&) const { - // NOTE: This node is handled by VariableDeclaration. + // NOTE: VariableDeclarator execution is handled by VariableDeclaration. ASSERT_NOT_REACHED(); } @@ -1894,15 +1894,18 @@ Value SwitchStatement::execute(Interpreter& interpreter, GlobalObject& global_ob falling_through = true; for (auto& statement : switch_case.consequent()) { - statement.execute(interpreter, global_object); + auto last_value = statement.execute(interpreter, global_object); if (interpreter.exception()) return {}; if (interpreter.vm().should_unwind()) { - if (interpreter.vm().should_unwind_until(ScopeType::Breakable, m_label)) { + if (interpreter.vm().should_unwind_until(ScopeType::Continuable, m_label)) { + ASSERT_NOT_REACHED(); + } else if (interpreter.vm().should_unwind_until(ScopeType::Breakable, m_label)) { interpreter.vm().stop_unwind(); return {}; + } else { + return last_value; } - return {}; } } } @@ -1912,6 +1915,8 @@ Value SwitchStatement::execute(Interpreter& interpreter, GlobalObject& global_ob Value SwitchCase::execute(Interpreter&, GlobalObject&) const { + // NOTE: SwitchCase execution is handled by SwitchStatement. + ASSERT_NOT_REACHED(); return {}; } |