diff --git a/lib/os.js b/lib/os.js index c3bb404b2d776b..860348a472f325 100644 --- a/lib/os.js +++ b/lib/os.js @@ -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} */ diff --git a/src/node_os.cc b/src/node_os.cc index 9079faf887dc7a..4a3b9f608d702f 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -149,10 +149,15 @@ static void GetTotalMemory(const FunctionCallbackInfo& args) { static void GetUptime(const FunctionCallbackInfo& 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); }