Skip to content

Commit

Permalink
Fix setting properties inside with blocks (#2847)
Browse files Browse the repository at this point in the history
This preserves the semantics of the abstract operation `Set` on `with` blocks; setting non-writable properties on non-strict mode just silently fails.
  • Loading branch information
jedel1043 committed Apr 20, 2023
1 parent 1b67e5d commit 65f9105
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions boa_engine/src/environments/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ impl Context<'_> {
mut binding_index: usize,
name: Identifier,
value: JsValue,
strict: bool,
) -> JsResult<bool> {
for env_index in (environment_index + 1..self.vm.environments.stack.len()).rev() {
let env = self.environment_expect(env_index);
Expand Down Expand Up @@ -983,7 +984,7 @@ impl Context<'_> {
continue;
}
}
return o.set(key, value, true, self);
return o.set(key, value, strict, self);
}
}
}
Expand Down Expand Up @@ -1017,6 +1018,7 @@ impl Context<'_> {
&mut self,
name: Identifier,
value: &JsValue,
strict: bool,
) -> JsResult<bool> {
for env_index in (0..self.vm.environments.stack.len()).rev() {
let env = self.environment_expect(env_index);
Expand Down Expand Up @@ -1056,7 +1058,7 @@ impl Context<'_> {
continue;
}
}
return o.set(key, value.clone(), true, self);
return o.set(key, value.clone(), strict, self);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion boa_engine/src/vm/opcode/define/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ impl Operation for DefInitVar {
binding_locator.throw_mutate_immutable(context)?;

if binding_locator.is_global() {
if !context.put_value_if_global_poisoned(binding_locator.name(), &value)? {
if !context.put_value_if_global_poisoned(
binding_locator.name(),
&value,
context.vm.frame().code_block.strict,
)? {
let key = context
.interner()
.resolve_expect(binding_locator.name().sym())
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 @@ -25,7 +25,11 @@ impl Operation for SetName {
binding_locator.throw_mutate_immutable(context)?;

if binding_locator.is_global() {
if !context.put_value_if_global_poisoned(binding_locator.name(), &value)? {
if !context.put_value_if_global_poisoned(
binding_locator.name(),
&value,
context.vm.frame().code_block.strict,
)? {
let key: JsString = context
.interner()
.resolve_expect(binding_locator.name().sym())
Expand Down Expand Up @@ -55,6 +59,7 @@ impl Operation for SetName {
binding_locator.binding_index(),
binding_locator.name(),
value,
context.vm.frame().code_block.strict,
)? {
return Err(JsNativeError::reference()
.with_message(format!(
Expand Down

0 comments on commit 65f9105

Please sign in to comment.