diff --git a/CHANGELOG.md b/CHANGELOG.md index 647f6383254..90855a6206b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,9 @@ * Deprecated parameters to `default` (`init`) and `initSync` in favor of an object. [#3995](https://github.com/rustwasm/wasm-bindgen/pull/3995) +* Update `AbortSignal` and `AbortController` according to the WHATWG specification. + [#4026](https://github.com/rustwasm/wasm-bindgen/pull/4026) + ### Fixed * Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`. diff --git a/crates/web-sys/src/features/gen_AbortController.rs b/crates/web-sys/src/features/gen_AbortController.rs index ff01ba37eaf..df2aa0b021a 100644 --- a/crates/web-sys/src/features/gen_AbortController.rs +++ b/crates/web-sys/src/features/gen_AbortController.rs @@ -34,4 +34,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `AbortController`*"] pub fn abort(this: &AbortController); + # [wasm_bindgen (method , structural , js_class = "AbortController" , js_name = abort)] + #[doc = "The `abort()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortController`*"] + pub fn abort_with_reason(this: &AbortController, reason: &::wasm_bindgen::JsValue); } diff --git a/crates/web-sys/src/features/gen_AbortSignal.rs b/crates/web-sys/src/features/gen_AbortSignal.rs index ecf05a7bdde..bc0b69718e6 100644 --- a/crates/web-sys/src/features/gen_AbortSignal.rs +++ b/crates/web-sys/src/features/gen_AbortSignal.rs @@ -19,6 +19,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] pub fn aborted(this: &AbortSignal) -> bool; + # [wasm_bindgen (structural , method , getter , js_class = "AbortSignal" , js_name = reason)] + #[doc = "Getter for the `reason` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn reason(this: &AbortSignal) -> ::wasm_bindgen::JsValue; # [wasm_bindgen (structural , method , getter , js_class = "AbortSignal" , js_name = onabort)] #[doc = "Getter for the `onabort` field of this object."] #[doc = ""] @@ -33,4 +40,46 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] pub fn set_onabort(this: &AbortSignal, value: Option<&::js_sys::Function>); + # [wasm_bindgen (static_method_of = AbortSignal , js_class = "AbortSignal" , js_name = abort)] + #[doc = "The `abort()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort_static)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn abort() -> AbortSignal; + # [wasm_bindgen (static_method_of = AbortSignal , js_class = "AbortSignal" , js_name = abort)] + #[doc = "The `abort()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort_static)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn abort_with_reason(reason: &::wasm_bindgen::JsValue) -> AbortSignal; + # [wasm_bindgen (static_method_of = AbortSignal , js_class = "AbortSignal" , js_name = any)] + #[doc = "The `any()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn any(signals: &::wasm_bindgen::JsValue) -> AbortSignal; + # [wasm_bindgen (method , structural , js_class = "AbortSignal" , js_name = throwIfAborted)] + #[doc = "The `throwIfAborted()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn throw_if_aborted(this: &AbortSignal); + # [wasm_bindgen (static_method_of = AbortSignal , js_class = "AbortSignal" , js_name = timeout)] + #[doc = "The `timeout()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn timeout_with_u32(milliseconds: u32) -> AbortSignal; + # [wasm_bindgen (static_method_of = AbortSignal , js_class = "AbortSignal" , js_name = timeout)] + #[doc = "The `timeout()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`*"] + pub fn timeout_with_f64(milliseconds: f64) -> AbortSignal; } diff --git a/crates/web-sys/src/features/gen_AddEventListenerOptions.rs b/crates/web-sys/src/features/gen_AddEventListenerOptions.rs index 3a600c0442e..d34654d22ee 100644 --- a/crates/web-sys/src/features/gen_AddEventListenerOptions.rs +++ b/crates/web-sys/src/features/gen_AddEventListenerOptions.rs @@ -40,6 +40,18 @@ extern "C" { #[doc = "*This API requires the following crate features to be activated: `AddEventListenerOptions`*"] #[wasm_bindgen(method, setter = "passive")] pub fn set_passive(this: &AddEventListenerOptions, val: bool); + #[cfg(feature = "AbortSignal")] + #[doc = "Get the `signal` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`, `AddEventListenerOptions`*"] + #[wasm_bindgen(method, getter = "signal")] + pub fn get_signal(this: &AddEventListenerOptions) -> Option; + #[cfg(feature = "AbortSignal")] + #[doc = "Change the `signal` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`, `AddEventListenerOptions`*"] + #[wasm_bindgen(method, setter = "signal")] + pub fn set_signal(this: &AddEventListenerOptions, val: &AbortSignal); } impl AddEventListenerOptions { #[doc = "Construct a new `AddEventListenerOptions`."] @@ -65,6 +77,12 @@ impl AddEventListenerOptions { self.set_passive(val); self } + #[cfg(feature = "AbortSignal")] + #[deprecated = "Use `set_signal()` instead."] + pub fn signal(&mut self, val: &AbortSignal) -> &mut Self { + self.set_signal(val); + self + } } impl Default for AddEventListenerOptions { fn default() -> Self { diff --git a/crates/web-sys/webidls/enabled/AbortController.webidl b/crates/web-sys/webidls/enabled/AbortController.webidl index 1fc3e8fd9e2..f7dec48087d 100644 --- a/crates/web-sys/webidls/enabled/AbortController.webidl +++ b/crates/web-sys/webidls/enabled/AbortController.webidl @@ -7,9 +7,11 @@ * https://dom.spec.whatwg.org/#abortcontroller */ -[Constructor(), Exposed=(Window,Worker,System)] +[Exposed=*] interface AbortController { - readonly attribute AbortSignal signal; + constructor(); - undefined abort(); + [SameObject] readonly attribute AbortSignal signal; + + undefined abort(optional any reason); }; diff --git a/crates/web-sys/webidls/enabled/AbortSignal.webidl b/crates/web-sys/webidls/enabled/AbortSignal.webidl index 6b66f76c4cd..b57c6a5feeb 100644 --- a/crates/web-sys/webidls/enabled/AbortSignal.webidl +++ b/crates/web-sys/webidls/enabled/AbortSignal.webidl @@ -7,9 +7,15 @@ * https://dom.spec.whatwg.org/#abortsignal */ -[Exposed=(Window,Worker,System)] +[Exposed=*] interface AbortSignal : EventTarget { + [NewObject] static AbortSignal abort(optional any reason); + [Exposed=(Window,Worker), NewObject] static AbortSignal timeout([EnforceRange] unsigned long long milliseconds); + [NewObject] static AbortSignal _any(sequence signals); + readonly attribute boolean aborted; + readonly attribute any reason; + undefined throwIfAborted(); attribute EventHandler onabort; }; diff --git a/crates/web-sys/webidls/enabled/EventTarget.webidl b/crates/web-sys/webidls/enabled/EventTarget.webidl index fc40a314faf..5e36a09d691 100644 --- a/crates/web-sys/webidls/enabled/EventTarget.webidl +++ b/crates/web-sys/webidls/enabled/EventTarget.webidl @@ -18,6 +18,7 @@ dictionary EventListenerOptions { dictionary AddEventListenerOptions : EventListenerOptions { boolean passive; boolean once = false; + AbortSignal signal; }; [Constructor,