mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Handle unwinding in while and do-while statements
For some reason, this was never added. So something like "while (true) { return }" would loop infinitely.
This commit is contained in:
parent
397e5766ff
commit
d980073122
Notes:
sideshowbarker
2024-07-19 01:57:31 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/d980073122b Pull-request: https://github.com/SerenityOS/serenity/pull/3726 Issue: https://github.com/SerenityOS/serenity/issues/3604
2 changed files with 20 additions and 0 deletions
|
@ -262,6 +262,16 @@ Value WhileStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
last_value = interpreter.execute_statement(global_object, *m_body);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
if (interpreter.vm().should_unwind()) {
|
||||
if (interpreter.vm().should_unwind_until(ScopeType::Continuable, m_label)) {
|
||||
interpreter.vm().stop_unwind();
|
||||
} else if (interpreter.vm().should_unwind_until(ScopeType::Breakable, m_label)) {
|
||||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return last_value;
|
||||
|
@ -276,6 +286,16 @@ Value DoWhileStatement::execute(Interpreter& interpreter, GlobalObject& global_o
|
|||
last_value = interpreter.execute_statement(global_object, *m_body);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
if (interpreter.vm().should_unwind()) {
|
||||
if (interpreter.vm().should_unwind_until(ScopeType::Continuable, m_label)) {
|
||||
interpreter.vm().stop_unwind();
|
||||
} else if (interpreter.vm().should_unwind_until(ScopeType::Breakable, m_label)) {
|
||||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
}
|
||||
}
|
||||
} while (m_test->execute(interpreter, global_object).to_boolean());
|
||||
|
||||
return last_value;
|
||||
|
|
0
Libraries/LibJS/Tests/return.js
Normal file
0
Libraries/LibJS/Tests/return.js
Normal file
Loading…
Reference in a new issue