Skip to content

Commit

Permalink
avm2: Don't use a Class's first ClassObject for its VTable if mor…
Browse files Browse the repository at this point in the history
…e than one `ClassObject` had been constructed for the class
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Feb 19, 2024
1 parent 53b1677 commit 06cbbe4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 8 additions & 0 deletions core/src/avm2/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ impl<'gc> Class<'gc> {
&self.class_objects
}

pub fn class_object(&self) -> Option<ClassObject<'gc>> {
if self.class_objects.len() == 1 {
Some(self.class_objects[0])
} else {
None
}
}

/// Construct a class from a `TranslationUnit` and its class index.
///
/// The returned class will be allocated, but no traits will be loaded. The
Expand Down
10 changes: 4 additions & 6 deletions core/src/avm2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ impl<'gc> Locals<'gc> {
// after the ClassObject refactor
self.0[index] = class
.read()
.class_objects()
.get(0)
.map(|c| ValueType::Class(*c))
.class_object()
.map(ValueType::Class)
.unwrap_or(ValueType::Any);
}

Expand Down Expand Up @@ -79,9 +78,8 @@ impl<'gc> Stack<'gc> {
self.0.push(
class
.read()
.class_objects()
.get(0)
.map(|c| ValueType::Class(*c))
.class_object()
.map(ValueType::Class)
.unwrap_or(ValueType::Any),
);
}
Expand Down

0 comments on commit 06cbbe4

Please sign in to comment.