| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 68671f4 commit 6e0ee39
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,22 @@ common.skipIf32Bits(); | |||
| 7 | 7 | const assert = require('node:assert'); | |
| 8 | 8 | const size = 2 ** 31; | |
| 9 | 9 | ||
| 10 | + let largeBuffer; | ||
| 11 | + | ||
| 10 | 12 | // Test Buffer.allocUnsafe with size larger than integer range | |
| 11 | 13 | try { | |
| 12 | - assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' }); | ||
| 14 | + largeBuffer = Buffer.allocUnsafeSlow(size); | ||
| 13 | 15 | } catch (e) { | |
| 14 | - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { | ||
| 15 | - throw e; | ||
| 16 | + if ( | ||
| 17 | + e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || | ||
| 18 | + /Array buffer allocation failed/.test(e.message) | ||
| 19 | + ) { | ||
| 20 | + common.skip('insufficient space for Buffer.allocUnsafeSlow'); | ||
| 16 | 21 | } | |
| 17 | - common.skip('insufficient space for Buffer.allocUnsafeSlow'); | ||
| 22 | + | ||
| 23 | + throw e; | ||
| 18 | 24 | } | |
| 25 | + | ||
| 26 | + assert.throws(() => largeBuffer.toString('utf8'), { | ||
| 27 | + code: 'ERR_STRING_TOO_LONG', | ||
| 28 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,14 +9,21 @@ const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH; | |||
| 9 | 9 | ||
| 10 | 10 | const size = 2 ** 31; | |
| 11 | 11 | ||
| 12 | - // Test Buffer.write with size larger than integer range | ||
| 12 | + let largeBuffer; | ||
| 13 | + | ||
| 13 | 14 | try { | |
| 14 | - const buf = Buffer.alloc(size); | ||
| 15 | - assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1); | ||
| 16 | - assert.strictEqual(buf.write('a', 2, size), 1); | ||
| 15 | + largeBuffer = Buffer.alloc(size); | ||
| 17 | 16 | } catch (e) { | |
| 18 | - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { | ||
| 19 | - throw e; | ||
| 17 | + if ( | ||
| 18 | + e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || | ||
| 19 | + /Array buffer allocation failed/.test(e.message) | ||
| 20 | + ) { | ||
| 21 | + common.skip('insufficient space for Buffer.alloc'); | ||
| 20 | 22 | } | |
| 21 | - common.skip('insufficient space for Buffer.alloc'); | ||
| 23 | + | ||
| 24 | + throw e; | ||
| 22 | 25 | } | |
| 26 | + | ||
| 27 | + // Test Buffer.write with size larger than integer range | ||
| 28 | + assert.strictEqual(largeBuffer.write('a', 2, kStringMaxLength), 1); | ||
| 29 | + assert.strictEqual(largeBuffer.write('a', 2, size), 1); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,12 @@ const size = 2 ** 31; | |||
| 15 | 15 | try { | |
| 16 | 16 | assert.throws(() => SlowBuffer(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' }); | |
| 17 | 17 | } catch (e) { | |
| 18 | - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { | ||
| 19 | - throw e; | ||
| 18 | + if ( | ||
| 19 | + e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || | ||
| 20 | + /Array buffer allocation failed/.test(e.message) | ||
| 21 | + ) { | ||
| 22 | + common.skip('insufficient space for slow Buffer allocation'); | ||
| 20 | 23 | } | |
| 21 | - common.skip('insufficient space for SlowBuffer'); | ||
| 24 | + | ||
| 25 | + throw e; | ||
| 22 | 26 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,13 +17,20 @@ const stringTooLongError = { | |||
| 17 | 17 | name: 'Error', | |
| 18 | 18 | }; | |
| 19 | 19 | ||
| 20 | + let largeBuffer; | ||
| 21 | + | ||
| 20 | 22 | try { | |
| 21 | - const buf = Buffer.allocUnsafe(size); | ||
| 22 | - const decoder = new StringDecoder('utf8'); | ||
| 23 | - assert.throws(() => decoder.write(buf), stringTooLongError); | ||
| 23 | + largeBuffer = Buffer.allocUnsafe(size); | ||
| 24 | 24 | } catch (e) { | |
| 25 | - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { | ||
| 26 | - throw e; | ||
| 25 | + if ( | ||
| 26 | + e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || | ||
| 27 | + /Array buffer allocation failed/.test(e.message) | ||
| 28 | + ) { | ||
| 29 | + common.skip('insufficient space for Buffer.allocUnsafe'); | ||
| 27 | 30 | } | |
| 28 | - common.skip('insufficient space for Buffer.alloc'); | ||
| 31 | + | ||
| 32 | + throw e; | ||
| 29 | 33 | } | |
| 34 | + | ||
| 35 | + const decoder = new StringDecoder('utf8'); | ||
| 36 | + assert.throws(() => decoder.write(largeBuffer), stringTooLongError); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments