summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-03-27 18:46:25 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-28 14:05:33 +0200
commit88901182b830525ccb471351f39b6cdf5e5d9ab6 (patch)
tree6c7728c62b746c42c64c6771453a6807c26d91c7 /Userland/Libraries/LibJS
parent741745baabf1c8d3625631114a961bf404a4ae7d (diff)
downloadserenity-88901182b830525ccb471351f39b6cdf5e5d9ab6.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index 49001ab8de..93a1b58b4d 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -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 {};
}