@@ -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
}
0 commit comments