Skip to content

Commit aa32f4a

Browse files
authored
Add complete WebIDL for ReadableStream (#2478)
* Add complete ReadableStream WebIDL * Add missing line * Readable Stream Binding Regenerated
1 parent 862e13d commit aa32f4a

File tree

7 files changed

+307
-4
lines changed

7 files changed

+307
-4
lines changed

crates/web-sys/src/features/gen_ReadableStream.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,73 @@ extern "C" {
1111
#[doc = ""]
1212
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
1313
pub type ReadableStream;
14+
# [wasm_bindgen (structural , method , getter , js_class = "ReadableStream" , js_name = locked)]
15+
#[doc = "Getter for the `locked` field of this object."]
16+
#[doc = ""]
17+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/locked)"]
18+
#[doc = ""]
19+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
20+
pub fn locked(this: &ReadableStream) -> bool;
21+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = cancel)]
22+
#[doc = "The `cancel()` method."]
23+
#[doc = ""]
24+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/cancel)"]
25+
#[doc = ""]
26+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
27+
pub fn cancel(this: &ReadableStream) -> ::js_sys::Promise;
28+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = cancel)]
29+
#[doc = "The `cancel()` method."]
30+
#[doc = ""]
31+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/cancel)"]
32+
#[doc = ""]
33+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
34+
pub fn cancel_with_reason(
35+
this: &ReadableStream,
36+
reason: &::wasm_bindgen::JsValue,
37+
) -> ::js_sys::Promise;
38+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)]
39+
#[doc = "The `getReader()` method."]
40+
#[doc = ""]
41+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader)"]
42+
#[doc = ""]
43+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
44+
pub fn get_reader(this: &ReadableStream) -> ::wasm_bindgen::JsValue;
45+
#[cfg(feature = "ReadableStreamGetReaderOptions")]
46+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)]
47+
#[doc = "The `getReader()` method."]
48+
#[doc = ""]
49+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader)"]
50+
#[doc = ""]
51+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableStreamGetReaderOptions`*"]
52+
pub fn get_reader_with_options(
53+
this: &ReadableStream,
54+
options: &ReadableStreamGetReaderOptions,
55+
) -> ::wasm_bindgen::JsValue;
56+
#[cfg(feature = "ReadableWritablePair")]
57+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)]
58+
#[doc = "The `pipeThrough()` method."]
59+
#[doc = ""]
60+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeThrough)"]
61+
#[doc = ""]
62+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableWritablePair`*"]
63+
pub fn pipe_through(this: &ReadableStream, transform: &ReadableWritablePair) -> ReadableStream;
64+
#[cfg(all(feature = "ReadableWritablePair", feature = "StreamPipeOptions",))]
65+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)]
66+
#[doc = "The `pipeThrough()` method."]
67+
#[doc = ""]
68+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeThrough)"]
69+
#[doc = ""]
70+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `ReadableWritablePair`, `StreamPipeOptions`*"]
71+
pub fn pipe_through_with_options(
72+
this: &ReadableStream,
73+
transform: &ReadableWritablePair,
74+
options: &StreamPipeOptions,
75+
) -> ReadableStream;
76+
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = tee)]
77+
#[doc = "The `tee()` method."]
78+
#[doc = ""]
79+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee)"]
80+
#[doc = ""]
81+
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"]
82+
pub fn tee(this: &ReadableStream) -> ::js_sys::Array;
1483
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[wasm_bindgen]
5+
extern "C" {
6+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamGetReaderOptions)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[doc = "The `ReadableStreamGetReaderOptions` dictionary."]
9+
#[doc = ""]
10+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`*"]
11+
pub type ReadableStreamGetReaderOptions;
12+
}
13+
impl ReadableStreamGetReaderOptions {
14+
#[doc = "Construct a new `ReadableStreamGetReaderOptions`."]
15+
#[doc = ""]
16+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`*"]
17+
pub fn new() -> Self {
18+
#[allow(unused_mut)]
19+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
20+
ret
21+
}
22+
#[cfg(feature = "ReadableStreamReaderMode")]
23+
#[doc = "Change the `mode` field of this object."]
24+
#[doc = ""]
25+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamGetReaderOptions`, `ReadableStreamReaderMode`*"]
26+
pub fn mode(&mut self, val: ReadableStreamReaderMode) -> &mut Self {
27+
use wasm_bindgen::JsValue;
28+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("mode"), &JsValue::from(val));
29+
debug_assert!(
30+
r.is_ok(),
31+
"setting properties should never fail on our dictionary objects"
32+
);
33+
let _ = r;
34+
self
35+
}
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[wasm_bindgen]
5+
extern "C" {
6+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamIteratorOptions)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[doc = "The `ReadableStreamIteratorOptions` dictionary."]
9+
#[doc = ""]
10+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"]
11+
pub type ReadableStreamIteratorOptions;
12+
}
13+
impl ReadableStreamIteratorOptions {
14+
#[doc = "Construct a new `ReadableStreamIteratorOptions`."]
15+
#[doc = ""]
16+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"]
17+
pub fn new() -> Self {
18+
#[allow(unused_mut)]
19+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
20+
ret
21+
}
22+
#[doc = "Change the `preventCancel` field of this object."]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamIteratorOptions`*"]
25+
pub fn prevent_cancel(&mut self, val: bool) -> &mut Self {
26+
use wasm_bindgen::JsValue;
27+
let r = ::js_sys::Reflect::set(
28+
self.as_ref(),
29+
&JsValue::from("preventCancel"),
30+
&JsValue::from(val),
31+
);
32+
debug_assert!(
33+
r.is_ok(),
34+
"setting properties should never fail on our dictionary objects"
35+
);
36+
let _ = r;
37+
self
38+
}
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![allow(unused_imports)]
2+
use wasm_bindgen::prelude::*;
3+
#[wasm_bindgen]
4+
#[doc = "The `ReadableStreamReaderMode` enum."]
5+
#[doc = ""]
6+
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamReaderMode`*"]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8+
pub enum ReadableStreamReaderMode {
9+
Byob = "byob",
10+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[wasm_bindgen]
5+
extern "C" {
6+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = StreamPipeOptions)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[doc = "The `StreamPipeOptions` dictionary."]
9+
#[doc = ""]
10+
#[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"]
11+
pub type StreamPipeOptions;
12+
}
13+
impl StreamPipeOptions {
14+
#[doc = "Construct a new `StreamPipeOptions`."]
15+
#[doc = ""]
16+
#[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"]
17+
pub fn new() -> Self {
18+
#[allow(unused_mut)]
19+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
20+
ret
21+
}
22+
#[doc = "Change the `preventAbort` field of this object."]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"]
25+
pub fn prevent_abort(&mut self, val: bool) -> &mut Self {
26+
use wasm_bindgen::JsValue;
27+
let r = ::js_sys::Reflect::set(
28+
self.as_ref(),
29+
&JsValue::from("preventAbort"),
30+
&JsValue::from(val),
31+
);
32+
debug_assert!(
33+
r.is_ok(),
34+
"setting properties should never fail on our dictionary objects"
35+
);
36+
let _ = r;
37+
self
38+
}
39+
#[doc = "Change the `preventCancel` field of this object."]
40+
#[doc = ""]
41+
#[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"]
42+
pub fn prevent_cancel(&mut self, val: bool) -> &mut Self {
43+
use wasm_bindgen::JsValue;
44+
let r = ::js_sys::Reflect::set(
45+
self.as_ref(),
46+
&JsValue::from("preventCancel"),
47+
&JsValue::from(val),
48+
);
49+
debug_assert!(
50+
r.is_ok(),
51+
"setting properties should never fail on our dictionary objects"
52+
);
53+
let _ = r;
54+
self
55+
}
56+
#[doc = "Change the `preventClose` field of this object."]
57+
#[doc = ""]
58+
#[doc = "*This API requires the following crate features to be activated: `StreamPipeOptions`*"]
59+
pub fn prevent_close(&mut self, val: bool) -> &mut Self {
60+
use wasm_bindgen::JsValue;
61+
let r = ::js_sys::Reflect::set(
62+
self.as_ref(),
63+
&JsValue::from("preventClose"),
64+
&JsValue::from(val),
65+
);
66+
debug_assert!(
67+
r.is_ok(),
68+
"setting properties should never fail on our dictionary objects"
69+
);
70+
let _ = r;
71+
self
72+
}
73+
#[cfg(feature = "AbortSignal")]
74+
#[doc = "Change the `signal` field of this object."]
75+
#[doc = ""]
76+
#[doc = "*This API requires the following crate features to be activated: `AbortSignal`, `StreamPipeOptions`*"]
77+
pub fn signal(&mut self, val: &AbortSignal) -> &mut Self {
78+
use wasm_bindgen::JsValue;
79+
let r =
80+
::js_sys::Reflect::set(self.as_ref(), &JsValue::from("signal"), &JsValue::from(val));
81+
debug_assert!(
82+
r.is_ok(),
83+
"setting properties should never fail on our dictionary objects"
84+
);
85+
let _ = r;
86+
self
87+
}
88+
}

crates/web-sys/src/features/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5290,6 +5290,24 @@ mod gen_ReadableStream;
52905290
#[cfg(feature = "ReadableStream")]
52915291
pub use gen_ReadableStream::*;
52925292

5293+
#[cfg(feature = "ReadableStreamGetReaderOptions")]
5294+
#[allow(non_snake_case)]
5295+
mod gen_ReadableStreamGetReaderOptions;
5296+
#[cfg(feature = "ReadableStreamGetReaderOptions")]
5297+
pub use gen_ReadableStreamGetReaderOptions::*;
5298+
5299+
#[cfg(feature = "ReadableStreamIteratorOptions")]
5300+
#[allow(non_snake_case)]
5301+
mod gen_ReadableStreamIteratorOptions;
5302+
#[cfg(feature = "ReadableStreamIteratorOptions")]
5303+
pub use gen_ReadableStreamIteratorOptions::*;
5304+
5305+
#[cfg(feature = "ReadableStreamReaderMode")]
5306+
#[allow(non_snake_case)]
5307+
mod gen_ReadableStreamReaderMode;
5308+
#[cfg(feature = "ReadableStreamReaderMode")]
5309+
pub use gen_ReadableStreamReaderMode::*;
5310+
52935311
#[cfg(feature = "RecordingState")]
52945312
#[allow(non_snake_case)]
52955313
mod gen_RecordingState;
@@ -6274,6 +6292,12 @@ mod gen_StorageType;
62746292
#[cfg(feature = "StorageType")]
62756293
pub use gen_StorageType::*;
62766294

6295+
#[cfg(feature = "StreamPipeOptions")]
6296+
#[allow(non_snake_case)]
6297+
mod gen_StreamPipeOptions;
6298+
#[cfg(feature = "StreamPipeOptions")]
6299+
pub use gen_StreamPipeOptions::*;
6300+
62776301
#[cfg(feature = "StyleRuleChangeEventInit")]
62786302
#[allow(non_snake_case)]
62796303
mod gen_StyleRuleChangeEventInit;
Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
21
/* This Source Code Form is subject to the terms of the Mozilla Public
32
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/.
45
* You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*
7+
* Source: https://streams.spec.whatwg.org/#rs-class-definition
58
*/
6-
7-
// Minimum viable ReadableStream, for use by other objects.
8-
[Exposed=(Window,Worker)]
9+
10+
[Exposed=(Window,Worker,Worklet), Transferable]
911
interface ReadableStream {
12+
constructor(optional object underlyingSource, optional QueuingStrategy strategy = {});
13+
14+
readonly attribute boolean locked;
15+
16+
Promise<undefined> cancel(optional any reason);
17+
ReadableStreamReader getReader(optional ReadableStreamGetReaderOptions options = {});
18+
ReadableStream pipeThrough(ReadableWritablePair transform, optional StreamPipeOptions options = {});
19+
Promise<undefined> pipeTo(WritableStream destination, optional StreamPipeOptions options = {});
20+
sequence<ReadableStream> tee();
21+
22+
async iterable<any>(optional ReadableStreamIteratorOptions options = {});
23+
};
24+
25+
typedef (ReadableStreamDefaultReader or ReadableStreamBYOBReader) ReadableStreamReader;
26+
27+
enum ReadableStreamReaderMode { "byob" };
28+
29+
dictionary ReadableStreamGetReaderOptions {
30+
ReadableStreamReaderMode mode;
31+
};
32+
33+
dictionary ReadableStreamIteratorOptions {
34+
boolean preventCancel = false;
35+
};
36+
37+
dictionary ReadableWritablePair {
38+
required ReadableStream readable;
39+
required WritableStream writable;
40+
};
41+
42+
dictionary StreamPipeOptions {
43+
boolean preventClose = false;
44+
boolean preventAbort = false;
45+
boolean preventCancel = false;
46+
AbortSignal signal;
1047
};

0 commit comments

Comments
 (0)