Skip to content

Commit

Permalink
avm2: Fix some small mistakes
Browse files Browse the repository at this point in the history
`op_has_next` should push `false`, not `0` when `cur_index` is negative, and Op::URShift should push the uint type in the optimizer, not the int type.
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Jan 15, 2025
1 parent cd6c38b commit 0b1bf17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
32 changes: 13 additions & 19 deletions core/src/avm2/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let cur_index = self.pop_stack().coerce_to_i32(self)?;

if cur_index < 0 {
self.push_stack(false);
self.push_stack(0);

return Ok(FrameControl::Continue);
}
Expand Down Expand Up @@ -2619,17 +2619,14 @@ impl<'a, 'gc> Activation<'a, 'gc> {

let value = self.pop_stack();
let object = match value.null_check(self, None)? {
Value::Object(obj) => Some(obj),
value => value.proto(self),
Value::Object(obj) => obj,
value => value
.proto(self)
.expect("Primitives always have a prototype"),
};

if let Some(object) = object {
let name = object.get_enumerant_name(cur_index as u32, self)?;

self.push_stack(name);
} else {
self.push_stack(Value::Undefined);
}
let name = object.get_enumerant_name(cur_index as u32, self)?;
self.push_stack(name);

Ok(FrameControl::Continue)
}
Expand All @@ -2645,17 +2642,14 @@ impl<'a, 'gc> Activation<'a, 'gc> {

let value = self.pop_stack();
let object = match value.null_check(self, None)? {
Value::Object(obj) => Some(obj),
value => value.proto(self),
Value::Object(obj) => obj,
value => value
.proto(self)
.expect("Primitives always have a prototype"),
};

if let Some(object) = object {
let value = object.get_enumerant_value(cur_index as u32, self)?;

self.push_stack(value);
} else {
self.push_stack(Value::Undefined);
}
let value = object.get_enumerant_value(cur_index as u32, self)?;
self.push_stack(value);

Ok(FrameControl::Continue)
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ pub fn optimize<'gc>(
Op::URShift => {
stack.pop(activation)?;
stack.pop(activation)?;
stack.push_class(activation, types.int)?;
stack.push_class(activation, types.uint)?;
}
Op::PushDouble { .. } => {
stack.push_class(activation, types.number)?;
Expand Down Expand Up @@ -1252,14 +1252,14 @@ pub fn optimize<'gc>(
Op::HasNext => {
stack.pop(activation)?;
stack.pop(activation)?;
stack.push_any(activation)?;
stack.push_class(activation, types.number)?;
}
Op::HasNext2 {
index_register,
object_register,
} => {
stack.push_class(activation, types.boolean)?;
local_types.set_any(*index_register as usize);
local_types.set(*index_register as usize, OptValue::of_type(types.number));
local_types.set_any(*object_register as usize);
}
Op::GetSlot { index: slot_id } => {
Expand Down

0 comments on commit 0b1bf17

Please sign in to comment.