diff --git a/boa_engine/src/bytecompiler/mod.rs b/boa_engine/src/bytecompiler/mod.rs index ddce437535..86333d9721 100644 --- a/boa_engine/src/bytecompiler/mod.rs +++ b/boa_engine/src/bytecompiler/mod.rs @@ -407,8 +407,10 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> { match opcode { BindingOpcode::Var => { let binding = self.variable_environment.get_identifier_reference(name); - let index = self.get_or_insert_binding(binding.locator()); - self.emit_with_varying_operand(Opcode::DefVar, index); + if !binding.locator().is_global() { + let index = self.get_or_insert_binding(binding.locator()); + self.emit_with_varying_operand(Opcode::DefVar, index); + } } BindingOpcode::InitVar => match self.lexical_environment.set_mutable_binding(name) { Ok(binding) => { diff --git a/boa_engine/src/vm/opcode/define/mod.rs b/boa_engine/src/vm/opcode/define/mod.rs index 57fd59cf99..bee48d200b 100644 --- a/boa_engine/src/vm/opcode/define/mod.rs +++ b/boa_engine/src/vm/opcode/define/mod.rs @@ -22,15 +22,11 @@ impl DefVar { // TODO: spec specifies to return `empty` on empty vars, but we're trying to initialize. let binding_locator = context.vm.frame().code_block.bindings[index]; - if binding_locator.is_global() { - // already initialized at compile time - } else { - context.vm.environments.put_value_if_uninitialized( - binding_locator.environment_index(), - binding_locator.binding_index(), - JsValue::undefined(), - ); - } + context.vm.environments.put_value_if_uninitialized( + binding_locator.environment_index(), + binding_locator.binding_index(), + JsValue::undefined(), + ); Ok(CompletionType::Normal) } }