From fa273509771c01d603d403002481bc1d01e4dd8b Mon Sep 17 00:00:00 2001 From: Milly Date: Thu, 23 May 2024 20:55:07 +0900 Subject: fix(ext/web): `ReadableStream.from()` ignores null `Symbol.asyncIterator` (#23910) If `@@asyncIterator` is `null` or `undefined`, it should ignores and fallback to `@@iterator`. Tests have been merged into WPT. https://github.com/web-platform-tests/wpt/pull/46374 The proposal of `ReadableStream.from` uses TC39 [GetIterator][] and [GetMethod][] within it. GetMethod treats null as undefined. So if `@@asyncIterator` is `null` it should be ignored and fallback to `@@iterator`. [GetIterator]: https://tc39.es/ecma262/#sec-getiterator [GetMethod]: https://tc39.es/ecma262/#sec-getmethod ```bash > deno eval "ReadableStream.from({ [Symbol.asyncIterator]: null, [Symbol.iterator]: () => ({ next: () => ({ done: true }) }) }).pipeTo(new WritableStream())" error: Uncaught (in promise) TypeError: obj[SymbolAsyncIterator] is not a function ReadableStream.from({ [Symbol.asyncIterator]: null, [Symbol.iterator]: () => ({ next: () => ({ done: true }) }) }).pipeTo(new WritableStream()) ^ at getIterator (ext:deno_web/06_streams.js:5105:38) at Function.from (ext:deno_web/06_streams.js:5207:22) at file:///D:/work/js/deno/tests/wpt/suite/$deno$eval:1:16 ``` --------- Co-authored-by: Asher Gomez --- ext/web/06_streams.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/web') diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index e01ece6c8..0192a54c6 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -5096,8 +5096,8 @@ async function* createAsyncFromSyncIterator(syncIterator) { // Ref: https://tc39.es/ecma262/#sec-getiterator function getIterator(obj, async = false) { if (async) { - if (obj[SymbolAsyncIterator] === undefined) { - if (obj[SymbolIterator] === undefined) { + if (obj[SymbolAsyncIterator] == null) { + if (obj[SymbolIterator] == null) { throw new TypeError("No iterator found"); } return createAsyncFromSyncIterator(obj[SymbolIterator]()); @@ -5105,7 +5105,7 @@ function getIterator(obj, async = false) { return obj[SymbolAsyncIterator](); } } else { - if (obj[SymbolIterator] === undefined) { + if (obj[SymbolIterator] == null) { throw new TypeError("No iterator found"); } return obj[SymbolIterator](); -- cgit v1.2.3