@@ -188,12 +188,7 @@ function onParseSearchComplete(flags, protocol, username, password,
188
188
if ( flags & binding . URL_FLAGS_FAILED )
189
189
return ;
190
190
const ctx = this [ context ] ;
191
- if ( query ) {
192
- ctx . query = query ;
193
- ctx . flags |= binding . URL_FLAGS_HAS_QUERY ;
194
- } else {
195
- ctx . flags &= ~ binding . URL_FLAGS_HAS_QUERY ;
196
- }
191
+ ctx . query = query ;
197
192
}
198
193
199
194
function onParseHashComplete ( flags , protocol , username , password ,
@@ -486,13 +481,15 @@ Object.defineProperties(URL.prototype, {
486
481
if ( ! search ) {
487
482
ctx . query = null ;
488
483
ctx . flags &= ~ binding . URL_FLAGS_HAS_QUERY ;
489
- this [ searchParams ] [ searchParams ] = { } ;
490
- return ;
484
+ } else {
485
+ if ( search [ 0 ] === '?' ) search = search . slice ( 1 ) ;
486
+ ctx . query = '' ;
487
+ ctx . flags |= binding . URL_FLAGS_HAS_QUERY ;
488
+ if ( search ) {
489
+ binding . parse ( search , binding . kQuery , null , ctx ,
490
+ onParseSearchComplete . bind ( this ) ) ;
491
+ }
491
492
}
492
- if ( search [ 0 ] === '?' ) search = search . slice ( 1 ) ;
493
- ctx . query = '' ;
494
- binding . parse ( search , binding . kQuery , null , ctx ,
495
- onParseSearchComplete . bind ( this ) ) ;
496
493
initSearchParams ( this [ searchParams ] , search ) ;
497
494
}
498
495
} ,
@@ -610,9 +607,11 @@ function update(url, params) {
610
607
}
611
608
}
612
609
613
- // Reused by the URL parse function invoked by
614
- // the href setter, and the URLSearchParams constructor
615
610
function initSearchParams ( url , init ) {
611
+ if ( ! init ) {
612
+ url [ searchParams ] = [ ] ;
613
+ return ;
614
+ }
616
615
url [ searchParams ] = getParamsFromObject ( querystring . parse ( init ) ) ;
617
616
}
618
617
0 commit comments