From 0f29587757a782973b0aeabdee255b79c30780a2 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 7734aaa2c2011c..36c5d4c5675413 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, @@ -178,8 +179,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,