From 1dc3609ff22e6a7be4d86d2ba983f81dfd8c1fd4 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sun, 15 Jan 2023 13:26:05 +0900 Subject: fix(core): Add `Generator` and `AsyncGenerator` to promordials (#17241) --- ext/web/06_streams.js | 5 ++--- ext/web/09_file.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'ext') diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 22baa1234..5b1c0141d 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -19,6 +19,7 @@ ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeShift, + AsyncGeneratorPrototype, BigInt64ArrayPrototype, BigUint64ArrayPrototype, DataView, @@ -4439,9 +4440,7 @@ } /** @type {AsyncIterator} */ - const asyncIteratorPrototype = ObjectGetPrototypeOf( - ObjectGetPrototypeOf(async function* () {}).prototype, - ); + const asyncIteratorPrototype = ObjectGetPrototypeOf(AsyncGeneratorPrototype); const _iteratorNext = Symbol("[[iteratorNext]]"); const _iteratorFinished = Symbol("[[iteratorFinished]]"); diff --git a/ext/web/09_file.js b/ext/web/09_file.js index f789a24d2..0fc1e7e96 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -20,6 +20,7 @@ ArrayBufferPrototypeSlice, ArrayBufferIsView, ArrayPrototypePush, + AsyncGeneratorPrototypeNext, Date, DatePrototypeGetTime, MathMax, @@ -330,7 +331,9 @@ /** @param {ReadableByteStreamController} controller */ async pull(controller) { while (true) { - const { value, done } = await partIterator.next(); + const { value, done } = await AsyncGeneratorPrototypeNext( + partIterator, + ); if (done) return controller.close(); if (value.byteLength > 0) { return controller.enqueue(value); @@ -354,11 +357,14 @@ const bytes = new Uint8Array(size); const partIterator = toIterator(this[_parts]); let offset = 0; - // deno-lint-ignore prefer-primordials - for await (const chunk of partIterator) { - const byteLength = chunk.byteLength; + while (true) { + const { value, done } = await AsyncGeneratorPrototypeNext( + partIterator, + ); + if (done) break; + const byteLength = value.byteLength; if (byteLength > 0) { - TypedArrayPrototypeSet(bytes, chunk, offset); + TypedArrayPrototypeSet(bytes, value, offset); offset += byteLength; } } -- cgit v1.2.3