Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webidl iterable support #3962

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ jobs:
- run: cargo doc --no-deps --manifest-path crates/web-sys/Cargo.toml --all-features
env:
RUSTDOCFLAGS: --cfg=web_sys_unstable_apis
- run: cargo doc --no-deps --manifest-path crates/futures/Cargo.toml
- run: cargo doc --no-deps --manifest-path crates/futures/Cargo.toml --all-features
env:
RUSTDOCFLAGS: --cfg=docsrs
- run: tar czvf docs.tar.gz target/doc
- uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
* Generate getters for all WebIDL dictionary types.
[#3993](https://github.com/rustwasm/wasm-bindgen/pull/3993)

* Support for iterable in WebIDL. Gives `entries`, `keys`, `values` methods for regular and asynchronous, as well as `for_each` for regular, iterables.
[#3962](https://github.com/rustwasm/wasm-bindgen/pull/3962)

### Changed

* Stabilize Web Share API.
Expand Down
4 changes: 4 additions & 0 deletions crates/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ version = "0.4.42"
edition = "2018"
rust-version = "1.57"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
cfg-if = "1.0.0"
js-sys = { path = "../js-sys", version = '0.3.69' }
Expand Down
2 changes: 2 additions & 0 deletions crates/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#![cfg_attr(target_feature = "atomics", feature(stdarch_wasm_atomic_wait))]
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
daxpedda marked this conversation as resolved.
Show resolved Hide resolved

use js_sys::Promise;
use std::cell::RefCell;
Expand All @@ -43,6 +44,7 @@ use std::task::{Context, Poll, Waker};
use wasm_bindgen::prelude::*;

mod queue;
#[cfg_attr(docsrs, doc(cfg(feature = "futures-core-03-stream")))]
#[cfg(feature = "futures-core-03-stream")]
pub mod stream;

Expand Down
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"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(web_sys_unstable_apis)'] }
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>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array::for_each() takes a &mut dyn FnMut() instead, which also can encode types. Both ways have tradeoffs and ideally we could have both, so I'm happy to leave it as is because I think it aligns more with all the other APIs web-sys currently exposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah while I think we eventually want that, I think it will need shims that aren't so easy to generated as I struggled with for the entries and co API too. Can write a new issue for doing this specifically (although maybe it fits one of the existing related issues already, and that just needs an update).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably be best to wait for demand first.
But I appreciate the offer!

# [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