Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent DefVar opcode emit for global binding #3453

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 5 additions & 9 deletions boa_engine/src/vm/opcode/define/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Loading