swf: `CallMethod` takes a `disp_id`, not any sort of `Index`

This commit is contained in:
Lord-McSweeney 2024-03-07 19:48:45 -08:00 committed by Lord-McSweeney
parent 028a61e744
commit b5f7fa0cd0
7 changed files with 12 additions and 17 deletions

View File

@ -1192,7 +1192,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
fn op_call_method(
&mut self,
index: Index<AbcMethod>,
index: u32,
arg_count: u32,
) -> Result<FrameControl<'gc>, Error<'gc>> {
// The entire implementation of VTable assumes that
@ -1205,7 +1205,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let args = self.pop_stack_args(arg_count);
let receiver = self.pop_stack().coerce_to_object_or_typeerror(self, None)?;
let value = receiver.call_method(index.0, &args, self)?;
let value = receiver.call_method(index, &args, self)?;
self.push_stack(value);

View File

@ -31,8 +31,7 @@ pub enum Op<'gc> {
num_args: u32,
},
CallMethod {
#[collect(require_static)]
index: Index<Method>,
index: u32,
num_args: u32,
},

View File

@ -8,7 +8,6 @@ use crate::avm2::property::Property;
use gc_arena::{Gc, GcCell};
use std::collections::HashSet;
use swf::avm2::types::Index;
#[derive(Clone, Copy, Debug)]
enum ValueType<'gc> {
@ -623,10 +622,10 @@ pub fn optimize<'gc>(
value_class,
);
}
Some(Property::Virtual { get: Some(get), .. }) => {
Some(Property::Virtual { get: Some(disp_id), .. }) => {
*op = Op::CallMethod {
num_args: 0,
index: Index::new(get),
index: disp_id,
};
}
_ => {}
@ -737,7 +736,7 @@ pub fn optimize<'gc>(
Some(Property::Method { disp_id }) => {
*op = Op::CallMethod {
num_args: *num_args,
index: Index::new(disp_id),
index: disp_id,
};
}
_ => {}

View File

@ -247,7 +247,7 @@ pub fn verify_method<'gc>(
// Misc opcode verification
AbcOp::CallMethod { index, .. } => {
return Err(Error::AvmError(if index.as_u30() == 0 {
return Err(Error::AvmError(if index == 0 {
verify_error(activation, "Error #1072: Disp_id 0 is illegal.", 1072)?
} else {
verify_error(

View File

@ -544,7 +544,7 @@ impl<'a> Reader<'a> {
num_args: self.read_u30()?,
},
OpCode::CallMethod => Op::CallMethod {
index: self.read_index()?,
index: self.read_u30()?,
num_args: self.read_u30()?,
},
OpCode::CallProperty => Op::CallProperty {

View File

@ -275,7 +275,7 @@ pub enum Op {
num_args: u32,
},
CallMethod {
index: Index<Method>,
index: u32,
num_args: u32,
},
CallProperty {

View File

@ -615,12 +615,9 @@ impl<W: Write> Writer<W> {
self.write_opcode(OpCode::Call)?;
self.write_u30(num_args)?;
}
Op::CallMethod {
ref index,
num_args,
} => {
Op::CallMethod { index, num_args } => {
self.write_opcode(OpCode::CallMethod)?;
self.write_index(index)?;
self.write_u30(index)?;
self.write_u30(num_args)?;
}
Op::CallProperty {
@ -1119,7 +1116,7 @@ pub mod tests {
assert_eq!(
write(Op::CallMethod {
index: Index::new(1),
index: 1,
num_args: 2
}),
b"\x43\x01\x02"