From c04c7bdfbd276c7ca16d7275da9ee633463b79d5 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 17 Mar 2016 10:49:25 -0700 Subject: [PATCH] Pull out new throws --- lib/buffer.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 58e5e47d9d0c18..545c80eb44d9bf 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -47,14 +47,8 @@ function alignPool() { function Buffer(arg, encodingOrOffset, length) { // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ); - } + if (typeof arg === 'number') return Buffer.allocUnsafe(arg); - } return Buffer.from(arg, encodingOrOffset, length); } @@ -155,9 +149,6 @@ function fromString(string, encoding) { if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8'; - if (!Buffer.isEncoding(encoding)) - throw new TypeError('"encoding" must be a valid string encoding'); - var length = byteLength(string, encoding); if (length >= (Buffer.poolSize >>> 1)) return binding.createFromString(string, encoding);