From 2faf35d43e80eb180080a76bde80f189c3e5fae6 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Mon, 27 Jul 2020 22:48:37 +0200 Subject: [PATCH] avm1: Set __constructor__ in Function::construct --- core/src/avm1/activation.rs | 36 ++---------------------------------- core/src/avm1/function.rs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index 7b196eb1d..87268564f 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -1728,23 +1728,7 @@ impl<'a, 'gc: 'a> Activation<'a, 'gc> { .get("prototype", self, context)? .coerce_to_object(self, context); - let mut 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(), - ); - } + let this = prototype.new(self, context, prototype, &args)?; //TODO: What happens if you `ActionNewMethod` without a method name? constructor.construct(self, context, this, &args)?; @@ -1781,23 +1765,7 @@ impl<'a, 'gc: 'a> Activation<'a, 'gc> { .get("prototype", self, context)? .coerce_to_object(self, context); - let mut 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(), - ); - } + let this = prototype.new(self, context, prototype, &args)?; constructor.construct(self, context, this, &args)?; diff --git a/core/src/avm1/function.rs b/core/src/avm1/function.rs index 709aa5108..c160446ce 100644 --- a/core/src/avm1/function.rs +++ b/core/src/avm1/function.rs @@ -578,9 +578,25 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> { &self, activation: &mut Activation<'_, 'gc>, context: &mut UpdateContext<'_, 'gc, '_>, - this: Object<'gc>, + mut this: Object<'gc>, args: &[Value<'gc>], ) -> Result, 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 { exec.exec( "[ctor]",