Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const {
},
hideStackFrames,
} = require('internal/errors');
const { getCIDR } = require('internal/util');
const {
assignFunctionName,
getCIDR,
} = require('internal/util');
const { validateInt32 } = require('internal/validators');

const {
Expand All @@ -59,15 +62,15 @@ const {
setPriority: _setPriority,
} = internalBinding('os');

function getCheckedFunction(fn) {
return hideStackFrames(function checkError() {
function getCheckedFunction(fn, name) {
return assignFunctionName(name, hideStackFrames(function checkError() {
const ctx = {};
const ret = fn(ctx);
if (ret === undefined) {
throw new ERR_SYSTEM_ERROR.HideStackFramesError(ctx);
}
return ret;
});
}));
}

const {
Expand All @@ -77,10 +80,10 @@ const {
3: machine,
} = _getOSInformation();

const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
const getHostname = getCheckedFunction(_getHostname);
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
const getUptime = getCheckedFunction(_getUptime);
const getHomeDirectory = getCheckedFunction(_getHomeDirectory, 'getHomeDirectory');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run benchmarks on these changes?

const getHostname = getCheckedFunction(_getHostname, 'getHostname');
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses, 'getInterfaceAddresses');
const getUptime = getCheckedFunction(_getUptime, 'getUptime');

/**
* @returns {string}
Expand Down
Loading