mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +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:
parent
d980073122
commit
6e05685ad4
3 changed files with 59 additions and 8 deletions
|
@ -269,7 +269,7 @@ Value WhileStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ Value DoWhileStatement::execute(Interpreter& interpreter, GlobalObject& global_o
|
|||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
}
|
||||
} while (m_test->execute(interpreter, global_object).to_boolean());
|
||||
|
@ -343,7 +343,7 @@ Value ForStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
|
|||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
}
|
||||
if (m_update) {
|
||||
|
@ -364,7 +364,7 @@ Value ForStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
|
|||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
}
|
||||
if (m_update) {
|
||||
|
@ -431,7 +431,7 @@ Value ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
interpreter.vm().stop_unwind();
|
||||
break;
|
||||
} else {
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -480,8 +480,6 @@ Value ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
if (interpreter.vm().should_unwind())
|
||||
return js_undefined();
|
||||
return last_value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue