mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 17:44:15 +00:00

PR-URL: https://github.com/nodejs/node/pull/49654 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
50 lines
892 B
JavaScript
50 lines
892 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectDefineProperties,
|
|
Symbol,
|
|
} = primordials;
|
|
|
|
const {
|
|
ERR_ILLEGAL_CONSTRUCTOR,
|
|
} = require('internal/errors').codes;
|
|
|
|
const {
|
|
kEnumerableProperty,
|
|
} = require('internal/util');
|
|
|
|
const {
|
|
getAvailableParallelism,
|
|
} = internalBinding('os');
|
|
|
|
const kInitialize = Symbol('kInitialize');
|
|
|
|
class Navigator {
|
|
// Private properties are used to avoid brand validations.
|
|
#availableParallelism;
|
|
|
|
constructor() {
|
|
if (arguments[0] === kInitialize) {
|
|
return;
|
|
}
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
get hardwareConcurrency() {
|
|
this.#availableParallelism ??= getAvailableParallelism();
|
|
return this.#availableParallelism;
|
|
}
|
|
}
|
|
|
|
ObjectDefineProperties(Navigator.prototype, {
|
|
hardwareConcurrency: kEnumerableProperty,
|
|
});
|
|
|
|
module.exports = {
|
|
navigator: new Navigator(kInitialize),
|
|
Navigator,
|
|
};
|