avm1: Replace `set` + `set_attributes` with `define_value`

This commit is contained in:
relrelb 2021-06-24 15:21:23 +03:00 committed by relrelb
parent c609fa937d
commit 3576a199cd
3 changed files with 21 additions and 29 deletions

View File

@ -1132,20 +1132,18 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
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_attributes(
sub_prototype.define_value(
self.context.gc_context,
Some("constructor"),
"constructor",
superclass.into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
sub_prototype.set("__constructor__", superclass.into(), self)?;
sub_prototype.set_attributes(
sub_prototype.define_value(
self.context.gc_context,
Some("__constructor__"),
"__constructor__",
superclass.into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
subclass.set("prototype", sub_prototype.into(), self)?;

View File

@ -576,20 +576,18 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<(), Error<'gc>> {
this.set("__constructor__", (*self).into(), activation)?;
this.set_attributes(
this.define_value(
activation.context.gc_context,
Some("__constructor__"),
"__constructor__",
(*self).into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
if activation.swf_version() < 7 {
this.set("constructor", (*self).into(), activation)?;
this.set_attributes(
this.define_value(
activation.context.gc_context,
Some("constructor"),
"constructor",
(*self).into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
}
if let Some(exec) = &self.data.read().constructor {
@ -618,20 +616,18 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
.coerce_to_object(activation);
let this = prototype.create_bare_object(activation, prototype)?;
this.set("__constructor__", (*self).into(), activation)?;
this.set_attributes(
this.define_value(
activation.context.gc_context,
Some("__constructor__"),
"__constructor__",
(*self).into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
if activation.swf_version() < 7 {
this.set("constructor", (*self).into(), activation)?;
this.set_attributes(
this.define_value(
activation.context.gc_context,
Some("constructor"),
"constructor",
(*self).into(),
Attribute::DONT_ENUM,
Attribute::empty(),
);
}
if let Some(exec) = &self.data.read().constructor {

View File

@ -27,14 +27,12 @@ pub fn constructor<'gc>(
// The target display object that this color will modify.
let target = args.get(0).cloned().unwrap_or(Value::Undefined);
// Set undocumented `target` property
this.set("target", target, activation)?;
this.set_attributes(
this.define_value(
activation.context.gc_context,
Some("target"),
"target",
target,
Attribute::DONT_DELETE | Attribute::READ_ONLY | Attribute::DONT_ENUM,
Attribute::empty(),
);
Ok(this.into())
}