@@ -21,6 +21,7 @@ const {
21
21
ReflectGetOwnPropertyDescriptor,
22
22
ReflectOwnKeys,
23
23
RegExpPrototypeSymbolReplace,
24
+ SafeMap,
24
25
StringPrototypeCharAt,
25
26
StringPrototypeCharCodeAt,
26
27
StringPrototypeCodePointAt,
@@ -225,7 +226,7 @@ class URLSearchParams {
225
226
} else {
226
227
// Record<USVString, USVString>
227
228
// Need to use reflection APIs for full spec compliance.
228
- const visited = { } ;
229
+ const visited = new SafeMap ( ) ;
229
230
const keys = ReflectOwnKeys ( init ) ;
230
231
for ( let i = 0 ; i < keys . length ; i ++ ) {
231
232
const key = keys [ i ] ;
@@ -234,14 +235,15 @@ class URLSearchParams {
234
235
const typedKey = toUSVString ( key ) ;
235
236
const typedValue = toUSVString ( init [ key ] ) ;
236
237
237
- // Two different key may result same after `toUSVString()`, we only
238
- // leave the later one. Refers to WPT.
239
- if ( visited [ typedKey ] !== undefined ) {
240
- this [ searchParams ] [ visited [ typedKey ] ] = typedValue ;
238
+ // Two different keys may become the same USVString after normalization.
239
+ // In that case, we retain the later one. Refer to WPT.
240
+ const keyIdx = visited . get ( typedKey ) ;
241
+ if ( keyIdx !== undefined ) {
242
+ this [ searchParams ] [ keyIdx ] = typedValue ;
241
243
} else {
242
- visited [ typedKey ] = ArrayPrototypePush ( this [ searchParams ] ,
243
- typedKey ,
244
- typedValue ) - 1 ;
244
+ visited . set ( typedKey , ArrayPrototypePush ( this [ searchParams ] ,
245
+ typedKey ,
246
+ typedValue ) - 1 ) ;
245
247
}
246
248
}
247
249
}
0 commit comments