@@ -28,6 +28,8 @@ const { _connectionListener: httpConnectionListener } = require('http');
28
28
const { createPromise, promiseResolve } = process . binding ( 'util' ) ;
29
29
const debug = util . debuglog ( 'http2' ) ;
30
30
31
+ const kMaxFrameSize = ( 2 ** 24 ) - 1 ;
32
+ const kMaxInt = ( 2 ** 32 ) - 1 ;
31
33
const kMaxStreams = ( 2 ** 31 ) - 1 ;
32
34
33
35
const {
@@ -330,9 +332,9 @@ function emitGoaway(self, code, lastStreamID, buf) {
330
332
return ;
331
333
if ( ! state . shuttingDown && ! state . shutdown ) {
332
334
self . shutdown ( { } , self . destroy . bind ( self ) ) ;
333
- } else {
334
- self . destroy ( ) ;
335
+ return ;
335
336
}
337
+ self . destroy ( ) ;
336
338
}
337
339
338
340
// Called by the native layer when a goaway frame has been received
@@ -580,14 +582,15 @@ function doShutdown(options) {
580
582
function submitShutdown ( options ) {
581
583
const type = this [ kType ] ;
582
584
debug ( `Http2Session ${ sessionName ( type ) } : submitting shutdown request` ) ;
585
+ const fn = doShutdown . bind ( this , options ) ;
583
586
if ( type === NGHTTP2_SESSION_SERVER && options . graceful === true ) {
584
587
// first send a shutdown notice
585
588
this [ kHandle ] . shutdownNotice ( ) ;
586
589
// then, on flip of the event loop, do the actual shutdown
587
- setImmediate ( doShutdown . bind ( this ) , options ) ;
588
- } else {
589
- doShutdown . call ( this , options ) ;
590
+ setImmediate ( fn ) ;
591
+ return ;
590
592
}
593
+ fn ( ) ;
591
594
}
592
595
593
596
function finishSessionDestroy ( socket ) {
@@ -842,19 +845,19 @@ class Http2Session extends EventEmitter {
842
845
settings = Object . assign ( Object . create ( null ) , settings ) ;
843
846
assertWithinRange ( 'headerTableSize' ,
844
847
settings . headerTableSize ,
845
- 0 , 2 ** 32 - 1 ) ;
848
+ 0 , kMaxInt ) ;
846
849
assertWithinRange ( 'initialWindowSize' ,
847
850
settings . initialWindowSize ,
848
- 0 , 2 ** 32 - 1 ) ;
851
+ 0 , kMaxInt ) ;
849
852
assertWithinRange ( 'maxFrameSize' ,
850
853
settings . maxFrameSize ,
851
- 16384 , 2 ** 24 - 1 ) ;
854
+ 16384 , kMaxFrameSize ) ;
852
855
assertWithinRange ( 'maxConcurrentStreams' ,
853
856
settings . maxConcurrentStreams ,
854
857
0 , kMaxStreams ) ;
855
858
assertWithinRange ( 'maxHeaderListSize' ,
856
859
settings . maxHeaderListSize ,
857
- 0 , 2 ** 32 - 1 ) ;
860
+ 0 , kMaxInt ) ;
858
861
if ( settings . enablePush !== undefined &&
859
862
typeof settings . enablePush !== 'boolean' ) {
860
863
const err = new errors . TypeError ( 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
@@ -869,11 +872,12 @@ class Http2Session extends EventEmitter {
869
872
debug ( `Http2Session ${ sessionName ( this [ kType ] ) } : sending settings` ) ;
870
873
871
874
state . pendingAck ++ ;
875
+ const fn = submitSettings . bind ( this , settings ) ;
872
876
if ( state . connecting ) {
873
- this . once ( 'connect' , submitSettings . bind ( this , settings ) ) ;
877
+ this . once ( 'connect' , fn ) ;
874
878
return ;
875
879
}
876
- submitSettings . call ( this , settings ) ;
880
+ fn ( ) ;
877
881
}
878
882
879
883
// Destroy the Http2Session
@@ -959,13 +963,14 @@ class Http2Session extends EventEmitter {
959
963
this . on ( 'shutdown' , callback ) ;
960
964
}
961
965
966
+ const fn = submitShutdown . bind ( this , options ) ;
962
967
if ( state . connecting ) {
963
- this . once ( 'connect' , submitShutdown . bind ( this , options ) ) ;
968
+ this . once ( 'connect' , fn ) ;
964
969
return ;
965
970
}
966
971
967
972
debug ( `Http2Session ${ sessionName ( type ) } : sending shutdown` ) ;
968
- submitShutdown . call ( this , options ) ;
973
+ fn ( ) ;
969
974
}
970
975
971
976
_onTimeout ( ) {
@@ -1366,7 +1371,7 @@ class Http2Stream extends Duplex {
1366
1371
rstStream ( code = NGHTTP2_NO_ERROR ) {
1367
1372
if ( typeof code !== 'number' )
1368
1373
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'code' , 'number' ) ;
1369
- if ( code < 0 || code > 2 ** 32 - 1 )
1374
+ if ( code < 0 || code > kMaxInt )
1370
1375
throw new errors . RangeError ( 'ERR_OUT_OF_RANGE' , 'code' ) ;
1371
1376
1372
1377
const fn = submitRstStream . bind ( this , code ) ;
@@ -2360,19 +2365,19 @@ function getPackedSettings(settings) {
2360
2365
settings = settings || Object . create ( null ) ;
2361
2366
assertWithinRange ( 'headerTableSize' ,
2362
2367
settings . headerTableSize ,
2363
- 0 , 2 ** 32 - 1 ) ;
2368
+ 0 , kMaxInt ) ;
2364
2369
assertWithinRange ( 'initialWindowSize' ,
2365
2370
settings . initialWindowSize ,
2366
- 0 , 2 ** 32 - 1 ) ;
2371
+ 0 , kMaxInt ) ;
2367
2372
assertWithinRange ( 'maxFrameSize' ,
2368
2373
settings . maxFrameSize ,
2369
- 16384 , 2 ** 24 - 1 ) ;
2374
+ 16384 , kMaxFrameSize ) ;
2370
2375
assertWithinRange ( 'maxConcurrentStreams' ,
2371
2376
settings . maxConcurrentStreams ,
2372
2377
0 , kMaxStreams ) ;
2373
2378
assertWithinRange ( 'maxHeaderListSize' ,
2374
2379
settings . maxHeaderListSize ,
2375
- 0 , 2 ** 32 - 1 ) ;
2380
+ 0 , kMaxInt ) ;
2376
2381
if ( settings . enablePush !== undefined &&
2377
2382
typeof settings . enablePush !== 'boolean' ) {
2378
2383
const err = new errors . TypeError ( 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
@@ -2423,22 +2428,22 @@ function getUnpackedSettings(buf, options = {}) {
2423
2428
if ( options != null && options . validate ) {
2424
2429
assertWithinRange ( 'headerTableSize' ,
2425
2430
settings . headerTableSize ,
2426
- 0 , 2 ** 32 - 1 ) ;
2431
+ 0 , kMaxInt ) ;
2427
2432
assertWithinRange ( 'enablePush' ,
2428
2433
settings . enablePush ,
2429
2434
0 , 1 ) ;
2430
2435
assertWithinRange ( 'initialWindowSize' ,
2431
2436
settings . initialWindowSize ,
2432
- 0 , 2 ** 32 - 1 ) ;
2437
+ 0 , kMaxInt ) ;
2433
2438
assertWithinRange ( 'maxFrameSize' ,
2434
2439
settings . maxFrameSize ,
2435
- 16384 , 2 ** 24 - 1 ) ;
2440
+ 16384 , kMaxFrameSize ) ;
2436
2441
assertWithinRange ( 'maxConcurrentStreams' ,
2437
2442
settings . maxConcurrentStreams ,
2438
2443
0 , kMaxStreams ) ;
2439
2444
assertWithinRange ( 'maxHeaderListSize' ,
2440
2445
settings . maxHeaderListSize ,
2441
- 0 , 2 ** 32 - 1 ) ;
2446
+ 0 , kMaxInt ) ;
2442
2447
}
2443
2448
2444
2449
if ( settings . enablePush !== undefined ) {
0 commit comments