diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 07a94486169a7c..da2ba93e7e93ae 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -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'); - - 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}`); - } + 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}`); } }