Skip to content

Conversation

@aestuans
Copy link
Contributor

@aestuans aestuans commented Dec 22, 2025

Add class_<T>::iterable() to implement Symbol.iterator. Use this in register_vector so bound vectors have better ergonomics, such as working with for...of and Array.from().

This is tangentially related to #11070 in that it's intended to make vector bindings nicer to use, but unlike what is suggested there it doesn't copy the vector to JS memory.

const makeIterator = (size, getValue) => {
const useBigInt = typeof size === 'bigint';
const one = useBigInt ? 1n : 1;
let index = useBigInt ? 0n : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we simply dictate that interables using size_t i.e. bigint on wasm64 and number on wasm32?

I don't image we will ever see 64-bit iterators on wasm32, right?

Copy link
Contributor Author

@aestuans aestuans Dec 23, 2025

Choose a reason for hiding this comment

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

I tried doing this, but register_vector seems to use unsigned int on purpose, so I presume forcing Bigint on wasm64 is undesirable?

Add `class_<T>::iterable()` to implement `Symbol.iterator`.
Use this in `register_vector` so bound vectors have better ergonomics, such as working with `for...of` and `Array.from()`.

This is tangentially related to emscripten-core#11070.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants