test: fix test-buffer-tostring-range on allocation failure · nodejs/node@4629b18

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,20 @@

1+

'use strict';

2+
3+

// This tests that Buffer.prototype.toString() works with buffers over 4GB.

4+

const common = require('../common');

5+
6+

// Must not throw when start and end are within kMaxLength

7+

// Cannot test on 32bit machine as we are testing the case

8+

// when start and end are above the threshold

9+

common.skipIf32Bits();

10+

const threshold = 0xFFFFFFFF; // 2^32 - 1

11+

let largeBuffer;

12+

try {

13+

largeBuffer = Buffer.alloc(threshold + 20);

14+

} catch (e) {

15+

if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || /Array buffer allocation failed/.test(e.message)) {

16+

common.skip('insufficient space for Buffer.alloc');

17+

}

18+

throw e;

19+

}

20+

largeBuffer.toString('utf8', threshold, threshold + 20);