mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-14 12:02:23 +03:00
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:
parent
7cca2751c1
commit
f5f9467211
@ -782,6 +782,7 @@ RadioNodeList = []
|
||||
Range = []
|
||||
RcwnPerfStats = []
|
||||
RcwnStatus = []
|
||||
ReadableStream = []
|
||||
RecordingState = []
|
||||
ReferrerPolicy = []
|
||||
RegisterRequest = []
|
||||
|
@ -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
crates/web-sys/webidls/enabled/Fetch.webidl
vendored
3
crates/web-sys/webidls/enabled/Fetch.webidl
vendored
@ -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
|
||||
|
10
crates/web-sys/webidls/enabled/ReadableStream.webidl
vendored
Normal file
10
crates/web-sys/webidls/enabled/ReadableStream.webidl
vendored
Normal 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 {
|
||||
};
|
11
crates/web-sys/webidls/enabled/Response.webidl
vendored
11
crates/web-sys/webidls/enabled/Response.webidl
vendored
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user