avm2: Move instance_allocator() to ClassObject

This commit is contained in:
Adrian Wielgosik 2021-09-18 12:03:45 +02:00 committed by Adrian Wielgosik
parent 1d22009c6b
commit 4380978b2a
2 changed files with 15 additions and 12 deletions

View File

@ -3,7 +3,7 @@
use crate::avm2::activation::Activation; use crate::avm2::activation::Activation;
use crate::avm2::array::ArrayStorage; use crate::avm2::array::ArrayStorage;
use crate::avm2::bytearray::ByteArrayStorage; use crate::avm2::bytearray::ByteArrayStorage;
use crate::avm2::class::{AllocatorFn, Class}; use crate::avm2::class::Class;
use crate::avm2::domain::Domain; use crate::avm2::domain::Domain;
use crate::avm2::events::{DispatchList, Event}; use crate::avm2::events::{DispatchList, Event};
use crate::avm2::function::Executable; use crate::avm2::function::Executable;
@ -1094,11 +1094,6 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
None None
} }
/// Get this class's instance allocator.
fn instance_allocator(self) -> Option<AllocatorFn> {
None
}
/// Get this object's `Executable`, if it has one. /// Get this object's `Executable`, if it has one.
fn as_executable(&self) -> Option<Executable<'gc>> { fn as_executable(&self) -> Option<Executable<'gc>> {
None None

View File

@ -106,7 +106,11 @@ impl<'gc> ClassObject<'gc> {
let instance_allocator = class let instance_allocator = class
.read() .read()
.instance_allocator() .instance_allocator()
.or_else(|| superclass_object.and_then(|c| c.instance_allocator())) .or_else(||
superclass_object
.and_then(|c| c.as_class_object_really())
.and_then(|c| c.instance_allocator())
)
.unwrap_or(scriptobject_allocator); .unwrap_or(scriptobject_allocator);
//TODO: Class prototypes are *not* instances of their class and should //TODO: Class prototypes are *not* instances of their class and should
@ -191,7 +195,11 @@ impl<'gc> ClassObject<'gc> {
let instance_allocator = class let instance_allocator = class
.read() .read()
.instance_allocator() .instance_allocator()
.or_else(|| superclass_object.and_then(|c| c.instance_allocator())) .or_else(||
superclass_object
.and_then(|c| c.as_class_object_really())
.and_then(|c| c.instance_allocator())
)
.unwrap_or(scriptobject_allocator); .unwrap_or(scriptobject_allocator);
let constructor = Executable::from_method(class.read().instance_init(), scope, None, mc); let constructor = Executable::from_method(class.read().instance_init(), scope, None, mc);
@ -347,6 +355,10 @@ impl<'gc> ClassObject<'gc> {
pub fn as_class_params(self) -> Option<Option<Object<'gc>>> { pub fn as_class_params(self) -> Option<Option<Object<'gc>>> {
self.0.read().params self.0.read().params
} }
fn instance_allocator(self) -> Option<AllocatorFn> {
Some(self.0.read().instance_allocator.0)
}
} }
impl<'gc> TObject<'gc> for ClassObject<'gc> { impl<'gc> TObject<'gc> for ClassObject<'gc> {
@ -451,10 +463,6 @@ impl<'gc> TObject<'gc> for ClassObject<'gc> {
.into()) .into())
} }
fn instance_allocator(self) -> Option<AllocatorFn> {
Some(self.0.read().instance_allocator.0)
}
fn get_scope(self) -> Option<GcCell<'gc, Scope<'gc>>> { fn get_scope(self) -> Option<GcCell<'gc, Scope<'gc>>> {
self.0.read().scope self.0.read().scope
} }