diff --git a/core/src/avm2/globals/vector.rs b/core/src/avm2/globals/vector.rs index 0971f65c4..eb4aa4b18 100644 --- a/core/src/avm2/globals/vector.rs +++ b/core/src/avm2/globals/vector.rs @@ -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); diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index a89f5e1f3..1dedf95ed 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -1047,21 +1047,25 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into> + 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> + 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>> { - None - } - /// Associate the object with a particular class object. /// /// This turns the object into an instance of that class. It should only be diff --git a/core/src/avm2/object/class_object.rs b/core/src/avm2/object/class_object.rs index e02a968d4..1b525d900 100644 --- a/core/src/avm2/object/class_object.rs +++ b/core/src/avm2/object/class_object.rs @@ -343,6 +343,10 @@ impl<'gc> ClassObject<'gc> { pub fn superclass_object(self) -> Option> { self.0.read().superclass_object } + + pub fn as_class_params(self) -> Option>> { + 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>> { - 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. } diff --git a/core/src/avm2/object/vector_object.rs b/core/src/avm2/object/vector_object.rs index 4c4ba8169..5ffa2d9e2 100644 --- a/core/src/avm2/object/vector_object.rs +++ b/core/src/avm2/object/vector_object.rs @@ -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);