From 3d1f4263ad2f0e17bf46826a31a65e43eac2f9c9 Mon Sep 17 00:00:00 2001 From: Jake Riesterer Date: Wed, 10 Oct 2018 01:44:40 -0500 Subject: [PATCH] Change UnionType to IdlType::Union function to include any supported types instead of returning None when there is at least one unsupported type For example, the constructor in Response.webidl accepts multiple types. However, one of those types is `ReadableStream` which isn't defined yet, and that causes all constructors for Response to be skipped even though the other argument types could be supported. --- crates/web-sys/tests/wasm/response.rs | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/web-sys/tests/wasm/response.rs b/crates/web-sys/tests/wasm/response.rs index 40c893f5..5da87aec 100644 --- a/crates/web-sys/tests/wasm/response.rs +++ b/crates/web-sys/tests/wasm/response.rs @@ -1,4 +1,12 @@ +extern crate futures; +extern crate js_sys; +extern crate wasm_bindgen_futures; + +use futures::Future; +use js_sys::{ArrayBuffer, DataView}; use wasm_bindgen::prelude::*; +use wasm_bindgen::JsCast; +use wasm_bindgen_futures::JsFuture; use wasm_bindgen_test::*; use web_sys::Response; @@ -8,9 +16,27 @@ extern "C" { } #[wasm_bindgen_test] -fn test_response() { +fn test_response_from_js() { let response = new_response(); assert!(!response.ok()); assert!(!response.redirected()); assert_eq!(response.status(), 501); } + +#[wasm_bindgen_test(async)] +fn test_response_from_bytes() -> impl Future { + let mut bytes: [u8; 3] = [1, 3, 5]; + let response = Response::new_with_opt_u8_array(Some(&mut bytes)).unwrap(); + assert!(response.ok()); + assert_eq!(response.status(), 200); + + let buf_promise = response.array_buffer().unwrap(); + JsFuture::from(buf_promise).map(move |buf_val| { + assert!(buf_val.is_instance_of::()); + let array_buf: ArrayBuffer = buf_val.dyn_into().unwrap(); + let data_view = DataView::new(&array_buf, 0, bytes.len()); + for (i, byte) in bytes.iter().enumerate() { + assert_eq!(&data_view.get_uint8(i), byte); + } + }) +}