Skip to content

Commit

Permalink
avm2: Fix NewClass not popping the base class and better null propa…
Browse files Browse the repository at this point in the history
…gation in optimizer
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Jun 8, 2024
1 parent bb7a315 commit 1d1eb6c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/avm2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. } => {
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down

0 comments on commit 1d1eb6c

Please sign in to comment.