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.
This commit is contained in:
quasicomputational 2019-09-08 17:00:02 +01:00 committed by Alex Crichton
parent 7cca2751c1
commit f5f9467211
5 changed files with 24 additions and 11 deletions

View File

@ -782,6 +782,7 @@ RadioNodeList = []
Range = []
RcwnPerfStats = []
RcwnStatus = []
ReadableStream = []
RecordingState = []
ReferrerPolicy = []
RegisterRequest = []

View File

@ -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);
}

View File

@ -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 {
@ -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

View File

@ -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 {
};

View File

@ -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();
@ -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";