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

@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLOrSVGElementBinding::FocusOptions;
use crate::dom::bindings::inheritance::Castable;
@ -62,14 +61,15 @@ pub(crate) trait Validatable {
return true;
}
// Step 1.1.
let event = self
// Step 1.1: Let report be the result of firing an event named invalid at element,
// with the cancelable attribute initialized to true.
let report = self
.as_element()
.upcast::<EventTarget>()
.fire_cancelable_event(atom!("invalid"), can_gc);
// Step 1.2.
if !event.DefaultPrevented() {
if report {
let flags = self.validity_state().invalid_flags();
println!(
"Validation error: {}",