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:
Juan José Arboleda
2022-08-24 17:21:42 -05:00
parent fc9d44c8ac
commit 7ee8bfe1cd
2 changed files with 10 additions and 3 deletions

View File

@@ -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}
*/

View File

@@ -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);
}