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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case wouldn't we only need to support number here? i.e. if register_vector is using unsigned int couldn't we mandate that all iterators do the same?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i.e. could we just assert typeof size === 'number' here, or are there cases (in the test code) where this is not true?

Copy link
Contributor Author

@aestuans aestuans Jan 13, 2026

Choose a reason for hiding this comment

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

I thought it would be better to leave it to the users whether they want size_t/bigint in their container classes or not, since it's fairly trivial to support both for the iterable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough, but if we want explicitly support this then maybe we should add test for it?

Also, should these lines be behind #if MEMORY64, of do you think somebody might using int64 as an interator an wasm32 ? Seems unlikely. Purring them behind #if MEMORY64 would also help signal the intent here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done.

@aestuans aestuans force-pushed the iterable branch 2 times, most recently from 2643dda to 3db19f4 Compare December 24, 2025 09:27
@aestuans aestuans requested a review from sbc100 December 24, 2025 10:28
@aestuans aestuans requested a review from brendandahl December 30, 2025 21:06
@aestuans
Copy link
Contributor Author

@sbc100 Just checking in to see if this PR can get another look. Appreciate it!

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm but I'll leave it to @brendandahl to do the final approval.

Copy link
Collaborator

@brendandahl brendandahl left a comment

Choose a reason for hiding this comment

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

Looks good to me, but please add an entry in the changelog as well.

ChangeLog.md Outdated
- A new `-sEXECUTABLE` setting was added which adds a #! line to the resulting
JavaScript and makes it executable. This setting defaults to true when the
output filename has no extension, or ends in `.out` (e.g. `a.out`) (#26085)
JavaScript and makes it executable. (#26085)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a bad merge? Delete this line maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my bad.

@sbc100 sbc100 enabled auto-merge (squash) January 13, 2026 20:22
@sbc100 sbc100 merged commit 1a55610 into emscripten-core:main Jan 13, 2026
35 checks passed
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.

3 participants