From 1d2fd8b65bacaf4401450edc8ed529106cbcfc67 Mon Sep 17 00:00:00 2001 From: Michaƫl Zasso Date: Sun, 4 Mar 2018 22:16:24 +0100 Subject: lib: port remaining errors to new system PR-URL: https://github.com/nodejs/node/pull/19137 Reviewed-By: Anatoli Papirovski Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- lib/internal/buffer.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'lib/internal/buffer.js') 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); -- cgit v1.2.3