diff options
author | Juan José Arboleda <soyjuanarbol@gmail.com> | 2020-03-10 06:18:03 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2020-03-11 00:58:46 +0300 |
commit | 258a80d3cc90a2f9fb4304822b8f2e729fa434a7 (patch) | |
tree | 6b7e766b5dbbfcd80137f04c172e07b0efd07ad8 /src/node_os.cc | |
parent | f2636598e86c5a5f258441f52d971af171fe4d91 (diff) |
src: create a getter for kernel version
Backport-PR-URL: https://github.com/nodejs/node/pull/32166
PR-URL: https://github.com/nodejs/node/pull/31732
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 12a4ec3551a..f84c0f216e3 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -76,7 +76,7 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) { } -static void GetOSType(const FunctionCallbackInfo<Value>& args) { +static void GetOSInformation(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); uv_utsname_t info; int err = uv_os_uname(&info); @@ -87,26 +87,16 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) { return args.GetReturnValue().SetUndefined(); } - args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), info.sysname, NewStringType::kNormal) - .ToLocalChecked()); -} - - -static void GetOSRelease(const FunctionCallbackInfo<Value>& args) { - Environment* env = Environment::GetCurrent(args); - uv_utsname_t info; - int err = uv_os_uname(&info); + // [sysname, version, release] + Local<Value> osInformation[] = { + String::NewFromUtf8(env->isolate(), info.sysname).ToLocalChecked(), + String::NewFromUtf8(env->isolate(), info.version).ToLocalChecked(), + String::NewFromUtf8(env->isolate(), info.release).ToLocalChecked() + }; - if (err != 0) { - CHECK_GE(args.Length(), 1); - env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_os_uname"); - return args.GetReturnValue().SetUndefined(); - } - - args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), info.release, NewStringType::kNormal) - .ToLocalChecked()); + args.GetReturnValue().Set(Array::New(env->isolate(), + osInformation, + arraysize(osInformation))); } @@ -398,8 +388,7 @@ void Initialize(Local<Object> target, env->SetMethod(target, "getTotalMem", GetTotalMemory); env->SetMethod(target, "getFreeMem", GetFreeMemory); env->SetMethod(target, "getCPUs", GetCPUInfo); - env->SetMethod(target, "getOSType", GetOSType); - env->SetMethod(target, "getOSRelease", GetOSRelease); + env->SetMethod(target, "getOSInformation", GetOSInformation); env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses); env->SetMethod(target, "getHomeDirectory", GetHomeDirectory); env->SetMethod(target, "getUserInfo", GetUserInfo); |