mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
671ffd7825
Instead of additional `if` statement, use min/max of `validateNumber`. PR-URL: https://github.com/nodejs/node/pull/45796 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { SlowBuffer } = require('buffer');
|
|
|
|
const msg = {
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
name: 'RangeError',
|
|
};
|
|
|
|
// Test that negative Buffer length inputs throw errors.
|
|
|
|
assert.throws(() => Buffer(-Buffer.poolSize), msg);
|
|
assert.throws(() => Buffer(-100), msg);
|
|
assert.throws(() => Buffer(-1), msg);
|
|
assert.throws(() => Buffer(NaN), msg);
|
|
|
|
assert.throws(() => Buffer.alloc(-Buffer.poolSize), msg);
|
|
assert.throws(() => Buffer.alloc(-100), msg);
|
|
assert.throws(() => Buffer.alloc(-1), msg);
|
|
assert.throws(() => Buffer.alloc(NaN), msg);
|
|
|
|
assert.throws(() => Buffer.allocUnsafe(-Buffer.poolSize), msg);
|
|
assert.throws(() => Buffer.allocUnsafe(-100), msg);
|
|
assert.throws(() => Buffer.allocUnsafe(-1), msg);
|
|
assert.throws(() => Buffer.allocUnsafe(NaN), msg);
|
|
|
|
assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg);
|
|
assert.throws(() => Buffer.allocUnsafeSlow(-100), msg);
|
|
assert.throws(() => Buffer.allocUnsafeSlow(-1), msg);
|
|
assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg);
|
|
|
|
assert.throws(() => SlowBuffer(-Buffer.poolSize), msg);
|
|
assert.throws(() => SlowBuffer(-100), msg);
|
|
assert.throws(() => SlowBuffer(-1), msg);
|
|
assert.throws(() => SlowBuffer(NaN), msg);
|