mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
3d353c749c
- 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>
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const buffer = require('buffer');
|
|
const Buffer = buffer.Buffer;
|
|
const SlowBuffer = buffer.SlowBuffer;
|
|
|
|
const kMaxLength = buffer.kMaxLength;
|
|
const bufferMaxSizeMsg = common.bufferMaxSizeMsg;
|
|
|
|
assert.throws(() => Buffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => SlowBuffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.alloc((-1 >>> 0) + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 1), bufferMaxSizeMsg);
|
|
|
|
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
|
|
|
|
// issue GH-4331
|
|
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFF), bufferMaxSizeMsg);
|
|
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);
|