lib: make navigator not runtime-lookup process.version/arch/platform · nodejs/node@f57d3ce · GitHub
Skip to content

Commit f57d3ce

Browse files
ljharbaduh95
authored andcommitted
lib: make navigator not runtime-lookup process.version/arch/platform
Preserves #53649. PR-URL: #53765 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 19488fd commit f57d3ce

5 files changed

Lines changed: 99 additions & 54 deletions

File tree

lib/internal/navigator.js

Lines changed: 34 additions & 33 deletions

lib/internal/process/per_thread.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ const {
4646
validateNumber,
4747
validateObject,
4848
} = require('internal/validators');
49-
const { getValidatedPath } = require('internal/fs/utils');
49+
5050
const constants = internalBinding('constants').os.signals;
5151

52+
let getValidatedPath; // We need to lazy load it because of the circular dependency.
53+
5254
const kInternal = Symbol('internal properties');
5355

5456
function assert(x, msg) {
@@ -253,6 +255,7 @@ function wrapProcessMethods(binding) {
253255
*/
254256
function loadEnvFile(path = undefined) { // Provide optional value so that `loadEnvFile.length` returns 0
255257
if (path != null) {
258+
getValidatedPath ??= require('internal/fs/utils').getValidatedPath;
256259
path = getValidatedPath(path);
257260
_loadEnvFile(path);
258261
} else {
@@ -421,11 +424,16 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
421424
}
422425
}
423426

427+
const { arch, platform, version } = process;
428+
424429
module.exports = {
425430
toggleTraceCategoryState,
426431
assert,
427432
buildAllowedFlags,
428433
wrapProcessMethods,
429434
hrtime,
430435
hrtimeBigInt,
436+
arch,
437+
platform,
438+
version,
431439
};

lib/internal/process/pre_execution.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const {
2121
globalThis,
2222
} = primordials;
2323

24+
const {
25+
Intl,
26+
} = globalThis;
27+
2428
const {
2529
getOptionValue,
2630
refreshOptions,
@@ -341,6 +345,7 @@ function setupNavigator() {
341345

342346
// https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object
343347
exposeLazyInterfaces(globalThis, 'internal/navigator', ['Navigator']);
348+
internalBinding('config').language = Intl?.Collator().resolvedOptions().locale || 'en-US';
344349
defineReplaceableLazyAttribute(globalThis, 'internal/navigator', ['navigator'], false);
345350
}
346351

lib/internal/url.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const {
4949
isWindows,
5050
} = require('internal/util');
5151

52+
const {
53+
platform,
54+
} = require('internal/process/per_thread');
55+
5256
const {
5357
markTransferMode,
5458
} = require('internal/worker/js_transferable');
@@ -1469,7 +1473,7 @@ function getPathFromURLWin32(url) {
14691473

14701474
function getPathFromURLPosix(url) {
14711475
if (url.hostname !== '') {
1472-
throw new ERR_INVALID_FILE_URL_HOST(process.platform);
1476+
throw new ERR_INVALID_FILE_URL_HOST(platform);
14731477
}
14741478
const pathname = url.pathname;
14751479
for (let n = 0; n < pathname.length; n++) {

test/parallel/test-navigator.js

Lines changed: 46 additions & 19 deletions

0 commit comments

Comments
 (0)