From 0c32918eef229ffa979fd46bbb982ae458aa6062 Mon Sep 17 00:00:00 2001 From: Wiyeong Seo Date: Fri, 23 Aug 2024 16:31:55 +0900 Subject: [PATCH] stream: change stream to use index instead of `for...of` PR-URL: https://github.com/nodejs/node/pull/54474 Refs: https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration Reviewed-By: Daeyeon Jeong Reviewed-By: Antoine du Hamel Reviewed-By: Matteo Collina Reviewed-By: Raz Luvaton Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- lib/stream.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/stream.js b/lib/stream.js index 420415a2259827..a26cc0b81c557e 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -61,7 +61,9 @@ Stream.isReadable = utils.isReadable; Stream.isWritable = utils.isWritable; Stream.Readable = require('internal/streams/readable'); -for (const key of ObjectKeys(streamReturningOperators)) { +const streamKeys = ObjectKeys(streamReturningOperators); +for (let i = 0; i < streamKeys.length; i++) { + const key = streamKeys[i]; const op = streamReturningOperators[key]; function fn(...args) { if (new.target) { @@ -79,7 +81,9 @@ for (const key of ObjectKeys(streamReturningOperators)) { writable: true, }); } -for (const key of ObjectKeys(promiseReturningOperators)) { +const promiseKeys = ObjectKeys(promiseReturningOperators); +for (let i = 0; i < promiseKeys.length; i++) { + const key = promiseKeys[i]; const op = promiseReturningOperators[key]; function fn(...args) { if (new.target) {