diff --git a/core/src/avm2.rs b/core/src/avm2.rs index 489c46fd3..b671880a8 100644 --- a/core/src/avm2.rs +++ b/core/src/avm2.rs @@ -314,10 +314,14 @@ impl<'gc> Avm2<'gc> { let num_scripts = abc.scripts.len(); let tunit = TranslationUnit::from_abc(abc, domain, context.gc_context); 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) { - script.globals(context)?; + 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)?; + } } } Ok(()) diff --git a/core/src/avm2/script.rs b/core/src/avm2/script.rs index b3c8387db..6dd027082 100644 --- a/core/src/avm2/script.rs +++ b/core/src/avm2/script.rs @@ -223,6 +223,11 @@ impl<'gc> TranslationUnit<'gc> { Ok(script) } + /// Gets a script in the ABC file by index. + pub fn get_script(&self, index: usize) -> Option> { + self.0.read().scripts.get(index).copied().flatten() + } + /// Load a string from the ABC's constant pool. /// /// This function yields an error if no such string index exists. diff --git a/tests/tests/swfs/avm2/eager_init/After.as b/tests/tests/swfs/avm2/eager_init/After.as new file mode 100644 index 000000000..1a0993b9c --- /dev/null +++ b/tests/tests/swfs/avm2/eager_init/After.as @@ -0,0 +1,11 @@ +package { + + public class After { + + public function After() { + // constructor code + } + + } + +} diff --git a/tests/tests/swfs/avm2/eager_init/Test.as b/tests/tests/swfs/avm2/eager_init/Test.as new file mode 100644 index 000000000..7fc8f10b4 --- /dev/null +++ b/tests/tests/swfs/avm2/eager_init/Test.as @@ -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!"); + } + } +} \ No newline at end of file diff --git a/tests/tests/swfs/avm2/eager_init/output.txt b/tests/tests/swfs/avm2/eager_init/output.txt new file mode 100644 index 000000000..8c19b05c1 --- /dev/null +++ b/tests/tests/swfs/avm2/eager_init/output.txt @@ -0,0 +1 @@ +Worked without errors! diff --git a/tests/tests/swfs/avm2/eager_init/test.fla b/tests/tests/swfs/avm2/eager_init/test.fla new file mode 100644 index 000000000..88bb1e68c Binary files /dev/null and b/tests/tests/swfs/avm2/eager_init/test.fla differ diff --git a/tests/tests/swfs/avm2/eager_init/test.swf b/tests/tests/swfs/avm2/eager_init/test.swf new file mode 100644 index 000000000..e80580717 Binary files /dev/null and b/tests/tests/swfs/avm2/eager_init/test.swf differ diff --git a/tests/tests/swfs/avm2/eager_init/test.toml b/tests/tests/swfs/avm2/eager_init/test.toml new file mode 100644 index 000000000..dbee897f5 --- /dev/null +++ b/tests/tests/swfs/avm2/eager_init/test.toml @@ -0,0 +1 @@ +num_frames = 1