script: Change signature of Event::dispatch to match the spec and simplify things (#38566)

- [Dispatch Event](https://dom.spec.whatwg.org/#concept-event-dispatch)
should return a Boolean. This function is used frequently in spec and
the change makes things easier to follow.
- Remove `enum EventStatus` and related functions.
- Update some dead spec link.
- Update some steps.

This is intended as cleanup before working on #38435 and reduces binary
size by 488KB in Release profile.

Testing: No behaviour change.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-08-09 16:04:31 +08:00 committed by GitHub
parent 21717158eb
commit 589d188a3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 40 additions and 68 deletions

View file

@ -279,7 +279,7 @@ impl Event {
legacy_target_override: bool,
can_gc: CanGc,
// TODO legacy_did_output_listeners_throw_flag for indexeddb
) -> EventStatus {
) -> bool {
let mut target = DomRoot::from_ref(target);
// Step 1. Set events dispatch flag.
@ -629,15 +629,7 @@ impl Event {
}
// Step 12 Return false if events canceled flag is set; otherwise true.
self.status()
}
pub(crate) fn status(&self) -> EventStatus {
if self.DefaultPrevented() {
EventStatus::Canceled
} else {
EventStatus::NotCanceled
}
!self.DefaultPrevented()
}
#[inline]
@ -673,8 +665,8 @@ impl Event {
self.composed.set(composed);
}
/// <https://html.spec.whatwg.org/multipage/#fire-a-simple-event>
pub(crate) fn fire(&self, target: &EventTarget, can_gc: CanGc) -> EventStatus {
/// <https://dom.spec.whatwg.org/#firing-events>
pub(crate) fn fire(&self, target: &EventTarget, can_gc: CanGc) -> bool {
self.set_trusted(true);
target.dispatch_event(self, can_gc)
}
@ -1105,12 +1097,6 @@ pub(crate) enum EventDefault {
Handled,
}
#[derive(Debug, PartialEq)]
pub(crate) enum EventStatus {
Canceled,
NotCanceled,
}
/// <https://dom.spec.whatwg.org/#concept-event-fire>
pub(crate) struct EventTask {
pub(crate) target: Trusted<EventTarget>,