mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
errors: validate input arguments
This makes sure the input arguments get validated so implementation errors will be caught early. It also improves a couple of error messages by providing more detailed information and fixes errors detected by the new functionality. Besides that a error type got simplified and tests got refactored. PR-URL: https://github.com/nodejs/node/pull/19924 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d5495e859c
commit
dca7fb2225
18 changed files with 215 additions and 178 deletions
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const LENGTH = 16;
|
||||
|
@ -58,14 +58,14 @@ assert.throws(function() {
|
|||
buf[0] = 9;
|
||||
assert.strictEqual(ab[1], 9);
|
||||
|
||||
common.expectsError(() => Buffer.from(ab.buffer, 6), {
|
||||
assert.throws(() => Buffer.from(ab.buffer, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
common.expectsError(() => Buffer.from(ab.buffer, 3, 6), {
|
||||
assert.throws(() => Buffer.from(ab.buffer, 3, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
@ -86,14 +86,14 @@ assert.throws(function() {
|
|||
buf[0] = 9;
|
||||
assert.strictEqual(ab[1], 9);
|
||||
|
||||
common.expectsError(() => Buffer(ab.buffer, 6), {
|
||||
assert.throws(() => Buffer(ab.buffer, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
common.expectsError(() => Buffer(ab.buffer, 3, 6), {
|
||||
assert.throws(() => Buffer(ab.buffer, 3, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
@ -111,11 +111,11 @@ assert.throws(function() {
|
|||
assert.deepStrictEqual(Buffer.from(ab, [1]), Buffer.from(ab, 1));
|
||||
|
||||
// If byteOffset is Infinity, throw.
|
||||
common.expectsError(() => {
|
||||
assert.throws(() => {
|
||||
Buffer.from(ab, Infinity);
|
||||
}, {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
@ -133,11 +133,11 @@ assert.throws(function() {
|
|||
assert.deepStrictEqual(Buffer.from(ab, 0, [1]), Buffer.from(ab, 0, 1));
|
||||
|
||||
// If length is Infinity, throw.
|
||||
common.expectsError(() => {
|
||||
assert.throws(() => {
|
||||
Buffer.from(ab, 0, Infinity);
|
||||
}, {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
type: RangeError,
|
||||
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue