mirror of
https://github.com/nodejs/node.git
synced 2025-05-22 15:25:51 +00:00

Co-authored-by: Mestery <mestery@protonmail.com> Co-authored-by: Voltrex <mohammadkeyvanzade94@gmail.com> PR-URL: https://github.com/nodejs/node/pull/47769 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
50 lines
888 B
JavaScript
50 lines
888 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 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,
|
|
};
|