Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/internal/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ function getNavigatorPlatform(arch, platform) {
}

class Navigator {
// Private properties are used to avoid brand validations.
// Private properties are used to avoid brand validations: reading a private
// field from a non-Navigator receiver throws a TypeError on its own.
#availableParallelism;
#locks;
#userAgent;
Expand Down Expand Up @@ -113,6 +114,10 @@ class Navigator {
* @returns {string}
*/
get language() {
// `language` does not read a private field, so brand-check explicitly
// to keep parity with the other getters when called on a non-Navigator
// receiver (e.g. `Navigator.prototype.language`).
this.#languages; // eslint-disable-line no-unused-expressions
// The default locale might be changed dynamically, so always invoke the
// binding.
return getDefaultLocale() || 'en-US';
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,19 @@ Object.defineProperty(navigator, 'language', { value: 'for-testing' });
assert.strictEqual(navigator.language, 'for-testing');
assert.strictEqual(navigator.languages.length, 1);
assert.strictEqual(navigator.languages[0] !== 'for-testing', true);

{
const { Navigator } = globalThis;
for (const name of Object.keys(Navigator.prototype)) {
assert.throws(
() => Navigator.prototype[name],
{ name: 'TypeError' },
`expected TypeError when reading ${name} on Navigator.prototype`,
);
assert.throws(
() => Reflect.get(Navigator.prototype, name, {}),
{ name: 'TypeError' },
`expected TypeError when reading ${name} on a plain object`,
);
}
}
Loading