3
3
const {
4
4
ArrayFrom,
5
5
ArrayIsArray,
6
- ArrayPrototypeForEach,
7
- ArrayPrototypePush,
8
- ArrayPrototypeUnshift,
9
- FunctionPrototypeBind,
10
- FunctionPrototypeCall,
11
6
MathMin,
12
7
Number,
13
8
ObjectAssign,
14
- ObjectKeys,
15
9
ObjectDefineProperty,
16
10
ObjectEntries,
17
- ObjectPrototypeHasOwnProperty,
11
+ ObjectHasOwn,
12
+ ObjectKeys,
18
13
Promise,
19
- PromisePrototypeThen,
20
14
Proxy,
21
15
ReflectApply,
22
16
ReflectGet,
23
17
ReflectGetPrototypeOf,
24
18
ReflectSet,
25
- RegExpPrototypeExec,
26
- SafeArrayIterator,
27
19
SafeMap,
28
20
SafeSet,
29
- StringPrototypeSlice,
30
21
Symbol,
31
22
SymbolAsyncDispose,
32
23
SymbolDispose,
33
- TypedArrayPrototypeGetLength,
34
24
Uint32Array,
35
25
Uint8Array,
36
26
} = primordials ;
@@ -205,22 +195,22 @@ function debugStream(id, sessionType, message, ...args) {
205
195
return ;
206
196
}
207
197
debug ( 'Http2Stream %s [Http2Session %s]: ' + message ,
208
- id , sessionName ( sessionType ) , ...new SafeArrayIterator ( args ) ) ;
198
+ id , sessionName ( sessionType ) , ...args ) ;
209
199
}
210
200
211
201
function debugStreamObj ( stream , message , ...args ) {
212
202
const session = stream [ kSession ] ;
213
203
const type = session ? session [ kType ] : undefined ;
214
- debugStream ( stream [ kID ] , type , message , ...new SafeArrayIterator ( args ) ) ;
204
+ debugStream ( stream [ kID ] , type , message , ...args ) ;
215
205
}
216
206
217
207
function debugSession ( sessionType , message , ...args ) {
218
208
debug ( 'Http2Session %s: ' + message , sessionName ( sessionType ) ,
219
- ...new SafeArrayIterator ( args ) ) ;
209
+ ...args ) ;
220
210
}
221
211
222
212
function debugSessionObj ( session , message , ...args ) {
223
- debugSession ( session [ kType ] , message , ...new SafeArrayIterator ( args ) ) ;
213
+ debugSession ( session [ kType ] , message , ...args ) ;
224
214
}
225
215
226
216
const kMaxFrameSize = ( 2 ** 24 ) - 1 ;
@@ -826,8 +816,7 @@ function submitSettings(settings, callback) {
826
816
debugSessionObj ( this , 'submitting settings' ) ;
827
817
this [ kUpdateTimer ] ( ) ;
828
818
updateSettingsBuffer ( settings ) ;
829
- if ( ! this [ kHandle ] . settings ( FunctionPrototypeBind ( settingsCallback ,
830
- this , callback ) ) ) {
819
+ if ( ! this [ kHandle ] . settings ( settingsCallback . bind ( this , callback ) ) ) {
831
820
this . destroy ( new ERR_HTTP2_MAX_PENDING_SETTINGS_ACK ( ) ) ;
832
821
}
833
822
}
@@ -869,7 +858,7 @@ const proxySocketHandler = {
869
858
case 'setTimeout' :
870
859
case 'ref' :
871
860
case 'unref' :
872
- return FunctionPrototypeBind ( session [ prop ] , session ) ;
861
+ return session [ prop ] . bind ( session ) ;
873
862
case 'destroy' :
874
863
case 'emit' :
875
864
case 'end' :
@@ -887,7 +876,7 @@ const proxySocketHandler = {
887
876
throw new ERR_HTTP2_SOCKET_UNBOUND ( ) ;
888
877
const value = socket [ prop ] ;
889
878
return typeof value === 'function' ?
890
- FunctionPrototypeBind ( value , socket ) :
879
+ value . bind ( socket ) :
891
880
value ;
892
881
}
893
882
}
@@ -998,7 +987,7 @@ const validateSettings = hideStackFrames((settings) => {
998
987
// Wrap a typed array in a proxy, and allow selectively copying the entries
999
988
// that have explicitly been set to another typed array.
1000
989
function trackAssignmentsTypedArray ( typedArray ) {
1001
- const typedArrayLength = TypedArrayPrototypeGetLength ( typedArray ) ;
990
+ const typedArrayLength = typedArray . length ;
1002
991
const modifiedEntries = new Uint8Array ( typedArrayLength ) ;
1003
992
1004
993
function copyAssigned ( target ) {
@@ -1183,8 +1172,7 @@ function closeSession(session, code, error) {
1183
1172
1184
1173
// Destroy the handle if it exists at this point.
1185
1174
if ( handle !== undefined ) {
1186
- handle . ondone = FunctionPrototypeBind ( finishSessionClose ,
1187
- null , session , error ) ;
1175
+ handle . ondone = finishSessionClose . bind ( null , session , error ) ;
1188
1176
handle . destroy ( code , socket . destroyed ) ;
1189
1177
} else {
1190
1178
finishSessionClose ( session , error ) ;
@@ -1276,8 +1264,7 @@ class Http2Session extends EventEmitter {
1276
1264
if ( typeof socket . disableRenegotiation === 'function' )
1277
1265
socket . disableRenegotiation ( ) ;
1278
1266
1279
- const setupFn = FunctionPrototypeBind ( setupHandle , this ,
1280
- socket , type , options ) ;
1267
+ const setupFn = setupHandle . bind ( this , socket , type , options ) ;
1281
1268
if ( socket . connecting || socket . secureConnecting ) {
1282
1269
const connectEvent =
1283
1270
socket instanceof tls . TLSSocket ? 'secureConnect' : 'connect' ;
@@ -1512,8 +1499,7 @@ class Http2Session extends EventEmitter {
1512
1499
1513
1500
this [ kState ] . pendingAck ++ ;
1514
1501
1515
- const settingsFn = FunctionPrototypeBind ( submitSettings , this ,
1516
- { ...settings } , callback ) ;
1502
+ const settingsFn = submitSettings . bind ( this , { ...settings } , callback ) ;
1517
1503
if ( this . connecting ) {
1518
1504
this . once ( 'connect' , settingsFn ) ;
1519
1505
return ;
@@ -1535,9 +1521,7 @@ class Http2Session extends EventEmitter {
1535
1521
validateNumber ( code , 'code' ) ;
1536
1522
validateNumber ( lastStreamID , 'lastStreamID' ) ;
1537
1523
1538
- const goawayFn = FunctionPrototypeBind ( submitGoaway ,
1539
- this ,
1540
- code , lastStreamID , opaqueData ) ;
1524
+ const goawayFn = submitGoaway . bind ( this , code , lastStreamID , opaqueData ) ;
1541
1525
if ( this . connecting ) {
1542
1526
this . once ( 'connect' , goawayFn ) ;
1543
1527
return ;
@@ -1693,7 +1677,7 @@ class ServerHttp2Session extends Http2Session {
1693
1677
}
1694
1678
1695
1679
validateString ( alt , 'alt' ) ;
1696
- if ( RegExpPrototypeExec ( kQuotedString , alt ) === null )
1680
+ if ( ! kQuotedString . test ( alt ) )
1697
1681
throw new ERR_INVALID_CHAR ( 'alt' ) ;
1698
1682
1699
1683
// Max length permitted for ALTSVC
@@ -1786,8 +1770,7 @@ class ClientHttp2Session extends Http2Session {
1786
1770
if ( getAuthority ( headers ) === undefined )
1787
1771
headers [ HTTP2_HEADER_AUTHORITY ] = this [ kAuthority ] ;
1788
1772
if ( headers [ HTTP2_HEADER_SCHEME ] === undefined )
1789
- headers [ HTTP2_HEADER_SCHEME ] = StringPrototypeSlice ( this [ kProtocol ] ,
1790
- 0 , - 1 ) ;
1773
+ headers [ HTTP2_HEADER_SCHEME ] = this [ kProtocol ] . slice ( 0 , - 1 ) ;
1791
1774
if ( headers [ HTTP2_HEADER_PATH ] === undefined )
1792
1775
headers [ HTTP2_HEADER_PATH ] = '/' ;
1793
1776
} else {
@@ -1839,15 +1822,14 @@ class ClientHttp2Session extends Http2Session {
1839
1822
}
1840
1823
}
1841
1824
1842
- const onConnect = FunctionPrototypeBind ( requestOnConnect ,
1843
- stream , headersList , options ) ;
1825
+ const onConnect = requestOnConnect . bind ( stream , headersList , options ) ;
1844
1826
if ( this . connecting ) {
1845
1827
if ( this [ kPendingRequestCalls ] !== null ) {
1846
- ArrayPrototypePush ( this [ kPendingRequestCalls ] , onConnect ) ;
1828
+ this [ kPendingRequestCalls ] . push ( onConnect ) ;
1847
1829
} else {
1848
1830
this [ kPendingRequestCalls ] = [ onConnect ] ;
1849
1831
this . once ( 'connect' , ( ) => {
1850
- ArrayPrototypeForEach ( this [ kPendingRequestCalls ] , ( f ) => f ( ) ) ;
1832
+ this [ kPendingRequestCalls ] . forEach ( ( f ) => f ( ) ) ;
1851
1833
this [ kPendingRequestCalls ] = null ;
1852
1834
} ) ;
1853
1835
}
@@ -1951,7 +1933,7 @@ function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
1951
1933
}
1952
1934
1953
1935
if ( rstStreamStatus !== kNoRstStream ) {
1954
- const finishFn = FunctionPrototypeBind ( finishCloseStream , stream , code ) ;
1936
+ const finishFn = finishCloseStream . bind ( stream , code ) ;
1955
1937
if ( ! ending || stream . writableFinished || code !== NGHTTP2_NO_ERROR ||
1956
1938
rstStreamStatus === kForceRstStream )
1957
1939
finishFn ( ) ;
@@ -1961,7 +1943,7 @@ function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
1961
1943
}
1962
1944
1963
1945
function finishCloseStream ( code ) {
1964
- const rstStreamFn = FunctionPrototypeBind ( submitRstStream , this , code ) ;
1946
+ const rstStreamFn = submitRstStream . bind ( this , code ) ;
1965
1947
// If the handle has not yet been assigned, queue up the request to
1966
1948
// ensure that the RST_STREAM frame is sent after the stream ID has
1967
1949
// been determined.
@@ -2145,8 +2127,7 @@ class Http2Stream extends Duplex {
2145
2127
if ( this . pending ) {
2146
2128
this . once (
2147
2129
'ready' ,
2148
- FunctionPrototypeBind ( this [ kWriteGeneric ] ,
2149
- this , writev , data , encoding , cb ) ,
2130
+ this [ kWriteGeneric ] . bind ( this , writev , data , encoding , cb ) ,
2150
2131
) ;
2151
2132
return ;
2152
2133
}
@@ -2238,7 +2219,7 @@ class Http2Stream extends Duplex {
2238
2219
this [ kState ] . didRead = true ;
2239
2220
}
2240
2221
if ( ! this . pending ) {
2241
- FunctionPrototypeCall ( streamOnResume , this ) ;
2222
+ streamOnResume . call ( this ) ;
2242
2223
} else {
2243
2224
this . once ( 'ready' , streamOnResume ) ;
2244
2225
}
@@ -2252,7 +2233,7 @@ class Http2Stream extends Duplex {
2252
2233
options = { ...options } ;
2253
2234
setAndValidatePriorityOptions ( options ) ;
2254
2235
2255
- const priorityFn = FunctionPrototypeBind ( submitPriority , this , options ) ;
2236
+ const priorityFn = submitPriority . bind ( this , options ) ;
2256
2237
2257
2238
// If the handle has not yet been assigned, queue up the priority
2258
2239
// frame to be sent as soon as the ready event is emitted.
@@ -2455,7 +2436,7 @@ function processHeaders(oldHeaders, options) {
2455
2436
if ( oldHeaders !== null && oldHeaders !== undefined ) {
2456
2437
// This loop is here for performance reason. Do not change.
2457
2438
for ( const key in oldHeaders ) {
2458
- if ( ObjectPrototypeHasOwnProperty ( oldHeaders , key ) ) {
2439
+ if ( ObjectHasOwn ( oldHeaders , key ) ) {
2459
2440
headers [ key ] = oldHeaders [ key ] ;
2460
2441
}
2461
2442
}
@@ -2493,8 +2474,7 @@ function processHeaders(oldHeaders, options) {
2493
2474
function onFileUnpipe ( ) {
2494
2475
const stream = this . sink [ kOwner ] ;
2495
2476
if ( stream . ownsFd )
2496
- PromisePrototypeThen ( this . source . close ( ) , undefined ,
2497
- FunctionPrototypeBind ( stream . destroy , stream ) ) ;
2477
+ this . source . close ( ) . catch ( stream . destroy . bind ( stream ) ) ;
2498
2478
else
2499
2479
this . source . releaseFD ( ) ;
2500
2480
}
@@ -2677,9 +2657,7 @@ function afterOpen(session, options, headers, streamOptions, err, fd) {
2677
2657
state . fd = fd ;
2678
2658
2679
2659
fs . fstat ( fd ,
2680
- FunctionPrototypeBind ( doSendFileFD , this ,
2681
- session , options , fd ,
2682
- headers , streamOptions ) ) ;
2660
+ doSendFileFD . bind ( this , session , options , fd , headers , streamOptions ) ) ;
2683
2661
}
2684
2662
2685
2663
class ServerHttp2Stream extends Http2Stream {
@@ -2882,9 +2860,7 @@ class ServerHttp2Stream extends Http2Stream {
2882
2860
2883
2861
if ( options . statCheck !== undefined ) {
2884
2862
fs . fstat ( fd ,
2885
- FunctionPrototypeBind ( doSendFD , this ,
2886
- session , options , fd ,
2887
- headers , streamOptions ) ) ;
2863
+ doSendFD . bind ( this , session , options , fd , headers , streamOptions ) ) ;
2888
2864
return ;
2889
2865
}
2890
2866
@@ -2943,8 +2919,7 @@ class ServerHttp2Stream extends Http2Stream {
2943
2919
}
2944
2920
2945
2921
fs . open ( path , 'r' ,
2946
- FunctionPrototypeBind ( afterOpen , this ,
2947
- session , options , headers , streamOptions ) ) ;
2922
+ afterOpen . bind ( this , session , options , headers , streamOptions ) ) ;
2948
2923
}
2949
2924
2950
2925
// Sends a block of informational headers. In theory, the HTTP/2 spec
@@ -2980,7 +2955,7 @@ class ServerHttp2Stream extends Http2Stream {
2980
2955
if ( ! this [ kInfoHeaders ] )
2981
2956
this [ kInfoHeaders ] = [ headers ] ;
2982
2957
else
2983
- ArrayPrototypePush ( this [ kInfoHeaders ] , headers ) ;
2958
+ this [ kInfoHeaders ] . push ( headers ) ;
2984
2959
2985
2960
const ret = this [ kHandle ] . info ( headersList ) ;
2986
2961
if ( ret < 0 )
@@ -3066,7 +3041,7 @@ function connectionListener(socket) {
3066
3041
if ( options . allowHTTP1 === true ) {
3067
3042
socket . server [ kIncomingMessage ] = options . Http1IncomingMessage ;
3068
3043
socket . server [ kServerResponse ] = options . Http1ServerResponse ;
3069
- return FunctionPrototypeCall ( httpConnectionListener , this , socket ) ;
3044
+ return httpConnectionListener . call ( this , socket ) ;
3070
3045
}
3071
3046
// Let event handler deal with the socket
3072
3047
debug ( 'Unknown protocol from %s:%s' ,
@@ -3164,7 +3139,7 @@ function initializeTLSOptions(options, servername) {
3164
3139
options = initializeOptions ( options ) ;
3165
3140
options . ALPNProtocols = [ 'h2' ] ;
3166
3141
if ( options . allowHTTP1 === true )
3167
- ArrayPrototypePush ( options . ALPNProtocols , 'http/1.1' ) ;
3142
+ options . ALPNProtocols . push ( 'http/1.1' ) ;
3168
3143
if ( servername !== undefined && ! options . servername )
3169
3144
options . servername = servername ;
3170
3145
return options ;
@@ -3249,7 +3224,7 @@ class Http2Server extends NETServer {
3249
3224
}
3250
3225
3251
3226
async [ SymbolAsyncDispose ] ( ) {
3252
- return FunctionPrototypeCall ( promisify ( super . close ) , this ) ;
3227
+ return promisify ( super . close ) . call ( this ) ;
3253
3228
}
3254
3229
}
3255
3230
@@ -3284,7 +3259,7 @@ Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(
3284
3259
break ;
3285
3260
}
3286
3261
default :
3287
- ArrayPrototypeUnshift ( args , err , event ) ;
3262
+ args . unshift ( err , event ) ;
3288
3263
ReflectApply ( net . Server . prototype [ EventEmitter . captureRejectionSymbol ] ,
3289
3264
this , args ) ;
3290
3265
}
@@ -3293,11 +3268,8 @@ Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(
3293
3268
function setupCompat ( ev ) {
3294
3269
if ( ev === 'request' ) {
3295
3270
this . removeListener ( 'newListener' , setupCompat ) ;
3296
- this . on ( 'stream' , FunctionPrototypeBind ( onServerStream ,
3297
- this ,
3298
- this [ kOptions ] . Http2ServerRequest ,
3299
- this [ kOptions ] . Http2ServerResponse ) ,
3300
- ) ;
3271
+ this . on ( 'stream' , onServerStream . bind ( this , this [ kOptions ] . Http2ServerRequest ,
3272
+ this [ kOptions ] . Http2ServerResponse ) ) ;
3301
3273
}
3302
3274
}
3303
3275
@@ -3344,7 +3316,7 @@ function connect(authority, options, listener) {
3344
3316
host = authority . hostname ;
3345
3317
3346
3318
if ( host [ 0 ] === '[' )
3347
- host = StringPrototypeSlice ( host , 1 , - 1 ) ;
3319
+ host = host . slice ( 1 , - 1 ) ;
3348
3320
} else if ( authority . host ) {
3349
3321
host = authority . host ;
3350
3322
}
0 commit comments