@@ -76,6 +76,7 @@ const {
7676 ERR_SOCKET_CLOSED
7777 }
7878} = require ( 'internal/errors' ) ;
79+ const { validateNumber } = require ( 'internal/validators' ) ;
7980const { utcDate } = require ( 'internal/http' ) ;
8081const { onServerStream,
8182 Http2ServerRequest,
@@ -1002,8 +1003,7 @@ class Http2Session extends EventEmitter {
10021003 if ( this . destroyed )
10031004 throw new ERR_HTTP2_INVALID_SESSION ( ) ;
10041005
1005- if ( typeof id !== 'number' )
1006- throw new ERR_INVALID_ARG_TYPE ( 'id' , 'number' , id ) ;
1006+ validateNumber ( id , 'id' ) ;
10071007 if ( id <= 0 || id > kMaxStreams )
10081008 throw new ERR_OUT_OF_RANGE ( 'id' , `> 0 and <= ${ kMaxStreams } ` , id ) ;
10091009 this [ kHandle ] . setNextStreamID ( id ) ;
@@ -1145,12 +1145,8 @@ class Http2Session extends EventEmitter {
11451145 [ 'Buffer' , 'TypedArray' , 'DataView' ] ,
11461146 opaqueData ) ;
11471147 }
1148- if ( typeof code !== 'number' ) {
1149- throw new ERR_INVALID_ARG_TYPE ( 'code' , 'number' , code ) ;
1150- }
1151- if ( typeof lastStreamID !== 'number' ) {
1152- throw new ERR_INVALID_ARG_TYPE ( 'lastStreamID' , 'number' , lastStreamID ) ;
1153- }
1148+ validateNumber ( code , 'code' ) ;
1149+ validateNumber ( lastStreamID , 'lastStreamID' ) ;
11541150
11551151 const goawayFn = submitGoaway . bind ( this , code , lastStreamID , opaqueData ) ;
11561152 if ( this . connecting ) {
@@ -1832,8 +1828,7 @@ class Http2Stream extends Duplex {
18321828 // close, it is still possible to queue up PRIORITY and RST_STREAM frames,
18331829 // but no DATA and HEADERS frames may be sent.
18341830 close ( code = NGHTTP2_NO_ERROR , callback ) {
1835- if ( typeof code !== 'number' )
1836- throw new ERR_INVALID_ARG_TYPE ( 'code' , 'number' , code ) ;
1831+ validateNumber ( code , 'code' ) ;
18371832 if ( code < 0 || code > kMaxInt )
18381833 throw new ERR_OUT_OF_RANGE ( 'code' , `>= 0 && <= ${ kMaxInt } ` , code ) ;
18391834 if ( callback !== undefined && typeof callback !== 'function' )
@@ -2327,8 +2322,7 @@ class ServerHttp2Stream extends Http2Stream {
23272322 this [ kState ] . flags |= STREAM_FLAGS_HAS_TRAILERS ;
23282323 }
23292324
2330- if ( typeof fd !== 'number' )
2331- throw new ERR_INVALID_ARG_TYPE ( 'fd' , 'number' , fd ) ;
2325+ validateNumber ( fd , 'fd' ) ;
23322326
23332327 debug ( `Http2Stream ${ this [ kID ] } [Http2Session ` +
23342328 `${ sessionName ( session [ kType ] ) } ]: initiating response from fd` ) ;
0 commit comments