avm2: Fix some very minor bugs with findprop optimization

This commit is contained in:
Lord-McSweeney 2024-05-09 18:13:29 -07:00 committed by Lord-McSweeney
parent 796dda1ae0
commit 92de618261
2 changed files with 19 additions and 13 deletions

View File

@ -265,6 +265,10 @@ pub fn optimize<'gc>(
} }
} }
if !method_body.exceptions.is_empty() {
has_simple_scoping = false;
}
// TODO: Fill out all ops, then add scope stack and stack merging, too // TODO: Fill out all ops, then add scope stack and stack merging, too
let mut state_map: HashMap<i32, Locals<'gc>> = HashMap::new(); let mut state_map: HashMap<i32, Locals<'gc>> = HashMap::new();
@ -769,17 +773,20 @@ pub fn optimize<'gc>(
} }
if !stack_push_done { if !stack_push_done {
if let Some((class, index)) = if let Some(info) = outer_scope.get_entry_for_multiname(&multiname) {
outer_scope.get_entry_for_multiname(&multiname) if let Some((class, index)) = info {
{ *op = Op::GetOuterScope {
*op = Op::GetOuterScope { index: index as u32,
index: index as u32, };
};
stack_push_done = true; stack_push_done = true;
if let Some(class) = class { if let Some(class) = class {
stack.push_class_object(class); stack.push_class_object(class);
} else {
stack.push_any();
}
} else { } else {
stack_push_done = true;
stack.push_any(); stack.push_any();
} }
} }
@ -791,7 +798,6 @@ pub fn optimize<'gc>(
{ {
*op = Op::GetScriptGlobals { script }; *op = Op::GetScriptGlobals { script };
let script_globals = script let script_globals = script
.globals(&mut activation.context) .globals(&mut activation.context)
.expect("Script should be resolved if traits exist"); .expect("Script should be resolved if traits exist");

View File

@ -237,18 +237,18 @@ impl<'gc> ScopeChain<'gc> {
pub fn get_entry_for_multiname( pub fn get_entry_for_multiname(
&self, &self,
multiname: &Multiname<'gc>, multiname: &Multiname<'gc>,
) -> Option<(Option<ClassObject<'gc>>, u32)> { ) -> Option<Option<(Option<ClassObject<'gc>>, u32)>> {
if let Some(container) = self.container { if let Some(container) = self.container {
for (index, scope) in container.scopes.iter().enumerate().skip(1).rev() { for (index, scope) in container.scopes.iter().enumerate().skip(1).rev() {
if scope.with() { if scope.with() {
// If this is a `with` scope, stop here because // If this is a `with` scope, stop here because
// dynamic properties could be added at any time // dynamic properties could be added at any time
return None; return Some(None);
} }
let values = scope.values(); let values = scope.values();
if values.has_trait(&multiname) { if values.has_trait(&multiname) {
return Some((values.instance_of(), index as u32)); return Some(Some((values.instance_of(), index as u32)));
} }
} }
} }