diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index c490dea4e..cfa023e28 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -1094,8 +1094,13 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into> + Clone + Copy class.inner_class_definition() } - /// Get this object's class object, if it has one. - fn as_class_object(&self) -> Option>; + /// Get this object's class object, if it has one - unless it's a class itself. + fn as_class_object(&self) -> Option> { + match self.as_class_object_really() { + Some(_class) => None, + None => self.instance_of() + } + } fn instance_of(&self) -> Option>; diff --git a/core/src/avm2/object/class_object.rs b/core/src/avm2/object/class_object.rs index d7680940b..1470f4822 100644 --- a/core/src/avm2/object/class_object.rs +++ b/core/src/avm2/object/class_object.rs @@ -494,10 +494,6 @@ impl<'gc> TObject<'gc> for ClassObject<'gc> { .resolve_any_class_trait(local_name)) } - fn as_class_object(&self) -> Option> { - None //AS3 does not have metaclasses - } - fn as_class_object_really(&self) -> Option> { Some(*self) } diff --git a/core/src/avm2/object/custom_object.rs b/core/src/avm2/object/custom_object.rs index 125ac5303..773d9a0b3 100644 --- a/core/src/avm2/object/custom_object.rs +++ b/core/src/avm2/object/custom_object.rs @@ -110,10 +110,6 @@ macro_rules! impl_avm2_custom_object_instance { self.0.read().$field.resolve_any_trait(local_name) } - fn as_class_object(&self) -> Option> { - self.0.read().$field.as_class_object() - } - fn instance_of(&self) -> Option> { self.0.read().$field.instance_of() } diff --git a/core/src/avm2/object/script_object.rs b/core/src/avm2/object/script_object.rs index 1e2314763..7ce783bae 100644 --- a/core/src/avm2/object/script_object.rs +++ b/core/src/avm2/object/script_object.rs @@ -299,10 +299,6 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> { self.0.write(mc).install_const(name, id, value, is_final) } - fn as_class_object(&self) -> Option> { - self.0.read().as_class_object() - } - fn instance_of(&self) -> Option> { self.0.read().instance_of() } @@ -366,7 +362,7 @@ impl<'gc> ScriptObjectData<'gc> { Some( activation .subclass_object() - .or_else(|| self.as_class_object()) + .or_else(|| self.instance_of()) .unwrap_or(receiver), ), ) @@ -382,7 +378,7 @@ impl<'gc> ScriptObjectData<'gc> { value: Value<'gc>, activation: &mut Activation<'_, 'gc, '_>, ) -> Result, Error> { - let class = self.as_class_object(); + let class = self.instance_of(); let slot_id = if let Some(prop) = self.values.get(name) { if let Some(slot_id) = prop.slot_id() { Some(slot_id) @@ -420,7 +416,7 @@ impl<'gc> ScriptObjectData<'gc> { value: Value<'gc>, activation: &mut Activation<'_, 'gc, '_>, ) -> Result, Error> { - let class = self.as_class_object(); + let class = self.instance_of(); if let Some(prop) = self.values.get_mut(name) { if let Some(slot_id) = prop.slot_id() { self.init_slot(slot_id, value, activation.context.gc_context)?; @@ -824,11 +820,6 @@ impl<'gc> ScriptObjectData<'gc> { } } - /// Get the class object for this object, if it has one. - pub fn as_class_object(&self) -> Option> { - self.instance_of - } - /// Get the class object for this object, if it has one. pub fn instance_of(&self) -> Option> { self.instance_of diff --git a/core/src/avm2/object/stage_object.rs b/core/src/avm2/object/stage_object.rs index 74e0aa06f..8b310594a 100644 --- a/core/src/avm2/object/stage_object.rs +++ b/core/src/avm2/object/stage_object.rs @@ -285,10 +285,6 @@ impl<'gc> TObject<'gc> for StageObject<'gc> { None } - fn as_class_object(&self) -> Option> { - self.0.read().base.as_class_object() - } - fn instance_of(&self) -> Option> { self.0.read().base.instance_of() }