Skip to content

Commit fc2956d

Browse files
committed
process: backport process/methods file
To ease future backports, create the process/methods file introduced in #19973. This commit just adds the JS functions that forward calls to C++ and does not change type checking. PR-URL: #21172 Reviewed-By: Joyee Cheung <[email protected]>
1 parent fc0b361 commit fc2956d

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

lib/internal/bootstrap/node.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
NativeModule.require('internal/process/warning').setup();
4141
NativeModule.require('internal/process/next_tick').setup();
4242
NativeModule.require('internal/process/stdio').setup();
43+
NativeModule.require('internal/process/methods').setup();
4344

4445
const perf = process.binding('performance');
4546
const {

lib/internal/process/methods.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';
2+
3+
function setupProcessMethods() {
4+
// Non-POSIX platforms like Windows don't have certain methods.
5+
if (process.setgid !== undefined) {
6+
setupPosixMethods();
7+
}
8+
9+
const { chdir: _chdir, umask: _umask } = process;
10+
11+
process.chdir = chdir;
12+
process.umask = umask;
13+
14+
function chdir(...args) {
15+
return _chdir(...args);
16+
}
17+
18+
function umask(...args) {
19+
return _umask(...args);
20+
}
21+
}
22+
23+
function setupPosixMethods() {
24+
const {
25+
initgroups: _initgroups,
26+
setegid: _setegid,
27+
seteuid: _seteuid,
28+
setgid: _setgid,
29+
setuid: _setuid,
30+
setgroups: _setgroups
31+
} = process;
32+
33+
process.initgroups = initgroups;
34+
process.setegid = setegid;
35+
process.seteuid = seteuid;
36+
process.setgid = setgid;
37+
process.setuid = setuid;
38+
process.setgroups = setgroups;
39+
40+
function initgroups(...args) {
41+
return _initgroups(...args);
42+
}
43+
44+
function setegid(...args) {
45+
return _setegid(...args);
46+
}
47+
48+
function seteuid(...args) {
49+
return _seteuid(...args);
50+
}
51+
52+
function setgid(...args) {
53+
return _setgid(...args);
54+
}
55+
56+
function setuid(...args) {
57+
return _setuid(...args);
58+
}
59+
60+
function setgroups(...args) {
61+
return _setgroups(...args);
62+
}
63+
}
64+
65+
exports.setup = setupProcessMethods;

node.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
'lib/internal/net.js',
121121
'lib/internal/os.js',
122122
'lib/internal/process/esm_loader.js',
123+
'lib/internal/process/methods.js',
123124
'lib/internal/process/next_tick.js',
124125
'lib/internal/process/promises.js',
125126
'lib/internal/process/stdio.js',
File renamed without changes.

0 commit comments

Comments
 (0)