From b40f0c30743aaecd57071f7be305df43e1083817 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 4 Jul 2023 18:55:34 -0400 Subject: [PATCH] lib: add `navigator.hardwareConcurrency` Co-authored-by: Mestery Co-authored-by: Voltrex PR-URL: https://github.com/nodejs/node/pull/47769 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina Reviewed-By: Moshe Atlow --- .eslintrc.js | 1 + doc/api/globals.md | 37 ++++++++++++++ lib/.eslintrc.yaml | 4 ++ .../bootstrap/web/exposed-window-or-worker.js | 6 ++- lib/internal/navigator.js | 49 +++++++++++++++++++ test/common/index.js | 8 +++ test/parallel/test-global.js | 1 + test/parallel/test-navigator.js | 15 ++++++ 8 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 lib/internal/navigator.js create mode 100644 test/parallel/test-navigator.js diff --git a/.eslintrc.js b/.eslintrc.js index 5a63c79371c984..43e41026b2007e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -328,6 +328,7 @@ module.exports = { DecompressionStream: 'readable', fetch: 'readable', FormData: 'readable', + navigator: 'readable', ReadableStream: 'readable', ReadableStreamDefaultReader: 'readable', ReadableStreamBYOBReader: 'readable', diff --git a/doc/api/globals.md b/doc/api/globals.md index 8285064c2e25e4..83aa62c86ea790 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -583,6 +583,41 @@ The `MessagePort` class. See [`MessagePort`][] for more details. This variable may appear to be global but is not. See [`module`][]. +## `Navigator` + + + +> Stability: 1 - Experimental + +An implementation of the [Navigator API][]. + +## `navigator` + + + +> Stability: 1 - Experimental + +An implementation of [`window.navigator`][]. + +### `navigator.hardwareConcurrency` + + + +* {number} + +The `navigator.hardwareConcurrency` read-only property returns the number of +logical processors available to the current Node.js instance. + +```js +console.log(`This process is running on ${navigator.hardwareConcurrency}`); +``` + ## `PerformanceEntry`