diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 36ac1046dab471..07a94486169a7c 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) { emitExperimentalWarning('process.execve'); const { isMainThread } = require('internal/worker'); diff --git a/node.gyp b/node.gyp index 677ccdcafd772b..4c2103b268b682 100644 --- a/node.gyp +++ b/node.gyp @@ -1332,6 +1332,13 @@ }], ] }, # overlapped-checker + { + 'target_name': 'nop', + 'type': 'executable', + 'sources': [ + 'test/nop/nop.c', + ] + }, # nop { 'target_name': 'node_js2c', 'type': 'executable', diff --git a/test/nop/nop.c b/test/nop/nop.c new file mode 100644 index 00000000000000..03b2213bb9a36c --- /dev/null +++ b/test/nop/nop.c @@ -0,0 +1,3 @@ +int main(void) { + return 0; +} diff --git a/test/parallel/test-process-execve-no-args.js b/test/parallel/test-process-execve-no-args.js new file mode 100644 index 00000000000000..908512622cf00f --- /dev/null +++ b/test/parallel/test-process-execve-no-args.js @@ -0,0 +1,25 @@ +'use strict'; + +const { skip, isWindows, isIBMi } = require('../common'); +const { fail } = require('assert'); +const { isMainThread } = require('worker_threads'); +const { dirname, join } = require('path'); +const { existsSync } = require('fs'); + +if (!isMainThread) { + skip('process.execve is not available in Workers'); +} else if (isWindows || isIBMi) { + skip('process.execve is not available in Windows or IBM i'); +} + +// Get full path to the executable used for the test +const executable = join(dirname(process.execPath), 'nop'); + +// Sanity check that the binary exists +if (!existsSync(executable)) { + skip(executable + ' binary is not available'); +} + +process.execve(executable); +// If process.execve succeeds, this should never be executed. +fail('process.execve failed');