avm1: Set __constructor__ in Function::construct

This commit is contained in:
Nathan Adams 2020-07-27 22:48:37 +02:00 committed by Mike Welsh
parent d9c8c43cf3
commit 2faf35d43e
2 changed files with 19 additions and 35 deletions

View File

@ -1728,23 +1728,7 @@ impl<'a, 'gc: 'a> Activation<'a, 'gc> {
.get("prototype", self, context)? .get("prototype", self, context)?
.coerce_to_object(self, context); .coerce_to_object(self, context);
let mut this = prototype.new(self, context, prototype, &args)?; let this = prototype.new(self, context, prototype, &args)?;
this.set("__constructor__", constructor.into(), self, context)?;
this.set_attributes(
context.gc_context,
Some("__constructor__"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
if self.current_swf_version() < 7 {
this.set("constructor", constructor.into(), self, context)?;
this.set_attributes(
context.gc_context,
Some("constructor"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
}
//TODO: What happens if you `ActionNewMethod` without a method name? //TODO: What happens if you `ActionNewMethod` without a method name?
constructor.construct(self, context, this, &args)?; constructor.construct(self, context, this, &args)?;
@ -1781,23 +1765,7 @@ impl<'a, 'gc: 'a> Activation<'a, 'gc> {
.get("prototype", self, context)? .get("prototype", self, context)?
.coerce_to_object(self, context); .coerce_to_object(self, context);
let mut this = prototype.new(self, context, prototype, &args)?; let this = prototype.new(self, context, prototype, &args)?;
this.set("__constructor__", constructor.into(), self, context)?;
this.set_attributes(
context.gc_context,
Some("__constructor__"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
if self.current_swf_version() < 7 {
this.set("constructor", constructor.into(), self, context)?;
this.set_attributes(
context.gc_context,
Some("constructor"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
}
constructor.construct(self, context, this, &args)?; constructor.construct(self, context, this, &args)?;

View File

@ -578,9 +578,25 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
&self, &self,
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
context: &mut UpdateContext<'_, 'gc, '_>, context: &mut UpdateContext<'_, 'gc, '_>,
this: Object<'gc>, mut this: Object<'gc>,
args: &[Value<'gc>], args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
this.set("__constructor__", (*self).into(), activation, context)?;
this.set_attributes(
context.gc_context,
Some("__constructor__"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
if activation.current_swf_version() < 7 {
this.set("constructor", (*self).into(), activation, context)?;
this.set_attributes(
context.gc_context,
Some("constructor"),
Attribute::DontEnum.into(),
EnumSet::empty(),
);
}
if let Some(exec) = &self.data.read().constructor { if let Some(exec) = &self.data.read().constructor {
exec.exec( exec.exec(
"[ctor]", "[ctor]",