mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Make "break" actually work inside "switch"
This commit is contained in:
parent
9d099835f9
commit
e3b92caa6d
Notes:
sideshowbarker
2024-07-19 07:55:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e3b92caa6d9
3 changed files with 33 additions and 1 deletions
|
@ -980,8 +980,13 @@ Value SwitchStatement::execute(Interpreter& interpreter) const
|
|||
statement.execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
if (interpreter.should_unwind())
|
||||
if (interpreter.should_unwind()) {
|
||||
if (interpreter.should_unwind_until(ScopeType::Breakable)) {
|
||||
interpreter.stop_unwind();
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,8 @@ public:
|
|||
Heap& heap() { return m_heap; }
|
||||
|
||||
void unwind(ScopeType type) { m_unwind_until = type; }
|
||||
void stop_unwind() { m_unwind_until = ScopeType::None; }
|
||||
bool should_unwind_until(ScopeType type) const { return m_unwind_until == type; }
|
||||
bool should_unwind() const { return m_unwind_until != ScopeType::None; }
|
||||
|
||||
Optional<Value> get_variable(const FlyString& name);
|
||||
|
|
25
Libraries/LibJS/Tests/switch-break.js
Normal file
25
Libraries/LibJS/Tests/switch-break.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var i = 0;
|
||||
var three;
|
||||
var five;
|
||||
|
||||
for (; i < 9; ) {
|
||||
switch (i) {
|
||||
case 3:
|
||||
three = i;
|
||||
break;
|
||||
case 5:
|
||||
five = i;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
assert(three === 3);
|
||||
assert(five === 5);
|
||||
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue