Skip to content

Commit 9694800

Browse files
committed
process: make execve's args argument optional
Align the code with the documentation and similar methods used to execute os commands - the `args` argument should be optional, and if omitted, treated as an empty array (`[]`). Fixes: #58411
1 parent 74acfdf commit 9694800

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

lib/internal/process/per_thread.js

Lines changed: 1 addition & 1 deletion
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) {
283283
emitExperimentalWarning('process.execve');
284284

285285
const { isMainThread } = require('internal/worker');

node.gyp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,13 @@
13321332
}],
13331333
]
13341334
}, # overlapped-checker
1335+
{
1336+
'target_name': 'nop',
1337+
'type': 'executable',
1338+
'sources': [
1339+
'test/nop/nop.c',
1340+
]
1341+
}, # nop
13351342
{
13361343
'target_name': 'node_js2c',
13371344
'type': 'executable',

test/nop/nop.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main(void) {
2+
return 0;
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const { skip, isWindows, isIBMi } = require('../common');
4+
const { fail } = require('assert');
5+
const { isMainThread } = require('worker_threads');
6+
const { dirname, join } = require('path');
7+
const { existsSync } = require('fs');
8+
9+
if (!isMainThread) {
10+
skip('process.execve is not available in Workers');
11+
} else if (isWindows || isIBMi) {
12+
skip('process.execve is not available in Windows or IBM i');
13+
}
14+
15+
// Get full path to the executable used for the test
16+
const executable = join(dirname(process.execPath), 'nop');
17+
18+
// Sanity check that the binary exists
19+
if (!existsSync(executable)) {
20+
skip(executable + ' binary is not available');
21+
}
22+
23+
process.execve(executable);
24+
// If process.execve succeeds, this should never be executed.
25+
fail('process.execve failed');

0 commit comments

Comments
 (0)