From 068aa6c746d618c1ab149d65bcd323203b6004cc Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Tue, 19 Mar 2024 03:09:45 +0100 Subject: [PATCH] Add missing environment creation in initial iteration of for loop --- core/engine/src/bytecompiler/statement/loop.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/engine/src/bytecompiler/statement/loop.rs b/core/engine/src/bytecompiler/statement/loop.rs index 4af3de4bff1..71c6f453e3f 100644 --- a/core/engine/src/bytecompiler/statement/loop.rs +++ b/core/engine/src/bytecompiler/statement/loop.rs @@ -59,6 +59,20 @@ impl ByteCompiler<'_> { } self.push_empty_loop_jump_control(use_expr); + + if let Some((let_binding_indices, env_index)) = &let_binding_indices { + for index in let_binding_indices { + self.emit_with_varying_operand(Opcode::GetName, *index); + } + + self.emit_opcode(Opcode::PopEnvironment); + self.emit_with_varying_operand(Opcode::PushDeclarativeEnvironment, *env_index); + + for index in let_binding_indices.iter().rev() { + self.emit_with_varying_operand(Opcode::PutLexicalValue, *index); + } + } + let initial_jump = self.jump(); let start_address = self.next_opcode_location();