Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AbortSignal and AbortController #4026

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
7 changes: 7 additions & 0 deletions crates/web-sys/src/features/gen_AbortController.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
49 changes: 49 additions & 0 deletions crates/web-sys/src/features/gen_AbortSignal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand All @@ -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;
}
18 changes: 18 additions & 0 deletions crates/web-sys/src/features/gen_AddEventListenerOptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbortSignal>;
#[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`."]
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions crates/web-sys/webidls/enabled/AbortController.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
8 changes: 7 additions & 1 deletion crates/web-sys/webidls/enabled/AbortSignal.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbortSignal> signals);

readonly attribute boolean aborted;
readonly attribute any reason;
undefined throwIfAborted();

attribute EventHandler onabort;
};
1 change: 1 addition & 0 deletions crates/web-sys/webidls/enabled/EventTarget.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dictionary EventListenerOptions {
dictionary AddEventListenerOptions : EventListenerOptions {
boolean passive;
boolean once = false;
AbortSignal signal;
};

[Constructor,
Expand Down