avm2: Make `RegExpObject::from_regexp` pull it's own constructor and call it's own initializer.

This doesn't appear to actually be in use, but I'm doing it for completeness' sake.
This commit is contained in:
David Wendt 2021-05-31 22:19:36 -04:00
parent c167912f52
commit 602895e2de
2 changed files with 26 additions and 27 deletions

View File

@ -111,6 +111,7 @@ pub struct SystemPrototypes<'gc> {
pub stage: Object<'gc>,
pub sprite: Object<'gc>,
pub simplebutton: Object<'gc>,
pub regexp: Object<'gc>,
}
impl<'gc> SystemPrototypes<'gc> {
@ -158,6 +159,7 @@ impl<'gc> SystemPrototypes<'gc> {
stage: empty,
sprite: empty,
simplebutton: empty,
regexp: empty,
}
}
}
@ -196,6 +198,7 @@ pub struct SystemConstructors<'gc> {
pub stage: Object<'gc>,
pub sprite: Object<'gc>,
pub simplebutton: Object<'gc>,
pub regexp: Object<'gc>,
}
impl<'gc> SystemConstructors<'gc> {
@ -243,6 +246,7 @@ impl<'gc> SystemConstructors<'gc> {
stage: empty,
sprite: empty,
simplebutton: empty,
regexp: empty,
}
}
}
@ -478,7 +482,7 @@ pub fn load_player_globals<'gc>(
constant(mc, "", "Infinity", f64::INFINITY.into(), domain, script)?;
class(activation, math::create_class(mc), domain, script)?;
class(activation, regexp::create_class(mc), domain, script)?;
avm2_system_class!(regexp, activation, regexp::create_class(mc), domain, script);
avm2_system_class!(xml, activation, xml::create_class(mc), domain, script);
avm2_system_class!(

View File

@ -21,11 +21,16 @@ pub fn regexp_deriver<'gc>(
proto: Object<'gc>,
activation: &mut Activation<'_, 'gc, '_>,
) -> Result<Object<'gc>, Error> {
Ok(RegExpObject::derive(
constr,
proto,
let base = ScriptObjectData::base_new(Some(proto), ScriptObjectClass::ClassInstance(constr));
Ok(RegExpObject(GcCell::allocate(
activation.context.gc_context,
RegExpObjectData {
base,
regexp: RegExp::new(""),
},
))
.into())
}
#[derive(Clone, Collect, Debug, Copy)]
@ -43,33 +48,23 @@ pub struct RegExpObjectData<'gc> {
impl<'gc> RegExpObject<'gc> {
pub fn from_regexp(
mc: MutationContext<'gc, '_>,
constr: Object<'gc>,
base_proto: Option<Object<'gc>>,
activation: &mut Activation<'_, 'gc, '_>,
regexp: RegExp<'gc>,
) -> Object<'gc> {
let base = ScriptObjectData::base_new(base_proto, ScriptObjectClass::ClassInstance(constr));
RegExpObject(GcCell::allocate(mc, RegExpObjectData { base, regexp })).into()
}
/// Instantiate a regexp subclass.
pub fn derive(
constr: Object<'gc>,
base_proto: Object<'gc>,
mc: MutationContext<'gc, '_>,
) -> Object<'gc> {
) -> Result<Object<'gc>, Error> {
let constr = activation.avm2().constructors().regexp;
let proto = activation.avm2().prototypes().regexp;
let base =
ScriptObjectData::base_new(Some(base_proto), ScriptObjectClass::ClassInstance(constr));
ScriptObjectData::base_new(Some(proto), ScriptObjectClass::ClassInstance(constr));
RegExpObject(GcCell::allocate(
mc,
RegExpObjectData {
base,
regexp: RegExp::new(""),
},
let this = RegExpObject(GcCell::allocate(
activation.context.gc_context,
RegExpObjectData { base, regexp },
))
.into()
.into();
constr.call_native_initializer(Some(this), &[], activation, Some(constr))?;
Ok(this)
}
}