avm2: Replace all uses of as_class_object by instance_of

This commit is contained in:
Adrian Wielgosik 2021-09-18 13:55:49 +02:00 committed by Adrian Wielgosik
parent 4b7f8b3dbd
commit 008162c514
9 changed files with 19 additions and 27 deletions

View File

@ -1107,7 +1107,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
.resolve_multiname(&multiname)?
.ok_or_else(|| format!("Could not find method {:?}", multiname.local_name()).into());
let name = name?;
let superclass_object = if let Some(c) = receiver.as_class_object() {
let superclass_object = if let Some(c) = receiver.instance_of() {
c.find_class_for_trait(&name)?
} else {
None
@ -1157,7 +1157,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
.resolve_multiname(&multiname)?
.ok_or_else(|| format!("Could not find method {:?}", multiname.local_name()).into());
let name = name?;
let superclass_object = if let Some(c) = receiver.as_class_object() {
let superclass_object = if let Some(c) = receiver.instance_of() {
c.find_class_for_trait(&name)?
} else {
None
@ -1182,7 +1182,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let method = self.table_method(method, index, false)?;
let scope = self.scope(); //TODO: Is this correct?
let function = FunctionObject::from_method(self, method.into(), scope, None);
let value = function.call(Some(receiver), &args, self, receiver.as_class_object())?;
let value = function.call(Some(receiver), &args, self, receiver.instance_of())?;
self.context.avm2.push(value);

View File

@ -22,11 +22,11 @@ pub fn instance_init<'gc>(
activation.super_init(this, &[])?;
let name = this
.as_class_object()
.instance_of()
.and_then(|t| t.as_class())
.map(|c| c.read().name().clone());
let character = this
.as_class_object()
.instance_of()
.and_then(|t| {
activation
.context

View File

@ -34,8 +34,8 @@ pub fn native_instance_init<'gc>(
if this.as_display_object().is_none() {
let class_object = this
.as_class_object()
.ok_or("Attempted to construct non-instance DisplayObject.")?;
.instance_of()
.ok_or("Attempted to construct DisplayObject on a bare object.")?;
if let Some((movie, symbol)) = activation
.context

View File

@ -25,8 +25,8 @@ pub fn instance_init<'gc>(
if this.as_display_object().is_none() {
let class_object = this
.as_class_object()
.ok_or("Attempted to construct non-instance MovieClip")?;
.instance_of()
.ok_or("Attempted to construct MovieClip on a bare object")?;
let movie = Arc::new(SwfMovie::empty(activation.context.swf.version()));
let new_do = MovieClip::new_with_avm2(
SwfSlice::empty(movie),

View File

@ -23,8 +23,8 @@ pub fn instance_init<'gc>(
if this.as_sound().is_none() {
let class_object = this
.as_class_object()
.ok_or("Attempted to construct non-instance Sound.")?;
.instance_of()
.ok_or("Attempted to construct Sound on a bare object.")?;
if let Some((movie, symbol)) = activation
.context

View File

@ -39,7 +39,7 @@ pub fn font_name<'gc>(
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some((movie, character_id)) =
this.and_then(|this| this.as_class_object())
this.and_then(|this| this.instance_of())
.and_then(|this| {
activation
.context
@ -70,7 +70,7 @@ pub fn font_style<'gc>(
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some((movie, character_id)) =
this.and_then(|this| this.as_class_object())
this.and_then(|this| this.instance_of())
.and_then(|this| {
activation
.context
@ -104,7 +104,7 @@ pub fn font_type<'gc>(
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some((movie, character_id)) =
this.and_then(|this| this.as_class_object())
this.and_then(|this| this.instance_of())
.and_then(|this| {
activation
.context
@ -134,7 +134,7 @@ pub fn has_glyphs<'gc>(
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some((movie, character_id)) =
this.and_then(|this| this.as_class_object())
this.and_then(|this| this.instance_of())
.and_then(|this| {
activation
.context

View File

@ -23,8 +23,8 @@ pub fn instance_init<'gc>(
activation.super_init(this, &[])?;
let class_object = this
.as_class_object()
.ok_or("Attempted to construct non-instance ByteArray")?;
.instance_of()
.ok_or("Attempted to construct ByteArray on a bare object")?;
if let Some((movie, id)) = activation
.context
.library

View File

@ -275,7 +275,7 @@ pub fn concat<'gc>(
};
let my_class = this
.as_class_object()
.instance_of()
.ok_or("TypeError: Tried to concat into a bare object")?;
let val_class = new_vector_storage.value_type();

View File

@ -1007,7 +1007,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
test_class: Object<'gc>,
activation: &mut Activation<'_, 'gc, '_>,
) -> Result<bool, Error> {
let my_class = self.as_class_object();
let my_class = self.instance_of();
// ES3 objects are not class instances but are still treated as
// instances of Object, which is an ES4 class.
@ -1094,14 +1094,6 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
Some(class.inner_class_definition())
}
/// Get this object's class object, if it has one - unless it's a class itself.
fn as_class_object(&self) -> Option<Object<'gc>> {
match self.as_class_object_really() {
Some(_class) => None,
None => self.instance_of()
}
}
fn instance_of(&self) -> Option<Object<'gc>>;
fn as_class_object_really(&self) -> Option<ClassObject<'gc>> {