avm1: Remove `TObject::type_of`
It can be simply determined in `Value::type_of`.
This commit is contained in:
parent
052cb40113
commit
3dbde841df
|
@ -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.
|
/// Represents an `Object` that holds executable code.
|
||||||
#[derive(Debug, Clone, Collect, Copy)]
|
#[derive(Debug, Clone, Collect, Copy)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
|
@ -793,10 +791,6 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
|
||||||
self.base.get_keys(activation)
|
self.base.get_keys(activation)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of(&self) -> &'static str {
|
|
||||||
TYPE_OF_FUNCTION
|
|
||||||
}
|
|
||||||
|
|
||||||
fn interfaces(&self) -> Vec<Object<'gc>> {
|
fn interfaces(&self) -> Vec<Object<'gc>> {
|
||||||
self.base.interfaces()
|
self.base.interfaces()
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,9 +442,6 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
|
||||||
/// Enumerate the object.
|
/// Enumerate the object.
|
||||||
fn get_keys(&self, activation: &mut Activation<'_, 'gc, '_>) -> Vec<AvmString<'gc>>;
|
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.
|
/// Enumerate all interfaces implemented by this object.
|
||||||
fn interfaces(&self) -> Vec<Object<'gc>>;
|
fn interfaces(&self) -> Vec<Object<'gc>>;
|
||||||
|
|
||||||
|
|
|
@ -243,10 +243,6 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
|
||||||
self.0.read().get_keys(activation)
|
self.0.read().get_keys(activation)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of(&self) -> &'static str {
|
|
||||||
self.0.read().type_of()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn interfaces(&self) -> Vec<Object<'gc>> {
|
fn interfaces(&self) -> Vec<Object<'gc>> {
|
||||||
self.0.read().interfaces()
|
self.0.read().interfaces()
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,10 +184,6 @@ macro_rules! impl_custom_object {
|
||||||
self.0.read().$field.get_keys(activation)
|
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>> {
|
fn interfaces(&self) -> Vec<$crate::avm1::Object<'gc>> {
|
||||||
self.0.read().$field.interfaces()
|
self.0.read().$field.interfaces()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ use crate::string::AvmString;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use gc_arena::{Collect, GcCell, MutationContext};
|
use gc_arena::{Collect, GcCell, MutationContext};
|
||||||
|
|
||||||
pub const TYPE_OF_OBJECT: &str = "object";
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Collect)]
|
#[derive(Debug, Clone, Collect)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
pub struct Watcher<'gc> {
|
pub struct Watcher<'gc> {
|
||||||
|
@ -56,7 +54,6 @@ pub struct ScriptObject<'gc>(GcCell<'gc, ScriptObjectData<'gc>>);
|
||||||
pub struct ScriptObjectData<'gc> {
|
pub struct ScriptObjectData<'gc> {
|
||||||
properties: PropertyMap<'gc, Property<'gc>>,
|
properties: PropertyMap<'gc, Property<'gc>>,
|
||||||
interfaces: Vec<Object<'gc>>,
|
interfaces: Vec<Object<'gc>>,
|
||||||
type_of: &'static str,
|
|
||||||
watchers: PropertyMap<'gc, Watcher<'gc>>,
|
watchers: PropertyMap<'gc, Watcher<'gc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +71,6 @@ impl<'gc> ScriptObject<'gc> {
|
||||||
let object = Self(GcCell::allocate(
|
let object = Self(GcCell::allocate(
|
||||||
gc_context,
|
gc_context,
|
||||||
ScriptObjectData {
|
ScriptObjectData {
|
||||||
type_of: TYPE_OF_OBJECT,
|
|
||||||
properties: PropertyMap::new(),
|
properties: PropertyMap::new(),
|
||||||
interfaces: vec![],
|
interfaces: vec![],
|
||||||
watchers: PropertyMap::new(),
|
watchers: PropertyMap::new(),
|
||||||
|
@ -108,10 +104,6 @@ impl<'gc> ScriptObject<'gc> {
|
||||||
Self::object(gc_context, None)
|
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.
|
/// Gets the value of a data property on this object.
|
||||||
///
|
///
|
||||||
/// Doesn't look up the prototype chain and ignores virtual properties, thus cannot cause
|
/// 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
|
out_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of(&self) -> &'static str {
|
|
||||||
self.0.read().type_of
|
|
||||||
}
|
|
||||||
|
|
||||||
fn interfaces(&self) -> Vec<Object<'gc>> {
|
fn interfaces(&self) -> Vec<Object<'gc>> {
|
||||||
self.0.read().interfaces.clone()
|
self.0.read().interfaces.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,6 @@ use crate::types::Percent;
|
||||||
use gc_arena::{Collect, GcCell, MutationContext};
|
use gc_arena::{Collect, GcCell, MutationContext};
|
||||||
use std::fmt;
|
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.
|
/// A ScriptObject that is inherently tied to a display node.
|
||||||
#[derive(Clone, Copy, Collect)]
|
#[derive(Clone, Copy, Collect)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
|
@ -43,17 +40,10 @@ impl<'gc> StageObject<'gc> {
|
||||||
display_object: DisplayObject<'gc>,
|
display_object: DisplayObject<'gc>,
|
||||||
proto: Option<Object<'gc>>,
|
proto: Option<Object<'gc>>,
|
||||||
) -> Self {
|
) -> 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(
|
Self(GcCell::allocate(
|
||||||
gc_context,
|
gc_context,
|
||||||
StageObjectData {
|
StageObjectData {
|
||||||
base,
|
base: ScriptObject::object(gc_context, proto),
|
||||||
display_object,
|
display_object,
|
||||||
text_field_bindings: Vec::new(),
|
text_field_bindings: Vec::new(),
|
||||||
},
|
},
|
||||||
|
@ -499,9 +489,6 @@ impl<'gc> TObject<'gc> for StageObject<'gc> {
|
||||||
.set_interfaces(gc_context, iface_list)
|
.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>> {
|
fn as_script_object(&self) -> Option<ScriptObject<'gc>> {
|
||||||
Some(self.0.read().base)
|
Some(self.0.read().base)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use crate::avm1::activation::Activation;
|
use crate::avm1::activation::Activation;
|
||||||
use crate::avm1::error::Error;
|
use crate::avm1::error::Error;
|
||||||
use crate::avm1::function::ExecutionReason;
|
use crate::avm1::function::ExecutionReason;
|
||||||
use crate::avm1::object::script_object::TYPE_OF_OBJECT;
|
|
||||||
use crate::avm1::object::{search_prototype, ExecutionName};
|
use crate::avm1::object::{search_prototype, ExecutionName};
|
||||||
use crate::avm1::property::Attribute;
|
use crate::avm1::property::Attribute;
|
||||||
use crate::avm1::{AvmString, Object, ObjectPtr, ScriptObject, TObject, Value};
|
use crate::avm1::{AvmString, Object, ObjectPtr, ScriptObject, TObject, Value};
|
||||||
|
@ -266,10 +265,6 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of(&self) -> &'static str {
|
|
||||||
TYPE_OF_OBJECT
|
|
||||||
}
|
|
||||||
|
|
||||||
fn length(&self, _activation: &mut Activation<'_, 'gc, '_>) -> Result<i32, Error<'gc>> {
|
fn length(&self, _activation: &mut Activation<'_, 'gc, '_>) -> Result<i32, Error<'gc>> {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,10 +230,6 @@ impl<'gc> TObject<'gc> for XmlAttributesObject<'gc> {
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of(&self) -> &'static str {
|
|
||||||
self.base().type_of()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn interfaces(&self) -> Vec<Object<'gc>> {
|
fn interfaces(&self) -> Vec<Object<'gc>> {
|
||||||
self.base().interfaces()
|
self.base().interfaces()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::avm1::activation::Activation;
|
||||||
use crate::avm1::error::Error;
|
use crate::avm1::error::Error;
|
||||||
use crate::avm1::object::value_object::ValueObject;
|
use crate::avm1::object::value_object::ValueObject;
|
||||||
use crate::avm1::{Object, TObject};
|
use crate::avm1::{Object, TObject};
|
||||||
|
use crate::display_object::TDisplayObject;
|
||||||
use crate::ecma_conversions::{
|
use crate::ecma_conversions::{
|
||||||
f64_to_wrapping_i16, f64_to_wrapping_i32, f64_to_wrapping_u16, f64_to_wrapping_u32,
|
f64_to_wrapping_i16, f64_to_wrapping_i32, f64_to_wrapping_u16, f64_to_wrapping_u32,
|
||||||
f64_to_wrapping_u8,
|
f64_to_wrapping_u8,
|
||||||
|
@ -474,7 +475,17 @@ impl<'gc> Value<'gc> {
|
||||||
Value::Number(_) => "number",
|
Value::Number(_) => "number",
|
||||||
Value::Bool(_) => "boolean",
|
Value::Bool(_) => "boolean",
|
||||||
Value::String(_) => "string",
|
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",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue