| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4b52727 commit e727eb0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ const { | |||
| 20 | 20 | ReflectGetOwnPropertyDescriptor, | |
| 21 | 21 | ReflectOwnKeys, | |
| 22 | 22 | RegExpPrototypeSymbolReplace, | |
| 23 | + SafeMap, | ||
| 23 | 24 | StringPrototypeCharAt, | |
| 24 | 25 | StringPrototypeCharCodeAt, | |
| 25 | 26 | StringPrototypeCodePointAt, | |
@@ -243,7 +244,7 @@ class URLSearchParams { | |||
| 243 | 244 | } else { | |
| 244 | 245 | // Record<USVString, USVString> | |
| 245 | 246 | // Need to use reflection APIs for full spec compliance. | |
| 246 | - const visited = {}; | ||
| 247 | + const visited = new SafeMap(); | ||
| 247 | 248 | const keys = ReflectOwnKeys(init); | |
| 248 | 249 | for (let i = 0; i < keys.length; i++) { | |
| 249 | 250 | const key = keys[i]; | |
@@ -252,14 +253,15 @@ class URLSearchParams { | |||
| 252 | 253 | const typedKey = toUSVString(key); | |
| 253 | 254 | const typedValue = toUSVString(init[key]); | |
| 254 | 255 | ||
| 255 | - // Two different key may result same after `toUSVString()`, we only | ||
| 256 | - // leave the later one. Refers to WPT. | ||
| 257 | - if (visited[typedKey] !== undefined) { | ||
| 258 | - this[searchParams][visited[typedKey]] = typedValue; | ||
| 256 | + // Two different keys may become the same USVString after normalization. | ||
| 257 | + // In that case, we retain the later one. Refer to WPT. | ||
| 258 | + const keyIdx = visited.get(typedKey); | ||
| 259 | + if (keyIdx !== undefined) { | ||
| 260 | + this[searchParams][keyIdx] = typedValue; | ||
| 259 | 261 | } else { | |
| 260 | - visited[typedKey] = ArrayPrototypePush(this[searchParams], | ||
| 261 | - typedKey, | ||
| 262 | - typedValue) - 1; | ||
| 262 | + visited.set(typedKey, ArrayPrototypePush(this[searchParams], | ||
| 263 | + typedKey, | ||
| 264 | + typedValue) - 1); | ||
| 263 | 265 | } | |
| 264 | 266 | } | |
| 265 | 267 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,8 +38,13 @@ function makeIterableFunc(array) { | |||
| 38 | 38 | makeIterableFunc([['key', 'val'], ['key2', 'val2']].map(makeIterableFunc)) | |
| 39 | 39 | ); | |
| 40 | 40 | assert.strictEqual(params.toString(), 'key=val&key2=val2'); | |
| 41 | + params = new URLSearchParams({ hasOwnProperty: 1 }); | ||
| 42 | + assert.strictEqual(params.get('hasOwnProperty'), '1'); | ||
| 43 | + assert.strictEqual(params.toString(), 'hasOwnProperty=1'); | ||
| 41 | 44 | assert.throws(() => new URLSearchParams([[1]]), tupleError); | |
| 42 | 45 | assert.throws(() => new URLSearchParams([[1, 2, 3]]), tupleError); | |
| 46 | + assert.throws(() => new URLSearchParams({ [Symbol('test')]: 42 }), | ||
| 47 | + TypeError); | ||
| 43 | 48 | assert.throws(() => new URLSearchParams({ [Symbol.iterator]: 42 }), | |
| 44 | 49 | iterableError); | |
| 45 | 50 | assert.throws(() => new URLSearchParams([{}]), tupleError); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments