avm2: Don't call global init in optimizer

This commit is contained in:
Lord-McSweeney 2024-05-09 20:33:08 -07:00 committed by Lord-McSweeney
parent 12174b5219
commit eb27151af7
2 changed files with 21 additions and 8 deletions

View File

@ -798,15 +798,15 @@ pub fn optimize<'gc>(
{
*op = Op::GetScriptGlobals { script };
let script_globals = script
.globals(&mut activation.context)
.expect("Script should be resolved if traits exist");
let script_globals = script.globals_if_init();
stack_push_done = true;
if let Some(global_class) = script_globals.instance_of() {
stack.push_class_object(global_class);
} else {
stack.push_any();
if let Some(script_globals) = script_globals {
stack_push_done = true;
if let Some(global_class) = script_globals.instance_of() {
stack.push_class_object(global_class);
} else {
stack.push_any();
}
}
}
}

View File

@ -597,6 +597,19 @@ impl<'gc> Script<'gc> {
}
}
/// Return the global scope for the script.
///
/// If the script has not yet been initialized, this will return None.
pub fn globals_if_init(&self) -> Option<Object<'gc>> {
let read = self.0.read();
if !read.initialized {
None
} else {
Some(read.globals)
}
}
/// Return traits for this script.
///
/// This function will return an error if it is incorrectly called before