LibJS/Rust: Push LeaveLexicalEnvironment boundary in for-of loops

When a for-of loop creates a per-iteration lexical environment for
let/const declarations, push a LeaveLexicalEnvironment boundary so
that continue/break/return properly restores the lexical environment.
The for-in codegen already did this but for-of was missing it.
This commit is contained in:
Andreas Kling 2026-03-01 17:05:59 +01:00 committed by Andreas Kling
parent f0c34d54a1
commit 7602e030e7

View file

@ -6747,6 +6747,9 @@ fn generate_for_of_statement_inner(
// Body
generator.begin_continuable_scope(update_block, labels, completion.clone());
if needs_lexical_env {
generator.start_boundary(BlockBoundaryType::LeaveLexicalEnvironment);
}
if !generator.is_current_block_terminated() {
generate_with_completion(body, generator, &completion, preferred_dst);
@ -6754,6 +6757,7 @@ fn generate_for_of_statement_inner(
// Restore lexical env before continuing
if needs_lexical_env {
generator.end_boundary(BlockBoundaryType::LeaveLexicalEnvironment);
generator.lexical_environment_register_stack.pop();
}
generator.end_continuable_scope();