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