summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-10-18 18:01:12 +0100
committerAndreas Kling <kling@serenityos.org>2020-10-18 19:08:52 +0200
commitf8886ef5baa6fe44688ac1f3a76984a322971653 (patch)
tree0e7bafc417dbdff00f627a61405c495df90bd741
parent8f54edb7a0846908266f66cc17a19908328d14d5 (diff)
downloadserenity-f8886ef5baa6fe44688ac1f3a76984a322971653.zip
LibJS: Handle continue in switch statement unwinding
-rw-r--r--Libraries/LibJS/AST.cpp3
-rw-r--r--Libraries/LibJS/Tests/switch-basic.js18
2 files changed, 20 insertions, 1 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index 098d4699dd..6bf047859a 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -1899,7 +1899,8 @@ Value SwitchStatement::execute(Interpreter& interpreter, GlobalObject& global_ob
return {};
if (interpreter.vm().should_unwind()) {
if (interpreter.vm().should_unwind_until(ScopeType::Continuable, m_label)) {
- ASSERT_NOT_REACHED();
+ // No stop_unwind(), the outer loop will handle that - we just need to break out of the switch/case.
+ return {};
} else if (interpreter.vm().should_unwind_until(ScopeType::Breakable, m_label)) {
interpreter.vm().stop_unwind();
return {};
diff --git a/Libraries/LibJS/Tests/switch-basic.js b/Libraries/LibJS/Tests/switch-basic.js
index b5cb52ae8d..5c2a851ac0 100644
--- a/Libraries/LibJS/Tests/switch-basic.js
+++ b/Libraries/LibJS/Tests/switch-basic.js
@@ -49,4 +49,22 @@ describe("basic switch tests", () => {
expect(foo(42)).toBe("return from 'case 42'");
expect(foo(43)).toBe("return from 'default'");
});
+
+ test("continue from switch statement", () => {
+ let i = 0;
+ for (; i < 5; ++i) {
+ switch (i) {
+ case 0:
+ continue;
+ expect().fail();
+ case 0:
+ expect().fail();
+ default:
+ continue;
+ expect().fail();
+ }
+ expect().fail();
+ }
+ expect(i).toBe(5);
+ });
});