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:
parent
4b76d1b32a
commit
73e9fd55fb
|
@ -314,12 +314,16 @@ 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) {
|
||||
for i in 0..num_scripts {
|
||||
if let Some(mut script) = tunit.get_script(i) {
|
||||
script.globals(context)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Script<'gc>> {
|
||||
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.
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package {
|
||||
|
||||
public class After {
|
||||
|
||||
public function After() {
|
||||
// constructor code
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Worked without errors!
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_frames = 1
|
Loading…
Reference in New Issue