avm1: Add TObject::set_proto

This commit is contained in:
Nathan Adams 2020-04-12 19:52:16 +02:00 committed by Mike Welsh
parent 6316d7e0b3
commit 6b48e77b61
10 changed files with 46 additions and 0 deletions

View File

@ -519,6 +519,10 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
self.base.proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base.set_proto(gc_context, prototype);
}
fn define_value(
&self,
gc_context: MutationContext<'gc, '_>,

View File

@ -118,6 +118,13 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
/// `get`.
fn proto(&self) -> Option<Object<'gc>>;
/// Sets the `__proto__` of a given object.
///
/// The proto is another object used to resolve methods across a class of
/// multiple objects. It should also be accessible as `__proto__` in
/// `set`.
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>);
/// Define a value on an object.
///
/// Unlike setting a value, this function is intended to replace any

View File

@ -409,6 +409,10 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
self.0.read().prototype
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.0.write(gc_context).prototype = prototype;
}
/// Checks if the object has a given named property.
fn has_property(
&self,

View File

@ -183,6 +183,10 @@ impl<'gc> TObject<'gc> for SoundObject<'gc> {
self.base().proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base().set_proto(gc_context, prototype);
}
fn define_value(
&self,
gc_context: MutationContext<'gc, '_>,

View File

@ -157,6 +157,10 @@ impl<'gc> TObject<'gc> for StageObject<'gc> {
self.base.proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base.set_proto(gc_context, prototype);
}
fn define_value(
&self,
gc_context: MutationContext<'gc, '_>,

View File

@ -134,6 +134,10 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
self.0.read().proto
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.0.write(gc_context).proto = prototype;
}
fn define_value(
&self,
_gc_context: MutationContext<'gc, '_>,

View File

@ -229,6 +229,13 @@ impl<'gc> TObject<'gc> for ValueObject<'gc> {
self.0.read().base.proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.0
.write(gc_context)
.base
.set_proto(gc_context, prototype);
}
fn has_property(
&self,
avm: &mut Avm1<'gc>,

View File

@ -169,6 +169,10 @@ impl<'gc> TObject<'gc> for XMLAttributesObject<'gc> {
self.base().proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base().set_proto(gc_context, prototype);
}
fn has_property(
&self,
avm: &mut Avm1<'gc>,

View File

@ -163,6 +163,10 @@ impl<'gc> TObject<'gc> for XMLIDMapObject<'gc> {
self.base().proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base().set_proto(gc_context, prototype);
}
fn has_property(
&self,
avm: &mut Avm1<'gc>,

View File

@ -157,6 +157,10 @@ impl<'gc> TObject<'gc> for XMLObject<'gc> {
self.base().proto()
}
fn set_proto(&self, gc_context: MutationContext<'gc, '_>, prototype: Option<Object<'gc>>) {
self.base().set_proto(gc_context, prototype);
}
fn has_property(
&self,
avm: &mut Avm1<'gc>,