avm2: Fix `NewClass` not popping the base class and better null propagation in optimizer

This commit is contained in:
Lord-McSweeney 2024-06-07 09:04:57 -07:00 committed by Lord-McSweeney
parent bb7a315afd
commit 1d1eb6c966
1 changed files with 6 additions and 1 deletions

View File

@ -678,6 +678,7 @@ pub fn optimize<'gc>(
stack.push_class_not_null(types.function);
}
Op::NewClass { .. } => {
stack.pop();
stack.push_class_not_null(types.class);
}
Op::NewCatch { .. } => {
@ -766,7 +767,7 @@ pub fn optimize<'gc>(
}
Op::Coerce { class } => {
let stack_value = stack.pop_or_any();
stack.push_class(*class);
let mut new_value = OptValue::of_type(*class);
if stack_value.is_null() {
// Coercing null to a non-primitive or void is a noop.
@ -777,13 +778,17 @@ pub fn optimize<'gc>(
&& *class != types.void
{
*op = Op::Nop;
new_value.null_state = NullState::IsNull;
}
} else if let Some(stack_class) = stack_value.class {
// TODO: this could check for inheritance
if *class == stack_class {
*op = Op::Nop;
new_value.null_state = stack_value.null_state;
}
}
stack.push(new_value);
}
Op::PushScope => {
let stack_value = stack.pop();