2
2
3
3
const {
4
4
Array,
5
+ ArrayPrototypeJoin,
6
+ ArrayPrototypeMap,
7
+ ArrayPrototypePush,
8
+ ArrayPrototypeReduce,
9
+ ArrayPrototypeSlice,
10
+ FunctionPrototypeBind,
5
11
Int8Array,
6
12
Number,
7
13
ObjectCreate,
@@ -10,9 +16,17 @@ const {
10
16
ObjectGetOwnPropertySymbols,
11
17
ObjectGetPrototypeOf,
12
18
ObjectKeys,
19
+ ReflectApply,
13
20
ReflectGetOwnPropertyDescriptor,
14
21
ReflectOwnKeys,
22
+ RegExpPrototypeExec,
15
23
String,
24
+ StringPrototypeCharCodeAt,
25
+ StringPrototypeIncludes,
26
+ StringPrototypeReplace,
27
+ StringPrototypeSlice,
28
+ StringPrototypeSplit,
29
+ StringPrototypeStartsWith,
16
30
Symbol,
17
31
SymbolIterator,
18
32
SymbolToStringTag,
@@ -101,7 +115,7 @@ function toUSVString(val) {
101
115
const str = `${ val } ` ;
102
116
// As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are
103
117
// slower than `unpairedSurrogateRe.exec()`.
104
- const match = unpairedSurrogateRe . exec ( str ) ;
118
+ const match = RegExpPrototypeExec ( unpairedSurrogateRe , str ) ;
105
119
if ( ! match )
106
120
return str ;
107
121
return _toUSVString ( str , match . index ) ;
@@ -166,16 +180,16 @@ class URLSearchParams {
166
180
}
167
181
const convertedPair = [ ] ;
168
182
for ( const element of pair )
169
- convertedPair . push ( toUSVString ( element ) ) ;
170
- pairs . push ( convertedPair ) ;
183
+ ArrayPrototypePush ( convertedPair , toUSVString ( element ) ) ;
184
+ ArrayPrototypePush ( pairs , convertedPair ) ;
171
185
}
172
186
173
187
this [ searchParams ] = [ ] ;
174
188
for ( const pair of pairs ) {
175
189
if ( pair . length !== 2 ) {
176
190
throw new ERR_INVALID_TUPLE ( 'Each query pair' , '[name, value]' ) ;
177
191
}
178
- this [ searchParams ] . push ( pair [ 0 ] , pair [ 1 ] ) ;
192
+ ArrayPrototypePush ( this [ searchParams ] , pair [ 0 ] , pair [ 1 ] ) ;
179
193
}
180
194
} else {
181
195
// Record<USVString, USVString>
@@ -221,16 +235,21 @@ class URLSearchParams {
221
235
const list = this [ searchParams ] ;
222
236
const output = [ ] ;
223
237
for ( let i = 0 ; i < list . length ; i += 2 )
224
- output . push ( `${ innerInspect ( list [ i ] ) } => ${ innerInspect ( list [ i + 1 ] ) } ` ) ;
238
+ ArrayPrototypePush (
239
+ output ,
240
+ `${ innerInspect ( list [ i ] ) } => ${ innerInspect ( list [ i + 1 ] ) } ` ) ;
225
241
226
- const length = output . reduce (
242
+ const length = ArrayPrototypeReduce (
243
+ output ,
227
244
( prev , cur ) => prev + removeColors ( cur ) . length + separator . length ,
228
245
- separator . length
229
246
) ;
230
247
if ( length > ctx . breakLength ) {
231
- return `${ this . constructor . name } {\n ${ output . join ( ',\n ' ) } }` ;
248
+ return `${ this . constructor . name } {\n` +
249
+ ` ${ ArrayPrototypeJoin ( output , ',\n ' ) } }` ;
232
250
} else if ( output . length ) {
233
- return `${ this . constructor . name } { ${ output . join ( separator ) } }` ;
251
+ return `${ this . constructor . name } { ` +
252
+ `${ ArrayPrototypeJoin ( output , separator ) } }` ;
234
253
}
235
254
return `${ this . constructor . name } {}` ;
236
255
}
@@ -290,9 +309,9 @@ function onParsePortComplete(flags, protocol, username, password,
290
309
291
310
function onParseHostComplete ( flags , protocol , username , password ,
292
311
host , port , path , query , fragment ) {
293
- onParseHostnameComplete . apply ( this , arguments ) ;
312
+ ReflectApply ( onParseHostnameComplete , this , arguments ) ;
294
313
if ( port !== null || ( ( flags & URL_FLAGS_IS_DEFAULT_SCHEME_PORT ) !== 0 ) )
295
- onParsePortComplete . apply ( this , arguments ) ;
314
+ ReflectApply ( onParsePortComplete , this , arguments ) ;
296
315
}
297
316
298
317
function onParsePathComplete ( flags , protocol , username , password ,
@@ -332,8 +351,8 @@ class URL {
332
351
base_context = new URL ( base ) [ context ] ;
333
352
}
334
353
this [ context ] = new URLContext ( ) ;
335
- parse ( input , - 1 , base_context , undefined , onParseComplete . bind ( this ) ,
336
- onParseError ) ;
354
+ parse ( input , - 1 , base_context , undefined ,
355
+ FunctionPrototypeBind ( onParseComplete , this ) , onParseError ) ;
337
356
}
338
357
339
358
get [ special ] ( ) {
@@ -454,8 +473,8 @@ ObjectDefineProperties(URL.prototype, {
454
473
set ( input ) {
455
474
// toUSVString is not needed.
456
475
input = `${ input } ` ;
457
- parse ( input , - 1 , undefined , undefined , onParseComplete . bind ( this ) ,
458
- onParseError ) ;
476
+ parse ( input , - 1 , undefined , undefined ,
477
+ FunctionPrototypeBind ( onParseComplete , this ) , onParseError ) ;
459
478
}
460
479
} ,
461
480
origin : { // readonly
@@ -502,7 +521,7 @@ ObjectDefineProperties(URL.prototype, {
502
521
return ;
503
522
}
504
523
parse ( scheme , kSchemeStart , null , ctx ,
505
- onParseProtocolComplete . bind ( this ) ) ;
524
+ FunctionPrototypeBind ( onParseProtocolComplete , this ) ) ;
506
525
}
507
526
} ,
508
527
username : {
@@ -565,7 +584,8 @@ ObjectDefineProperties(URL.prototype, {
565
584
// Cannot set the host if cannot-be-base is set
566
585
return ;
567
586
}
568
- parse ( host , kHost , null , ctx , onParseHostComplete . bind ( this ) ) ;
587
+ parse ( host , kHost , null , ctx ,
588
+ FunctionPrototypeBind ( onParseHostComplete , this ) ) ;
569
589
}
570
590
} ,
571
591
hostname : {
@@ -602,7 +622,8 @@ ObjectDefineProperties(URL.prototype, {
602
622
ctx . port = null ;
603
623
return ;
604
624
}
605
- parse ( port , kPort , null , ctx , onParsePortComplete . bind ( this ) ) ;
625
+ parse ( port , kPort , null , ctx ,
626
+ FunctionPrototypeBind ( onParsePortComplete , this ) ) ;
606
627
}
607
628
} ,
608
629
pathname : {
@@ -614,7 +635,7 @@ ObjectDefineProperties(URL.prototype, {
614
635
return ctx . path [ 0 ] ;
615
636
if ( ctx . path . length === 0 )
616
637
return '' ;
617
- return `/${ ctx . path . join ( '/' ) } ` ;
638
+ return `/${ ArrayPrototypeJoin ( ctx . path , '/' ) } ` ;
618
639
} ,
619
640
set ( path ) {
620
641
// toUSVString is not needed.
@@ -641,11 +662,12 @@ ObjectDefineProperties(URL.prototype, {
641
662
ctx . query = null ;
642
663
ctx . flags &= ~ URL_FLAGS_HAS_QUERY ;
643
664
} else {
644
- if ( search [ 0 ] === '?' ) search = search . slice ( 1 ) ;
665
+ if ( search [ 0 ] === '?' ) search = StringPrototypeSlice ( search , 1 ) ;
645
666
ctx . query = '' ;
646
667
ctx . flags |= URL_FLAGS_HAS_QUERY ;
647
668
if ( search ) {
648
- parse ( search , kQuery , null , ctx , onParseSearchComplete . bind ( this ) ) ;
669
+ parse ( search , kQuery , null , ctx ,
670
+ FunctionPrototypeBind ( onParseSearchComplete , this ) ) ;
649
671
}
650
672
}
651
673
initSearchParams ( this [ searchParams ] , search ) ;
@@ -676,10 +698,11 @@ ObjectDefineProperties(URL.prototype, {
676
698
ctx . flags &= ~ URL_FLAGS_HAS_FRAGMENT ;
677
699
return ;
678
700
}
679
- if ( hash [ 0 ] === '#' ) hash = hash . slice ( 1 ) ;
701
+ if ( hash [ 0 ] === '#' ) hash = StringPrototypeSlice ( hash , 1 ) ;
680
702
ctx . fragment = '' ;
681
703
ctx . flags |= URL_FLAGS_HAS_FRAGMENT ;
682
- parse ( hash , kFragment , null , ctx , onParseHashComplete . bind ( this ) ) ;
704
+ parse ( hash , kFragment , null , ctx ,
705
+ FunctionPrototypeBind ( onParseHashComplete , this ) ) ;
683
706
}
684
707
} ,
685
708
toJSON : {
@@ -728,7 +751,7 @@ function parseParams(qs) {
728
751
let encodeCheck = 0 ;
729
752
let i ;
730
753
for ( i = 0 ; i < qs . length ; ++ i ) {
731
- const code = qs . charCodeAt ( i ) ;
754
+ const code = StringPrototypeCharCodeAt ( qs , i ) ;
732
755
733
756
// Try matching key/value pair separator
734
757
if ( code === CHAR_AMPERSAND ) {
@@ -776,7 +799,7 @@ function parseParams(qs) {
776
799
// Handle + and percent decoding.
777
800
if ( code === CHAR_PLUS ) {
778
801
if ( lastPos < i )
779
- buf += qs . slice ( lastPos , i ) ;
802
+ buf += StringPrototypeSlice ( qs , lastPos , i ) ;
780
803
buf += ' ' ;
781
804
lastPos = i + 1 ;
782
805
} else if ( ! encoded ) {
@@ -804,14 +827,14 @@ function parseParams(qs) {
804
827
return out ;
805
828
806
829
if ( lastPos < i )
807
- buf += qs . slice ( lastPos , i ) ;
830
+ buf += StringPrototypeSlice ( qs , lastPos , i ) ;
808
831
if ( encoded )
809
832
buf = querystring . unescape ( buf ) ;
810
- out . push ( buf ) ;
833
+ ArrayPrototypePush ( out , buf ) ;
811
834
812
835
// If `buf` is the key, add an empty value.
813
836
if ( ! seenSep )
814
- out . push ( '' ) ;
837
+ ArrayPrototypePush ( out , '' ) ;
815
838
816
839
return out ;
817
840
}
@@ -925,7 +948,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
925
948
926
949
name = toUSVString ( name ) ;
927
950
value = toUSVString ( value ) ;
928
- this [ searchParams ] . push ( name , value ) ;
951
+ ArrayPrototypePush ( this [ searchParams ] , name , value ) ;
929
952
update ( this [ context ] , this ) ;
930
953
} ,
931
954
@@ -1039,7 +1062,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
1039
1062
// Otherwise, append a new name-value pair whose name is `name` and value
1040
1063
// is `value`, to `list`.
1041
1064
if ( ! found ) {
1042
- list . push ( name , value ) ;
1065
+ ArrayPrototypePush ( list , name , value ) ;
1043
1066
}
1044
1067
1045
1068
update ( this [ context ] , this ) ;
@@ -1225,24 +1248,28 @@ defineIDLClass(URLSearchParamsIteratorPrototype, 'URLSearchParams Iterator', {
1225
1248
kind,
1226
1249
index
1227
1250
} = this [ context ] ;
1228
- const output = target [ searchParams ] . slice ( index ) . reduce ( ( prev , cur , i ) => {
1229
- const key = i % 2 === 0 ;
1230
- if ( kind === 'key' && key ) {
1231
- prev . push ( cur ) ;
1232
- } else if ( kind === 'value' && ! key ) {
1233
- prev . push ( cur ) ;
1234
- } else if ( kind === 'key+value' && ! key ) {
1235
- prev . push ( [ target [ searchParams ] [ index + i - 1 ] , cur ] ) ;
1236
- }
1237
- return prev ;
1238
- } , [ ] ) ;
1251
+ const output = ArrayPrototypeReduce (
1252
+ ArrayPrototypeSlice ( target [ searchParams ] , index ) ,
1253
+ ( prev , cur , i ) => {
1254
+ const key = i % 2 === 0 ;
1255
+ if ( kind === 'key' && key ) {
1256
+ ArrayPrototypePush ( prev , cur ) ;
1257
+ } else if ( kind === 'value' && ! key ) {
1258
+ ArrayPrototypePush ( prev , cur ) ;
1259
+ } else if ( kind === 'key+value' && ! key ) {
1260
+ ArrayPrototypePush ( prev , [ target [ searchParams ] [ index + i - 1 ] , cur ] ) ;
1261
+ }
1262
+ return prev ;
1263
+ } ,
1264
+ [ ]
1265
+ ) ;
1239
1266
const breakLn = inspect ( output , innerOpts ) . includes ( '\n' ) ;
1240
- const outputStrs = output . map ( ( p ) => inspect ( p , innerOpts ) ) ;
1267
+ const outputStrs = ArrayPrototypeMap ( output , ( p ) => inspect ( p , innerOpts ) ) ;
1241
1268
let outputStr ;
1242
1269
if ( breakLn ) {
1243
- outputStr = `\n ${ outputStrs . join ( ',\n ' ) } ` ;
1270
+ outputStr = `\n ${ ArrayPrototypeJoin ( outputStrs , ',\n ' ) } ` ;
1244
1271
} else {
1245
- outputStr = ` ${ outputStrs . join ( ', ' ) } ` ;
1272
+ outputStr = ` ${ ArrayPrototypeJoin ( outputStrs , ', ' ) } ` ;
1246
1273
}
1247
1274
return `${ this [ SymbolToStringTag ] } {${ outputStr } }` ;
1248
1275
}
@@ -1270,8 +1297,9 @@ function domainToUnicode(domain) {
1270
1297
function urlToOptions ( url ) {
1271
1298
const options = {
1272
1299
protocol : url . protocol ,
1273
- hostname : typeof url . hostname === 'string' && url . hostname . startsWith ( '[' ) ?
1274
- url . hostname . slice ( 1 , - 1 ) :
1300
+ hostname : typeof url . hostname === 'string' &&
1301
+ StringPrototypeStartsWith ( url . hostname , '[' ) ?
1302
+ StringPrototypeSlice ( url . hostname , 1 , - 1 ) :
1275
1303
url . hostname ,
1276
1304
hash : url . hash ,
1277
1305
search : url . search ,
@@ -1371,25 +1399,25 @@ const carriageReturnRegEx = /\r/g;
1371
1399
const tabRegEx = / \t / g;
1372
1400
1373
1401
function encodePathChars ( filepath ) {
1374
- if ( filepath . includes ( '%' ) )
1375
- filepath = filepath . replace ( percentRegEx , '%25' ) ;
1402
+ if ( StringPrototypeIncludes ( filepath , '%' ) )
1403
+ filepath = StringPrototypeReplace ( filepath , percentRegEx , '%25' ) ;
1376
1404
// In posix, backslash is a valid character in paths:
1377
- if ( ! isWindows && filepath . includes ( '\\' ) )
1378
- filepath = filepath . replace ( backslashRegEx , '%5C' ) ;
1379
- if ( filepath . includes ( '\n' ) )
1380
- filepath = filepath . replace ( newlineRegEx , '%0A' ) ;
1381
- if ( filepath . includes ( '\r' ) )
1382
- filepath = filepath . replace ( carriageReturnRegEx , '%0D' ) ;
1383
- if ( filepath . includes ( '\t' ) )
1384
- filepath = filepath . replace ( tabRegEx , '%09' ) ;
1405
+ if ( ! isWindows && StringPrototypeIncludes ( filepath , '\\' ) )
1406
+ filepath = StringPrototypeReplace ( filepath , backslashRegEx , '%5C' ) ;
1407
+ if ( StringPrototypeIncludes ( filepath , '\n' ) )
1408
+ filepath = StringPrototypeReplace ( filepath , newlineRegEx , '%0A' ) ;
1409
+ if ( StringPrototypeIncludes ( filepath , '\r' ) )
1410
+ filepath = StringPrototypeReplace ( filepath , carriageReturnRegEx , '%0D' ) ;
1411
+ if ( StringPrototypeIncludes ( filepath , '\t' ) )
1412
+ filepath = StringPrototypeReplace ( filepath , tabRegEx , '%09' ) ;
1385
1413
return filepath ;
1386
1414
}
1387
1415
1388
1416
function pathToFileURL ( filepath ) {
1389
1417
const outURL = new URL ( 'file://' ) ;
1390
- if ( isWindows && filepath . startsWith ( '\\\\' ) ) {
1418
+ if ( isWindows && StringPrototypeStartsWith ( filepath , '\\\\' ) ) {
1391
1419
// UNC path format: \\server\share\resource
1392
- const paths = filepath . split ( '\\' ) ;
1420
+ const paths = StringPrototypeSplit ( filepath , '\\' ) ;
1393
1421
if ( paths . length <= 3 ) {
1394
1422
throw new ERR_INVALID_ARG_VALUE (
1395
1423
'filepath' ,
@@ -1406,11 +1434,13 @@ function pathToFileURL(filepath) {
1406
1434
) ;
1407
1435
}
1408
1436
outURL . hostname = domainToASCII ( hostname ) ;
1409
- outURL . pathname = encodePathChars ( paths . slice ( 3 ) . join ( '/' ) ) ;
1437
+ outURL . pathname = encodePathChars (
1438
+ ArrayPrototypeJoin ( ArrayPrototypeSlice ( paths , 3 ) , '/' ) ) ;
1410
1439
} else {
1411
1440
let resolved = path . resolve ( filepath ) ;
1412
1441
// path.resolve strips trailing slashes so we must add them back
1413
- const filePathLast = filepath . charCodeAt ( filepath . length - 1 ) ;
1442
+ const filePathLast = StringPrototypeCharCodeAt ( filepath ,
1443
+ filepath . length - 1 ) ;
1414
1444
if ( ( filePathLast === CHAR_FORWARD_SLASH ||
1415
1445
( isWindows && filePathLast === CHAR_BACKWARD_SLASH ) ) &&
1416
1446
resolved [ resolved . length - 1 ] !== path . sep )
0 commit comments