Skip to content
Open
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
16 changes: 16 additions & 0 deletions core/src/avm2/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
Op::GetDescendants { multiname } => self.op_get_descendants(*multiname),
Op::GetSlot { index } => self.op_get_slot(*index),
Op::SetSlot { index } => self.op_set_slot(*index),
Op::SetSlotCoerceI { index } => self.op_set_slot_coerce_i(*index),
Op::SetSlotNoCoerce { index } => self.op_set_slot_no_coerce(*index),
Op::SetGlobalSlot { index } => self.op_set_global_slot(*index),
Op::Construct { num_args } => self.op_construct(*num_args),
Expand Down Expand Up @@ -1689,6 +1690,21 @@ impl<'a, 'gc> Activation<'a, 'gc> {
Ok(())
}

fn op_set_slot_coerce_i(&mut self, index: usize) -> Result<(), Error<'gc>> {
let value = self.pop_stack();
let object = self
.pop_stack()
.null_check(self, None)?
.as_object()
.expect("Cannot set_slot on primitive");

let value = value.coerce_to_i32(self)?;

object.set_slot_no_coerce(index, value.into(), self.gc());

Ok(())
}

fn op_set_slot_no_coerce(&mut self, index: usize) -> Result<(), Error<'gc>> {
let value = self.pop_stack();
let object = self
Expand Down
4 changes: 4 additions & 0 deletions core/src/avm2/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ pub enum Op<'gc> {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetSlotCoerceI {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetSlotNoCoerce {
// note: 0-indexed, as opposed to FP.
index: usize,
Expand Down
10 changes: 10 additions & 0 deletions core/src/avm2/optimizer/type_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,9 @@ fn abstract_interpret_ops<'gc>(
// Skip the coercion when possible
if set_value.matches_type(resolved_value_class) {
optimize_op_to!(Op::SetSlotNoCoerce { index: slot_id });
} else if resolved_value_class.is_some_and(|c| c.is_builtin_int()) {
// Special case for integer coercion, for performance
optimize_op_to!(Op::SetSlotCoerceI { index: slot_id });
}
}
Op::GetPropertyStatic { multiname } => {
Expand Down Expand Up @@ -1547,6 +1550,9 @@ fn abstract_interpret_ops<'gc>(

if set_value.matches_type(resolved_value_class) {
optimize_op_to!(Op::SetSlotNoCoerce { index: slot_id });
} else if resolved_value_class.is_some_and(|c| c.is_builtin_int()) {
// Special case for integer coercion, for performance
optimize_op_to!(Op::SetSlotCoerceI { index: slot_id });
} else {
optimize_op_to!(Op::SetSlot { index: slot_id });
}
Expand Down Expand Up @@ -1602,6 +1608,9 @@ fn abstract_interpret_ops<'gc>(

if set_value.matches_type(resolved_value_class) {
optimize_op_to!(Op::SetSlotNoCoerce { index: slot_id });
} else if resolved_value_class.is_some_and(|c| c.is_builtin_int()) {
// Special case for integer coercion, for performance
optimize_op_to!(Op::SetSlotCoerceI { index: slot_id });
} else {
optimize_op_to!(Op::SetSlot { index: slot_id });
}
Expand Down Expand Up @@ -2116,6 +2125,7 @@ fn abstract_interpret_ops<'gc>(
| Op::ConstructSlot { .. }
| Op::GetScriptGlobals { .. }
| Op::PopJump { .. }
| Op::SetSlotCoerceI { .. }
| Op::SetSlotNoCoerce { .. } => unreachable!("Custom ops should not be encountered"),
}
}
Expand Down
Loading