From 7cbc5f6ee61102864528eed513e399f256b4e5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BClker?= Date: Tue, 17 Sep 2024 14:02:42 +0200 Subject: [PATCH] Update CustomEvent webidl interface (#33481) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- components/script/dom/customevent.rs | 7 +++---- components/script/dom/webidls/CustomEvent.webidl | 13 ++++++++++--- components/script/dom/webidls/Event.webidl | 2 +- tests/wpt/meta/dom/events/CustomEvent.html.ini | 3 --- tests/wpt/meta/dom/idlharness.any.js.ini | 3 --- tests/wpt/meta/dom/idlharness.window.js.ini | 3 --- 6 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 tests/wpt/meta/dom/events/CustomEvent.html.ini diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 156dc00af54..7cad0f7be2f 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -11,7 +11,6 @@ use servo_atoms::Atom; use crate::dom::bindings::codegen::Bindings::CustomEventBinding; use crate::dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods; use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use crate::dom::bindings::error::Fallible; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::root::DomRoot; @@ -75,8 +74,8 @@ impl CustomEvent { can_gc: CanGc, type_: DOMString, init: RootedTraceableBox, - ) -> Fallible> { - Ok(CustomEvent::new( + ) -> DomRoot { + CustomEvent::new( global, proto, Atom::from(type_), @@ -84,7 +83,7 @@ impl CustomEvent { init.parent.cancelable, init.detail.handle(), can_gc, - )) + ) } fn init_custom_event( diff --git a/components/script/dom/webidls/CustomEvent.webidl b/components/script/dom/webidls/CustomEvent.webidl index 36e01e0d9b2..af57bfdf1a2 100644 --- a/components/script/dom/webidls/CustomEvent.webidl +++ b/components/script/dom/webidls/CustomEvent.webidl @@ -13,12 +13,19 @@ * 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 { - [Throws] constructor(DOMString type, optional CustomEventInit eventInitDict = {}); + constructor(DOMString type, optional CustomEventInit eventInitDict = {}); + 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 { diff --git a/components/script/dom/webidls/Event.webidl b/components/script/dom/webidls/Event.webidl index 89d12daea80..0fd7d2ba881 100644 --- a/components/script/dom/webidls/Event.webidl +++ b/components/script/dom/webidls/Event.webidl @@ -6,7 +6,7 @@ * https://dom.spec.whatwg.org/#event */ -[Exposed=(Window,Worker)] +[Exposed=*] interface Event { [Throws] constructor(DOMString type, optional EventInit eventInitDict = {}); [Pure] diff --git a/tests/wpt/meta/dom/events/CustomEvent.html.ini b/tests/wpt/meta/dom/events/CustomEvent.html.ini deleted file mode 100644 index d6382aee306..00000000000 --- a/tests/wpt/meta/dom/events/CustomEvent.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[CustomEvent.html] - [initCustomEvent's default parameter values.] - expected: FAIL diff --git a/tests/wpt/meta/dom/idlharness.any.js.ini b/tests/wpt/meta/dom/idlharness.any.js.ini index 6424f8a1253..83de015989d 100644 --- a/tests/wpt/meta/dom/idlharness.any.js.ini +++ b/tests/wpt/meta/dom/idlharness.any.js.ini @@ -11,9 +11,6 @@ [Event interface: new Event("foo") must inherit property "composed" with the proper type] 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] expected: FAIL diff --git a/tests/wpt/meta/dom/idlharness.window.js.ini b/tests/wpt/meta/dom/idlharness.window.js.ini index 6646a4b08c6..abec304c66f 100644 --- a/tests/wpt/meta/dom/idlharness.window.js.ini +++ b/tests/wpt/meta/dom/idlharness.window.js.ini @@ -169,9 +169,6 @@ [XPathExpression interface: existence and properties of interface prototype object] 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] expected: FAIL