Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: More work on the class refactor #16655

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/avm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod vtable;
pub use crate::avm2::activation::Activation;
pub use crate::avm2::array::ArrayStorage;
pub use crate::avm2::call_stack::{CallNode, CallStack};
pub use crate::avm2::class::Class;
#[allow(unused)] // For debug_ui
pub use crate::avm2::domain::{Domain, DomainPtr};
pub use crate::avm2::error::Error;
Expand Down Expand Up @@ -179,7 +180,7 @@ pub struct Avm2<'gc> {
orphan_objects: Rc<Vec<DisplayObjectWeak<'gc>>>,

alias_to_class_map: FnvHashMap<AvmString<'gc>, ClassObject<'gc>>,
class_to_alias_map: FnvHashMap<ClassObject<'gc>, AvmString<'gc>>,
class_to_alias_map: FnvHashMap<Class<'gc>, AvmString<'gc>>,

/// The api version of our root movie clip. Note - this is used as the
/// api version for swfs loaded via `Loader`, overriding the api version
Expand Down Expand Up @@ -293,14 +294,15 @@ impl<'gc> Avm2<'gc> {

pub fn register_class_alias(&mut self, name: AvmString<'gc>, class_object: ClassObject<'gc>) {
self.alias_to_class_map.insert(name, class_object);
self.class_to_alias_map.insert(class_object, name);
self.class_to_alias_map
.insert(class_object.inner_class_definition(), name);
}

pub fn get_class_by_alias(&self, name: AvmString<'gc>) -> Option<ClassObject<'gc>> {
self.alias_to_class_map.get(&name).copied()
}

pub fn get_alias_by_class(&self, cls: ClassObject<'gc>) -> Option<AvmString<'gc>> {
pub fn get_alias_by_class(&self, cls: Class<'gc>) -> Option<AvmString<'gc>> {
self.class_to_alias_map.get(&cls).copied()
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/avm2/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

fn op_get_outer_scope(&mut self, index: u32) -> Result<FrameControl<'gc>, Error<'gc>> {
// Verifier ensures that this points to a valid outer scope

let scope = self.outer.get_unchecked(index as usize);

self.push_stack(scope.values());
Expand Down Expand Up @@ -1730,10 +1731,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
} else {
// Even if it's an object with the "descendants" property, we won't support it.
let class_name = object
.instance_of()
.instance_class()
.map(|cls| {
cls.inner_class_definition()
.name()
cls.name()
.to_qualified_name_err_message(self.context.gc_context)
})
.unwrap_or_else(|| AvmString::from("<UNKNOWN>"));
Expand Down
28 changes: 17 additions & 11 deletions core/src/avm2/amf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::rc::Rc;

use crate::avm2::bytearray::ByteArrayStorage;
use crate::avm2::class::Class;
use crate::avm2::object::{ByteArrayObject, ClassObject, TObject, VectorObject};
use crate::avm2::vector::VectorStorage;
use crate::avm2::ArrayObject;
Expand Down Expand Up @@ -72,7 +73,7 @@ pub fn serialize_value<'gc>(
Some(AmfValue::ECMAArray(dense, sparse, len))
} else if let Some(vec) = o.as_vector_storage() {
let val_type = vec.value_type();
if val_type == Some(activation.avm2().classes().int) {
if val_type == Some(activation.avm2().classes().int.inner_class_definition()) {
let int_vec: Vec<_> = vec
.iter()
.map(|v| {
Expand All @@ -81,7 +82,9 @@ pub fn serialize_value<'gc>(
})
.collect();
Some(AmfValue::VectorInt(int_vec, vec.is_fixed()))
} else if val_type == Some(activation.avm2().classes().uint) {
} else if val_type
== Some(activation.avm2().classes().uint.inner_class_definition())
{
let uint_vec: Vec<_> = vec
.iter()
.map(|v| {
Expand All @@ -90,7 +93,9 @@ pub fn serialize_value<'gc>(
})
.collect();
Some(AmfValue::VectorUInt(uint_vec, vec.is_fixed()))
} else if val_type == Some(activation.avm2().classes().number) {
} else if val_type
== Some(activation.avm2().classes().number.inner_class_definition())
{
let num_vec: Vec<_> = vec
.iter()
.map(|v| {
Expand All @@ -108,7 +113,8 @@ pub fn serialize_value<'gc>(
})
.collect();

let val_type = val_type.unwrap_or(activation.avm2().classes().object);
let val_type = val_type
.unwrap_or(activation.avm2().classes().object.inner_class_definition());

let name = class_to_alias(activation, val_type);
Some(AmfValue::VectorObject(obj_vec, name, vec.is_fixed()))
Expand All @@ -125,11 +131,11 @@ pub fn serialize_value<'gc>(
} else if let Some(bytearray) = o.as_bytearray() {
Some(AmfValue::ByteArray(bytearray.bytes().to_vec()))
} else {
let class = o.instance_of().expect("Missing ClassObject");
let class = o.instance_class().expect("Missing Class");
let name = class_to_alias(activation, class);

let mut attributes = EnumSet::empty();
if !class.inner_class_definition().is_sealed() {
if !class.is_sealed() {
attributes.insert(Attribute::Dynamic);
}

Expand Down Expand Up @@ -173,7 +179,7 @@ fn alias_to_class<'gc>(
}
}

fn class_to_alias<'gc>(activation: &mut Activation<'_, 'gc>, class: ClassObject<'gc>) -> String {
fn class_to_alias<'gc>(activation: &mut Activation<'_, 'gc>, class: Class<'gc>) -> String {
if let Some(alias) = activation.avm2().get_alias_by_class(class) {
alias.to_string()
} else {
Expand Down Expand Up @@ -359,23 +365,23 @@ pub fn deserialize_value<'gc>(
let storage = VectorStorage::from_values(
vec.iter().map(|v| (*v).into()).collect(),
*is_fixed,
Some(activation.avm2().classes().number),
Some(activation.avm2().classes().number.inner_class_definition()),
);
VectorObject::from_vector(storage, activation)?.into()
}
AmfValue::VectorUInt(vec, is_fixed) => {
let storage = VectorStorage::from_values(
vec.iter().map(|v| (*v).into()).collect(),
*is_fixed,
Some(activation.avm2().classes().uint),
Some(activation.avm2().classes().uint.inner_class_definition()),
);
VectorObject::from_vector(storage, activation)?.into()
}
AmfValue::VectorInt(vec, is_fixed) => {
let storage = VectorStorage::from_values(
vec.iter().map(|v| (*v).into()).collect(),
*is_fixed,
Some(activation.avm2().classes().int),
Some(activation.avm2().classes().int.inner_class_definition()),
);
VectorObject::from_vector(storage, activation)?.into()
}
Expand All @@ -397,7 +403,7 @@ pub fn deserialize_value<'gc>(
})
.collect::<Result<Vec<_>, _>>()?,
*is_fixed,
Some(class),
Some(class.inner_class_definition()),
);
VectorObject::from_vector(storage, activation)?.into()
}
Expand Down
Loading
Loading