-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: make navigator not runtime-lookup process.version/arch/platform
Preserves most of #53649, except for `#language` due to the lack of Intl primordials.
- Loading branch information
Showing
7 changed files
with
101 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,52 +27,54 @@ const { | |
} = internalBinding('os'); | ||
|
||
const kInitialize = Symbol('kInitialize'); | ||
const nodeVersion = process.version; | ||
const nodeVersion = require('internal/process/version'); | ||
const platform = require('internal/process/platform'); | ||
const arch = require('internal/process/arch'); | ||
|
||
/** | ||
* @param {object} process | ||
Check warning on line 35 in lib/internal/navigator.js GitHub Actions / lint-js-and-md
|
||
* @param {string} process.platform | ||
* @param {string} process.arch | ||
* @returns {string} | ||
*/ | ||
function getNavigatorPlatform(process) { | ||
if (process.platform === 'darwin') { | ||
function getNavigatorPlatform(arch, platform) { | ||
if (platform === 'darwin') { | ||
// On macOS, modern browsers return 'MacIntel' even if running on Apple Silicon. | ||
return 'MacIntel'; | ||
} else if (process.platform === 'win32') { | ||
} else if (platform === 'win32') { | ||
// On Windows, modern browsers return 'Win32' even if running on a 64-bit version of Windows. | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#usage_notes | ||
return 'Win32'; | ||
} else if (process.platform === 'linux') { | ||
if (process.arch === 'ia32') { | ||
} else if (platform === 'linux') { | ||
if (arch === 'ia32') { | ||
return 'Linux i686'; | ||
} else if (process.arch === 'x64') { | ||
} else if (arch === 'x64') { | ||
return 'Linux x86_64'; | ||
} | ||
return `Linux ${process.arch}`; | ||
} else if (process.platform === 'freebsd') { | ||
if (process.arch === 'ia32') { | ||
return `Linux ${arch}`; | ||
} else if (platform === 'freebsd') { | ||
if (arch === 'ia32') { | ||
return 'FreeBSD i386'; | ||
} else if (process.arch === 'x64') { | ||
} else if (arch === 'x64') { | ||
return 'FreeBSD amd64'; | ||
} | ||
return `FreeBSD ${process.arch}`; | ||
} else if (process.platform === 'openbsd') { | ||
if (process.arch === 'ia32') { | ||
return `FreeBSD ${arch}`; | ||
} else if (platform === 'openbsd') { | ||
if (arch === 'ia32') { | ||
return 'OpenBSD i386'; | ||
} else if (process.arch === 'x64') { | ||
} else if (arch === 'x64') { | ||
return 'OpenBSD amd64'; | ||
} | ||
return `OpenBSD ${process.arch}`; | ||
} else if (process.platform === 'sunos') { | ||
if (process.arch === 'ia32') { | ||
return `OpenBSD ${arch}`; | ||
} else if (platform === 'sunos') { | ||
if (arch === 'ia32') { | ||
return 'SunOS i86pc'; | ||
} | ||
return `SunOS ${process.arch}`; | ||
} else if (process.platform === 'aix') { | ||
return `SunOS ${arch}`; | ||
} else if (platform === 'aix') { | ||
return 'AIX'; | ||
} | ||
return `${StringPrototypeToUpperCase(process.platform[0])}${StringPrototypeSlice(process.platform, 1)} ${process.arch}`; | ||
return `${StringPrototypeToUpperCase(platform[0])}${StringPrototypeSlice(platform, 1)} ${arch}`; | ||
} | ||
|
||
class Navigator { | ||
|
@@ -126,7 +128,7 @@ class Navigator { | |
* @return {string} | ||
*/ | ||
get platform() { | ||
this.#platform ??= getNavigatorPlatform(process); | ||
this.#platform ??= getNavigatorPlatform(arch, platform); | ||
return this.#platform; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('process').arch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('process').platform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('process').version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters