diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 1301d20ab..45ef8928a 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -782,6 +782,7 @@ RadioNodeList = [] Range = [] RcwnPerfStats = [] RcwnStatus = [] +ReadableStream = [] RecordingState = [] ReferrerPolicy = [] RegisterRequest = [] diff --git a/crates/web-sys/tests/wasm/response.rs b/crates/web-sys/tests/wasm/response.rs index 045062df1..0bbaa5012 100644 --- a/crates/web-sys/tests/wasm/response.rs +++ b/crates/web-sys/tests/wasm/response.rs @@ -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); +} diff --git a/crates/web-sys/webidls/enabled/Fetch.webidl b/crates/web-sys/webidls/enabled/Fetch.webidl index 66e4b570c..056b15f9d 100644 --- a/crates/web-sys/webidls/enabled/Fetch.webidl +++ b/crates/web-sys/webidls/enabled/Fetch.webidl @@ -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(); [Throws] Promise text(); + readonly attribute ReadableStream? body; }; // These are helper dictionaries for the parsing of a diff --git a/crates/web-sys/webidls/enabled/ReadableStream.webidl b/crates/web-sys/webidls/enabled/ReadableStream.webidl new file mode 100644 index 000000000..0594df8e0 --- /dev/null +++ b/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 { +}; diff --git a/crates/web-sys/webidls/enabled/Response.webidl b/crates/web-sys/webidls/enabled/Response.webidl index 0b05bea14..2e69ae277 100644 --- a/crates/web-sys/webidls/enabled/Response.webidl +++ b/crates/web-sys/webidls/enabled/Response.webidl @@ -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";