From 698bffaa90f0746699d76df22ed37a3508ebdd8b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 12 Feb 2021 12:40:03 +0100 Subject: [PATCH] worker: refactor to avoid unsafe array iteration PR-URL: https://github.com/nodejs/node/pull/37346 Reviewed-By: Darshan Sen Reviewed-By: Harshitha K P Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell --- lib/internal/main/worker_thread.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 2c6902b5d7462a..3528ebccfdba35 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -5,6 +5,7 @@ const { ArrayPrototypeConcat, + ArrayPrototypeForEach, ArrayPrototypeSplice, ObjectDefineProperty, PromisePrototypeCatch, @@ -181,8 +182,9 @@ port.on('message', (message) => { } } else if (message.type === STDIO_PAYLOAD) { const { stream, chunks } = message; - for (const { chunk, encoding } of chunks) + ArrayPrototypeForEach(chunks, ({ chunk, encoding }) => { process[stream].push(chunk, encoding); + }); } else { assert( message.type === STDIO_WANTS_MORE_DATA,