Skip to content

Commit

Permalink
process: backport process/methods file
Browse files Browse the repository at this point in the history
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 <joyeec9h3@gmail.com>
  • Loading branch information
targos committed Jun 13, 2018
1 parent fc0b361 commit fc2956d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
65 changes: 65 additions & 0 deletions lib/internal/process/methods.js
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.

0 comments on commit fc2956d

Please sign in to comment.