avm2: Make sure scripts get initialized after all scripts have been loaded when lazy init is disabled (#9478)

* avm2: Initialize scripts **after** all scripts have been loaded

* tests: Add test for eager initialization
This commit is contained in:
Bale 2023-02-10 16:38:38 -08:00 committed by GitHub
parent 4b76d1b32a
commit 73e9fd55fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 3 deletions

View File

@ -314,12 +314,16 @@ impl<'gc> Avm2<'gc> {
let num_scripts = abc.scripts.len(); let num_scripts = abc.scripts.len();
let tunit = TranslationUnit::from_abc(abc, domain, context.gc_context); let tunit = TranslationUnit::from_abc(abc, domain, context.gc_context);
for i in (0..num_scripts).rev() { for i in (0..num_scripts).rev() {
let mut script = tunit.load_script(i as u32, context)?; tunit.load_script(i as u32, context)?;
}
if !do_abc.flags.contains(DoAbcFlag::LAZY_INITIALIZE) { if !do_abc.flags.contains(DoAbcFlag::LAZY_INITIALIZE) {
for i in 0..num_scripts {
if let Some(mut script) = tunit.get_script(i) {
script.globals(context)?; script.globals(context)?;
} }
} }
}
Ok(()) Ok(())
} }

View File

@ -223,6 +223,11 @@ impl<'gc> TranslationUnit<'gc> {
Ok(script) Ok(script)
} }
/// Gets a script in the ABC file by index.
pub fn get_script(&self, index: usize) -> Option<Script<'gc>> {
self.0.read().scripts.get(index).copied().flatten()
}
/// Load a string from the ABC's constant pool. /// Load a string from the ABC's constant pool.
/// ///
/// This function yields an error if no such string index exists. /// This function yields an error if no such string index exists.

View File

@ -0,0 +1,11 @@
package {
public class After {
public function After() {
// constructor code
}
}
}

View File

@ -0,0 +1,11 @@
/* NOTE: The SWF generated from this needs to be modified to have lazy init disabled,
so that we can properly demonstrate the behavior of eager initialization.
*/
package {
public class Test extends After {
public function Test() {
trace("Worked without errors!");
}
}
}

View File

@ -0,0 +1 @@
Worked without errors!

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
num_frames = 1