Skip to content

Commit

Permalink
Minimum viable ReadableStream.
Browse files Browse the repository at this point in the history
No methods or attributes are mapped (yet).

This is mostly useful for constructing a `Response` from another one's
body in a streaming fashion.
  • Loading branch information
quasicomputational authored and alexcrichton committed Sep 12, 2019
1 parent 7cca275 commit f5f9467
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions crates/web-sys/Cargo.toml
Expand Up @@ -782,6 +782,7 @@ RadioNodeList = []
Range = []
RcwnPerfStats = []
RcwnStatus = []
ReadableStream = []
RecordingState = []
ReferrerPolicy = []
RegisterRequest = []
Expand Down
10 changes: 10 additions & 0 deletions crates/web-sys/tests/wasm/response.rs
Expand Up @@ -34,3 +34,13 @@ async fn test_response_from_bytes() {
assert_eq!(&data_view.get_uint8(i), byte);
}
}

#[wasm_bindgen_test]
async fn test_response_from_other_body() {
let input = "Hello, world!";
let response_a = Response::new_with_opt_str(Some(input)).unwrap();
let body = response_a.body();
let response_b = Response::new_with_opt_readable_stream(body.as_ref()).unwrap();
let output = JsFuture::from(response_b.text().unwrap()).await.unwrap();
assert_eq!(JsValue::from_str(input), output);
}
3 changes: 2 additions & 1 deletion crates/web-sys/webidls/enabled/Fetch.webidl
Expand Up @@ -8,7 +8,7 @@
*/

typedef object JSON;
typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
typedef (Blob or BufferSource or FormData or URLSearchParams or USVString or ReadableStream) BodyInit;

[Exposed=(Window,Worker)]
interface mixin Body {
Expand All @@ -23,6 +23,7 @@ interface mixin Body {
Promise<JSON> json();
[Throws]
Promise<USVString> text();
readonly attribute ReadableStream? body;
};

// These are helper dictionaries for the parsing of a
Expand Down
10 changes: 10 additions & 0 deletions crates/web-sys/webidls/enabled/ReadableStream.webidl
@@ -0,0 +1,10 @@
/* -*- 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,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/

// Minimum viable ReadableStream, for use by other objects.
[Exposed=(Window,Worker)]
interface ReadableStream {
};
11 changes: 1 addition & 10 deletions crates/web-sys/webidls/enabled/Response.webidl
Expand Up @@ -7,9 +7,7 @@
* https://fetch.spec.whatwg.org/#response-class
*/

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

// This should be part of Body but we don't want to expose body to request yet.
// See bug 1387483.
partial interface Response {
[GetterThrows, Func="mozilla::dom::DOMPrefs::StreamsEnabled"]
readonly attribute ReadableStream? body;
};

dictionary ResponseInit {
unsigned short status = 200;
ByteString statusText = "OK";
Expand Down

0 comments on commit f5f9467

Please sign in to comment.