mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Handle continue in switch statement unwinding
This commit is contained in:
parent
8f54edb7a0
commit
f8886ef5ba
Notes:
sideshowbarker
2024-07-19 01:51:22 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/f8886ef5baa Pull-request: https://github.com/SerenityOS/serenity/pull/3791 Issue: https://github.com/SerenityOS/serenity/issues/3790
2 changed files with 20 additions and 1 deletions
|
@ -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 {};
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue