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 <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent c34de75 commit 0dea866
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 0dea866

Please sign in to comment.