Skip to content

Commit 3d2f919

Browse files
mureinikaduh95
authored andcommitted
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 PR-URL: #58412 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 5457c7a commit 3d2f919

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
returntrue;
280280
}
281281

282-
functionexecve(execPath,args,env){
282+
functionexecve(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
@@ -1336,6 +1336,13 @@
13361336
}],
13371337
]
13381338
}, # overlapped-checker
1339+
{
1340+
'target_name': 'nop',
1341+
'type': 'executable',
1342+
'sources': [
1343+
'test/nop/nop.c',
1344+
]
1345+
}, # nop
13391346
{
13401347
'target_name': 'node_js2c',
13411348
'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+
intmain(void){
2+
return0;
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+
}elseif(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+
constexecutable=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)