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:
parent
9604b525d5
commit
31faf62baf
|
@ -196,21 +196,18 @@ impl<'gc> Domain<'gc> {
|
|||
self,
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
) -> Result<(), Error> {
|
||||
let bytearray_proto = activation.avm2().prototypes().bytearray;
|
||||
let bytearray_constr = activation.avm2().constructors().bytearray;
|
||||
|
||||
let domain_memory = ByteArrayObject::new(
|
||||
activation.context.gc_context,
|
||||
bytearray_constr,
|
||||
Some(bytearray_proto),
|
||||
);
|
||||
let domain_memory = bytearray_constr.construct(activation, &[])?;
|
||||
domain_memory
|
||||
.as_bytearray_mut(activation.context.gc_context)
|
||||
.unwrap()
|
||||
.set_length(1024);
|
||||
|
||||
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(())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::avm2::class::{Class, ClassAttributes};
|
|||
use crate::avm2::method::{Method, NativeMethod};
|
||||
use crate::avm2::names::{Namespace, QName};
|
||||
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::{AvmString, Error};
|
||||
|
@ -308,14 +308,9 @@ pub fn bytes<'gc>(
|
|||
return Err("Error: The stage's loader info does not have a bytestream".into())
|
||||
}
|
||||
LoaderStream::Swf(root, _) => {
|
||||
let ba_proto = activation.context.avm2.prototypes().bytearray;
|
||||
let ba_constr = activation.context.avm2.constructors().bytearray;
|
||||
|
||||
let ba = ByteArrayObject::construct(
|
||||
activation.context.gc_context,
|
||||
ba_constr,
|
||||
Some(ba_proto),
|
||||
);
|
||||
let ba = ba_constr.construct(activation, &[])?;
|
||||
let mut ba_write = ba.as_bytearray_mut(activation.context.gc_context).unwrap();
|
||||
|
||||
// First, write a fake header corresponding to an
|
||||
|
|
|
@ -19,7 +19,16 @@ pub fn bytearray_deriver<'gc>(
|
|||
proto: Object<'gc>,
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
) -> 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)]
|
||||
|
@ -35,49 +44,6 @@ pub struct ByteArrayObjectData<'gc> {
|
|||
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_avm2_custom_object!(base);
|
||||
|
||||
|
|
Loading…
Reference in New Issue