avm2: Move as_class_params() to ClassObject

This commit is contained in:
Adrian Wielgosik 2021-09-18 11:33:59 +02:00 committed by Adrian Wielgosik
parent 0679fd1a9e
commit f3ab6c9da3
4 changed files with 32 additions and 27 deletions

View File

@ -517,8 +517,11 @@ pub fn filter<'gc>(
.ok();
let value_type = this
.as_class_object()
.and_then(|c| c.as_class_params())
.instance_of()
.unwrap()
.as_class_object_really()
.unwrap()
.as_class_params()
.ok_or("Cannot filter unparameterized vector")?
.unwrap_or(activation.avm2().classes().object);
let mut new_storage = VectorStorage::new(0, false, value_type, activation);
@ -676,8 +679,11 @@ pub fn map<'gc>(
.ok();
let value_type = this
.as_class_object()
.and_then(|c| c.as_class_params())
.instance_of()
.unwrap()
.as_class_object_really()
.unwrap()
.as_class_params()
.ok_or("Cannot filter unparameterized vector")?
.unwrap_or(activation.avm2().classes().object);
let mut new_storage = VectorStorage::new(0, false, value_type, activation);

View File

@ -1047,21 +1047,25 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
}
}
if let (Some(my_param), Some(test_param)) =
(class.as_class_params(), test_class.as_class_params())
if let (Some(class), Some(test_class)) =
(class.as_class_object_really(), test_class.as_class_object_really())
{
let mut are_all_params_coercible = true;
if let (Some(my_param), Some(test_param)) =
(class.as_class_params(), test_class.as_class_params())
{
let mut are_all_params_coercible = true;
are_all_params_coercible &= match (my_param, test_param) {
(Some(my_param), Some(test_param)) => {
my_param.has_class_in_chain(test_param, activation)?
are_all_params_coercible &= match (my_param, test_param) {
(Some(my_param), Some(test_param)) => {
my_param.has_class_in_chain(test_param, activation)?
}
(None, Some(_)) => false,
_ => true,
};
if are_all_params_coercible {
return Ok(true);
}
(None, Some(_)) => false,
_ => true,
};
if are_all_params_coercible {
return Ok(true);
}
}
@ -1090,13 +1094,6 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
None
}
/// Get the parameters of this class object, if present.
///
/// Only specialized generic classes will yield their parameters.
fn as_class_params(&self) -> Option<Option<Object<'gc>>> {
None
}
/// Associate the object with a particular class object.
///
/// This turns the object into an instance of that class. It should only be

View File

@ -343,6 +343,10 @@ impl<'gc> ClassObject<'gc> {
pub fn superclass_object(self) -> Option<Object<'gc>> {
self.0.read().superclass_object
}
pub fn as_class_params(self) -> Option<Option<Object<'gc>>> {
self.0.read().params
}
}
impl<'gc> TObject<'gc> for ClassObject<'gc> {
@ -494,10 +498,6 @@ impl<'gc> TObject<'gc> for ClassObject<'gc> {
self.0.read().base.instance_of()
}
fn as_class_params(&self) -> Option<Option<Object<'gc>>> {
self.0.read().params
}
fn set_class_object(self, _mc: MutationContext<'gc, '_>, _class_object: Object<'gc>) {
//Do nothing, as classes cannot be turned into instances.
}

View File

@ -26,6 +26,8 @@ pub fn vector_allocator<'gc>(
//the unspecialized Vector class, we have to fall back to Object when
//getting the parameter type for our storage.
let param_type = class
.as_class_object_really()
.unwrap()
.as_class_params()
.flatten()
.unwrap_or_else(|| activation.avm2().classes().object);