mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
os: don't use getCheckedFunction() in userInfo()
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: https://github.com/nodejs/node/pull/22609 Refs: https://github.com/nodejs/node/pull/22599 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
18
lib/os.js
18
lib/os.js
@@ -40,7 +40,7 @@ const {
|
||||
getOSType: _getOSType,
|
||||
getPriority: _getPriority,
|
||||
getTotalMem,
|
||||
getUserInfo: _getUserInfo,
|
||||
getUserInfo,
|
||||
getUptime,
|
||||
isBigEndian,
|
||||
setPriority: _setPriority
|
||||
@@ -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();
|
||||
@@ -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,
|
||||
@@ -255,7 +267,7 @@ module.exports = {
|
||||
tmpdir,
|
||||
totalmem: getTotalMem,
|
||||
type: getOSType,
|
||||
userInfo: getUserInfo,
|
||||
userInfo,
|
||||
uptime: getUptime,
|
||||
|
||||
// Deprecated APIs
|
||||
|
||||
Reference in New Issue
Block a user