@@ -76,6 +76,7 @@ const {
76
76
ERR_SOCKET_CLOSED
77
77
}
78
78
} = require ( 'internal/errors' ) ;
79
+ const { validateNumber } = require ( 'internal/validators' ) ;
79
80
const { utcDate } = require ( 'internal/http' ) ;
80
81
const { onServerStream,
81
82
Http2ServerRequest,
@@ -1002,8 +1003,7 @@ class Http2Session extends EventEmitter {
1002
1003
if ( this . destroyed )
1003
1004
throw new ERR_HTTP2_INVALID_SESSION ( ) ;
1004
1005
1005
- if ( typeof id !== 'number' )
1006
- throw new ERR_INVALID_ARG_TYPE ( 'id' , 'number' , id ) ;
1006
+ validateNumber ( id , 'id' ) ;
1007
1007
if ( id <= 0 || id > kMaxStreams )
1008
1008
throw new ERR_OUT_OF_RANGE ( 'id' , `> 0 and <= ${ kMaxStreams } ` , id ) ;
1009
1009
this [ kHandle ] . setNextStreamID ( id ) ;
@@ -1145,12 +1145,8 @@ class Http2Session extends EventEmitter {
1145
1145
[ 'Buffer' , 'TypedArray' , 'DataView' ] ,
1146
1146
opaqueData ) ;
1147
1147
}
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' ) ;
1154
1150
1155
1151
const goawayFn = submitGoaway . bind ( this , code , lastStreamID , opaqueData ) ;
1156
1152
if ( this . connecting ) {
@@ -1832,8 +1828,7 @@ class Http2Stream extends Duplex {
1832
1828
// close, it is still possible to queue up PRIORITY and RST_STREAM frames,
1833
1829
// but no DATA and HEADERS frames may be sent.
1834
1830
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' ) ;
1837
1832
if ( code < 0 || code > kMaxInt )
1838
1833
throw new ERR_OUT_OF_RANGE ( 'code' , `>= 0 && <= ${ kMaxInt } ` , code ) ;
1839
1834
if ( callback !== undefined && typeof callback !== 'function' )
@@ -2327,8 +2322,7 @@ class ServerHttp2Stream extends Http2Stream {
2327
2322
this [ kState ] . flags |= STREAM_FLAGS_HAS_TRAILERS ;
2328
2323
}
2329
2324
2330
- if ( typeof fd !== 'number' )
2331
- throw new ERR_INVALID_ARG_TYPE ( 'fd' , 'number' , fd ) ;
2325
+ validateNumber ( fd , 'fd' ) ;
2332
2326
2333
2327
debug ( `Http2Stream ${ this [ kID ] } [Http2Session ` +
2334
2328
`${ sessionName ( session [ kType ] ) } ]: initiating response from fd` ) ;
0 commit comments