Skip to content

Commit

Permalink
wasi: refactor to avoid unsafe array iteration
Browse files Browse the repository at this point in the history
PR-URL: #36724
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and danielleadams committed Jan 12, 2021
1 parent e3a091d commit d5a9799
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/wasi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const {
ArrayPrototypeForEach,
ArrayPrototypeMap,
ArrayPrototypePush,
FunctionPrototypeBind,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d5a9799

Please sign in to comment.