@@ -179,6 +179,10 @@ class URLContext {
179
179
}
180
180
}
181
181
182
+ function isURLSearchParams ( self ) {
183
+ return self && self [ searchParams ] && ! self [ searchParams ] [ searchParams ] ;
184
+ }
185
+
182
186
class URLSearchParams {
183
187
// URL Standard says the default value is '', but as undefined and '' have
184
188
// the same result, undefined is used to prevent unnecessary parsing.
@@ -248,9 +252,8 @@ class URLSearchParams {
248
252
}
249
253
250
254
[ inspect . custom ] ( recurseTimes , ctx ) {
251
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
255
+ if ( ! isURLSearchParams ( this ) )
252
256
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
253
- }
254
257
255
258
if ( typeof recurseTimes === 'number' && recurseTimes < 0 )
256
259
return ctx . stylize ( '[Object]' , 'special' ) ;
@@ -285,9 +288,9 @@ class URLSearchParams {
285
288
}
286
289
287
290
append ( name , value ) {
288
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
291
+ if ( ! isURLSearchParams ( this ) )
289
292
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
290
- }
293
+
291
294
if ( arguments . length < 2 ) {
292
295
throw new ERR_MISSING_ARGS ( 'name' , 'value' ) ;
293
296
}
@@ -299,9 +302,9 @@ class URLSearchParams {
299
302
}
300
303
301
304
delete ( name ) {
302
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
305
+ if ( ! isURLSearchParams ( this ) )
303
306
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
304
- }
307
+
305
308
if ( arguments . length < 1 ) {
306
309
throw new ERR_MISSING_ARGS ( 'name' ) ;
307
310
}
@@ -320,9 +323,9 @@ class URLSearchParams {
320
323
}
321
324
322
325
get ( name ) {
323
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
326
+ if ( ! isURLSearchParams ( this ) )
324
327
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
325
- }
328
+
326
329
if ( arguments . length < 1 ) {
327
330
throw new ERR_MISSING_ARGS ( 'name' ) ;
328
331
}
@@ -338,9 +341,9 @@ class URLSearchParams {
338
341
}
339
342
340
343
getAll ( name ) {
341
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
344
+ if ( ! isURLSearchParams ( this ) )
342
345
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
343
- }
346
+
344
347
if ( arguments . length < 1 ) {
345
348
throw new ERR_MISSING_ARGS ( 'name' ) ;
346
349
}
@@ -357,9 +360,9 @@ class URLSearchParams {
357
360
}
358
361
359
362
has ( name ) {
360
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
363
+ if ( ! isURLSearchParams ( this ) )
361
364
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
362
- }
365
+
363
366
if ( arguments . length < 1 ) {
364
367
throw new ERR_MISSING_ARGS ( 'name' ) ;
365
368
}
@@ -375,9 +378,9 @@ class URLSearchParams {
375
378
}
376
379
377
380
set ( name , value ) {
378
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
381
+ if ( ! isURLSearchParams ( this ) )
379
382
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
380
- }
383
+
381
384
if ( arguments . length < 2 ) {
382
385
throw new ERR_MISSING_ARGS ( 'name' , 'value' ) ;
383
386
}
@@ -462,17 +465,16 @@ class URLSearchParams {
462
465
// Define entries here rather than [Symbol.iterator] as the function name
463
466
// must be set to `entries`.
464
467
entries ( ) {
465
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
468
+ if ( ! isURLSearchParams ( this ) )
466
469
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
467
- }
468
470
469
471
return createSearchParamsIterator ( this , 'key+value' ) ;
470
472
}
471
473
472
474
forEach ( callback , thisArg = undefined ) {
473
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
475
+ if ( ! isURLSearchParams ( this ) )
474
476
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
475
- }
477
+
476
478
validateCallback ( callback ) ;
477
479
478
480
let list = this [ searchParams ] ;
@@ -490,27 +492,24 @@ class URLSearchParams {
490
492
491
493
// https://heycam.github.io/webidl/#es-iterable
492
494
keys ( ) {
493
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
495
+ if ( ! isURLSearchParams ( this ) )
494
496
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
495
- }
496
497
497
498
return createSearchParamsIterator ( this , 'key' ) ;
498
499
}
499
500
500
501
values ( ) {
501
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
502
+ if ( ! isURLSearchParams ( this ) )
502
503
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
503
- }
504
504
505
505
return createSearchParamsIterator ( this , 'value' ) ;
506
506
}
507
507
508
508
// https://heycam.github.io/webidl/#es-stringifier
509
509
// https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
510
510
toString ( ) {
511
- if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
511
+ if ( ! isURLSearchParams ( this ) )
512
512
throw new ERR_INVALID_THIS ( 'URLSearchParams' ) ;
513
- }
514
513
515
514
return serializeParams ( this [ searchParams ] ) ;
516
515
}
0 commit comments