@@ -239,8 +239,10 @@ class URL {
239
239
constructor ( input , base ) {
240
240
// toUSVString is not needed.
241
241
input = `${ input } ` ;
242
- if ( base !== undefined && ! ( base instanceof URL ) )
242
+ if ( base !== undefined &&
243
+ ( ! base [ searchParams ] || ! base [ searchParams ] [ searchParams ] ) ) {
243
244
base = new URL ( base ) ;
245
+ }
244
246
parse ( this , input , base ) ;
245
247
}
246
248
@@ -885,7 +887,7 @@ class URLSearchParams {
885
887
}
886
888
887
889
[ util . inspect . custom ] ( recurseTimes , ctx ) {
888
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
890
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
889
891
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
890
892
}
891
893
@@ -947,7 +949,7 @@ function merge(out, start, mid, end, lBuffer, rBuffer) {
947
949
948
950
defineIDLClass ( URLSearchParams . prototype , 'URLSearchParams' , {
949
951
append ( name , value ) {
950
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
952
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
951
953
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
952
954
}
953
955
if ( arguments . length < 2 ) {
@@ -961,7 +963,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
961
963
} ,
962
964
963
965
delete ( name ) {
964
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
966
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
965
967
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
966
968
}
967
969
if ( arguments . length < 1 ) {
@@ -982,7 +984,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
982
984
} ,
983
985
984
986
get ( name ) {
985
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
987
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
986
988
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
987
989
}
988
990
if ( arguments . length < 1 ) {
@@ -1000,7 +1002,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1000
1002
} ,
1001
1003
1002
1004
getAll ( name ) {
1003
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1005
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1004
1006
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1005
1007
}
1006
1008
if ( arguments . length < 1 ) {
@@ -1019,7 +1021,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1019
1021
} ,
1020
1022
1021
1023
has ( name ) {
1022
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1024
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1023
1025
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1024
1026
}
1025
1027
if ( arguments . length < 1 ) {
@@ -1037,7 +1039,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1037
1039
} ,
1038
1040
1039
1041
set ( name , value ) {
1040
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1042
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1041
1043
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1042
1044
}
1043
1045
if ( arguments . length < 2 ) {
@@ -1125,15 +1127,15 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1125
1127
// Define entries here rather than [Symbol.iterator] as the function name
1126
1128
// must be set to `entries`.
1127
1129
entries ( ) {
1128
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1130
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1129
1131
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1130
1132
}
1131
1133
1132
1134
return createSearchParamsIterator ( this , 'key+value' ) ;
1133
1135
} ,
1134
1136
1135
1137
forEach ( callback , thisArg = undefined ) {
1136
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1138
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1137
1139
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1138
1140
}
1139
1141
if ( typeof callback !== 'function' ) {
@@ -1155,15 +1157,15 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1155
1157
1156
1158
// https://heycam.github.io/webidl/#es-iterable
1157
1159
keys ( ) {
1158
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1160
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1159
1161
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1160
1162
}
1161
1163
1162
1164
return createSearchParamsIterator ( this , 'key' ) ;
1163
1165
} ,
1164
1166
1165
1167
values ( ) {
1166
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1168
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1167
1169
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1168
1170
}
1169
1171
@@ -1173,7 +1175,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1173
1175
// https://heycam.github.io/webidl/#es-stringifier
1174
1176
// https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
1175
1177
toString ( ) {
1176
- if ( ! this || ! ( this instanceof URLSearchParams ) ) {
1178
+ if ( ! this || ! this [ searchParams ] || this [ searchParams ] [ searchParams ] ) {
1177
1179
throw new TypeError ( 'Value of `this` is not a URLSearchParams' ) ;
1178
1180
}
1179
1181
@@ -1275,8 +1277,10 @@ defineIDLClass(URLSearchParamsIteratorPrototype, 'URLSearchParamsIterator', {
1275
1277
} ) ;
1276
1278
1277
1279
function originFor ( url , base ) {
1278
- if ( ! ( url instanceof URL ) )
1280
+ if ( url != undefined &&
1281
+ ( ! url [ searchParams ] || ! url [ searchParams ] [ searchParams ] ) ) {
1279
1282
url = new URL ( url , base ) ;
1283
+ }
1280
1284
var origin ;
1281
1285
const protocol = url . protocol ;
1282
1286
switch ( protocol ) {
@@ -1399,8 +1403,10 @@ function getPathFromURLPosix(url) {
1399
1403
}
1400
1404
1401
1405
function getPathFromURL ( path ) {
1402
- if ( ! ( path instanceof URL ) )
1406
+ if ( path == undefined || ! path [ searchParams ] ||
1407
+ ! path [ searchParams ] [ searchParams ] ) {
1403
1408
return path ;
1409
+ }
1404
1410
if ( path . protocol !== 'file:' )
1405
1411
return new TypeError ( 'Only `file:` URLs are supported' ) ;
1406
1412
return isWindows ? getPathFromURLWin32 ( path ) : getPathFromURLPosix ( path ) ;
0 commit comments