From bdaac04c1019e78a0677adc23d0cb6c26afe9cbd Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 6 Jan 2020 00:23:50 -0500 Subject: [PATCH] wasi: improve use of primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/31212 Reviewed-By: Michaƫl Zasso Reviewed-By: Jiawen Geng Reviewed-By: David Carlier Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- lib/wasi.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/wasi.js b/lib/wasi.js index cf25cd922660d5..8cc1a09f5e7ab7 100644 --- a/lib/wasi.js +++ b/lib/wasi.js @@ -2,10 +2,10 @@ /* global WebAssembly */ const { ArrayIsArray, - ArrayPrototypeForEach, ArrayPrototypeMap, + ArrayPrototypePush, FunctionPrototypeBind, - ObjectKeys, + ObjectEntries, Symbol, } = primordials; @@ -40,7 +40,7 @@ class WASI { for (const key in env) { const value = env[key]; if (value !== undefined) - envPairs.push(`${key}=${value}`); + ArrayPrototypePush(envPairs, `${key}=${value}`); } } else if (env !== undefined) { throw new ERR_INVALID_ARG_TYPE('options.env', 'Object', env); @@ -49,10 +49,9 @@ class WASI { const preopenArray = []; if (typeof preopens === 'object' && preopens !== null) { - ArrayPrototypeForEach(ObjectKeys(preopens), (key) => { - preopenArray.push(String(key)); - preopenArray.push(String(preopens[key])); - }); + for (const [key, value] of ObjectEntries(preopens)) { + ArrayPrototypePush(preopenArray, String(key), String(value)); + } } else if (preopens !== undefined) { throw new ERR_INVALID_ARG_TYPE('options.preopens', 'Object', preopens); }