mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
os: add machine method
PR-URL: https://github.com/nodejs/node/pull/44416 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
89c837a48d
commit
8f3e8bb1fd
4 files changed
+30
-7
No files matched your search
@@ -443,6 +443,22 @@ On POSIX systems, the operating system release is determined by calling
|
||||
available, `GetVersionExW()` will be used. See
|
||||
<https://en.wikipedia.org/wiki/Uname#Examples> for more information.
|
||||
|
||||
## `os.machine()`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Returns {string}
|
||||
|
||||
Returns the machine type as a string, such as `arm`, `aarch64`, `mips`,
|
||||
`mips64`, `ppc64`, `ppc64le`, `s390`, `s390x`, `i386`, `i686`, `x86_64`.
|
||||
|
||||
On POSIX systems, the machine type is determined by calling
|
||||
[`uname(3)`][]. On Windows, `RtlGetVersion()` is used, and if it is not
|
||||
available, `GetVersionExW()` will be used. See
|
||||
<https://en.wikipedia.org/wiki/Uname#Examples> for more information.
|
||||
|
||||
## OS constants
|
||||
|
||||
The following constants are exported by `os.constants`.
|
||||
|
||||
@@ -75,6 +75,7 @@ const {
|
||||
0: type,
|
||||
1: version,
|
||||
2: release,
|
||||
3: machine,
|
||||
} = _getOSInformation();
|
||||
|
||||
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
|
||||
@@ -94,12 +95,17 @@ const getOSType = () => type;
|
||||
* @returns {string}
|
||||
*/
|
||||
const getOSVersion = () => version;
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
const getMachine = () => machine;
|
||||
|
||||
getFreeMem[SymbolToPrimitive] = () => getFreeMem();
|
||||
getHostname[SymbolToPrimitive] = () => getHostname();
|
||||
getOSVersion[SymbolToPrimitive] = () => getOSVersion();
|
||||
getOSType[SymbolToPrimitive] = () => getOSType();
|
||||
getOSRelease[SymbolToPrimitive] = () => getOSRelease();
|
||||
getMachine[SymbolToPrimitive] = () => getMachine();
|
||||
getHomeDirectory[SymbolToPrimitive] = () => getHomeDirectory();
|
||||
getTotalMem[SymbolToPrimitive] = () => getTotalMem();
|
||||
getUptime[SymbolToPrimitive] = () => getUptime();
|
||||
@@ -369,7 +375,8 @@ module.exports = {
|
||||
type: getOSType,
|
||||
userInfo,
|
||||
uptime: getUptime,
|
||||
version: getOSVersion
|
||||
version: getOSVersion,
|
||||
machine: getMachine,
|
||||
};
|
||||
|
||||
ObjectDefineProperties(module.exports, {
|
||||
|
||||
+5
-5
@@ -86,12 +86,12 @@ static void GetOSInformation(const FunctionCallbackInfo<Value>& args) {
|
||||
return args.GetReturnValue().SetUndefined();
|
||||
}
|
||||
|
||||
// [sysname, version, release]
|
||||
// [sysname, version, release, machine]
|
||||
Local<Value> osInformation[] = {
|
||||
String::NewFromUtf8(env->isolate(), info.sysname).ToLocalChecked(),
|
||||
String::NewFromUtf8(env->isolate(), info.version).ToLocalChecked(),
|
||||
String::NewFromUtf8(env->isolate(), info.release).ToLocalChecked()
|
||||
};
|
||||
String::NewFromUtf8(env->isolate(), info.sysname).ToLocalChecked(),
|
||||
String::NewFromUtf8(env->isolate(), info.version).ToLocalChecked(),
|
||||
String::NewFromUtf8(env->isolate(), info.release).ToLocalChecked(),
|
||||
String::NewFromUtf8(env->isolate(), info.machine).ToLocalChecked()};
|
||||
|
||||
args.GetReturnValue().Set(Array::New(env->isolate(),
|
||||
osInformation,
|
||||
|
||||
@@ -245,7 +245,7 @@ assert.strictEqual(`${os.tmpdir}`, os.tmpdir());
|
||||
assert.strictEqual(`${os.arch}`, os.arch());
|
||||
assert.strictEqual(`${os.platform}`, os.platform());
|
||||
assert.strictEqual(`${os.version}`, os.version());
|
||||
|
||||
assert.strictEqual(`${os.machine}`, os.machine());
|
||||
assert.strictEqual(+os.totalmem, os.totalmem());
|
||||
|
||||
// Assert that the following values are coercible to numbers.
|
||||
|
||||
Reference in new issue
Block a user