From 0dea86634d765ba8834b6ac34ba710f8a87c48b3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 31 Dec 2020 12:37:41 +0100 Subject: [PATCH] wasi: refactor to avoid unsafe array iteration PR-URL: https://github.com/nodejs/node/pull/36724 Reviewed-By: James M Snell Reviewed-By: Rich Trott --- lib/wasi.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/wasi.js b/lib/wasi.js index 072f19be9235ae..b3c14fc2f14840 100644 --- a/lib/wasi.js +++ b/lib/wasi.js @@ -1,5 +1,6 @@ 'use strict'; const { + ArrayPrototypeForEach, ArrayPrototypeMap, ArrayPrototypePush, FunctionPrototypeBind, @@ -62,18 +63,22 @@ class WASI { const env = []; if (options.env !== undefined) { validateObject(options.env, 'options.env'); - for (const [key, value] of ObjectEntries(options.env)) { - if (value !== undefined) - ArrayPrototypePush(env, `${key}=${value}`); - } + ArrayPrototypeForEach( + ObjectEntries(options.env), + ({ 0: key, 1: value }) => { + if (value !== undefined) + ArrayPrototypePush(env, `${key}=${value}`); + }); } const preopens = []; if (options.preopens !== undefined) { validateObject(options.preopens, 'options.preopens'); - for (const [key, value] of ObjectEntries(options.preopens)) { - ArrayPrototypePush(preopens, String(key), String(value)); - } + ArrayPrototypeForEach( + ObjectEntries(options.preopens), + ({ 0: key, 1: value }) => + ArrayPrototypePush(preopens, String(key), String(value)) + ); } const { stdin = 0, stdout = 1, stderr = 2 } = options;