1
+ // Flags: --expose-gc
1
2
'use strict' ;
2
3
const common = require ( '../common' ) ;
3
4
@@ -22,19 +23,22 @@ const stringTooLongError = {
22
23
const size = 2 ** 31 ;
23
24
24
25
// Test Buffer.toString
25
- const bufferMethodsToTest = [ SlowBuffer , Buffer . alloc , Buffer . allocUnsafe , Buffer . allocUnsafeSlow ] ;
26
-
27
- bufferMethodsToTest . forEach ( ( method ) => {
28
- test ( `${ method . name } with too long size` , ( ) => {
29
- try {
30
- assert . throws ( ( ) => method ( size ) . toString ( 'utf8' ) , stringTooLongError ) ;
31
- } catch ( e ) {
32
- if ( e . code !== 'ERR_MEMORY_ALLOCATION_FAILED' ) {
33
- throw e ;
34
- }
35
- common . skip ( 'insufficient space for Buffer.alloc' ) ;
26
+ test ( 'Buffer.toString with too long size' , ( ) => {
27
+ try {
28
+ assert . throws ( ( ) => SlowBuffer ( size ) . toString ( 'utf8' ) , stringTooLongError ) ;
29
+ globalThis . gc ( { type : 'major' } ) ;
30
+ assert . throws ( ( ) => Buffer . alloc ( size ) . toString ( 'utf8' ) , stringTooLongError ) ;
31
+ globalThis . gc ( { type : 'major' } ) ;
32
+ assert . throws ( ( ) => Buffer . allocUnsafe ( size ) . toString ( 'utf8' ) , stringTooLongError ) ;
33
+ globalThis . gc ( { type : 'major' } ) ;
34
+ assert . throws ( ( ) => Buffer . allocUnsafeSlow ( size ) . toString ( 'utf8' ) , stringTooLongError ) ;
35
+ globalThis . gc ( { type : 'major' } ) ;
36
+ } catch ( e ) {
37
+ if ( e . code !== 'ERR_MEMORY_ALLOCATION_FAILED' ) {
38
+ throw e ;
36
39
}
37
- } ) ;
40
+ common . skip ( 'insufficient space for Buffer.alloc' ) ;
41
+ }
38
42
} ) ;
39
43
40
44
// Test Buffer.write
@@ -43,6 +47,7 @@ test('Buffer.write with too long size', () => {
43
47
const buf = Buffer . alloc ( size ) ;
44
48
assert . strictEqual ( buf . write ( 'a' , 2 , kStringMaxLength ) , 1 ) ;
45
49
assert . strictEqual ( buf . write ( 'a' , 2 , size ) , 1 ) ;
50
+ globalThis . gc ( { type : 'major' } ) ;
46
51
} catch ( e ) {
47
52
if ( e . code !== 'ERR_MEMORY_ALLOCATION_FAILED' ) {
48
53
throw e ;
0 commit comments