@@ -21,6 +21,7 @@ const {
2121 ReflectGetOwnPropertyDescriptor,
2222 ReflectOwnKeys,
2323 RegExpPrototypeSymbolReplace,
24+ SafeMap,
2425 StringPrototypeCharAt,
2526 StringPrototypeCharCodeAt,
2627 StringPrototypeCodePointAt,
@@ -225,7 +226,7 @@ class URLSearchParams {
225226 } else {
226227 // Record<USVString, USVString>
227228 // Need to use reflection APIs for full spec compliance.
228- const visited = { } ;
229+ const visited = new SafeMap ( ) ;
229230 const keys = ReflectOwnKeys ( init ) ;
230231 for ( let i = 0 ; i < keys . length ; i ++ ) {
231232 const key = keys [ i ] ;
@@ -234,14 +235,15 @@ class URLSearchParams {
234235 const typedKey = toUSVString ( key ) ;
235236 const typedValue = toUSVString ( init [ key ] ) ;
236237
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 ;
241243 } else {
242- visited [ typedKey ] = ArrayPrototypePush ( this [ searchParams ] ,
243- typedKey ,
244- typedValue ) - 1 ;
244+ visited . set ( typedKey , ArrayPrototypePush ( this [ searchParams ] ,
245+ typedKey ,
246+ typedValue ) - 1 ) ;
245247 }
246248 }
247249 }
0 commit comments