@@ -77,6 +77,71 @@ function checkArgs(connected) {
7777 message : 'Already connected'
7878 }
7979 ) ;
80+
81+ for ( const input of [ 'hello' , Buffer . from ( 'hello' ) ,
82+ Buffer . from ( 'hello world' ) . subarray ( 0 , 5 ) ,
83+ Buffer . from ( 'hello world' ) . subarray ( 6 ) ] ) {
84+ assert . throws (
85+ ( ) => { sock . send ( input , 6 , 0 ) ; } ,
86+ {
87+ code : 'ERR_OUT_OF_RANGE' ,
88+ name : 'RangeError' ,
89+ message : 'The value of "offset" is out of range. ' +
90+ 'It must be <= 5. Received 6'
91+ }
92+ ) ;
93+
94+ assert . throws (
95+ ( ) => { sock . send ( input , 0 , 6 ) ; } ,
96+ {
97+ code : 'ERR_OUT_OF_RANGE' ,
98+ name : 'RangeError' ,
99+ message : 'The value of "length" is out of range. ' +
100+ 'It must be <= 5. Received 6'
101+ }
102+ ) ;
103+
104+ assert . throws (
105+ ( ) => { sock . send ( input , 3 , 4 ) ; } ,
106+ {
107+ code : 'ERR_OUT_OF_RANGE' ,
108+ name : 'RangeError' ,
109+ message : 'The value of "length" is out of range. ' +
110+ 'It must be <= 2. Received 4'
111+ }
112+ ) ;
113+ }
114+
115+ for ( const input of [ new Uint8Array ( [ 1 , 2 , 3 , 4 , 5 ] ) ,
116+ new DataView ( new ArrayBuffer ( 5 ) , 0 ) ,
117+ new DataView ( new ArrayBuffer ( 6 ) , 2 ) ] ) {
118+ assert . throws (
119+ ( ) => { sock . send ( input , 6 , 0 ) ; } ,
120+ {
121+ code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
122+ name : 'RangeError' ,
123+ message : '"offset" is outside of buffer bounds' ,
124+ }
125+ ) ;
126+
127+ assert . throws (
128+ ( ) => { sock . send ( input , 0 , 6 ) ; } ,
129+ {
130+ code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
131+ name : 'RangeError' ,
132+ message : '"length" is outside of buffer bounds' ,
133+ }
134+ ) ;
135+
136+ assert . throws (
137+ ( ) => { sock . send ( input , 3 , 4 ) ; } ,
138+ {
139+ code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
140+ name : 'RangeError' ,
141+ message : '"length" is outside of buffer bounds' ,
142+ }
143+ ) ;
144+ }
80145 } else {
81146 assert . throws ( ( ) => { sock . send ( buf , 1 , 1 , - 1 , host ) ; } , RangeError ) ;
82147 assert . throws ( ( ) => { sock . send ( buf , 1 , 1 , 0 , host ) ; } , RangeError ) ;
0 commit comments