avm1: Remove `TObject::type_of`

It can be simply determined in `Value::type_of`.
This commit is contained in:
relrelb 2022-03-10 20:40:52 +02:00 committed by Mike Welsh
parent 052cb40113
commit 3dbde841df
9 changed files with 13 additions and 53 deletions

View File

@ -403,8 +403,6 @@ impl<'gc> From<Gc<'gc, Avm1Function<'gc>>> for Executable<'gc> {
}
}
pub const TYPE_OF_FUNCTION: &str = "function";
/// Represents an `Object` that holds executable code.
#[derive(Debug, Clone, Collect, Copy)]
#[collect(no_drop)]
@ -793,10 +791,6 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
self.base.get_keys(activation)
}
fn type_of(&self) -> &'static str {
TYPE_OF_FUNCTION
}
fn interfaces(&self) -> Vec<Object<'gc>> {
self.base.interfaces()
}

View File

@ -442,9 +442,6 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
/// Enumerate the object.
fn get_keys(&self, activation: &mut Activation<'_, 'gc, '_>) -> Vec<AvmString<'gc>>;
/// Get the object's type string.
fn type_of(&self) -> &'static str;
/// Enumerate all interfaces implemented by this object.
fn interfaces(&self) -> Vec<Object<'gc>>;

View File

@ -243,10 +243,6 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
self.0.read().get_keys(activation)
}
fn type_of(&self) -> &'static str {
self.0.read().type_of()
}
fn interfaces(&self) -> Vec<Object<'gc>> {
self.0.read().interfaces()
}

View File

@ -184,10 +184,6 @@ macro_rules! impl_custom_object {
self.0.read().$field.get_keys(activation)
}
fn type_of(&self) -> &'static str {
self.0.read().$field.type_of()
}
fn interfaces(&self) -> Vec<$crate::avm1::Object<'gc>> {
self.0.read().$field.interfaces()
}

View File

@ -8,8 +8,6 @@ use crate::string::AvmString;
use core::fmt;
use gc_arena::{Collect, GcCell, MutationContext};
pub const TYPE_OF_OBJECT: &str = "object";
#[derive(Debug, Clone, Collect)]
#[collect(no_drop)]
pub struct Watcher<'gc> {
@ -56,7 +54,6 @@ pub struct ScriptObject<'gc>(GcCell<'gc, ScriptObjectData<'gc>>);
pub struct ScriptObjectData<'gc> {
properties: PropertyMap<'gc, Property<'gc>>,
interfaces: Vec<Object<'gc>>,
type_of: &'static str,
watchers: PropertyMap<'gc, Watcher<'gc>>,
}
@ -74,7 +71,6 @@ impl<'gc> ScriptObject<'gc> {
let object = Self(GcCell::allocate(
gc_context,
ScriptObjectData {
type_of: TYPE_OF_OBJECT,
properties: PropertyMap::new(),
interfaces: vec![],
watchers: PropertyMap::new(),
@ -108,10 +104,6 @@ impl<'gc> ScriptObject<'gc> {
Self::object(gc_context, None)
}
pub fn set_type_of(&mut self, gc_context: MutationContext<'gc, '_>, type_of: &'static str) {
self.0.write(gc_context).type_of = type_of;
}
/// Gets the value of a data property on this object.
///
/// Doesn't look up the prototype chain and ignores virtual properties, thus cannot cause
@ -477,10 +469,6 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
out_keys
}
fn type_of(&self) -> &'static str {
self.0.read().type_of
}
fn interfaces(&self) -> Vec<Object<'gc>> {
self.0.read().interfaces.clone()
}

View File

@ -13,9 +13,6 @@ use crate::types::Percent;
use gc_arena::{Collect, GcCell, MutationContext};
use std::fmt;
/// The type string for MovieClip objects.
pub const TYPE_OF_MOVIE_CLIP: &str = "movieclip";
/// A ScriptObject that is inherently tied to a display node.
#[derive(Clone, Copy, Collect)]
#[collect(no_drop)]
@ -43,17 +40,10 @@ impl<'gc> StageObject<'gc> {
display_object: DisplayObject<'gc>,
proto: Option<Object<'gc>>,
) -> Self {
let mut base = ScriptObject::object(gc_context, proto);
// MovieClips have a special typeof "movieclip", while others are the default "object".
if display_object.as_movie_clip().is_some() {
base.set_type_of(gc_context, TYPE_OF_MOVIE_CLIP);
}
Self(GcCell::allocate(
gc_context,
StageObjectData {
base,
base: ScriptObject::object(gc_context, proto),
display_object,
text_field_bindings: Vec::new(),
},
@ -499,9 +489,6 @@ impl<'gc> TObject<'gc> for StageObject<'gc> {
.set_interfaces(gc_context, iface_list)
}
fn type_of(&self) -> &'static str {
self.0.read().base.type_of()
}
fn as_script_object(&self) -> Option<ScriptObject<'gc>> {
Some(self.0.read().base)
}

View File

@ -3,7 +3,6 @@
use crate::avm1::activation::Activation;
use crate::avm1::error::Error;
use crate::avm1::function::ExecutionReason;
use crate::avm1::object::script_object::TYPE_OF_OBJECT;
use crate::avm1::object::{search_prototype, ExecutionName};
use crate::avm1::property::Attribute;
use crate::avm1::{AvmString, Object, ObjectPtr, ScriptObject, TObject, Value};
@ -266,10 +265,6 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
vec![]
}
fn type_of(&self) -> &'static str {
TYPE_OF_OBJECT
}
fn length(&self, _activation: &mut Activation<'_, 'gc, '_>) -> Result<i32, Error<'gc>> {
Ok(0)
}

View File

@ -230,10 +230,6 @@ impl<'gc> TObject<'gc> for XmlAttributesObject<'gc> {
base
}
fn type_of(&self) -> &'static str {
self.base().type_of()
}
fn interfaces(&self) -> Vec<Object<'gc>> {
self.base().interfaces()
}

View File

@ -2,6 +2,7 @@ use crate::avm1::activation::Activation;
use crate::avm1::error::Error;
use crate::avm1::object::value_object::ValueObject;
use crate::avm1::{Object, TObject};
use crate::display_object::TDisplayObject;
use crate::ecma_conversions::{
f64_to_wrapping_i16, f64_to_wrapping_i32, f64_to_wrapping_u16, f64_to_wrapping_u32,
f64_to_wrapping_u8,
@ -474,7 +475,17 @@ impl<'gc> Value<'gc> {
Value::Number(_) => "number",
Value::Bool(_) => "boolean",
Value::String(_) => "string",
Value::Object(object) => object.type_of(),
Value::Object(object) if object.as_executable().is_some() => "function",
// MovieClips have a special typeof "movieclip", while others have the default "object".
Value::Object(object)
if object
.as_display_object()
.and_then(|o| o.as_movie_clip())
.is_some() =>
{
"movieclip"
}
Value::Object(_) => "object",
}
}