From: Volker Mische Date: Fri, 19 Jan 2018 15:06:03 +0000 (+0100) Subject: Node.js also supports Buffer creation from {buffer: ArrayBuffer} X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=cf6061e81ec898e07c35215cb82f3ec0d6c6cc2a;p=buffer.git Node.js also supports Buffer creation from {buffer: ArrayBuffer} --- diff --git a/index.js b/index.js index 0ee40c1..bc48ecc 100644 --- a/index.js +++ b/index.js @@ -104,7 +104,7 @@ function from (value, encodingOrOffset, length) { throw new TypeError('"value" argument must not be a number') } - if (isArrayBuffer(value)) { + if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) { return fromArrayBuffer(value, encodingOrOffset, length) } diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index 8b3e52b..f8137bd 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -999,9 +999,8 @@ assert.doesNotThrow(() => Buffer.from(new ArrayBuffer())); // Test that ArrayBuffer from a different context is detected correctly var arrayBuf = vm.runInNewContext('new ArrayBuffer()'); assert.doesNotThrow(() => Buffer.from(arrayBuf)); -/* assert.doesNotThrow(() => Buffer.from({ buffer: arrayBuf })); - +/* assert.throws(() => Buffer.alloc({ valueOf: () => 1 }), /"size" argument must be of type number/); assert.throws(() => Buffer.alloc({ valueOf: () => -1 }),