| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e17f665 commit e7513a8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,8 @@ function getNavigatorPlatform(arch, platform) { | |||
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | class Navigator { | |
| 82 | - // Private properties are used to avoid brand validations. | ||
| 82 | + // Private properties are used to avoid brand validations: reading a private | ||
| 83 | + // field from a non-Navigator receiver throws a TypeError on its own. | ||
| 83 | 84 | #availableParallelism; | |
| 84 | 85 | #locks; | |
| 85 | 86 | #userAgent; | |
@@ -113,6 +114,10 @@ class Navigator { | |||
| 113 | 114 | * @returns {string} | |
| 114 | 115 | */ | |
| 115 | 116 | get language() { | |
| 117 | + // `language` does not read a private field, so brand-check explicitly | ||
| 118 | + // to keep parity with the other getters when called on a non-Navigator | ||
| 119 | + // receiver (e.g. `Navigator.prototype.language`). | ||
| 120 | + this.#languages; // eslint-disable-line no-unused-expressions | ||
| 116 | 121 | // The default locale might be changed dynamically, so always invoke the | |
| 117 | 122 | // binding. | |
| 118 | 123 | return getDefaultLocale() || 'en-US'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,3 +147,19 @@ Object.defineProperty(navigator, 'language', { value: 'for-testing' }); | |||
| 147 | 147 | assert.strictEqual(navigator.language, 'for-testing'); | |
| 148 | 148 | assert.strictEqual(navigator.languages.length, 1); | |
| 149 | 149 | assert.strictEqual(navigator.languages[0] !== 'for-testing', true); | |
| 150 | + | ||
| 151 | + { | ||
| 152 | + const { Navigator } = globalThis; | ||
| 153 | + for (const name of Object.keys(Navigator.prototype)) { | ||
| 154 | + assert.throws( | ||
| 155 | + () => Navigator.prototype[name], | ||
| 156 | + { name: 'TypeError' }, | ||
| 157 | + `expected TypeError when reading ${name} on Navigator.prototype`, | ||
| 158 | + ); | ||
| 159 | + assert.throws( | ||
| 160 | + () => Reflect.get(Navigator.prototype, name, {}), | ||
| 161 | + { name: 'TypeError' }, | ||
| 162 | + `expected TypeError when reading ${name} on a plain object`, | ||
| 163 | + ); | ||
| 164 | + } | ||
| 165 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments