Skip to content

Commit 0dea866

Browse files
aduh95targos
authored andcommitted
wasi: refactor to avoid unsafe array iteration
PR-URL: #36724 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent c34de75 commit 0dea866

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/wasi.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const {
3+
ArrayPrototypeForEach,
34
ArrayPrototypeMap,
45
ArrayPrototypePush,
56
FunctionPrototypeBind,
@@ -62,18 +63,22 @@ class WASI {
6263
const env = [];
6364
if (options.env !== undefined) {
6465
validateObject(options.env, 'options.env');
65-
for (const [key, value] of ObjectEntries(options.env)) {
66-
if (value !== undefined)
67-
ArrayPrototypePush(env, `${key}=${value}`);
68-
}
66+
ArrayPrototypeForEach(
67+
ObjectEntries(options.env),
68+
({ 0: key, 1: value }) => {
69+
if (value !== undefined)
70+
ArrayPrototypePush(env, `${key}=${value}`);
71+
});
6972
}
7073

7174
const preopens = [];
7275
if (options.preopens !== undefined) {
7376
validateObject(options.preopens, 'options.preopens');
74-
for (const [key, value] of ObjectEntries(options.preopens)) {
75-
ArrayPrototypePush(preopens, String(key), String(value));
76-
}
77+
ArrayPrototypeForEach(
78+
ObjectEntries(options.preopens),
79+
({ 0: key, 1: value }) =>
80+
ArrayPrototypePush(preopens, String(key), String(value))
81+
);
7782
}
7883

7984
const { stdin = 0, stdout = 1, stderr = 2 } = options;

0 commit comments

Comments
 (0)