mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: add error handling to uv_uptime call
PR-URL: https://github.com/nodejs/node/pull/44386 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -55,7 +55,7 @@ const {
|
||||
getOSInformation: _getOSInformation,
|
||||
getTotalMem,
|
||||
getUserInfo,
|
||||
getUptime,
|
||||
getUptime: _getUptime,
|
||||
isBigEndian,
|
||||
setPriority: _setPriority
|
||||
} = internalBinding('os');
|
||||
@@ -81,6 +81,8 @@ const {
|
||||
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
|
||||
const getHostname = getCheckedFunction(_getHostname);
|
||||
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
|
||||
const getUptime = getCheckedFunction(_getUptime);
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
@@ -149,10 +149,15 @@ static void GetTotalMemory(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
|
||||
static void GetUptime(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
double uptime;
|
||||
int err = uv_uptime(&uptime);
|
||||
if (err == 0)
|
||||
args.GetReturnValue().Set(uptime);
|
||||
if (err != 0) {
|
||||
env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_uptime");
|
||||
return args.GetReturnValue().SetUndefined();
|
||||
}
|
||||
|
||||
args.GetReturnValue().Set(uptime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user