script: Make EventTarget::fire return bool according to spec (#39308)

This is a continuation of #38566, newly discovered when fixing
https://github.com/servo/servo/issues/38616#issuecomment-3261561671.

We add more documentation and return `bool` for the function family of
[event firing](https://dom.spec.whatwg.org/#concept-event-fire).

Testing: No behaviour change.

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-09-15 16:07:08 +08:00 committed by GitHub
parent 059a2fd86d
commit 8f4ced66d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 20 deletions

View file

@ -885,7 +885,7 @@ impl EventTarget {
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub(crate) fn fire_event(&self, name: Atom, can_gc: CanGc) -> DomRoot<Event> {
pub(crate) fn fire_event(&self, name: Atom, can_gc: CanGc) -> bool {
self.fire_event_with_params(
name,
EventBubbles::DoesNotBubble,
@ -896,7 +896,7 @@ impl EventTarget {
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub(crate) fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> DomRoot<Event> {
pub(crate) fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> bool {
self.fire_event_with_params(
name,
EventBubbles::Bubbles,
@ -907,7 +907,7 @@ impl EventTarget {
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub(crate) fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> DomRoot<Event> {
pub(crate) fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> bool {
self.fire_event_with_params(
name,
EventBubbles::DoesNotBubble,
@ -918,11 +918,7 @@ impl EventTarget {
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub(crate) fn fire_bubbling_cancelable_event(
&self,
name: Atom,
can_gc: CanGc,
) -> DomRoot<Event> {
pub(crate) fn fire_bubbling_cancelable_event(&self, name: Atom, can_gc: CanGc) -> bool {
self.fire_event_with_params(
name,
EventBubbles::Bubbles,
@ -940,11 +936,10 @@ impl EventTarget {
cancelable: EventCancelable,
composed: EventComposed,
can_gc: CanGc,
) -> DomRoot<Event> {
) -> bool {
let event = Event::new(&self.global(), name, bubbles, cancelable, can_gc);
event.set_composed(composed.into());
event.fire(self, can_gc);
event
event.fire(self, can_gc)
}
/// <https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener>