| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c449ed commit bffd4ec
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,22 @@ const message = { | |||
| 18 | 18 | code: 'ERR_STRING_TOO_LONG', | |
| 19 | 19 | name: 'Error', | |
| 20 | 20 | }; | |
| 21 | - assert.throws(() => Buffer(len).toString('utf8'), message); | ||
| 22 | - assert.throws(() => SlowBuffer(len).toString('utf8'), message); | ||
| 23 | - assert.throws(() => Buffer.alloc(len).toString('utf8'), message); | ||
| 24 | - assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message); | ||
| 25 | - assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message); | ||
| 21 | + | ||
| 22 | + function test(getBuffer) { | ||
| 23 | + let buf; | ||
| 24 | + try { | ||
| 25 | + buf = getBuffer(); | ||
| 26 | + } catch (e) { | ||
| 27 | + // If the buffer allocation fails, we skip the test. | ||
| 28 | + if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || /Array buffer allocation failed/.test(e.message)) { | ||
| 29 | + return; | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + assert.throws(() => { buf.toString('utf8'); }, message); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + test(() => Buffer(len)); | ||
| 36 | + test(() => SlowBuffer(len)); | ||
| 37 | + test(() => Buffer.alloc(len)); | ||
| 38 | + test(() => Buffer.allocUnsafe(len)); | ||
| 39 | + test(() => Buffer.allocUnsafeSlow(len)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments