diff options
author | Juan José Arboleda <soyjuanarbol@gmail.com> | 2020-02-11 10:38:24 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-03-09 14:44:16 +0300 |
commit | c1e672595f230d7e41ede5a96d778ada1c1e71ac (patch) | |
tree | 87d88e04804ccbc28818cd9c37981d9a308a80f2 /src/node_os.cc | |
parent | 0a539ddc0ad53c609199465dcb85008811e57bd2 (diff) |
src: create a getter for kernel version
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 | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 12a4ec3551a..b64b75fa6b9 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -75,8 +75,7 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) { .ToLocalChecked()); } - -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,29 +86,18 @@ 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); - - if (err != 0) { - CHECK_GE(args.Length(), 1); - env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_os_uname"); - return args.GetReturnValue().SetUndefined(); - } + // [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() + }; - args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), info.release, NewStringType::kNormal) - .ToLocalChecked()); + args.GetReturnValue().Set(Array::New(env->isolate(), + osInformation, + arraysize(osInformation))); } - static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); @@ -398,13 +386,12 @@ 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, "getInterfaceAddresses", GetInterfaceAddresses); env->SetMethod(target, "getHomeDirectory", GetHomeDirectory); env->SetMethod(target, "getUserInfo", GetUserInfo); env->SetMethod(target, "setPriority", SetPriority); env->SetMethod(target, "getPriority", GetPriority); + env->SetMethod(target, "getOSInformation", GetOSInformation); target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"), Boolean::New(env->isolate(), IsBigEndian())).Check(); |