summaryrefslogtreecommitdiff
path: root/lib/internal/buffer.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/buffer.js')
-rw-r--r--lib/internal/buffer.js28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js
index b5da69a5b3..fe10b20c80 100644
--- a/lib/internal/buffer.js
+++ b/lib/internal/buffer.js
@@ -1,7 +1,11 @@
'use strict';
const binding = process.binding('buffer');
-const { TypeError, RangeError } = require('internal/errors');
+const {
+ ERR_BUFFER_OUT_OF_BOUNDS,
+ ERR_INVALID_ARG_TYPE,
+ ERR_OUT_OF_RANGE
+} = require('internal/errors').codes;
const { setupBufferJS } = binding;
// Remove from the binding so that function is only available as exported here.
@@ -26,33 +30,29 @@ function checkBounds(buf, offset, byteLength) {
function checkInt(value, min, max, buf, offset, byteLength) {
if (value > max || value < min) {
- throw new RangeError('ERR_OUT_OF_RANGE',
- 'value', `>= ${min} and <= ${max}`, value);
+ throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value);
}
checkBounds(buf, offset, byteLength);
}
function checkNumberType(value, type) {
if (typeof value !== 'number') {
- throw new TypeError('ERR_INVALID_ARG_TYPE',
- type || 'offset', 'number', value);
+ throw new ERR_INVALID_ARG_TYPE(type || 'offset', 'number', value);
}
}
function boundsError(value, length, type) {
if (Math.floor(value) !== value) {
checkNumberType(value, type);
- throw new RangeError('ERR_OUT_OF_RANGE',
- type || 'offset', 'an integer', value);
+ throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value);
}
if (length < 0)
- throw new RangeError('ERR_BUFFER_OUT_OF_BOUNDS', null, true);
+ throw new ERR_BUFFER_OUT_OF_BOUNDS(null, true);
- throw new RangeError('ERR_OUT_OF_RANGE',
- type || 'offset',
- `>= ${type ? 1 : 0} and <= ${length}`,
- value);
+ throw new ERR_OUT_OF_RANGE(type || 'offset',
+ `>= ${type ? 1 : 0} and <= ${length}`,
+ value);
}
// Read integers.
@@ -545,9 +545,7 @@ function writeU_Int8(buf, value, offset, min, max) {
// `checkInt()` can not be used here because it checks two entries.
checkNumberType(offset);
if (value > max || value < min) {
- throw new RangeError('ERR_OUT_OF_RANGE',
- 'value',
- `>= ${min} and <= ${max}`, value);
+ throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value);
}
if (buf[offset] === undefined)
boundsError(offset, buf.length - 1);