summaryrefslogtreecommitdiff
path: root/lib/internal/buffer.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-03-04 22:16:24 +0100
committerMichaël Zasso <targos@protonmail.com>2018-03-07 14:54:38 +0100
commit1d2fd8b65bacaf4401450edc8ed529106cbcfc67 (patch)
treedd6230e888c69ef3dc1b19de1ea8f9de7a81fd63 /lib/internal/buffer.js
parentcb5f9a6d871f6b2e0da8fa72dc2e91fb37ef9713 (diff)
downloadandroid-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.gz
android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.bz2
android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.zip
lib: port remaining errors to new system
PR-URL: https://github.com/nodejs/node/pull/19137 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
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);