Skip to content

Commit

Permalink
os: don't use getCheckedFunction() in userInfo()
Browse files Browse the repository at this point in the history
os.userInfo() takes an optional object as its first argument.
getCheckedFunction() adds a context object to the argument list
passed to the binding layer. The context object has the potential
to confuse the binding layer, particularly if an error occurs.
This commit makes userInfo() explicitly call into the binding
layer with two arguments.

PR-URL: #22609
Refs: #22599
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Sep 3, 2018
1 parent cb15017 commit ad0072a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const {
getOSType: _getOSType,
getPriority: _getPriority,
getTotalMem,
getUserInfo: _getUserInfo,
getUserInfo,
getUptime,
isBigEndian,
setPriority: _setPriority
Expand All @@ -64,7 +64,6 @@ const getHostname = getCheckedFunction(_getHostname);
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
const getOSRelease = getCheckedFunction(_getOSRelease);
const getOSType = getCheckedFunction(_getOSType);
const getUserInfo = getCheckedFunction(_getUserInfo);

getFreeMem[Symbol.toPrimitive] = () => getFreeMem();
getHostname[Symbol.toPrimitive] = () => getHostname();
Expand Down Expand Up @@ -239,6 +238,19 @@ function getPriority(pid) {
return priority;
}

function userInfo(options) {
if (typeof options !== 'object')
options = null;

const ctx = {};
const user = getUserInfo(options, ctx);

if (user === undefined)
throw new ERR_SYSTEM_ERROR(ctx);

return user;
}

module.exports = {
arch,
cpus,
Expand All @@ -255,7 +267,7 @@ module.exports = {
tmpdir,
totalmem: getTotalMem,
type: getOSType,
userInfo: getUserInfo,
userInfo,
uptime: getUptime,

// Deprecated APIs
Expand Down

0 comments on commit ad0072a

Please sign in to comment.