Skip to content

Commit cff4a76

Browse files
richardlautargos
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 <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 77ec400 commit cff4a76

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
@@ -279,7 +279,7 @@ function wrapProcessMethods(binding) {
279279
return true;
280280
}
281281

282-
function execve(execPath, args = [], env) {
282+
function execve(execPath, args = [], env = process.env) {
283283
emitExperimentalWarning('process.execve');
284284

285285
const { isMainThread } = require('internal/worker');
@@ -301,22 +301,20 @@ function wrapProcessMethods(binding) {
301301
}
302302

303303
const envArray = [];
304-
if (env !== undefined) {
305-
validateObject(env, 'env');
306-
307-
for (const { 0: key, 1: value } of ObjectEntries(env)) {
308-
if (
309-
typeof key !== 'string' ||
310-
typeof value !== 'string' ||
311-
StringPrototypeIncludes(key, '\u0000') ||
312-
StringPrototypeIncludes(value, '\u0000')
313-
) {
314-
throw new ERR_INVALID_ARG_VALUE(
315-
'env', env, 'must be an object with string keys and values without null bytes',
316-
);
317-
} else {
318-
ArrayPrototypePush(envArray, `${key}=${value}`);
319-
}
304+
validateObject(env, 'env');
305+
306+
for (const { 0: key, 1: value } of ObjectEntries(env)) {
307+
if (
308+
typeof key !== 'string' ||
309+
typeof value !== 'string' ||
310+
StringPrototypeIncludes(key, '\u0000') ||
311+
StringPrototypeIncludes(value, '\u0000')
312+
) {
313+
throw new ERR_INVALID_ARG_VALUE(
314+
'env', env, 'must be an object with string keys and values without null bytes',
315+
);
316+
} else {
317+
ArrayPrototypePush(envArray, `${key}=${value}`);
320318
}
321319
}
322320

0 commit comments

Comments
 (0)