@@ -28,11 +28,10 @@ const kHandle = Symbol('kHandle');
2828const { owner_symbol } = internalBinding ( 'symbols' ) ;
2929
3030const {
31- ERR_INVALID_ARG_TYPE ,
3231 ERR_INVALID_ARG_VALUE ,
3332} = require ( 'internal/errors' ) . codes ;
3433
35- const { validateInt32 } = require ( 'internal/validators' ) ;
34+ const { validateInt32, validateString } = require ( 'internal/validators' ) ;
3635
3736class BlockList extends JSTransferable {
3837 constructor ( ) {
@@ -56,10 +55,8 @@ class BlockList extends JSTransferable {
5655 }
5756
5857 addAddress ( address , family = 'ipv4' ) {
59- if ( typeof address !== 'string' )
60- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
61- if ( typeof family !== 'string' )
62- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
58+ validateString ( address , 'address' ) ;
59+ validateString ( family , 'family' ) ;
6360 family = family . toLowerCase ( ) ;
6461 if ( family !== 'ipv4' && family !== 'ipv6' )
6562 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -68,12 +65,9 @@ class BlockList extends JSTransferable {
6865 }
6966
7067 addRange ( start , end , family = 'ipv4' ) {
71- if ( typeof start !== 'string' )
72- throw new ERR_INVALID_ARG_TYPE ( 'start' , 'string' , start ) ;
73- if ( typeof end !== 'string' )
74- throw new ERR_INVALID_ARG_TYPE ( 'end' , 'string' , end ) ;
75- if ( typeof family !== 'string' )
76- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
68+ validateString ( start , 'start' ) ;
69+ validateString ( end , 'end' ) ;
70+ validateString ( family , 'family' ) ;
7771 family = family . toLowerCase ( ) ;
7872 if ( family !== 'ipv4' && family !== 'ipv6' )
7973 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -84,10 +78,8 @@ class BlockList extends JSTransferable {
8478 }
8579
8680 addSubnet ( network , prefix , family = 'ipv4' ) {
87- if ( typeof network !== 'string' )
88- throw new ERR_INVALID_ARG_TYPE ( 'network' , 'string' , network ) ;
89- if ( typeof family !== 'string' )
90- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
81+ validateString ( network , 'network' ) ;
82+ validateString ( family , 'family' ) ;
9183 family = family . toLowerCase ( ) ;
9284 let type ;
9385 switch ( family ) {
@@ -106,10 +98,8 @@ class BlockList extends JSTransferable {
10698 }
10799
108100 check ( address , family = 'ipv4' ) {
109- if ( typeof address !== 'string' )
110- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
111- if ( typeof family !== 'string' )
112- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
101+ validateString ( address , 'address' ) ;
102+ validateString ( family , 'family' ) ;
113103 family = family . toLowerCase ( ) ;
114104 if ( family !== 'ipv4' && family !== 'ipv6' )
115105 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
0 commit comments