Skip to content

Commit

Permalink
avm2/swf: Remove parsed_code from MethodBody and rename `Bytecode…
Browse files Browse the repository at this point in the history
…Method`'s `try_verify` to `needs_verify`
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Dec 31, 2023
1 parent 2dcd48f commit da0a0a4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
14 changes: 6 additions & 8 deletions core/src/avm2/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,24 +837,22 @@ impl<'a, 'gc> Activation<'a, 'gc> {
&mut self,
method: Gc<'gc, BytecodeMethod<'gc>>,
) -> Result<Value<'gc>, Error<'gc>> {
if method.try_verify.get() {
if method.needs_verify.get() {
method.verify(self)?;
method.try_verify.set(false);
method.needs_verify.set(false);
}

let verified = method.verified_method_body.borrow();
let verified = verified.as_ref().unwrap();

let parsed_code = &verified.parsed_code;
let verified_code = method.parsed_code.borrow();
let verified_code = verified_code.as_ref().unwrap().as_slice();

if parsed_code.len() == 0 {
if verified_code.len() == 0 {
return Ok(Value::Undefined);
}

self.ip = 0;

let val = loop {
let result = self.do_next_opcode(method, parsed_code);
let result = self.do_next_opcode(method, verified_code);
match result {
Ok(FrameControl::Return(value)) => break Ok(value),
Ok(FrameControl::Continue) => {}
Expand Down
13 changes: 9 additions & 4 deletions core/src/avm2/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::rc::Rc;
use std::sync::Arc;
use swf::avm2::types::{
AbcFile, Index, Method as AbcMethod, MethodBody as AbcMethodBody,
MethodFlags as AbcMethodFlags, MethodParam as AbcMethodParam,
MethodFlags as AbcMethodFlags, MethodParam as AbcMethodParam, Op,
};

/// Represents a function defined in Ruffle's code.
Expand Down Expand Up @@ -120,9 +120,12 @@ pub struct BytecodeMethod<'gc> {
/// The ABC method body this function uses.
pub abc_method_body: Option<u32>,

pub try_verify: Cell<bool>,
pub needs_verify: Cell<bool>,
pub verified_method_body: RefCell<Option<AbcMethodBody>>,

#[collect(require_static)]
pub parsed_code: RefCell<Option<Vec<Op>>>,

/// The parameter signature of this method.
pub signature: Vec<ParamConfig<'gc>>,

Expand Down Expand Up @@ -170,8 +173,9 @@ impl<'gc> BytecodeMethod<'gc> {
abc: txunit.abc(),
abc_method: abc_method.0,
abc_method_body: Some(index as u32),
try_verify: Cell::new(true),
needs_verify: Cell::new(true),
verified_method_body: RefCell::new(None),
parsed_code: RefCell::new(None),
signature,
return_type,
is_function,
Expand All @@ -186,8 +190,9 @@ impl<'gc> BytecodeMethod<'gc> {
abc: txunit.abc(),
abc_method: abc_method.0,
abc_method_body: None,
try_verify: Cell::new(true),
needs_verify: Cell::new(true),
verified_method_body: RefCell::new(None),
parsed_code: RefCell::new(None),
signature,
return_type,
is_function,
Expand Down
5 changes: 3 additions & 2 deletions core/src/avm2/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ pub fn verify_method<'gc>(
init_scope_depth: body.init_scope_depth,
max_scope_depth: body.max_scope_depth,
code: vec![],
parsed_code: vec![],
exceptions: body.exceptions.clone(),
traits: body.traits.clone(),
};

let new_code = &mut new_body.parsed_code;
let mut new_code = Vec::new();

let mut byte_offset_to_idx = HashMap::new();
let mut idx_to_byte_offset = vec![0];
Expand Down Expand Up @@ -265,6 +264,8 @@ pub fn verify_method<'gc>(
}
}

*method.parsed_code.borrow_mut() = Some(new_code);

Ok(new_body)
}

Expand Down
1 change: 0 additions & 1 deletion swf/src/avm2/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ impl<'a> Reader<'a> {
init_scope_depth,
max_scope_depth,
code,
parsed_code: vec![],
exceptions,
traits,
})
Expand Down
1 change: 0 additions & 1 deletion swf/src/avm2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub struct MethodBody {
pub init_scope_depth: u32,
pub max_scope_depth: u32,
pub code: Vec<u8>,
pub parsed_code: Vec<Op>,
pub exceptions: Vec<Exception>,
pub traits: Vec<Trait>,
}
Expand Down
2 changes: 0 additions & 2 deletions swf/src/test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2720,7 +2720,6 @@ pub fn avm2_tests() -> Vec<Avm2TestData> {
init_scope_depth: 1,
max_scope_depth: 2,
code: vec![208, 48, 93, 3, 44, 5, 79, 3, 1, 71],
parsed_code: vec![],
exceptions: vec![],
traits: vec![],
},
Expand All @@ -2731,7 +2730,6 @@ pub fn avm2_tests() -> Vec<Avm2TestData> {
init_scope_depth: 1,
max_scope_depth: 2,
code: vec![208, 48, 93, 2, 70, 2, 0, 130, 213, 209, 72],
parsed_code: vec![],
exceptions: vec![],
traits: vec![],
},
Expand Down

0 comments on commit da0a0a4

Please sign in to comment.