fix(ext/web): `ReadableStream.from()` allows `Iterable` instead of `IterableIterator`
createAsyncFromSyncIterator(x) which is used in ReadableStream.from() expects x as Iterable but, previous implements specify Iterator or IterableIterator. If it was IterableIterator, it would work, but if it was Iterator, an exception will occur.
Tests have been merged into WPT. https://github.com/web-platform-tests/wpt/pull/46365
CC @iuioiua
I'll update this PR once #23910 is merged.
This change fixes the following (WPT) tests:
/streams/readable-streams/from.any.html - ReadableStream.from accepts a sync iterable of values
/streams/readable-streams/from.any.html - ReadableStream.from accepts a sync iterable of promises
However, it also causes the following (WPT) tests to fail:
/streams/readable-streams/from.any.html - ReadableStream.from throws on invalid iterables; specifically an object with a non-callable @@iterator method
/streams/readable-streams/from.any.html - ReadableStream.from re-throws errors from calling the @@iterator method
/streams/readable-streams/from.any.html - ReadableStream.from ignores a null @@asyncIterator
The 3 failures all show the same error:
assert_throws_js: from() should throw a TypeError function "() => ReadableStream.from(iterable)" did not throw...
Currently, async generator + yield * is used to create an async iterator from a sync iterable.
That is because it implements TC39 GetIterator.
However, the test fails because yield * does not throw an error even if an invalid Iterable is given.
Currently, the getIterator() function is only used to implement ReadableStream.from().
So instead of reproducing TC39 GetIterator (creating an async iterator from a sync iterator), I think it would be better to simply create a function that returns an async iterator or a sync iterator. In that case, the caller of the function must use try-catch and await appropriately for using iterator.
Cool. There's been an improvement. The current failures give the same error:
assert_object_equals: first read should be correct expected property "0" missing
In that case, the caller of the function must use try-catch and await appropriately for using iterator.
I made a mistake by not keeping up with what I said.