LibJS: Generate update Jump in for/in/of only if block is not terminated

The body of for/in/of can contain an unconditional block terminator
(e.g. return, throw), so we have to check for that before generating
the Jump to the loop update block.
This commit is contained in:
Luke Wilde 2022-03-27 18:46:25 +01:00 committed by Andreas Kling
parent 741745baab
commit 88901182b8
Notes: sideshowbarker 2024-07-17 16:38:18 +09:00

View file

@ -1999,7 +1999,11 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
// 3. If iteratorKind is async, return ? AsyncIteratorClose(iteratorRecord, status).
// 4. Return ? IteratorClose(iteratorRecord, status).
// o. If result.[[Value]] is not empty, set V to result.[[Value]].
generator.emit<Bytecode::Op::Jump>().set_targets(Bytecode::Label { loop_update }, {});
// The body can contain an unconditional block terminator (e.g. return, throw), so we have to check for that before generating the Jump.
if (!generator.is_current_block_terminated())
generator.emit<Bytecode::Op::Jump>().set_targets(Bytecode::Label { loop_update }, {});
generator.switch_to_basic_block(loop_end);
return {};
}