process: fix default env for process.execve

The `env` parameter for `process.execve` is documented to default
to `process.env`.

PR-URL: https://github.com/nodejs/node/pull/60029
Refs: https://github.com/nodejs/build/pull/4156
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Richard Lau 2025-10-01 13:47:07 +01:00 committed by GitHub
parent c08164d016
commit b8ea0e8e85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -279,7 +279,7 @@ function wrapProcessMethods(binding) {
return true;
}
function execve(execPath, args = [], env) {
function execve(execPath, args = [], env = process.env) {
emitExperimentalWarning('process.execve');
const { isMainThread } = require('internal/worker');
@ -301,22 +301,20 @@ function wrapProcessMethods(binding) {
}
const envArray = [];
if (env !== undefined) {
validateObject(env, 'env');
validateObject(env, 'env');
for (const { 0: key, 1: value } of ObjectEntries(env)) {
if (
typeof key !== 'string' ||
typeof value !== 'string' ||
StringPrototypeIncludes(key, '\u0000') ||
StringPrototypeIncludes(value, '\u0000')
) {
throw new ERR_INVALID_ARG_VALUE(
'env', env, 'must be an object with string keys and values without null bytes',
);
} else {
ArrayPrototypePush(envArray, `${key}=${value}`);
}
for (const { 0: key, 1: value } of ObjectEntries(env)) {
if (
typeof key !== 'string' ||
typeof value !== 'string' ||
StringPrototypeIncludes(key, '\u0000') ||
StringPrototypeIncludes(value, '\u0000')
) {
throw new ERR_INVALID_ARG_VALUE(
'env', env, 'must be an object with string keys and values without null bytes',
);
} else {
ArrayPrototypePush(envArray, `${key}=${value}`);
}
}