From 4ff48db331ab9aa8f2959e41518237002daad823 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 29 Aug 2023 15:08:56 +0200 Subject: [PATCH] Remove `ReadableStreamByobReader::read_with_u8_array()` --- CHANGELOG.md | 5 ++ .../features/gen_ReadableStreamByobReader.rs | 10 ---- crates/web-sys/webidls/enabled/Streams.webidl | 1 + crates/webidl/src/constants.rs | 4 ++ crates/webidl/src/idl_type.rs | 47 ++++++++++++------- crates/webidl/src/util.rs | 6 ++- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c07eb12e3da..33776de3656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,11 @@ * Fixed optional parameters in JSDoc. [#3577](https://github.com/rustwasm/wasm-bindgen/pull/3577) +### Removed + +* Removed `ReadableStreamByobReader::read_with_u8_array()` because it doesn't work with Wasm. + [#3582](https://github.com/rustwasm/wasm-bindgen/pull/3582) + ## [0.2.87](https://github.com/rustwasm/wasm-bindgen/compare/0.2.86...0.2.87) Released 2023-06-12. diff --git a/crates/web-sys/src/features/gen_ReadableStreamByobReader.rs b/crates/web-sys/src/features/gen_ReadableStreamByobReader.rs index 4a12b6ee5a6..fb169472383 100644 --- a/crates/web-sys/src/features/gen_ReadableStreamByobReader.rs +++ b/crates/web-sys/src/features/gen_ReadableStreamByobReader.rs @@ -37,16 +37,6 @@ extern "C" { this: &ReadableStreamByobReader, view: &::js_sys::Object, ) -> ::js_sys::Promise; - # [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = read)] - #[doc = "The `read()` method."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ReadableStreamByobReader`*"] - pub fn read_with_u8_array( - this: &ReadableStreamByobReader, - view: &mut [u8], - ) -> ::js_sys::Promise; # [wasm_bindgen (method , structural , js_class = "ReadableStreamBYOBReader" , js_name = releaseLock)] #[doc = "The `releaseLock()` method."] #[doc = ""] diff --git a/crates/web-sys/webidls/enabled/Streams.webidl b/crates/web-sys/webidls/enabled/Streams.webidl index bf57ef4ff11..b3a9201fbc8 100644 --- a/crates/web-sys/webidls/enabled/Streams.webidl +++ b/crates/web-sys/webidls/enabled/Streams.webidl @@ -91,6 +91,7 @@ dictionary ReadableStreamReadResult { interface ReadableStreamBYOBReader { [Throws] constructor(ReadableStream stream); + [RustNotWasmMemory] Promise read(ArrayBufferView view); undefined releaseLock(); }; diff --git a/crates/webidl/src/constants.rs b/crates/webidl/src/constants.rs index 651c99aac3b..0d68af02da7 100644 --- a/crates/webidl/src/constants.rs +++ b/crates/webidl/src/constants.rs @@ -140,5 +140,9 @@ pub(crate) static FIXED_INTERFACES: Lazy< "OffscreenCanvasRenderingContext2d", canvas_rendering_context, ), + ( + "ReadableStreamByobReader", + BTreeMap::from_iter([("read", "read_with_array_buffer_view")]), + ), ]) }); diff --git a/crates/webidl/src/idl_type.rs b/crates/webidl/src/idl_type.rs index 08ef155b9da..1843210da5a 100644 --- a/crates/webidl/src/idl_type.rs +++ b/crates/webidl/src/idl_type.rs @@ -1,5 +1,6 @@ use proc_macro2::{Ident, Span}; use wasm_bindgen_backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident}; +use weedle::attribute::{ExtendedAttribute, ExtendedAttributeList}; use weedle::common::Identifier; use weedle::term; use weedle::types::*; @@ -659,36 +660,36 @@ impl<'a> IdlType<'a> { /// but also flattens unions inside generics of other types. /// /// [flattened union member types]: https://heycam.github.io/webidl/#dfn-flattened-union-member-types - pub(crate) fn flatten(&self) -> Vec { + pub(crate) fn flatten(&self, attrs: Option<&ExtendedAttributeList<'_>>) -> Vec { match self { IdlType::Nullable(idl_type) => idl_type - .flatten() + .flatten(attrs) .into_iter() .map(Box::new) .map(IdlType::Nullable) .collect(), IdlType::FrozenArray(idl_type) => idl_type - .flatten() + .flatten(attrs) .into_iter() .map(Box::new) .map(IdlType::FrozenArray) .collect(), IdlType::Sequence(idl_type) => idl_type - .flatten() + .flatten(attrs) .into_iter() .map(Box::new) .map(IdlType::Sequence) .collect(), IdlType::Promise(idl_type) => idl_type - .flatten() + .flatten(attrs) .into_iter() .map(Box::new) .map(IdlType::Promise) .collect(), IdlType::Record(idl_type_from, idl_type_to) => { let mut idl_types = Vec::new(); - for idl_type_from in idl_type_from.flatten() { - for idl_type_to in idl_type_to.flatten() { + for idl_type_from in idl_type_from.flatten(attrs) { + for idl_type_to in idl_type_to.flatten(attrs) { idl_types.push(IdlType::Record( Box::new(idl_type_from.clone()), Box::new(idl_type_to.clone()), @@ -699,16 +700,30 @@ impl<'a> IdlType<'a> { } IdlType::Union(idl_types) => idl_types .iter() - .flat_map(|idl_type| idl_type.flatten()) + .flat_map(|idl_type| idl_type.flatten(attrs)) .collect(), - IdlType::ArrayBufferView { immutable } => vec![ - IdlType::ArrayBufferView { + IdlType::ArrayBufferView { immutable } => { + let view = IdlType::ArrayBufferView { immutable: *immutable, - }, - IdlType::Uint8Array { - immutable: *immutable, - }, - ], + }; + + if let Some(attrs) = attrs { + for attr in &attrs.body.list { + if let ExtendedAttribute::NoArgs(attr) = attr { + if attr.0 .0 == "RustNotWasmMemory" { + return vec![view]; + } + } + } + } + + vec![ + view, + IdlType::Uint8Array { + immutable: *immutable, + }, + ] + } IdlType::BufferSource { immutable } => vec![ IdlType::BufferSource { immutable: *immutable, @@ -758,7 +773,7 @@ fn idl_type_flatten_test() { Interface("NodeList"), ])),), ]) - .flatten(), + .flatten(None), vec![ Interface("Node"), Sequence(Box::new(Long)), diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 343996952c7..04c07e3d991 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -266,7 +266,11 @@ impl<'src> FirstPassRecord<'src> { // in-place, but all other flattened types will cause new // signatures to be created. let cur = actual_signatures.len(); - for (j, idl_type) in idl_type.flatten().into_iter().enumerate() { + for (j, idl_type) in idl_type + .flatten(signature.attrs.as_ref()) + .into_iter() + .enumerate() + { for k in start..cur { if j == 0 { actual_signatures[k].args.push(idl_type.clone());