mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test: skip in test-buffer-tostring-rangeerror on allocation failure
If the buffer allocation fails due to insufficient memory, there is no point continue testing toString(). PR-URL: https://github.com/nodejs/node/pull/58415 Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
8287f6748b
commit
996a774eba
|
|
@ -23,8 +23,22 @@ const message = {
|
|||
code: 'ERR_STRING_TOO_LONG',
|
||||
name: 'Error',
|
||||
};
|
||||
assert.throws(() => Buffer(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
|
||||
|
||||
function test(getBuffer) {
|
||||
let buf;
|
||||
try {
|
||||
buf = getBuffer();
|
||||
} catch (e) {
|
||||
// If the buffer allocation fails, we skip the test.
|
||||
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || /Array buffer allocation failed/.test(e.message)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert.throws(() => { buf.toString('utf8'); }, message);
|
||||
}
|
||||
|
||||
test(() => Buffer(len));
|
||||
test(() => Buffer.allocUnsafeSlow(len));
|
||||
test(() => Buffer.alloc(len));
|
||||
test(() => Buffer.allocUnsafe(len));
|
||||
test(() => Buffer.allocUnsafeSlow(len));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user