avm1: Create proper underlying type when extending native objects (fix #2682)

This commit is contained in:
Mike Welsh 2021-01-20 23:39:20 -08:00
parent 8bc64be012
commit a6ea28d9b4
1 changed files with 7 additions and 3 deletions

View File

@ -1133,10 +1133,14 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
//TODO: What happens if we try to extend an object which has no `prototype`? //TODO: What happens if we try to extend an object which has no `prototype`?
//e.g. `class Whatever extends Object.prototype` or `class Whatever extends 5` //e.g. `class Whatever extends Object.prototype` or `class Whatever extends 5`
let super_proto = superclass.get("prototype", self)?.coerce_to_object(self);
let sub_prototype: Object<'gc> = // Use `create_bare_object` to ensure the proper underlying object type when
ScriptObject::object(self.context.gc_context, Some(super_proto)).into(); // extending native objects.
// TODO: This doesn't work if the user manually wires up `prototype`/`__proto__`.
// The native object needs to be created later by the superclass's constructor.
// (see #701)
let super_prototype = superclass.get("prototype", self)?.coerce_to_object(self);
let sub_prototype = super_prototype.create_bare_object(self, super_prototype)?;
sub_prototype.set("constructor", superclass.into(), self)?; sub_prototype.set("constructor", superclass.into(), self)?;
sub_prototype.set_attributes( sub_prototype.set_attributes(