diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 4d95529c4b58e6..d6fd67fe5d2c85 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -40,6 +40,7 @@ NativeModule.require('internal/process/warning').setup(); NativeModule.require('internal/process/next_tick').setup(); NativeModule.require('internal/process/stdio').setup(); + NativeModule.require('internal/process/methods').setup(); const perf = process.binding('performance'); const { diff --git a/lib/internal/process/methods.js b/lib/internal/process/methods.js new file mode 100644 index 00000000000000..1a720c5cb0e5e4 --- /dev/null +++ b/lib/internal/process/methods.js @@ -0,0 +1,65 @@ +'use strict'; + +function setupProcessMethods() { + // Non-POSIX platforms like Windows don't have certain methods. + if (process.setgid !== undefined) { + setupPosixMethods(); + } + + const { chdir: _chdir, umask: _umask } = process; + + process.chdir = chdir; + process.umask = umask; + + function chdir(...args) { + return _chdir(...args); + } + + function umask(...args) { + return _umask(...args); + } +} + +function setupPosixMethods() { + const { + initgroups: _initgroups, + setegid: _setegid, + seteuid: _seteuid, + setgid: _setgid, + setuid: _setuid, + setgroups: _setgroups + } = process; + + process.initgroups = initgroups; + process.setegid = setegid; + process.seteuid = seteuid; + process.setgid = setgid; + process.setuid = setuid; + process.setgroups = setgroups; + + function initgroups(...args) { + return _initgroups(...args); + } + + function setegid(...args) { + return _setegid(...args); + } + + function seteuid(...args) { + return _seteuid(...args); + } + + function setgid(...args) { + return _setgid(...args); + } + + function setuid(...args) { + return _setuid(...args); + } + + function setgroups(...args) { + return _setgroups(...args); + } +} + +exports.setup = setupProcessMethods; diff --git a/node.gyp b/node.gyp index 19367d9bd9517d..7bcc17ce843798 100644 --- a/node.gyp +++ b/node.gyp @@ -120,6 +120,7 @@ 'lib/internal/net.js', 'lib/internal/os.js', 'lib/internal/process/esm_loader.js', + 'lib/internal/process/methods.js', 'lib/internal/process/next_tick.js', 'lib/internal/process/promises.js', 'lib/internal/process/stdio.js', diff --git a/test/parallel/test-umask.js b/test/parallel/test-process-umask.js similarity index 100% rename from test/parallel/test-umask.js rename to test/parallel/test-process-umask.js