diff --git a/lib/buffer.js b/lib/buffer.js index b9fe5bfb84b64a..403c344bdbe9c8 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -105,6 +105,10 @@ function fromObject(obj) { return b; } + if (obj == null) { + throw new TypeError('must start with number, buffer, array or string'); + } + if (obj instanceof ArrayBuffer) { return binding.createFromArrayBuffer(obj); } diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index 3daa02eac790f1..d5013c355289c8 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -1181,3 +1181,11 @@ Buffer.poolSize = ps; assert.throws(function() { Buffer(10).copy(); }); + +assert.throws(function() { + new Buffer(); +}, /must start with number, buffer, array or string/); + +assert.throws(function() { + new Buffer(null); +}, /must start with number, buffer, array or string/);