@@ -74,41 +74,22 @@ new Buffer('', 'latin1');
74
74
new Buffer ( '' , 'binary' ) ;
75
75
Buffer ( 0 ) ;
76
76
77
+ const outOfBoundsError = {
78
+ code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
79
+ type : RangeError
80
+ } ;
81
+
77
82
// try to write a 0-length string beyond the end of b
78
- common . expectsError (
79
- ( ) => b . write ( '' , 2048 ) ,
80
- {
81
- code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
82
- type : RangeError
83
- }
84
- ) ;
83
+ common . expectsError ( ( ) => b . write ( '' , 2048 ) , outOfBoundsError ) ;
85
84
86
85
// throw when writing to negative offset
87
- common . expectsError (
88
- ( ) => b . write ( 'a' , - 1 ) ,
89
- {
90
- code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
91
- type : RangeError
92
- }
93
- ) ;
86
+ common . expectsError ( ( ) => b . write ( 'a' , - 1 ) , outOfBoundsError ) ;
94
87
95
88
// throw when writing past bounds from the pool
96
- common . expectsError (
97
- ( ) => b . write ( 'a' , 2048 ) ,
98
- {
99
- code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
100
- type : RangeError
101
- }
102
- ) ;
89
+ common . expectsError ( ( ) => b . write ( 'a' , 2048 ) , outOfBoundsError ) ;
103
90
104
91
// throw when writing to negative offset
105
- common . expectsError (
106
- ( ) => b . write ( 'a' , - 1 ) ,
107
- {
108
- code : 'ERR_BUFFER_OUT_OF_BOUNDS' ,
109
- type : RangeError
110
- }
111
- ) ;
92
+ common . expectsError ( ( ) => b . write ( 'a' , - 1 ) , outOfBoundsError ) ;
112
93
113
94
// try to copy 0 bytes worth of data into an empty buffer
114
95
b . copy ( Buffer . alloc ( 0 ) , 0 , 0 , 0 ) ;
@@ -804,20 +785,34 @@ assert.strictEqual(Buffer.from('13.37').length, 5);
804
785
Buffer . from ( Buffer . allocUnsafe ( 0 ) , 0 , 0 ) ;
805
786
806
787
// issue GH-5587
807
- assert . throws ( ( ) => Buffer . alloc ( 8 ) . writeFloatLE ( 0 , 5 ) , RangeError ) ;
808
- assert . throws ( ( ) => Buffer . alloc ( 16 ) . writeDoubleLE ( 0 , 9 ) , RangeError ) ;
788
+ common . expectsError (
789
+ ( ) => Buffer . alloc ( 8 ) . writeFloatLE ( 0 , 5 ) ,
790
+ outOfBoundsError
791
+ ) ;
792
+ common . expectsError (
793
+ ( ) => Buffer . alloc ( 16 ) . writeDoubleLE ( 0 , 9 ) ,
794
+ outOfBoundsError
795
+ ) ;
809
796
810
797
// attempt to overflow buffers, similar to previous bug in array buffers
811
- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , 0xffffffff ) ,
812
- RangeError ) ;
813
- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , 0xffffffff ) ,
814
- RangeError ) ;
815
-
798
+ common . expectsError (
799
+ ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , 0xffffffff ) ,
800
+ outOfBoundsError
801
+ ) ;
802
+ common . expectsError (
803
+ ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , 0xffffffff ) ,
804
+ outOfBoundsError
805
+ ) ;
816
806
817
807
// ensure negative values can't get past offset
818
- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , - 1 ) , RangeError ) ;
819
- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , - 1 ) , RangeError ) ;
820
-
808
+ common . expectsError (
809
+ ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , - 1 ) ,
810
+ outOfBoundsError
811
+ ) ;
812
+ common . expectsError (
813
+ ( ) => Buffer . allocUnsafe ( 8 ) . writeFloatLE ( 0.0 , - 1 ) ,
814
+ outOfBoundsError
815
+ ) ;
821
816
822
817
// test for common write(U)IntLE/BE
823
818
{
@@ -1010,10 +1005,7 @@ common.expectsError(() => {
1010
1005
const a = Buffer . alloc ( 1 ) ;
1011
1006
const b = Buffer . alloc ( 1 ) ;
1012
1007
a . copy ( b , 0 , 0x100000000 , 0x100000001 ) ;
1013
- } , {
1014
- code : 'ERR_OUT_OF_RANGE' ,
1015
- type : RangeError
1016
- } ) ;
1008
+ } , outOfBoundsError ) ;
1017
1009
1018
1010
// Unpooled buffer (replaces SlowBuffer)
1019
1011
{
0 commit comments