1+ // Flags: --expose-gc
12'use strict' ;
23const common = require ( '../common' ) ;
34
@@ -22,19 +23,22 @@ const stringTooLongError = {
2223const size = 2 ** 31 ;
2324
2425// 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 ;
3639 }
37- } ) ;
40+ common . skip ( 'insufficient space for Buffer.alloc' ) ;
41+ }
3842} ) ;
3943
4044// Test Buffer.write
@@ -43,6 +47,7 @@ test('Buffer.write with too long size', () => {
4347 const buf = Buffer . alloc ( size ) ;
4448 assert . strictEqual ( buf . write ( 'a' , 2 , kStringMaxLength ) , 1 ) ;
4549 assert . strictEqual ( buf . write ( 'a' , 2 , size ) , 1 ) ;
50+ globalThis . gc ( { type : 'major' } ) ;
4651 } catch ( e ) {
4752 if ( e . code !== 'ERR_MEMORY_ALLOCATION_FAILED' ) {
4853 throw e ;
0 commit comments