avm2: Remove all alternative `ByteArrayObject` constructors.

The only way to build a `ByteArrayObject` now is to invoke it's constructor.
This commit is contained in:
David Wendt 2021-05-31 14:29:35 -04:00
parent 9604b525d5
commit 31faf62baf
3 changed files with 16 additions and 58 deletions

View File

@ -196,21 +196,18 @@ impl<'gc> Domain<'gc> {
self, self,
activation: &mut Activation<'_, 'gc, '_>, activation: &mut Activation<'_, 'gc, '_>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let bytearray_proto = activation.avm2().prototypes().bytearray;
let bytearray_constr = activation.avm2().constructors().bytearray; let bytearray_constr = activation.avm2().constructors().bytearray;
let domain_memory = ByteArrayObject::new( let domain_memory = bytearray_constr.construct(activation, &[])?;
activation.context.gc_context,
bytearray_constr,
Some(bytearray_proto),
);
domain_memory domain_memory
.as_bytearray_mut(activation.context.gc_context) .as_bytearray_mut(activation.context.gc_context)
.unwrap() .unwrap()
.set_length(1024); .set_length(1024);
let mut write = self.0.write(activation.context.gc_context); let mut write = self.0.write(activation.context.gc_context);
write.domain_memory.get_or_insert(domain_memory); write
.domain_memory
.get_or_insert(domain_memory.as_bytearray_object().unwrap());
Ok(()) Ok(())
} }

View File

@ -6,7 +6,7 @@ use crate::avm2::class::{Class, ClassAttributes};
use crate::avm2::method::{Method, NativeMethod}; use crate::avm2::method::{Method, NativeMethod};
use crate::avm2::names::{Namespace, QName}; use crate::avm2::names::{Namespace, QName};
use crate::avm2::object::{ use crate::avm2::object::{
loaderinfo_deriver, ByteArrayObject, DomainObject, LoaderStream, Object, ScriptObject, TObject, loaderinfo_deriver, DomainObject, LoaderStream, Object, ScriptObject, TObject,
}; };
use crate::avm2::value::Value; use crate::avm2::value::Value;
use crate::avm2::{AvmString, Error}; use crate::avm2::{AvmString, Error};
@ -308,14 +308,9 @@ pub fn bytes<'gc>(
return Err("Error: The stage's loader info does not have a bytestream".into()) return Err("Error: The stage's loader info does not have a bytestream".into())
} }
LoaderStream::Swf(root, _) => { LoaderStream::Swf(root, _) => {
let ba_proto = activation.context.avm2.prototypes().bytearray;
let ba_constr = activation.context.avm2.constructors().bytearray; let ba_constr = activation.context.avm2.constructors().bytearray;
let ba = ByteArrayObject::construct( let ba = ba_constr.construct(activation, &[])?;
activation.context.gc_context,
ba_constr,
Some(ba_proto),
);
let mut ba_write = ba.as_bytearray_mut(activation.context.gc_context).unwrap(); let mut ba_write = ba.as_bytearray_mut(activation.context.gc_context).unwrap();
// First, write a fake header corresponding to an // First, write a fake header corresponding to an

View File

@ -19,7 +19,16 @@ pub fn bytearray_deriver<'gc>(
proto: Object<'gc>, proto: Object<'gc>,
activation: &mut Activation<'_, 'gc, '_>, activation: &mut Activation<'_, 'gc, '_>,
) -> Result<Object<'gc>, Error> { ) -> Result<Object<'gc>, Error> {
ByteArrayObject::derive(constr, proto, activation.context.gc_context) let base = ScriptObjectData::base_new(Some(proto), ScriptObjectClass::ClassInstance(constr));
Ok(ByteArrayObject(GcCell::allocate(
activation.context.gc_context,
ByteArrayObjectData {
base,
storage: ByteArrayStorage::new(),
},
))
.into())
} }
#[derive(Clone, Collect, Debug, Copy)] #[derive(Clone, Collect, Debug, Copy)]
@ -35,49 +44,6 @@ pub struct ByteArrayObjectData<'gc> {
storage: ByteArrayStorage, storage: ByteArrayStorage,
} }
impl<'gc> ByteArrayObject<'gc> {
pub fn new(
mc: MutationContext<'gc, '_>,
constr: Object<'gc>,
proto: Option<Object<'gc>>,
) -> ByteArrayObject<'gc> {
let base = ScriptObjectData::base_new(proto, ScriptObjectClass::ClassInstance(constr));
ByteArrayObject(GcCell::allocate(
mc,
ByteArrayObjectData {
base,
storage: ByteArrayStorage::new(),
},
))
}
pub fn construct(
mc: MutationContext<'gc, '_>,
constr: Object<'gc>,
base_proto: Option<Object<'gc>>,
) -> Object<'gc> {
Self::new(mc, constr, base_proto).into()
}
pub fn derive(
constr: Object<'gc>,
base_proto: Object<'gc>,
mc: MutationContext<'gc, '_>,
) -> Result<Object<'gc>, Error> {
let base =
ScriptObjectData::base_new(Some(base_proto), ScriptObjectClass::ClassInstance(constr));
Ok(ByteArrayObject(GcCell::allocate(
mc,
ByteArrayObjectData {
base,
storage: ByteArrayStorage::new(),
},
))
.into())
}
}
impl<'gc> TObject<'gc> for ByteArrayObject<'gc> { impl<'gc> TObject<'gc> for ByteArrayObject<'gc> {
impl_avm2_custom_object!(base); impl_avm2_custom_object!(base);