Skip to content

Commit 81a3055

Browse files
richardlauaduh95
authored andcommitted
process: fix default env for process.execve
The `env` parameter for `process.execve` is documented to default to `process.env`. PR-URL: #60029 Refs: nodejs/build#4156 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 4206406 commit 81a3055

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

lib/internal/process/per_thread.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function wrapProcessMethods(binding) {
283283
return true;
284284
}
285285

286-
function execve(execPath, args = [], env) {
286+
function execve(execPath, args = [], env = process.env) {
287287
emitExperimentalWarning('process.execve');
288288

289289
const { isMainThread } = require('internal/worker');
@@ -305,22 +305,20 @@ function wrapProcessMethods(binding) {
305305
}
306306

307307
const envArray = [];
308-
if (env !== undefined) {
309-
validateObject(env, 'env');
310-
311-
for (const { 0: key, 1: value } of ObjectEntries(env)) {
312-
if (
313-
typeof key !== 'string' ||
314-
typeof value !== 'string' ||
315-
StringPrototypeIncludes(key, '\u0000') ||
316-
StringPrototypeIncludes(value, '\u0000')
317-
) {
318-
throw new ERR_INVALID_ARG_VALUE(
319-
'env', env, 'must be an object with string keys and values without null bytes',
320-
);
321-
} else {
322-
ArrayPrototypePush(envArray, `${key}=${value}`);
323-
}
308+
validateObject(env, 'env');
309+
310+
for (const { 0: key, 1: value } of ObjectEntries(env)) {
311+
if (
312+
typeof key !== 'string' ||
313+
typeof value !== 'string' ||
314+
StringPrototypeIncludes(key, '\u0000') ||
315+
StringPrototypeIncludes(value, '\u0000')
316+
) {
317+
throw new ERR_INVALID_ARG_VALUE(
318+
'env', env, 'must be an object with string keys and values without null bytes',
319+
);
320+
} else {
321+
ArrayPrototypePush(envArray, `${key}=${value}`);
324322
}
325323
}
326324

0 commit comments

Comments
 (0)