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

Add complete WebIDL for ReadableStream #2478

Merged
merged 3 commits into from
Apr 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions crates/web-sys/src/features/gen_ReadableStream.rs
Expand Up @@ -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;
}
36 changes: 36 additions & 0 deletions 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
}
}
39 changes: 39 additions & 0 deletions 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
}
}
10 changes: 10 additions & 0 deletions 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",
}
88 changes: 88 additions & 0 deletions 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
}
}
24 changes: 24 additions & 0 deletions crates/web-sys/src/features/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 41 additions & 4 deletions 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<undefined> cancel(optional any reason);
ReadableStreamReader getReader(optional ReadableStreamGetReaderOptions options = {});
ReadableStream pipeThrough(ReadableWritablePair transform, optional StreamPipeOptions options = {});
Promise<undefined> pipeTo(WritableStream destination, optional StreamPipeOptions options = {});
sequence<ReadableStream> tee();

async iterable<any>(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;
};