fix(ext/webidl): follow GetIterator semantics in async iterable converter#34872
Closed
crowlbot wants to merge 3 commits into
Closed
fix(ext/webidl): follow GetIterator semantics in async iterable converter#34872crowlbot wants to merge 3 commits into
crowlbot wants to merge 3 commits into
Conversation
…rter The async iterable converter used by ReadableStream.from() rejected non-Object values and only treated an `undefined` (not `null`) @@asynciterator / @@iterator as an absent method. Per the GetIterator(obj, async) abstract operation, the iterator methods are looked up with GetMethod semantics, which (1) performs ToObject on the value, so primitives such as strings are accepted, and (2) treats both `undefined` and `null` as an absent method. Fixes two WPT subtests in streams/readable-streams/from.any: - ReadableStream.from accepts a string - ReadableStream.from ignores a null @@asynciterator
The unit test asserted ReadableStream.from(string) throws, which was the pre-spec behavior. Per the Streams spec it accepts any iterable, including strings; update the test to assert characters are yielded.
The ReadableStream.from type signature requires an object, so passing a string primitive is a static type error even though it is iterable at runtime. Add a @ts-expect-error directive (matching the prior test).
Member
|
This is incorrect, see whatwg/webidl#1397, whatwg/streams#1372 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The WebIDL async iterable converter (used by
ReadableStream.from()and anyoperation taking an
async iterable<T>argument) did not follow theGetIterator(obj, async)abstract operation:Objectvalue up front (type(V) !== "Object"throws),so primitives such as strings could never be converted, even though
GetIteratorperformsToObject(V)and strings are iterable.@@asyncIterator/@@iteratormethods it only treatedundefinedas "method absent". PerGetMethod, anullvalue must also betreated as absent, so a
null@@asyncIteratorshould fall back to the sync@@iteratorrather than being called.This fix narrows the early rejection to only
undefined/null(the values thatToObjectwould reject) and treats bothundefinedandnullmethod values asabsent, matching
GetIterator/GetMethod.Spec
GetIterator/GetMethodReadableStream.from(asyncIterable)WPT
Flips the following subtests from failing to passing under
streams/readable-streams/from.any.{html,worker.html}(+4 total):ReadableStream.from accepts a stringReadableStream.from ignores a null @@asyncIteratorExpectations in
tests/wpt/runner/expectations/streams.jsonupdatedaccordingly (both
from.any.htmlandfrom.any.worker.htmlnow fully pass).