summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r--Libraries/LibJS/AST.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index 81b224ccf2..b3daa4eb3b 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -873,7 +873,31 @@ Value ThrowStatement::execute(Interpreter& interpreter) const
Value SwitchStatement::execute(Interpreter& interpreter) const
{
- (void)interpreter;
+ auto discriminant_result = m_discriminant->execute(interpreter);
+ if (interpreter.exception())
+ return {};
+
+ bool falling_through = false;
+
+ for (auto& switch_case : m_cases) {
+ if (!falling_through && switch_case.test()) {
+ auto test_result = switch_case.test()->execute(interpreter);
+ if (interpreter.exception())
+ return {};
+ if (!eq(discriminant_result, test_result).to_boolean())
+ continue;
+ }
+ falling_through = true;
+
+ for (auto& statement : switch_case.consequent()) {
+ statement.execute(interpreter);
+ if (interpreter.exception())
+ return {};
+ if (interpreter.should_unwind())
+ return {};
+ }
+ }
+
return {};
}
@@ -885,7 +909,7 @@ Value SwitchCase::execute(Interpreter& interpreter) const
Value BreakStatement::execute(Interpreter& interpreter) const
{
- (void)interpreter;
+ interpreter.unwind(ScopeType::Breakable);
return {};
}