mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
PR-URL: https://github.com/nodejs/node/pull/50467 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
62 lines
1.2 KiB
JavaScript
62 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectDefineProperties,
|
|
StringPrototypeIndexOf,
|
|
StringPrototypeSlice,
|
|
Symbol,
|
|
} = primordials;
|
|
|
|
const {
|
|
ERR_ILLEGAL_CONSTRUCTOR,
|
|
} = require('internal/errors').codes;
|
|
|
|
const {
|
|
kEnumerableProperty,
|
|
} = require('internal/util');
|
|
|
|
const {
|
|
getAvailableParallelism,
|
|
} = internalBinding('os');
|
|
|
|
const kInitialize = Symbol('kInitialize');
|
|
const nodeVersion = process.version;
|
|
|
|
class Navigator {
|
|
// Private properties are used to avoid brand validations.
|
|
#availableParallelism;
|
|
#userAgent = `Node.js/${StringPrototypeSlice(nodeVersion, 1, StringPrototypeIndexOf(nodeVersion, '.'))}`;
|
|
|
|
constructor() {
|
|
if (arguments[0] === kInitialize) {
|
|
return;
|
|
}
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
get hardwareConcurrency() {
|
|
this.#availableParallelism ??= getAvailableParallelism();
|
|
return this.#availableParallelism;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
get userAgent() {
|
|
return this.#userAgent;
|
|
}
|
|
}
|
|
|
|
ObjectDefineProperties(Navigator.prototype, {
|
|
hardwareConcurrency: kEnumerableProperty,
|
|
userAgent: kEnumerableProperty,
|
|
});
|
|
|
|
module.exports = {
|
|
navigator: new Navigator(kInitialize),
|
|
Navigator,
|
|
};
|