Skip to content

Commit abdc9d5

Browse files
Lord-McSweeneyLord-McSweeney
Lord-McSweeney
authored andcommitted
avm2: Fix some small mistakes
`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.
1 parent becce39 commit abdc9d5

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

core/src/avm2/activation.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
25312531
let cur_index = self.pop_stack().coerce_to_i32(self)?;
25322532

25332533
if cur_index < 0 {
2534-
self.push_stack(false);
2534+
self.push_stack(0);
25352535

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

26202620
let value = self.pop_stack();
26212621
let object = match value.null_check(self, None)? {
2622-
Value::Object(obj) => Some(obj),
2623-
value => value.proto(self),
2622+
Value::Object(obj) => obj,
2623+
value => value
2624+
.proto(self)
2625+
.expect("Primitives always have a prototype"),
26242626
};
26252627

2626-
if let Some(object) = object {
2627-
let name = object.get_enumerant_name(cur_index as u32, self)?;
2628-
2629-
self.push_stack(name);
2630-
} else {
2631-
self.push_stack(Value::Undefined);
2632-
}
2628+
let name = object.get_enumerant_name(cur_index as u32, self)?;
2629+
self.push_stack(name);
26332630

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

26462643
let value = self.pop_stack();
26472644
let object = match value.null_check(self, None)? {
2648-
Value::Object(obj) => Some(obj),
2649-
value => value.proto(self),
2645+
Value::Object(obj) => obj,
2646+
value => value
2647+
.proto(self)
2648+
.expect("Primitives always have a prototype"),
26502649
};
26512650

2652-
if let Some(object) = object {
2653-
let value = object.get_enumerant_value(cur_index as u32, self)?;
2654-
2655-
self.push_stack(value);
2656-
} else {
2657-
self.push_stack(Value::Undefined);
2658-
}
2651+
let value = object.get_enumerant_value(cur_index as u32, self)?;
2652+
self.push_stack(value);
26592653

26602654
Ok(FrameControl::Continue)
26612655
}

core/src/avm2/object/proxy_object.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ impl<'gc> TObject<'gc> for ProxyObject<'gc> {
153153
.coerce_to_boolean())
154154
}
155155

156+
// FIXME: The AS-side Proxy.nextNameIndex returns an int, so this should return an i32
156157
fn get_next_enumerant(
157158
self,
158159
last_index: u32,

core/src/avm2/optimize.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ pub fn optimize<'gc>(
951951
Op::URShift => {
952952
stack.pop(activation)?;
953953
stack.pop(activation)?;
954-
stack.push_class(activation, types.int)?;
954+
stack.push_class(activation, types.uint)?;
955955
}
956956
Op::PushDouble { .. } => {
957957
stack.push_class(activation, types.number)?;
@@ -1252,14 +1252,20 @@ pub fn optimize<'gc>(
12521252
Op::HasNext => {
12531253
stack.pop(activation)?;
12541254
stack.pop(activation)?;
1255-
stack.push_any(activation)?;
1255+
1256+
// FIXME this should push `int` instead of `number`, but we have
1257+
// to fix TObject::get_next_enumerant to return i32 for that
1258+
stack.push_class(activation, types.number)?;
12561259
}
12571260
Op::HasNext2 {
12581261
index_register,
12591262
object_register,
12601263
} => {
12611264
stack.push_class(activation, types.boolean)?;
1262-
local_types.set_any(*index_register as usize);
1265+
1266+
// FIXME this should set the local to `int` instead of `number`, but
1267+
// we have to fix TObject::get_next_enumerant to return i32 for that
1268+
local_types.set(*index_register as usize, OptValue::of_type(types.number));
12631269
local_types.set_any(*object_register as usize);
12641270
}
12651271
Op::GetSlot { index: slot_id } => {

0 commit comments

Comments
 (0)