@@ -22,9 +22,10 @@ const { owner_symbol } = internalBinding('symbols');
22
22
const {
23
23
ERR_INVALID_ARG_TYPE ,
24
24
ERR_INVALID_ARG_VALUE ,
25
- ERR_OUT_OF_RANGE ,
26
25
} = require ( 'internal/errors' ) . codes ;
27
26
27
+ const { validateInt32 } = require ( 'internal/validators' ) ;
28
+
28
29
class BlockList {
29
30
constructor ( handle = new BlockListHandle ( ) ) {
30
31
// The handle argument is an intentionally undocumented
@@ -81,22 +82,18 @@ class BlockList {
81
82
addSubnet ( network , prefix , family = 'ipv4' ) {
82
83
if ( typeof network !== 'string' )
83
84
throw new ERR_INVALID_ARG_TYPE ( 'network' , 'string' , network ) ;
84
- if ( typeof prefix !== 'number' )
85
- throw new ERR_INVALID_ARG_TYPE ( 'prefix' , 'number' , prefix ) ;
86
85
if ( typeof family !== 'string' )
87
86
throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
88
87
family = family . toLowerCase ( ) ;
89
88
let type ;
90
89
switch ( family ) {
91
90
case 'ipv4' :
92
91
type = AF_INET ;
93
- if ( prefix < 0 || prefix > 32 )
94
- throw new ERR_OUT_OF_RANGE ( prefix , '>= 0 and <= 32' , prefix ) ;
92
+ validateInt32 ( prefix , 'prefix' , 0 , 32 ) ;
95
93
break ;
96
94
case 'ipv6' :
97
95
type = AF_INET6 ;
98
- if ( prefix < 0 || prefix > 128 )
99
- throw new ERR_OUT_OF_RANGE ( prefix , '>= 0 and <= 128' , prefix ) ;
96
+ validateInt32 ( prefix , 'prefix' , 0 , 128 ) ;
100
97
break ;
101
98
default :
102
99
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
0 commit comments