Skip to content

Commit

Permalink
Fix binding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed May 3, 2023
1 parent adf48c5 commit 1cad14e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion boa_engine/src/environments/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl BindingLocator {
}

/// Creates a binding locator that indicates that the binding is on the global object.
pub(crate) const fn global(name: Identifier) -> Self {
pub(super) const fn global(name: Identifier) -> Self {
Self {
name,
environment_index: 0,
Expand Down
7 changes: 3 additions & 4 deletions boa_engine/src/vm/call_frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
vm::CodeBlock,
};
use boa_gc::{Finalize, Gc, Trace};
use boa_interner::Sym;
use thin_vec::ThinVec;

pub(crate) use abrupt_record::AbruptCompletionRecord;
Expand Down Expand Up @@ -44,8 +43,8 @@ pub struct CallFrame {
// Iterators and their `[[Done]]` flags that must be closed when an abrupt completion is thrown.
pub(crate) iterators: ThinVec<(JsObject, bool)>,

// The current binding being updated.
pub(crate) current_binding: BindingLocator,
// The stack of bindings being updated.
pub(crate) binding_stack: Vec<BindingLocator>,
}

/// ---- `CallFrame` public API ----
Expand Down Expand Up @@ -76,7 +75,7 @@ impl CallFrame {
promise_capability: None,
async_generator: None,
iterators: ThinVec::new(),
current_binding: BindingLocator::global(Sym::EMPTY_STRING.into()),
binding_stack: Vec::new(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/get/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Operation for GetLocator {
let mut binding_locator = context.vm.frame().code_block.bindings[index as usize];
context.find_runtime_binding(&mut binding_locator)?;

context.vm.frame_mut().current_binding = binding_locator;
context.vm.frame_mut().binding_stack.push(binding_locator);

Ok(CompletionType::Normal)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Operation for GetNameAndLocator {
JsNativeError::reference().with_message(format!("{name} is not defined"))
})?;

context.vm.frame_mut().current_binding = binding_locator;
context.vm.frame_mut().binding_stack.push(binding_locator);
context.vm.push(value);
Ok(CompletionType::Normal)
}
Expand Down
7 changes: 6 additions & 1 deletion boa_engine/src/vm/opcode/set/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ impl Operation for SetNameByLocator {
const INSTRUCTION: &'static str = "INST - SetNameByLocator";

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let binding_locator = context.vm.frame().current_binding;
let binding_locator = context
.vm
.frame_mut()
.binding_stack
.pop()
.expect("locator should have been popped before");
let value = context.vm.pop();
if binding_locator.is_silent() {
return Ok(CompletionType::Normal);
Expand Down

0 comments on commit 1cad14e

Please sign in to comment.