Skip to content

Commit f5f9467

Browse files
quasicomputationalalexcrichton
authored andcommitted
Minimum viable ReadableStream.
No methods or attributes are mapped (yet). This is mostly useful for constructing a `Response` from another one's body in a streaming fashion.
1 parent 7cca275 commit f5f9467

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

crates/web-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ RadioNodeList = []
782782
Range = []
783783
RcwnPerfStats = []
784784
RcwnStatus = []
785+
ReadableStream = []
785786
RecordingState = []
786787
ReferrerPolicy = []
787788
RegisterRequest = []

crates/web-sys/tests/wasm/response.rs

+10
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ async fn test_response_from_bytes() {
3434
assert_eq!(&data_view.get_uint8(i), byte);
3535
}
3636
}
37+
38+
#[wasm_bindgen_test]
39+
async fn test_response_from_other_body() {
40+
let input = "Hello, world!";
41+
let response_a = Response::new_with_opt_str(Some(input)).unwrap();
42+
let body = response_a.body();
43+
let response_b = Response::new_with_opt_readable_stream(body.as_ref()).unwrap();
44+
let output = JsFuture::from(response_b.text().unwrap()).await.unwrap();
45+
assert_eq!(JsValue::from_str(input), output);
46+
}

crates/web-sys/webidls/enabled/Fetch.webidl

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
typedef object JSON;
11-
typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
11+
typedef (Blob or BufferSource or FormData or URLSearchParams or USVString or ReadableStream) BodyInit;
1212

1313
[Exposed=(Window,Worker)]
1414
interface mixin Body {
@@ -23,6 +23,7 @@ interface mixin Body {
2323
Promise<JSON> json();
2424
[Throws]
2525
Promise<USVString> text();
26+
readonly attribute ReadableStream? body;
2627
};
2728

2829
// These are helper dictionaries for the parsing of a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
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/.
5+
*/
6+
7+
// Minimum viable ReadableStream, for use by other objects.
8+
[Exposed=(Window,Worker)]
9+
interface ReadableStream {
10+
};

crates/web-sys/webidls/enabled/Response.webidl

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
* https://fetch.spec.whatwg.org/#response-class
88
*/
99

10-
// This should be Constructor(optional BodyInit... but BodyInit doesn't include
11-
// ReadableStream yet because we don't want to expose Streams API to Request.
12-
[Constructor(optional (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString)? body, optional ResponseInit init),
10+
[Constructor(optional BodyInit? body, optional ResponseInit init),
1311
Exposed=(Window,Worker)]
1412
interface Response {
1513
[NewObject] static Response error();
@@ -32,13 +30,6 @@ interface Response {
3230
};
3331
Response includes Body;
3432

35-
// This should be part of Body but we don't want to expose body to request yet.
36-
// See bug 1387483.
37-
partial interface Response {
38-
[GetterThrows, Func="mozilla::dom::DOMPrefs::StreamsEnabled"]
39-
readonly attribute ReadableStream? body;
40-
};
41-
4233
dictionary ResponseInit {
4334
unsigned short status = 200;
4435
ByteString statusText = "OK";

0 commit comments

Comments
 (0)