From 386e11aff232ce1fe0b5a6dd990d8ebb21769436 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Sun, 21 Jan 2018 02:17:42 +0100 Subject: [PATCH] Fix outdated error message --- index.js | 2 +- test/node/test-buffer-arraybuffer.js | 34 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 5befc08..3ad1093 100644 --- a/index.js +++ b/index.js @@ -241,7 +241,7 @@ function fromArrayBuffer (array, byteOffset, length) { } if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') + throw new RangeError('"length" is outside of buffer bounds') } var buf diff --git a/test/node/test-buffer-arraybuffer.js b/test/node/test-buffer-arraybuffer.js index 4036812..4e3b31a 100644 --- a/test/node/test-buffer-arraybuffer.js +++ b/test/node/test-buffer-arraybuffer.js @@ -1,6 +1,6 @@ 'use strict'; var Buffer = require('../../').Buffer; - +var common = require('../common'); var assert = require('assert'); @@ -70,15 +70,15 @@ b.writeDoubleBE(11.11, 0, true); buf[0] = 9; assert.equal(ab[1], 9); - assert.throws(() => Buffer.from(ab.buffer, 6), (err) => { - assert(err instanceof RangeError); - assert(/'offset' is out of bounds/.test(err.message)); - return true; + common.expectsError(() => Buffer.from(ab.buffer, 6), { + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"offset" is outside of buffer bounds' }); - assert.throws(() => Buffer.from(ab.buffer, 3, 6), (err) => { - assert(err instanceof RangeError); - assert(/'length' is out of bounds/.test(err.message)); - return true; + common.expectsError(() => Buffer.from(ab.buffer, 3, 6), { + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"length" is outside of buffer bounds' }); } @@ -98,15 +98,15 @@ b.writeDoubleBE(11.11, 0, true); buf[0] = 9; assert.equal(ab[1], 9); - assert.throws(() => Buffer(ab.buffer, 6), (err) => { - assert(err instanceof RangeError); - assert(/'offset' is out of bounds/.test(err.message)); - return true; + common.expectsError(() => Buffer(ab.buffer, 6), { + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"offset" is outside of buffer bounds' }); - assert.throws(() => Buffer(ab.buffer, 3, 6), (err) => { - assert(err instanceof RangeError); - assert(/'length' is out of bounds/.test(err.message)); - return true; + common.expectsError(() => Buffer(ab.buffer, 3, 6), { + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"length" is outside of buffer bounds' }); } -- 2.34.1