avm1: Rename `set_watcher` and `remove_watcher` to `watch` and `unwatch`

This better reflects their correspondence to `Object.watch` and
`Object.unwatch` respectively.
This commit is contained in:
relrelb 2021-07-16 00:50:27 +03:00 committed by relrelb
parent e8e0467673
commit 536526a342
10 changed files with 32 additions and 36 deletions

View File

@ -736,18 +736,18 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
.add_property_with_case(activation, name, get, set, attributes)
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
callback: Object<'gc>,
user_data: Value<'gc>,
) {
self.base.set_watcher(activation, name, callback, user_data);
self.base.watch(activation, name, callback, user_data);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base.remove_watcher(activation, name)
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base.unwatch(activation, name)
}
fn has_property(&self, activation: &mut Activation<'_, 'gc, '_>, name: &str) -> bool {

View File

@ -213,7 +213,7 @@ fn watch<'gc>(
}
let user_data = args.get(2).cloned().unwrap_or(Value::Undefined);
this.set_watcher(activation, Cow::Borrowed(&name), callback, user_data);
this.watch(activation, Cow::Borrowed(&name), callback, user_data);
Ok(true.into())
}
@ -230,7 +230,7 @@ fn unwatch<'gc>(
return Ok(false.into());
};
let result = this.remove_watcher(activation, Cow::Borrowed(&name));
let result = this.unwatch(activation, Cow::Borrowed(&name));
Ok(result.into())
}

View File

@ -357,7 +357,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
/// Set the 'watcher' of a given property.
///
/// The property does not need to exist at the time of this being called.
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
@ -369,7 +369,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
///
/// The return value will indicate if there was a watcher present before this method was
/// called.
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool;
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool;
/// Checks if the object has a given named property.
fn has_property(&self, activation: &mut Activation<'_, 'gc, '_>, name: &str) -> bool;

View File

@ -183,20 +183,18 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
.add_property_with_case(activation, name, get, set, attributes)
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
callback: Object<'gc>,
user_data: Value<'gc>,
) {
self.0
.read()
.set_watcher(activation, name, callback, user_data);
self.0.read().watch(activation, name, callback, user_data);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.0.read().remove_watcher(activation, name)
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.0.read().unwatch(activation, name)
}
fn define_value(

View File

@ -251,7 +251,7 @@ macro_rules! impl_custom_object {
self.0.read().$field.delete_element(activation, index)
}
fn set_watcher(
fn watch(
&self,
activation: &mut crate::avm1::Activation<'_, 'gc, '_>,
name: std::borrow::Cow<str>,
@ -261,15 +261,15 @@ macro_rules! impl_custom_object {
self.0
.read()
.$field
.set_watcher(activation, name, callback, user_data);
.watch(activation, name, callback, user_data);
}
fn remove_watcher(
fn unwatch(
&self,
activation: &mut crate::avm1::Activation<'_, 'gc, '_>,
name: std::borrow::Cow<str>,
) -> bool {
self.0.read().$field.remove_watcher(activation, name)
self.0.read().$field.unwatch(activation, name)
}
};
}

View File

@ -369,7 +369,7 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
);
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
@ -383,7 +383,7 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
let old = self
.0
.write(activation.context.gc_context)

View File

@ -333,7 +333,7 @@ impl<'gc> TObject<'gc> for StageObject<'gc> {
.add_property_with_case(activation, name, get, set, attributes)
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
@ -343,11 +343,11 @@ impl<'gc> TObject<'gc> for StageObject<'gc> {
self.0
.read()
.base
.set_watcher(activation, name, callback, user_data);
.watch(activation, name, callback, user_data);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.0.read().base.remove_watcher(activation, name)
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.0.read().base.unwatch(activation, name)
}
fn has_property(&self, activation: &mut Activation<'_, 'gc, '_>, name: &str) -> bool {

View File

@ -213,7 +213,7 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
//`super` cannot have properties defined on it
}
fn set_watcher(
fn watch(
&self,
_activation: &mut Activation<'_, 'gc, '_>,
_name: Cow<str>,
@ -223,7 +223,7 @@ impl<'gc> TObject<'gc> for SuperObject<'gc> {
//`super` cannot have properties defined on it
}
fn remove_watcher(&self, _activation: &mut Activation<'_, 'gc, '_>, _name: Cow<str>) -> bool {
fn unwatch(&self, _activation: &mut Activation<'_, 'gc, '_>, _name: Cow<str>) -> bool {
//`super` cannot have properties defined on it
false
}

View File

@ -142,19 +142,18 @@ impl<'gc> TObject<'gc> for XmlAttributesObject<'gc> {
.add_property_with_case(activation, name, get, set, attributes)
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
callback: Object<'gc>,
user_data: Value<'gc>,
) {
self.base()
.set_watcher(activation, name, callback, user_data);
self.base().watch(activation, name, callback, user_data);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base().remove_watcher(activation, name)
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base().unwatch(activation, name)
}
fn define_value(

View File

@ -143,19 +143,18 @@ impl<'gc> TObject<'gc> for XmlIdMapObject<'gc> {
.add_property_with_case(activation, name, get, set, attributes)
}
fn set_watcher(
fn watch(
&self,
activation: &mut Activation<'_, 'gc, '_>,
name: Cow<str>,
callback: Object<'gc>,
user_data: Value<'gc>,
) {
self.base()
.set_watcher(activation, name, callback, user_data);
self.base().watch(activation, name, callback, user_data);
}
fn remove_watcher(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base().remove_watcher(activation, name)
fn unwatch(&self, activation: &mut Activation<'_, 'gc, '_>, name: Cow<str>) -> bool {
self.base().unwatch(activation, name)
}
fn define_value(