nodejs/test/parallel/test-buffer-tostring-rangeerror.js
Filip Skokan daced4ab98
buffer: move SlowBuffer to EOL
This commits reverts da69d13623e6c9ec8692d8002297e63cf2f656d8

PR-URL: https://github.com/nodejs/node/pull/58220
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2025-05-09 19:41:31 +00:00

31 lines
884 B
JavaScript

'use strict';
const common = require('../common');
// This test ensures that Node.js throws an Error when trying to convert a
// large buffer into a string.
// Regression test for https://github.com/nodejs/node/issues/649.
if (!common.enoughTestMem) {
common.skip('skipped due to memory requirements');
}
const assert = require('assert');
const {
Buffer,
constants: {
MAX_STRING_LENGTH,
},
} = require('buffer');
const len = MAX_STRING_LENGTH + 1;
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);