GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: use primordials for navigator.userAgent · nodejs/node@48dbde7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • navigator.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/navigator.js‎

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
const {
4+
ObjectDefineProperties,
5+
StringPrototypeIndexOf,
6+
StringPrototypeSlice,
7+
Symbol,
8+
} = primordials;
9+
10+
const {
11+
ERR_ILLEGAL_CONSTRUCTOR,
12+
} = require('internal/errors').codes;
13+
14+
const {
15+
kEnumerableProperty,
16+
} = require('internal/util');
17+
18+
const {
19+
getAvailableParallelism,
20+
} = internalBinding('os');
21+
22+
const kInitialize = Symbol('kInitialize');
23+
const nodeVersion = process.version;
24+
25+
class Navigator {
26+
// Private properties are used to avoid brand validations.
27+
#availableParallelism;
28+
#userAgent = `Node.js/${StringPrototypeSlice(nodeVersion, 1, StringPrototypeIndexOf(nodeVersion, '.'))}`;
29+
30+
constructor() {
31+
if (arguments[0] === kInitialize) {
32+
return;
33+
}
34+
throw new ERR_ILLEGAL_CONSTRUCTOR();
35+
}
36+
37+
/**
38+
* @return {number}
39+
*/
40+
get hardwareConcurrency() {
41+
this.#availableParallelism ??= getAvailableParallelism();
42+
return this.#availableParallelism;
43+
}
44+
45+
/**
46+
* @return {string}
47+
*/
48+
get userAgent() {
49+
return this.#userAgent;
50+
}
51+
}
52+
53+
ObjectDefineProperties(Navigator.prototype, {
54+
hardwareConcurrency: kEnumerableProperty,
55+
userAgent: kEnumerableProperty,
56+
});
57+
58+
module.exports = {
59+
navigator: new Navigator(kInitialize),
60+
Navigator,
61+
};

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.