@@ -20,6 +20,7 @@ const {
2020 ReflectGetOwnPropertyDescriptor,
2121 ReflectOwnKeys,
2222 RegExpPrototypeSymbolReplace,
23+ SafeMap,
2324 StringPrototypeCharAt,
2425 StringPrototypeCharCodeAt,
2526 StringPrototypeCodePointAt,
@@ -243,7 +244,7 @@ class URLSearchParams {
243244 } else {
244245 // Record<USVString, USVString>
245246 // Need to use reflection APIs for full spec compliance.
246- const visited = { } ;
247+ const visited = new SafeMap ( ) ;
247248 const keys = ReflectOwnKeys ( init ) ;
248249 for ( let i = 0 ; i < keys . length ; i ++ ) {
249250 const key = keys [ i ] ;
@@ -252,14 +253,15 @@ class URLSearchParams {
252253 const typedKey = toUSVString ( key ) ;
253254 const typedValue = toUSVString ( init [ key ] ) ;
254255
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 ;
259261 } else {
260- visited [ typedKey ] = ArrayPrototypePush ( this [ searchParams ] ,
261- typedKey ,
262- typedValue ) - 1 ;
262+ visited . set ( typedKey , ArrayPrototypePush ( this [ searchParams ] ,
263+ typedKey ,
264+ typedValue ) - 1 ) ;
263265 }
264266 }
265267 }
0 commit comments