mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 23:10:15 +00:00

- Always return the same error message(hopefully more informative) for buffer length > kMaxLength and avoid getting into V8 C++ land for unnecessary checks. - Use accurate RegExp(reusable as `common.bufferMaxSizeMsg`) in tests for this error. - Separate related tests from test-buffer-alloc. PR-URL: https://github.com/nodejs/node/pull/10152 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
15 lines
608 B
JavaScript
15 lines
608 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const SlowBuffer = require('buffer').SlowBuffer;
|
|
|
|
// Regression test for https://github.com/nodejs/node/issues/649.
|
|
const len = 1422561062959;
|
|
const message = common.bufferMaxSizeMsg;
|
|
assert.throws(() => Buffer(len).toString('utf8'), message);
|
|
assert.throws(() => SlowBuffer(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);
|