Skip to content

Commit ed29b1c

Browse files
committed
It turns out Macromedia just used an undocumented but user-modifiable property called __constructor__ to store the constructor.
A previous version of this PR (whose history has been scrubbed, but go check 918d88a if you're curious) implemented a new `TObject` property which basically every line of code that dealt with object construction had to populate. It was terrible.
1 parent bb87987 commit ed29b1c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

core/src/avm1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ impl<'gc> Avm1<'gc> {
15901590
ScriptObject::object(context.gc_context, Some(super_proto)).into();
15911591

15921592
sub_prototype.set("constructor", superclass.into(), self, context)?;
1593+
sub_prototype.set("__constructor__", superclass.into(), self, context)?;
15931594
subclass.set("prototype", sub_prototype.into(), self, context)?;
15941595

15951596
Ok(())
@@ -2077,6 +2078,7 @@ impl<'gc> Avm1<'gc> {
20772078

20782079
let this = prototype.new(self, context, prototype, &args)?;
20792080

2081+
this.set("__constructor__", constructor.into(), self, context)?;
20802082
if self.current_swf_version() < 7 {
20812083
this.set("constructor", constructor.into(), self, context)?;
20822084
}
@@ -2119,6 +2121,7 @@ impl<'gc> Avm1<'gc> {
21192121
{
21202122
let this = prototype.new(self, context, prototype, &args)?;
21212123

2124+
this.set("__constructor__", constructor.into(), self, context)?;
21222125
if self.current_swf_version() < 7 {
21232126
this.set("constructor", constructor.into(), self, context)?;
21242127
}

core/src/avm1/super_object.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'gc> SuperObject<'gc> {
6868
) -> Result<Option<Object<'gc>>, Error> {
6969
if let Some(super_proto) = self.super_proto() {
7070
Ok(super_proto
71-
.get("constructor", avm, context)?
71+
.get("__constructor__", avm, context)?
7272
.resolve(avm, context)?
7373
.as_object()
7474
.ok())
@@ -181,7 +181,9 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
181181
}
182182

183183
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
184-
self.0.write(gc_context).proto = prototype;
184+
if let Some(prototype) = prototype {
185+
self.0.write(gc_context).base_proto = prototype;
186+
}
185187
}
186188

187189
fn define_value(

0 commit comments

Comments
 (0)