diff --git a/core/src/avm2/activation.rs b/core/src/avm2/activation.rs index 8b12f977a7e6..72b874b1ff23 100644 --- a/core/src/avm2/activation.rs +++ b/core/src/avm2/activation.rs @@ -837,24 +837,22 @@ impl<'a, 'gc> Activation<'a, 'gc> { &mut self, method: Gc<'gc, BytecodeMethod<'gc>>, ) -> Result, 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) => {} diff --git a/core/src/avm2/method.rs b/core/src/avm2/method.rs index 802ca9d40d0a..345d87fc4aa3 100644 --- a/core/src/avm2/method.rs +++ b/core/src/avm2/method.rs @@ -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. @@ -120,9 +120,12 @@ pub struct BytecodeMethod<'gc> { /// The ABC method body this function uses. pub abc_method_body: Option, - pub try_verify: Cell, + pub needs_verify: Cell, pub verified_method_body: RefCell>, + #[collect(require_static)] + pub parsed_code: RefCell>>, + /// The parameter signature of this method. pub signature: Vec>, @@ -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, @@ -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, diff --git a/core/src/avm2/verify.rs b/core/src/avm2/verify.rs index 44df3b5b1762..ed30958639c3 100644 --- a/core/src/avm2/verify.rs +++ b/core/src/avm2/verify.rs @@ -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]; @@ -265,6 +264,8 @@ pub fn verify_method<'gc>( } } + *method.parsed_code.borrow_mut() = Some(new_code); + Ok(new_body) } diff --git a/swf/src/avm2/read.rs b/swf/src/avm2/read.rs index 9fbb24b073b6..04644cd037f0 100644 --- a/swf/src/avm2/read.rs +++ b/swf/src/avm2/read.rs @@ -507,7 +507,6 @@ impl<'a> Reader<'a> { init_scope_depth, max_scope_depth, code, - parsed_code: vec![], exceptions, traits, }) diff --git a/swf/src/avm2/types.rs b/swf/src/avm2/types.rs index 6479e30b0e16..4c92070e6313 100644 --- a/swf/src/avm2/types.rs +++ b/swf/src/avm2/types.rs @@ -129,7 +129,6 @@ pub struct MethodBody { pub init_scope_depth: u32, pub max_scope_depth: u32, pub code: Vec, - pub parsed_code: Vec, pub exceptions: Vec, pub traits: Vec, } diff --git a/swf/src/test_data.rs b/swf/src/test_data.rs index 5a0c6b0cf08c..42c325c6e2fe 100644 --- a/swf/src/test_data.rs +++ b/swf/src/test_data.rs @@ -2720,7 +2720,6 @@ pub fn avm2_tests() -> Vec { 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![], }, @@ -2731,7 +2730,6 @@ pub fn avm2_tests() -> Vec { 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![], },