Skip to content

Commit

Permalink
Add support for webidl iterables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RaoulHC committed Jul 12, 2024
1 parent 4b1ca86 commit 4287de8
Show file tree
Hide file tree
Showing 18 changed files with 674 additions and 13 deletions.
3 changes: 2 additions & 1 deletion crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 28 additions & 0 deletions crates/web-sys/src/features/gen_DomTokenList.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,34 @@ 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 = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/item)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `DomTokenList`*"]
pub fn item(this: &DomTokenList, index: u32) -> Option<String>;
# [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 = ""]
Expand Down Expand Up @@ -275,6 +296,13 @@ extern "C" {
token: &str,
force: bool,
) -> Result<bool, JsValue>;
# [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 = ""]
Expand Down
21 changes: 21 additions & 0 deletions crates/web-sys/src/features/gen_FileSystemDirectoryHandle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand Down Expand Up @@ -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 = ""]
Expand Down Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions crates/web-sys/src/features/gen_FormData.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand All @@ -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."]
Expand Down Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions crates/web-sys/src/features/gen_Headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand All @@ -63,11 +77,25 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Headers`*"]
pub fn has(this: &Headers, name: &str) -> Result<bool, JsValue>;
# [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 = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Headers/set)"]
#[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;
}
29 changes: 29 additions & 0 deletions crates/web-sys/src/features/gen_MediaKeyStatusMap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand Down Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions crates/web-sys/src/features/gen_NodeList.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."]
Expand All @@ -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<Node>;
# [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]`."]
Expand Down
21 changes: 21 additions & 0 deletions crates/web-sys/src/features/gen_ReadableStream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""]
Expand All @@ -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."]
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 4287de8

Please sign in to comment.