Skip to content

Commit

Permalink
Enabling more Stream functionality (#2584)
Browse files Browse the repository at this point in the history
This is useful when compiling to WASM for the Cloudflare Workers:
https://developers.cloudflare.com/workers/runtime-apis/streams

Added Unstable WebIDL:
   unstable/ReadableStreamDefaultReader.webidl
   unstable/ReadableStreamGenericReader.webidl
   unstable/QueuingStrategy.webidl
   unstable/ReadableStreamBYOBReader.webidl
   unstable/TransformStream.webidl
   unstable/WritableStream.webidl
   unstable/WritableStreamDefaultWriter.webidl
  • Loading branch information
halzy authored Jun 17, 2021
1 parent 87406a6 commit 316b0ce
Show file tree
Hide file tree
Showing 19 changed files with 954 additions and 2 deletions.
9 changes: 9 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,19 @@ PushSubscriptionJson = []
PushSubscriptionKeys = []
PushSubscriptionOptions = []
PushSubscriptionOptionsInit = []
QueuingStrategy = []
RadioNodeList = ["NodeList"]
Range = []
RcwnPerfStats = []
RcwnStatus = []
ReadableStream = []
ReadableStreamByobReadResult = []
ReadableStreamByobReader = []
ReadableStreamDefaultReadResult = []
ReadableStreamDefaultReader = []
ReadableStreamGetReaderOptions = []
ReadableStreamReaderMode = []
ReadableWritablePair = []
RecordingState = []
ReferrerPolicy = []
RegisterRequest = []
Expand Down Expand Up @@ -1237,6 +1243,7 @@ TouchInit = []
TouchList = []
TrackEvent = ["Event"]
TrackEventInit = []
TransformStream = ["ReadableStream", "WritableStream"]
TransitionEvent = ["Event"]
TransitionEventInit = []
Transport = []
Expand Down Expand Up @@ -1364,6 +1371,8 @@ WorkerOptions = []
Worklet = []
WorkletGlobalScope = []
WorkletOptions = []
WritableStream = []
WritableStreamDefaultWriter = []
XPathExpression = []
XPathNsResolver = []
XPathResult = []
Expand Down
68 changes: 68 additions & 0 deletions crates/web-sys/src/features/gen_QueuingStrategy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = QueuingStrategy)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `QueuingStrategy` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `QueuingStrategy`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type QueuingStrategy;
}
#[cfg(web_sys_unstable_apis)]
impl QueuingStrategy {
#[doc = "Construct a new `QueuingStrategy`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `QueuingStrategy`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `highWaterMark` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `QueuingStrategy`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn high_water_mark(&mut self, val: f64) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("highWaterMark"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `size` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `QueuingStrategy`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn size(&mut self, val: &::js_sys::Function) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("size"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
32 changes: 30 additions & 2 deletions crates/web-sys/src/features/gen_ReadableStream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
#[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;
pub fn get_reader(this: &ReadableStream) -> ::js_sys::Object;
#[cfg(feature = "ReadableStreamGetReaderOptions")]
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)]
#[doc = "The `getReader()` method."]
Expand All @@ -52,7 +52,7 @@ extern "C" {
pub fn get_reader_with_options(
this: &ReadableStream,
options: &ReadableStreamGetReaderOptions,
) -> ::wasm_bindgen::JsValue;
) -> ::js_sys::Object;
#[cfg(feature = "ReadableWritablePair")]
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)]
#[doc = "The `pipeThrough()` method."]
Expand All @@ -73,6 +73,34 @@ extern "C" {
transform: &ReadableWritablePair,
options: &StreamPipeOptions,
) -> ReadableStream;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "WritableStream")]
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeTo)]
#[doc = "The `pipeTo()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeTo)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `WritableStream`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn pipe_to(this: &ReadableStream, destination: &WritableStream) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "StreamPipeOptions", feature = "WritableStream",))]
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeTo)]
#[doc = "The `pipeTo()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeTo)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStream`, `StreamPipeOptions`, `WritableStream`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn pipe_to_with_options(
this: &ReadableStream,
destination: &WritableStream,
options: &StreamPipeOptions,
) -> ::js_sys::Promise;
# [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = tee)]
#[doc = "The `tee()` method."]
#[doc = ""]
Expand Down
64 changes: 64 additions & 0 deletions crates/web-sys/src/features/gen_ReadableStreamByobReadResult.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamBYOBReadResult)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ReadableStreamByobReadResult` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ReadableStreamByobReadResult;
}
#[cfg(web_sys_unstable_apis)]
impl ReadableStreamByobReadResult {
#[doc = "Construct a new `ReadableStreamByobReadResult`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `done` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn done(&mut self, val: bool) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("done"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `value` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn value(&mut self, val: &::js_sys::Object) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("value"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
93 changes: 93 additions & 0 deletions crates/web-sys/src/features/gen_ReadableStreamByobReader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamBYOBReader , typescript_type = "ReadableStreamBYOBReader")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ReadableStreamByobReader` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ReadableStreamByobReader;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ReadableStreamBYOBReader" , js_name = closed)]
#[doc = "Getter for the `closed` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/closed)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn closed(this: &ReadableStreamByobReader) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = read)]
#[doc = "The `read()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn read_with_array_buffer_view(
this: &ReadableStreamByobReader,
view: &::js_sys::Object,
) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = read)]
#[doc = "The `read()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn read_with_u8_array(
this: &ReadableStreamByobReader,
view: &mut [u8],
) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = releaseLock)]
#[doc = "The `releaseLock()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/releaseLock)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn release_lock(this: &ReadableStreamByobReader);
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = cancel)]
#[doc = "The `cancel()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/cancel)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn cancel(this: &ReadableStreamByobReader) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = cancel)]
#[doc = "The `cancel()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/cancel)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn cancel_with_reason(
this: &ReadableStreamByobReader,
reason: &::wasm_bindgen::JsValue,
) -> ::js_sys::Promise;
}
64 changes: 64 additions & 0 deletions crates/web-sys/src/features/gen_ReadableStreamDefaultReadResult.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ReadableStreamDefaultReadResult)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ReadableStreamDefaultReadResult` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamDefaultReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ReadableStreamDefaultReadResult;
}
#[cfg(web_sys_unstable_apis)]
impl ReadableStreamDefaultReadResult {
#[doc = "Construct a new `ReadableStreamDefaultReadResult`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamDefaultReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `done` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamDefaultReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn done(&mut self, val: bool) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("done"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `value` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ReadableStreamDefaultReadResult`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn value(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("value"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
Loading

0 comments on commit 316b0ce

Please sign in to comment.