diff --git a/crates/web-sys/src/features/gen_ReadableStream.rs b/crates/web-sys/src/features/gen_ReadableStream.rs index 42cf6f09ab1..2f7ce882af6 100644 --- a/crates/web-sys/src/features/gen_ReadableStream.rs +++ b/crates/web-sys/src/features/gen_ReadableStream.rs @@ -11,4 +11,73 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] pub type ReadableStream; + # [wasm_bindgen (structural , method , getter , js_class = "ReadableStream" , js_name = locked)] + #[doc = "Getter for the `locked` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/locked)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn locked(this: &ReadableStream) -> bool; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = cancel)] + #[doc = "The `cancel()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/cancel)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn cancel(this: &ReadableStream) -> ::js_sys::Promise; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = cancel)] + #[doc = "The `cancel()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/cancel)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn cancel_with_reason( + this: &ReadableStream, + reason: &::wasm_bindgen::JsValue, + ) -> ::js_sys::Promise; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)] + #[doc = "The `getReader()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn get_reader(this: &ReadableStream) -> ::wasm_bindgen::JsValue; + #[cfg(feature = "ReadableStreamGetReaderOptions")] + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)] + #[doc = "The `getReader()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableStreamGetReaderOptions`*"] + pub fn get_reader_with_options( + this: &ReadableStream, + options: &ReadableStreamGetReaderOptions, + ) -> ::wasm_bindgen::JsValue; + #[cfg(feature = "ReadableWritablePair")] + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)] + #[doc = "The `pipeThrough()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeThrough)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableWritablePair`*"] + pub fn pipe_through(this: &ReadableStream, transform: &ReadableWritablePair) -> ReadableStream; + #[cfg(all(feature = "ReadableWritablePair", feature = "StreamPipeOptions",))] + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)] + #[doc = "The `pipeThrough()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeThrough)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableWritablePair`, `StreamPipeOptions`*"] + pub fn pipe_through_with_options( + this: &ReadableStream, + transform: &ReadableWritablePair, + options: &StreamPipeOptions, + ) -> ReadableStream; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = tee)] + #[doc = "The `tee()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn tee(this: &ReadableStream) -> ::js_sys::Array; } diff --git a/crates/web-sys/src/features/gen_ReadableStreamGetReaderOptions.rs b/crates/web-sys/src/features/gen_ReadableStreamGetReaderOptions.rs new file mode 100644 index 00000000000..33153474c03 --- /dev/null +++ b/crates/web-sys/src/features/gen_ReadableStreamGetReaderOptions.rs @@ -0,0 +1,36 @@ +#![allow(unused_imports)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamGetReaderOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `ReadableStreamGetReaderOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`*"] + pub type ReadableStreamGetReaderOptions; +} +impl ReadableStreamGetReaderOptions { + #[doc = "Construct a new `ReadableStreamGetReaderOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[cfg(feature = "ReadableStreamReaderMode")] + #[doc = "Change the `mode` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`, `ReadableStreamReaderMode`*"] + pub fn mode(&mut self, val: ReadableStreamReaderMode) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("mode"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_ReadableStreamIteratorOptions.rs b/crates/web-sys/src/features/gen_ReadableStreamIteratorOptions.rs new file mode 100644 index 00000000000..d231eb199cf --- /dev/null +++ b/crates/web-sys/src/features/gen_ReadableStreamIteratorOptions.rs @@ -0,0 +1,39 @@ +#![allow(unused_imports)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamIteratorOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `ReadableStreamIteratorOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"] + pub type ReadableStreamIteratorOptions; +} +impl ReadableStreamIteratorOptions { + #[doc = "Construct a new `ReadableStreamIteratorOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `preventCancel` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"] + pub fn prevent_cancel(&mut self, val: bool) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("preventCancel"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_ReadableStreamReaderMode.rs b/crates/web-sys/src/features/gen_ReadableStreamReaderMode.rs new file mode 100644 index 00000000000..a01a07dacc1 --- /dev/null +++ b/crates/web-sys/src/features/gen_ReadableStreamReaderMode.rs @@ -0,0 +1,10 @@ +#![allow(unused_imports)] +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +#[doc = "The `ReadableStreamReaderMode` enum."] +#[doc = ""] +#[doc = "*This API requires the following crate features to be activated: `ReadableStreamReaderMode`*"] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ReadableStreamReaderMode { + Byob = "byob", +} diff --git a/crates/web-sys/src/features/gen_StreamPipeOptions.rs b/crates/web-sys/src/features/gen_StreamPipeOptions.rs new file mode 100644 index 00000000000..3af63d39195 --- /dev/null +++ b/crates/web-sys/src/features/gen_StreamPipeOptions.rs @@ -0,0 +1,88 @@ +#![allow(unused_imports)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = StreamPipeOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `StreamPipeOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"] + pub type StreamPipeOptions; +} +impl StreamPipeOptions { + #[doc = "Construct a new `StreamPipeOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `preventAbort` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"] + pub fn prevent_abort(&mut self, val: bool) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("preventAbort"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `preventCancel` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"] + pub fn prevent_cancel(&mut self, val: bool) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("preventCancel"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `preventClose` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"] + pub fn prevent_close(&mut self, val: bool) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("preventClose"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[cfg(feature = "AbortSignal")] + #[doc = "Change the `signal` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `AbortSignal`, `StreamPipeOptions`*"] + pub fn signal(&mut self, val: &AbortSignal) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("signal"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index f7e2fd20cf8..e432b7bed34 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -5242,6 +5242,24 @@ mod gen_ReadableStream; #[cfg(feature = "ReadableStream")] pub use gen_ReadableStream::*; +#[cfg(feature = "ReadableStreamGetReaderOptions")] +#[allow(non_snake_case)] +mod gen_ReadableStreamGetReaderOptions; +#[cfg(feature = "ReadableStreamGetReaderOptions")] +pub use gen_ReadableStreamGetReaderOptions::*; + +#[cfg(feature = "ReadableStreamIteratorOptions")] +#[allow(non_snake_case)] +mod gen_ReadableStreamIteratorOptions; +#[cfg(feature = "ReadableStreamIteratorOptions")] +pub use gen_ReadableStreamIteratorOptions::*; + +#[cfg(feature = "ReadableStreamReaderMode")] +#[allow(non_snake_case)] +mod gen_ReadableStreamReaderMode; +#[cfg(feature = "ReadableStreamReaderMode")] +pub use gen_ReadableStreamReaderMode::*; + #[cfg(feature = "RecordingState")] #[allow(non_snake_case)] mod gen_RecordingState; @@ -6226,6 +6244,12 @@ mod gen_StorageType; #[cfg(feature = "StorageType")] pub use gen_StorageType::*; +#[cfg(feature = "StreamPipeOptions")] +#[allow(non_snake_case)] +mod gen_StreamPipeOptions; +#[cfg(feature = "StreamPipeOptions")] +pub use gen_StreamPipeOptions::*; + #[cfg(feature = "StyleRuleChangeEventInit")] #[allow(non_snake_case)] mod gen_StyleRuleChangeEventInit; diff --git a/crates/web-sys/webidls/enabled/ReadableStream.webidl b/crates/web-sys/webidls/enabled/ReadableStream.webidl index 0594df8e0c6..00c8bbc8a4a 100644 --- a/crates/web-sys/webidls/enabled/ReadableStream.webidl +++ b/crates/web-sys/webidls/enabled/ReadableStream.webidl @@ -1,10 +1,47 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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, + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Source: https://streams.spec.whatwg.org/#rs-class-definition */ - -// Minimum viable ReadableStream, for use by other objects. -[Exposed=(Window,Worker)] + +[Exposed=(Window,Worker,Worklet), Transferable] interface ReadableStream { + constructor(optional object underlyingSource, optional QueuingStrategy strategy = {}); + + readonly attribute boolean locked; + + Promise cancel(optional any reason); + ReadableStreamReader getReader(optional ReadableStreamGetReaderOptions options = {}); + ReadableStream pipeThrough(ReadableWritablePair transform, optional StreamPipeOptions options = {}); + Promise pipeTo(WritableStream destination, optional StreamPipeOptions options = {}); + sequence tee(); + + async iterable(optional ReadableStreamIteratorOptions options = {}); +}; + +typedef (ReadableStreamDefaultReader or ReadableStreamBYOBReader) ReadableStreamReader; + +enum ReadableStreamReaderMode { "byob" }; + +dictionary ReadableStreamGetReaderOptions { + ReadableStreamReaderMode mode; +}; + +dictionary ReadableStreamIteratorOptions { + boolean preventCancel = false; +}; + +dictionary ReadableWritablePair { + required ReadableStream readable; + required WritableStream writable; +}; + +dictionary StreamPipeOptions { + boolean preventClose = false; + boolean preventAbort = false; + boolean preventCancel = false; + AbortSignal signal; };