From 4287de8be52d40b472f30abcc3030c6230c4f169 Mon Sep 17 00:00:00 2001 From: Raoul Hidalgo Charman Date: Tue, 14 May 2024 17:01:31 +0800 Subject: [PATCH] Add support for webidl iterables Most of the plumbing was there but now (async) iterable instances generate the `entries`, `keys` and `values` methods. `forEach` is also generated for the non-async iterable. --- crates/web-sys/Cargo.toml | 3 +- .../web-sys/src/features/gen_DomTokenList.rs | 28 +++ .../features/gen_FileSystemDirectoryHandle.rs | 21 +++ crates/web-sys/src/features/gen_FormData.rs | 28 +++ crates/web-sys/src/features/gen_Headers.rs | 28 +++ .../src/features/gen_MediaKeyStatusMap.rs | 29 +++ crates/web-sys/src/features/gen_NodeList.rs | 28 +++ .../src/features/gen_ReadableStream.rs | 21 +++ .../src/features/gen_UrlSearchParams.rs | 28 +++ crates/web-sys/src/features/gen_XrHand.rs | 44 +++++ .../src/features/gen_XrInputSourceArray.rs | 47 +++++ crates/web-sys/tests/wasm/headers.js | 4 + crates/web-sys/tests/wasm/headers.rs | 39 ++++ crates/web-sys/tests/wasm/main.rs | 1 + crates/web-sys/tests/wasm/opfs.rs | 156 ++++++++++++++++ crates/webidl/src/constants.rs | 1 + crates/webidl/src/first_pass.rs | 176 ++++++++++++++++-- crates/webidl/src/idl_type.rs | 5 + 18 files changed, 674 insertions(+), 13 deletions(-) create mode 100644 crates/web-sys/tests/wasm/opfs.rs diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 59db9b495871..3edd41b23e10 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -27,7 +27,8 @@ js-sys = { path = '../js-sys', version = '0.3.69' } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = { path = '../test', version = '0.3.42' } -wasm-bindgen-futures = { path = '../futures', version = '0.4.42' } +wasm-bindgen-futures = { path = '../futures', version = '0.4.42', features = [ "futures-core-03-stream" ] } +futures = "0.3" # This list is auto-generated by the wasm-bindgen-webidl program [features] diff --git a/crates/web-sys/src/features/gen_DomTokenList.rs b/crates/web-sys/src/features/gen_DomTokenList.rs index d88b957cd660..742a389ddc57 100644 --- a/crates/web-sys/src/features/gen_DomTokenList.rs +++ b/crates/web-sys/src/features/gen_DomTokenList.rs @@ -138,6 +138,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] pub fn contains(this: &DomTokenList, token: &str) -> bool; + # [wasm_bindgen (method , structural , js_class = "DOMTokenList" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] + pub fn entries(this: &DomTokenList) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "DOMTokenList" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] + pub fn for_each(this: &DomTokenList, callback: &::js_sys::Function) -> Result<(), JsValue>; # [wasm_bindgen (method , structural , js_class = "DOMTokenList" , js_name = item)] #[doc = "The `item()` method."] #[doc = ""] @@ -145,6 +159,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] pub fn item(this: &DomTokenList, index: u32) -> Option; + # [wasm_bindgen (method , structural , js_class = "DOMTokenList" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] + pub fn keys(this: &DomTokenList) -> ::js_sys::Iterator; # [wasm_bindgen (catch , method , structural , variadic , js_class = "DOMTokenList" , js_name = remove)] #[doc = "The `remove()` method."] #[doc = ""] @@ -275,6 +296,13 @@ extern "C" { token: &str, force: bool, ) -> Result; + # [wasm_bindgen (method , structural , js_class = "DOMTokenList" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"] + pub fn values(this: &DomTokenList) -> ::js_sys::Iterator; #[wasm_bindgen(method, structural, js_class = "DOMTokenList", indexing_getter)] #[doc = "Indexing getter. As in the literal Javascript `this[key]`."] #[doc = ""] diff --git a/crates/web-sys/src/features/gen_FileSystemDirectoryHandle.rs b/crates/web-sys/src/features/gen_FileSystemDirectoryHandle.rs index cfac88f43e07..c7ce4bed22c8 100644 --- a/crates/web-sys/src/features/gen_FileSystemDirectoryHandle.rs +++ b/crates/web-sys/src/features/gen_FileSystemDirectoryHandle.rs @@ -12,6 +12,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `FileSystemDirectoryHandle`*"] pub type FileSystemDirectoryHandle; + # [wasm_bindgen (method , structural , js_class = "FileSystemDirectoryHandle" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FileSystemDirectoryHandle`*"] + pub fn entries(this: &FileSystemDirectoryHandle) -> ::js_sys::AsyncIterator; # [wasm_bindgen (method , structural , js_class = "FileSystemDirectoryHandle" , js_name = getDirectoryHandle)] #[doc = "The `getDirectoryHandle()` method."] #[doc = ""] @@ -50,6 +57,13 @@ extern "C" { name: &str, options: &FileSystemGetFileOptions, ) -> ::js_sys::Promise; + # [wasm_bindgen (method , structural , js_class = "FileSystemDirectoryHandle" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FileSystemDirectoryHandle`*"] + pub fn keys(this: &FileSystemDirectoryHandle) -> ::js_sys::AsyncIterator; # [wasm_bindgen (method , structural , js_class = "FileSystemDirectoryHandle" , js_name = removeEntry)] #[doc = "The `removeEntry()` method."] #[doc = ""] @@ -79,4 +93,11 @@ extern "C" { this: &FileSystemDirectoryHandle, possible_descendant: &FileSystemHandle, ) -> ::js_sys::Promise; + # [wasm_bindgen (method , structural , js_class = "FileSystemDirectoryHandle" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FileSystemDirectoryHandle`*"] + pub fn values(this: &FileSystemDirectoryHandle) -> ::js_sys::AsyncIterator; } diff --git a/crates/web-sys/src/features/gen_FormData.rs b/crates/web-sys/src/features/gen_FormData.rs index a75c95b008d5..959d014ed3ba 100644 --- a/crates/web-sys/src/features/gen_FormData.rs +++ b/crates/web-sys/src/features/gen_FormData.rs @@ -62,6 +62,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `FormData`*"] pub fn delete(this: &FormData, name: &str); + # [wasm_bindgen (method , structural , js_class = "FormData" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FormData/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FormData`*"] + pub fn entries(this: &FormData) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "FormData" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FormData/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FormData`*"] + pub fn for_each(this: &FormData, callback: &::js_sys::Function) -> Result<(), JsValue>; # [wasm_bindgen (method , structural , js_class = "FormData" , js_name = get)] #[doc = "The `get()` method."] #[doc = ""] @@ -83,6 +97,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `FormData`*"] pub fn has(this: &FormData, name: &str) -> bool; + # [wasm_bindgen (method , structural , js_class = "FormData" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FormData/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FormData`*"] + pub fn keys(this: &FormData) -> ::js_sys::Iterator; #[cfg(feature = "Blob")] # [wasm_bindgen (catch , method , structural , js_class = "FormData" , js_name = set)] #[doc = "The `set()` method."] @@ -111,4 +132,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `FormData`*"] pub fn set_with_str(this: &FormData, name: &str, value: &str) -> Result<(), JsValue>; + # [wasm_bindgen (method , structural , js_class = "FormData" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FormData/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FormData`*"] + pub fn values(this: &FormData) -> ::js_sys::Iterator; } diff --git a/crates/web-sys/src/features/gen_Headers.rs b/crates/web-sys/src/features/gen_Headers.rs index 143f68a63da8..c7f7deeee98c 100644 --- a/crates/web-sys/src/features/gen_Headers.rs +++ b/crates/web-sys/src/features/gen_Headers.rs @@ -49,6 +49,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Headers`*"] pub fn delete(this: &Headers, name: &str) -> Result<(), JsValue>; + # [wasm_bindgen (method , structural , js_class = "Headers" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Headers`*"] + pub fn entries(this: &Headers) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "Headers" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Headers`*"] + pub fn for_each(this: &Headers, callback: &::js_sys::Function) -> Result<(), JsValue>; # [wasm_bindgen (catch , method , structural , js_class = "Headers" , js_name = get)] #[doc = "The `get()` method."] #[doc = ""] @@ -63,6 +77,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Headers`*"] pub fn has(this: &Headers, name: &str) -> Result; + # [wasm_bindgen (method , structural , js_class = "Headers" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Headers`*"] + pub fn keys(this: &Headers) -> ::js_sys::Iterator; # [wasm_bindgen (catch , method , structural , js_class = "Headers" , js_name = set)] #[doc = "The `set()` method."] #[doc = ""] @@ -70,4 +91,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Headers`*"] pub fn set(this: &Headers, name: &str, value: &str) -> Result<(), JsValue>; + # [wasm_bindgen (method , structural , js_class = "Headers" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Headers/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Headers`*"] + pub fn values(this: &Headers) -> ::js_sys::Iterator; } diff --git a/crates/web-sys/src/features/gen_MediaKeyStatusMap.rs b/crates/web-sys/src/features/gen_MediaKeyStatusMap.rs index ea2a4aef6760..f753b5a98e21 100644 --- a/crates/web-sys/src/features/gen_MediaKeyStatusMap.rs +++ b/crates/web-sys/src/features/gen_MediaKeyStatusMap.rs @@ -19,6 +19,21 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] pub fn size(this: &MediaKeyStatusMap) -> u32; + # [wasm_bindgen (method , structural , js_class = "MediaKeyStatusMap" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyStatusMap/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] + pub fn entries(this: &MediaKeyStatusMap) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "MediaKeyStatusMap" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyStatusMap/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] + pub fn for_each(this: &MediaKeyStatusMap, callback: &::js_sys::Function) + -> Result<(), JsValue>; # [wasm_bindgen (catch , method , structural , js_class = "MediaKeyStatusMap" , js_name = get)] #[doc = "The `get()` method."] #[doc = ""] @@ -53,4 +68,18 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] pub fn has_with_u8_array(this: &MediaKeyStatusMap, key_id: &mut [u8]) -> bool; + # [wasm_bindgen (method , structural , js_class = "MediaKeyStatusMap" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyStatusMap/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] + pub fn keys(this: &MediaKeyStatusMap) -> ::js_sys::Iterator; + # [wasm_bindgen (method , structural , js_class = "MediaKeyStatusMap" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyStatusMap/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `MediaKeyStatusMap`*"] + pub fn values(this: &MediaKeyStatusMap) -> ::js_sys::Iterator; } diff --git a/crates/web-sys/src/features/gen_NodeList.rs b/crates/web-sys/src/features/gen_NodeList.rs index 3a3a959371d8..21edd471cbce 100644 --- a/crates/web-sys/src/features/gen_NodeList.rs +++ b/crates/web-sys/src/features/gen_NodeList.rs @@ -19,6 +19,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `NodeList`*"] pub fn length(this: &NodeList) -> u32; + # [wasm_bindgen (method , structural , js_class = "NodeList" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NodeList`*"] + pub fn entries(this: &NodeList) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "NodeList" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NodeList`*"] + pub fn for_each(this: &NodeList, callback: &::js_sys::Function) -> Result<(), JsValue>; #[cfg(feature = "Node")] # [wasm_bindgen (method , structural , js_class = "NodeList" , js_name = item)] #[doc = "The `item()` method."] @@ -27,6 +41,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Node`, `NodeList`*"] pub fn item(this: &NodeList, index: u32) -> Option; + # [wasm_bindgen (method , structural , js_class = "NodeList" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NodeList`*"] + pub fn keys(this: &NodeList) -> ::js_sys::Iterator; + # [wasm_bindgen (method , structural , js_class = "NodeList" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NodeList`*"] + pub fn values(this: &NodeList) -> ::js_sys::Iterator; #[cfg(feature = "Node")] #[wasm_bindgen(method, structural, js_class = "NodeList", indexing_getter)] #[doc = "Indexing getter. As in the literal Javascript `this[key]`."] diff --git a/crates/web-sys/src/features/gen_ReadableStream.rs b/crates/web-sys/src/features/gen_ReadableStream.rs index 77a44341a631..352be8a833b8 100644 --- a/crates/web-sys/src/features/gen_ReadableStream.rs +++ b/crates/web-sys/src/features/gen_ReadableStream.rs @@ -63,6 +63,13 @@ extern "C" { this: &ReadableStream, reason: &::wasm_bindgen::JsValue, ) -> ::js_sys::Promise; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn entries(this: &ReadableStream) -> ::js_sys::AsyncIterator; # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = getReader)] #[doc = "The `getReader()` method."] #[doc = ""] @@ -81,6 +88,13 @@ extern "C" { this: &ReadableStream, options: &ReadableStreamGetReaderOptions, ) -> ::js_sys::Object; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn keys(this: &ReadableStream) -> ::js_sys::AsyncIterator; #[cfg(feature = "ReadableWritablePair")] # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = pipeThrough)] #[doc = "The `pipeThrough()` method."] @@ -128,4 +142,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] pub fn tee(this: &ReadableStream) -> ::js_sys::Array; + # [wasm_bindgen (method , structural , js_class = "ReadableStream" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ReadableStream`*"] + pub fn values(this: &ReadableStream) -> ::js_sys::AsyncIterator; } diff --git a/crates/web-sys/src/features/gen_UrlSearchParams.rs b/crates/web-sys/src/features/gen_UrlSearchParams.rs index a2cb9204e503..7872f099e3ca 100644 --- a/crates/web-sys/src/features/gen_UrlSearchParams.rs +++ b/crates/web-sys/src/features/gen_UrlSearchParams.rs @@ -49,6 +49,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] pub fn delete(this: &UrlSearchParams, name: &str); + # [wasm_bindgen (method , structural , js_class = "URLSearchParams" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] + pub fn entries(this: &UrlSearchParams) -> ::js_sys::Iterator; + # [wasm_bindgen (catch , method , structural , js_class = "URLSearchParams" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] + pub fn for_each(this: &UrlSearchParams, callback: &::js_sys::Function) -> Result<(), JsValue>; # [wasm_bindgen (method , structural , js_class = "URLSearchParams" , js_name = get)] #[doc = "The `get()` method."] #[doc = ""] @@ -70,6 +84,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] pub fn has(this: &UrlSearchParams, name: &str) -> bool; + # [wasm_bindgen (method , structural , js_class = "URLSearchParams" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] + pub fn keys(this: &UrlSearchParams) -> ::js_sys::Iterator; # [wasm_bindgen (method , structural , js_class = "URLSearchParams" , js_name = set)] #[doc = "The `set()` method."] #[doc = ""] @@ -84,4 +105,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] pub fn sort(this: &UrlSearchParams) -> Result<(), JsValue>; + # [wasm_bindgen (method , structural , js_class = "URLSearchParams" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `UrlSearchParams`*"] + pub fn values(this: &UrlSearchParams) -> ::js_sys::Iterator; } diff --git a/crates/web-sys/src/features/gen_XrHand.rs b/crates/web-sys/src/features/gen_XrHand.rs index ad496a99f12f..0812d5a3e9c9 100644 --- a/crates/web-sys/src/features/gen_XrHand.rs +++ b/crates/web-sys/src/features/gen_XrHand.rs @@ -28,6 +28,28 @@ extern "C" { #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn size(this: &XrHand) -> u32; #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRHand" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRHand/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrHand`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn entries(this: &XrHand) -> ::js_sys::Iterator; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (catch , method , structural , js_class = "XRHand" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRHand/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrHand`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn for_each(this: &XrHand, callback: &::js_sys::Function) -> Result<(), JsValue>; + #[cfg(web_sys_unstable_apis)] #[cfg(all(feature = "XrHandJoint", feature = "XrJointSpace",))] # [wasm_bindgen (method , structural , js_class = "XRHand" , js_name = get)] #[doc = "The `get()` method."] @@ -39,4 +61,26 @@ extern "C" { #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn get(this: &XrHand, key: XrHandJoint) -> XrJointSpace; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRHand" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRHand/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrHand`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn keys(this: &XrHand) -> ::js_sys::Iterator; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRHand" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRHand/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrHand`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn values(this: &XrHand) -> ::js_sys::Iterator; } diff --git a/crates/web-sys/src/features/gen_XrInputSourceArray.rs b/crates/web-sys/src/features/gen_XrInputSourceArray.rs index 8489fb12a022..131e956e5698 100644 --- a/crates/web-sys/src/features/gen_XrInputSourceArray.rs +++ b/crates/web-sys/src/features/gen_XrInputSourceArray.rs @@ -28,6 +28,53 @@ extern "C" { #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn length(this: &XrInputSourceArray) -> u32; #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRInputSourceArray" , js_name = entries)] + #[doc = "The `entries()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray/entries)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrInputSourceArray`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn entries(this: &XrInputSourceArray) -> ::js_sys::Iterator; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (catch , method , structural , js_class = "XRInputSourceArray" , js_name = forEach)] + #[doc = "The `forEach()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray/forEach)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrInputSourceArray`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn for_each( + this: &XrInputSourceArray, + callback: &::js_sys::Function, + ) -> Result<(), JsValue>; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRInputSourceArray" , js_name = keys)] + #[doc = "The `keys()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray/keys)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrInputSourceArray`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn keys(this: &XrInputSourceArray) -> ::js_sys::Iterator; + #[cfg(web_sys_unstable_apis)] + # [wasm_bindgen (method , structural , js_class = "XRInputSourceArray" , js_name = values)] + #[doc = "The `values()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray/values)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `XrInputSourceArray`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn values(this: &XrInputSourceArray) -> ::js_sys::Iterator; + #[cfg(web_sys_unstable_apis)] #[cfg(feature = "XrInputSource")] #[wasm_bindgen(method, structural, js_class = "XRInputSourceArray", indexing_getter)] #[doc = "Indexing getter. As in the literal Javascript `this[key]`."] diff --git a/crates/web-sys/tests/wasm/headers.js b/crates/web-sys/tests/wasm/headers.js index 3b71cdc66ab9..267c0744c00f 100644 --- a/crates/web-sys/tests/wasm/headers.js +++ b/crates/web-sys/tests/wasm/headers.js @@ -1,3 +1,7 @@ export function new_headers() { return new Headers({'Content-Type': 'text/plain'}); } + +export function new_headers_2() { + return new Headers({'Content-Type': 'text/plain', 'Cookie': 'foobarbaz'}); +} diff --git a/crates/web-sys/tests/wasm/headers.rs b/crates/web-sys/tests/wasm/headers.rs index 08751444b607..f7cb4f7d7e8e 100644 --- a/crates/web-sys/tests/wasm/headers.rs +++ b/crates/web-sys/tests/wasm/headers.rs @@ -1,3 +1,4 @@ +use js_sys::{Array, Function, JsString}; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; use web_sys::Headers; @@ -5,6 +6,7 @@ use web_sys::Headers; #[wasm_bindgen(module = "/tests/wasm/headers.js")] extern "C" { fn new_headers() -> Headers; + fn new_headers_2() -> Headers; } #[wasm_bindgen_test] @@ -29,3 +31,40 @@ fn headers() { assert!(headers.append("a", "z").is_ok()); assert_eq!(headers.get("a").unwrap(), Some("y, z".to_string())); } + +#[wasm_bindgen_test] +fn headers_iter() { + let headers = new_headers_2() + .entries() + .into_iter() + .map(|x| { + let array = x.unwrap().dyn_into::().unwrap(); + assert_eq!(array.length(), 2); + let k: String = array.at(0).as_string().unwrap(); + let v: String = array.at(1).as_string().unwrap(); + (k, v) + }) + .collect::>(); + + assert_eq!(headers.len(), 2); + assert_eq!(&headers[0].0, "content-type"); + assert_eq!(&headers[0].1, "text/plain"); + assert_eq!(&headers[1].0, "cookie"); + assert_eq!(&headers[1].1, "foobarbaz"); +} + +#[wasm_bindgen_test] +fn headers_for_each() { + let mut count = 0; + let cb = Closure::wrap(Box::new(move |jval: JsValue| { + let val: String = jval.as_string().unwrap(); + if count == 0 { + assert_eq!(val, "text/plain"); + } else { + assert_eq!(val, "foobarbaz"); + } + count += 1; + }) as Box); + let res = new_headers_2().for_each(&cb.as_ref().unchecked_ref()); + assert!(res.is_ok()); +} diff --git a/crates/web-sys/tests/wasm/main.rs b/crates/web-sys/tests/wasm/main.rs index a587b9f69218..737d1029a3e4 100644 --- a/crates/web-sys/tests/wasm/main.rs +++ b/crates/web-sys/tests/wasm/main.rs @@ -30,6 +30,7 @@ pub mod meta_element; pub mod meter_element; pub mod mod_elements; pub mod olist_element; +pub mod opfs; pub mod optgroup_element; pub mod option_element; pub mod options_collection; diff --git a/crates/web-sys/tests/wasm/opfs.rs b/crates/web-sys/tests/wasm/opfs.rs new file mode 100644 index 000000000000..98bd9fc92c6d --- /dev/null +++ b/crates/web-sys/tests/wasm/opfs.rs @@ -0,0 +1,156 @@ +use std::collections::BTreeMap; + +use futures::stream::StreamExt; +use js_sys::{Array, JsString}; +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::{stream::JsStream, JsFuture}; +use wasm_bindgen_test::*; +use web_sys::{ + window, File, FileSystemDirectoryHandle, FileSystemFileHandle, FileSystemGetDirectoryOptions, + FileSystemGetFileOptions, FileSystemWritableFileStream, +}; + +// aux functions + +async fn get_storage() -> FileSystemDirectoryHandle { + let storage_promise = window().unwrap().navigator().storage().get_directory(); + JsFuture::from(storage_promise) + .await + .unwrap() + .dyn_into::() + .unwrap() +} + +async fn create_directory( + dir: &FileSystemDirectoryHandle, + path: &str, +) -> FileSystemDirectoryHandle { + let mut opts = FileSystemGetDirectoryOptions::new(); + opts.create(true); + JsFuture::from(dir.get_directory_handle_with_options(&path, &opts)) + .await + .expect("Couldn't create test directory") + .dyn_into::() + .unwrap() +} + +async fn create_test_directory(path: &str) -> FileSystemDirectoryHandle { + let storage = get_storage().await; + create_directory(&storage, path).await +} + +async fn create_file(dir: &FileSystemDirectoryHandle, path: &str) { + let mut opts = FileSystemGetFileOptions::new(); + opts.create(true); + let _ = JsFuture::from(dir.get_file_handle_with_options(path, &opts)).await; +} + +// Tests + +// Check we can access the root opfs directory +#[wasm_bindgen_test] +async fn access_storage() { + let storage_promise = window().unwrap().navigator().storage().get_directory(); + let storage = JsFuture::from(storage_promise).await; + assert!(storage.is_ok()); +} + +// Creating a directory in the root dir and test it's there +#[wasm_bindgen_test] +async fn test_create_directory() { + let _test_dir = create_test_directory("create_directory").await; + let storage = get_storage().await; + let dir = JsFuture::from(storage.get_directory_handle("create_directory")).await; + assert!(dir.is_ok()); +} + +#[wasm_bindgen_test] +async fn test_create_file() { + let test_dir = create_test_directory("create_file").await; + create_file(&test_dir, "test.txt").await; + let stream = JsStream::from(test_dir.keys()); + let mut res = stream.collect::>>().await; + assert_eq!(res.len(), 1, "Expected number of files"); + let path = res.pop().unwrap().unwrap().dyn_into::().unwrap(); + assert_eq!(path, "test.txt", "Searched for file"); +} + +#[wasm_bindgen_test] +async fn test_write_to_file() { + let test_dir = create_test_directory("write_to_file").await; + + // create file + let mut opts = FileSystemGetFileOptions::new(); + opts.create(true); + let file = JsFuture::from(test_dir.get_file_handle_with_options(&"test.txt", &opts)) + .await + .expect("Couldn't create file") + .dyn_into::() + .unwrap(); + + // Write to file + let test_txt = "testing testing"; + let write_stream = JsFuture::from(file.create_writable()) + .await + .unwrap() + .dyn_into::() + .unwrap(); + JsFuture::from(write_stream.write_with_str(test_txt).unwrap()).await; + JsFuture::from(write_stream.close()).await.unwrap(); + + // Read and check contents + let mut values = JsStream::from(test_dir.values()) + .map(|x| x.unwrap().dyn_into::().unwrap()) + .collect::>() + .await; + assert_eq!(values.len(), 1); + + let file = JsFuture::from(values[0].get_file()) + .await + .unwrap() + .dyn_into::() + .unwrap(); + + let text = JsFuture::from(file.text()) + .await + .unwrap() + .dyn_into::() + .unwrap(); + assert_eq!(&text, test_txt); +} + +// Create a couple of entries in a directory and check entries returns them all +#[wasm_bindgen_test] +async fn test_entries() { + let test_dir = create_test_directory("entries").await; + create_directory(&test_dir, "dir").await; + create_file(&test_dir, "file").await; + create_file(&test_dir, "file2").await; + + let entries = JsStream::from(test_dir.entries()) + .map(|x| { + let array: Vec = x.unwrap().dyn_into::().unwrap().to_vec(); + assert_eq!(array.len(), 2); + let path: String = array[0].clone().dyn_into::().unwrap().into(); + (path, array[1].clone()) + }) + .collect::>() + .await; + + assert_eq!(entries.len(), 3); + + match entries.get("dir") { + Some(handle) => assert!(FileSystemDirectoryHandle::instanceof(&handle)), + _ => panic!("Didn't find directory"), + } + + match entries.get("file") { + Some(handle) => assert!(FileSystemFileHandle::instanceof(&handle)), + _ => panic!("Couldn't find file"), + } + + match entries.get("file2") { + Some(handle) => assert!(FileSystemFileHandle::instanceof(&handle)), + _ => panic!("Couldn't find file2"), + } +} diff --git a/crates/webidl/src/constants.rs b/crates/webidl/src/constants.rs index de9129f96a04..33144506e02f 100644 --- a/crates/webidl/src/constants.rs +++ b/crates/webidl/src/constants.rs @@ -33,6 +33,7 @@ pub(crate) static BUILTIN_IDENTS: Lazy> = Lazy::new(|| { "Clamped", "DataView", "Iterator", + "AsyncIterator", ]) }); diff --git a/crates/webidl/src/first_pass.rs b/crates/webidl/src/first_pass.rs index bc0d56954306..cf0f09d5d98a 100644 --- a/crates/webidl/src/first_pass.rs +++ b/crates/webidl/src/first_pass.rs @@ -71,6 +71,7 @@ pub(crate) struct FirstPassRecord<'src> { pub(crate) dictionaries: BTreeMap<&'src str, DictionaryData<'src>>, pub(crate) callbacks: BTreeSet<&'src str>, pub(crate) iterators: BTreeSet<&'src str>, + pub(crate) async_iterators: BTreeSet<&'src str>, pub(crate) callback_interfaces: BTreeMap<&'src str, CallbackInterfaceData<'src>>, } @@ -546,11 +547,8 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::Int InterfaceMember::Constructor(constr) => constr.first_pass(record, ctx), InterfaceMember::Maplike(ml) => ml.first_pass(record, ctx), InterfaceMember::Setlike(sl) => sl.first_pass(record, ctx), - // TODO - InterfaceMember::Iterable(_iterable) => { - log::warn!("Unsupported WebIDL iterable interface member: {:?}", self); - Ok(()) - } + InterfaceMember::Iterable(iterable) => iterable.first_pass(record, ctx), + InterfaceMember::AsyncIterable(iterable) => iterable.first_pass(record, ctx), InterfaceMember::Stringifier(_) => { log::warn!( "Unsupported WebIDL Stringifier interface member: {:?}", @@ -558,13 +556,6 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::Int ); Ok(()) } - InterfaceMember::AsyncIterable(_iterable) => { - log::warn!( - "Unsupported WebIDL async iterable interface member: {:?}", - self - ); - Ok(()) - } } } } @@ -1077,6 +1068,167 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> Ok(()) } } +impl<'src> FirstPass<'src, (&'src str, ApiStability)> + for weedle::interface::IterableInterfaceMember<'src> +{ + fn first_pass( + &'src self, + record: &mut FirstPassRecord<'src>, + ctx: (&'src str, ApiStability), + ) -> Result<()> { + record.iterators.insert("Iterator"); + + // [NewObject] Iterator entries(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("entries"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("Iterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + + // [NewObject] Iterator keys(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("keys"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("Iterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + + // [NewObject] Iterator values(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("values"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("Iterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + + let undefined_ret = || ReturnType::Undefined(term!(undefined)); + + // callback SetlikeForEachCallback = undefined (V value); + // TODO: the signature of the callback is erased, could we keep it? + let foreach_callback_arg = Arg { + name: "callback", + ty: &Type::Single(SingleType::NonAny(NonAnyType::Identifier(MayBeNull { + type_: Identifier("IterableForEachCallback"), + q_mark: None, + }))), + optional: false, + variadic: false, + }; + + record.callbacks.insert("IterableForEachCallback"); + + // [Throws] undefined forEach(SetlikeForEachCallback cb); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("forEach"))], + [foreach_callback_arg], + &undefined_ret(), + &THROWS_ATTR, + false, + ctx.1, + ); + Ok(()) + } +} + +impl<'src> FirstPass<'src, (&'src str, ApiStability)> + for weedle::interface::AsyncIterableInterfaceMember<'src> +{ + fn first_pass( + &'src self, + record: &mut FirstPassRecord<'src>, + ctx: (&'src str, ApiStability), + ) -> Result<()> { + record.async_iterators.insert("AsyncIterator"); + + // [NewObject] MapLikeIterator entries(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("entries"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("AsyncIterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + // [NewObject] MapLikeIterator keys(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("keys"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("AsyncIterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + // [NewObject] MapLikeIterator values(); + first_pass_operation( + record, + FirstPassOperationType::Interface, + ctx.0, + &[OperationId::Operation(Some("values"))], + &[], + &ReturnType::Type(Type::Single(SingleType::NonAny(NonAnyType::Identifier( + MayBeNull { + type_: Identifier("AsyncIterator"), + q_mark: None, + }, + )))), + &NEW_OBJECT_ATTR, + false, + ctx.1, + ); + + Ok(()) + } +} impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::AttributeInterfaceMember<'src> diff --git a/crates/webidl/src/idl_type.rs b/crates/webidl/src/idl_type.rs index 1843210da5a7..27839d8d8669 100644 --- a/crates/webidl/src/idl_type.rs +++ b/crates/webidl/src/idl_type.rs @@ -31,6 +31,7 @@ pub(crate) enum IdlType<'a> { Error, Callback, Iterator, + AsyncIterator, ArrayBuffer, DataView, @@ -335,6 +336,8 @@ impl<'a> ToIdlType<'a> for Identifier<'a> { IdlType::Callback } else if record.iterators.contains(self.0) { IdlType::Iterator + } else if record.async_iterators.contains(self.0) { + IdlType::AsyncIterator } else if let Some(data) = record.callback_interfaces.get(self.0) { IdlType::CallbackInterface { name: self.0, @@ -438,6 +441,7 @@ impl<'a> IdlType<'a> { IdlType::Error => dst.push_str("error"), IdlType::Callback => dst.push_str("callback"), IdlType::Iterator => dst.push_str("iterator"), + IdlType::AsyncIterator => dst.push_str("async_iterator"), IdlType::ArrayBuffer => dst.push_str("array_buffer"), IdlType::DataView => dst.push_str("data_view"), @@ -650,6 +654,7 @@ impl<'a> IdlType<'a> { IdlType::Undefined => Ok(None), IdlType::Callback => Ok(js_sys("Function")), IdlType::Iterator => Ok(js_sys("Iterator")), + IdlType::AsyncIterator => Ok(js_sys("AsyncIterator")), IdlType::UnknownInterface(_) => Err(TypeError::CannotConvert), } }