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