1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

LibJS: Fix return statements not working properly in loops

Previously, when a loop detected an unwind of type ScopeType::Function
(which means a return statement was executed inside of the loop), it
would just return undefined. This set the VM's last_value to undefined,
when it should have been the returned value. This patch makes all loop
statements return the appropriate value in the above case.
This commit is contained in:
Matthew Olsson 2020-10-08 13:17:40 -07:00 committed by Andreas Kling
parent d980073122
commit 6e05685ad4
3 changed files with 59 additions and 8 deletions

View file

@ -167,7 +167,7 @@ public:
m_unwind_until_label = label;
}
void stop_unwind() { m_unwind_until = ScopeType::None; }
bool should_unwind_until(ScopeType type, FlyString label) const
bool should_unwind_until(ScopeType type, FlyString label = {}) const
{
if (m_unwind_until_label.is_null())
return m_unwind_until == type;