From fc2956d37a75bd51de6392378ae59b0aeae0105e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 6 Jun 2018 15:05:20 +0200 Subject: [PATCH] process: backport process/methods file To ease future backports, create the process/methods file introduced in https://github.com/nodejs/node/pull/19973. This commit just adds the JS functions that forward calls to C++ and does not change type checking. PR-URL: https://github.com/nodejs/node/pull/21172 Reviewed-By: Joyee Cheung --- lib/internal/bootstrap/node.js | 1 + lib/internal/process/methods.js | 65 +++++++++++++++++++ node.gyp | 1 + .../{test-umask.js => test-process-umask.js} | 0 4 files changed, 67 insertions(+) create mode 100644 lib/internal/process/methods.js rename test/parallel/{test-umask.js => test-process-umask.js} (100%) 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