diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 0f59546726..6d2a552320 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -53,10 +53,8 @@ const { NumberIsInteger, NumberIsNaN, ObjectCreate, - ObjectDefineProperties, ObjectDefineProperty, ObjectGetPrototypeOf, - ObjectPrototype, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, Promise, @@ -4651,26 +4649,6 @@ function writableStreamUpdateBackpressure(stream, backpressure) { stream[_backpressure] = backpressure; } -/** - * @template T - * @param {T} value - * @param {boolean} done - * @returns {IteratorResult} - */ -function createIteratorResult(value, done) { - const result = ObjectCreate(ObjectPrototype); - ObjectDefineProperties(result, { - value: { value, writable: true, enumerable: true, configurable: true }, - done: { - value: done, - writable: true, - enumerable: true, - configurable: true, - }, - }); - return result; -} - /** @type {AsyncIterator} */ const asyncIteratorPrototype = ObjectGetPrototypeOf(AsyncGeneratorPrototype); @@ -4685,7 +4663,7 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ const reader = this[_reader]; function nextSteps() { if (reader[_iteratorFinished]) { - return PromiseResolve(createIteratorResult(undefined, true)); + return PromiseResolve({ value: undefined, done: true }); } if (reader[_stream] === undefined) { @@ -4701,11 +4679,11 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ /** @type {ReadRequest} */ const readRequest = { chunkSteps(chunk) { - promise.resolve(createIteratorResult(chunk, false)); + promise.resolve({ value: chunk, done: false }); }, closeSteps() { readableStreamDefaultReaderRelease(reader); - promise.resolve(createIteratorResult(undefined, true)); + promise.resolve({ value: undefined, done: true }); }, errorSteps(e) { readableStreamDefaultReaderRelease(reader); @@ -4718,7 +4696,7 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ reader[_iteratorNext] = null; if (result.done === true) { reader[_iteratorFinished] = true; - return createIteratorResult(undefined, true); + return { value: undefined, done: true }; } return result; }, (reason) => { @@ -4743,12 +4721,12 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ const reader = this[_reader]; const returnSteps = () => { if (reader[_iteratorFinished]) { - return PromiseResolve(createIteratorResult(arg, true)); + return PromiseResolve({ value: arg, done: true }); } reader[_iteratorFinished] = true; if (reader[_stream] === undefined) { - return PromiseResolve(createIteratorResult(undefined, true)); + return PromiseResolve({ value: undefined, done: true }); } assert(reader[_readRequests].length === 0); if (this[_preventCancel] === false) { @@ -4757,7 +4735,7 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ return result; } readableStreamDefaultReaderRelease(reader); - return PromiseResolve(createIteratorResult(undefined, true)); + return PromiseResolve({ value: undefined, done: true }); }; const returnPromise = reader[_iteratorNext] @@ -4765,7 +4743,7 @@ const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({ : returnSteps(); return PromisePrototypeThen( returnPromise, - () => createIteratorResult(arg, true), + () => ({ value: arg, done: true }), ); }, }, asyncIteratorPrototype);