Update CustomEvent webidl interface (#33481)

The [idl interface](https://dom.spec.whatwg.org/#interface-customevent) and servo's implementation had diverged.

* Extra arguments to initCustomEvent are optional (fixes `dom/events/CustomEvent.html`)
* The CustomEvent constructor is infallible
* "[Exposed=*]" (and the same for the "Event" interface since it's
  CustomEvent's parent.)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2024-09-17 14:02:42 +02:00 committed by GitHub
parent 4c3b3529a8
commit 7cbc5f6ee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 14 additions and 17 deletions

View file

@ -11,7 +11,6 @@ use servo_atoms::Atom;
use crate::dom::bindings::codegen::Bindings::CustomEventBinding; use crate::dom::bindings::codegen::Bindings::CustomEventBinding;
use crate::dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods; use crate::dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods; use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
@ -75,8 +74,8 @@ impl CustomEvent {
can_gc: CanGc, can_gc: CanGc,
type_: DOMString, type_: DOMString,
init: RootedTraceableBox<CustomEventBinding::CustomEventInit>, init: RootedTraceableBox<CustomEventBinding::CustomEventInit>,
) -> Fallible<DomRoot<CustomEvent>> { ) -> DomRoot<CustomEvent> {
Ok(CustomEvent::new( CustomEvent::new(
global, global,
proto, proto,
Atom::from(type_), Atom::from(type_),
@ -84,7 +83,7 @@ impl CustomEvent {
init.parent.cancelable, init.parent.cancelable,
init.detail.handle(), init.detail.handle(),
can_gc, can_gc,
)) )
} }
fn init_custom_event( fn init_custom_event(

View file

@ -13,12 +13,19 @@
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
*/ */
[Exposed=(Window,Worker)] // https://dom.spec.whatwg.org/#dom-customevent-initcustomevent
[Exposed=*]
interface CustomEvent : Event { interface CustomEvent : Event {
[Throws] constructor(DOMString type, optional CustomEventInit eventInitDict = {}); constructor(DOMString type, optional CustomEventInit eventInitDict = {});
readonly attribute any detail; readonly attribute any detail;
undefined initCustomEvent(DOMString type, boolean bubbles, boolean cancelable, any detail); undefined initCustomEvent(
DOMString type,
optional boolean bubbles = false,
optional boolean cancelable = false,
optional any detail = null
); // legacy
}; };
dictionary CustomEventInit : EventInit { dictionary CustomEventInit : EventInit {

View file

@ -6,7 +6,7 @@
* https://dom.spec.whatwg.org/#event * https://dom.spec.whatwg.org/#event
*/ */
[Exposed=(Window,Worker)] [Exposed=*]
interface Event { interface Event {
[Throws] constructor(DOMString type, optional EventInit eventInitDict = {}); [Throws] constructor(DOMString type, optional EventInit eventInitDict = {});
[Pure] [Pure]

View file

@ -1,3 +0,0 @@
[CustomEvent.html]
[initCustomEvent's default parameter values.]
expected: FAIL

View file

@ -11,9 +11,6 @@
[Event interface: new Event("foo") must inherit property "composed" with the proper type] [Event interface: new Event("foo") must inherit property "composed" with the proper type]
expected: FAIL expected: FAIL
[CustomEvent interface: operation initCustomEvent(DOMString, optional boolean, optional boolean, optional any)]
expected: FAIL
[Event interface: new CustomEvent("foo") must inherit property "composed" with the proper type] [Event interface: new CustomEvent("foo") must inherit property "composed" with the proper type]
expected: FAIL expected: FAIL

View file

@ -169,9 +169,6 @@
[XPathExpression interface: existence and properties of interface prototype object] [XPathExpression interface: existence and properties of interface prototype object]
expected: FAIL expected: FAIL
[CustomEvent interface: operation initCustomEvent(DOMString, optional boolean, optional boolean, optional any)]
expected: FAIL
[XPathResult interface: constant ORDERED_NODE_ITERATOR_TYPE on interface object] [XPathResult interface: constant ORDERED_NODE_ITERATOR_TYPE on interface object]
expected: FAIL expected: FAIL