From: Feross Aboukhadijeh Date: Wed, 20 Apr 2016 05:48:28 +0000 (-0700) Subject: IE10 fix: don't pass undefined length to typed array constructor X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6b92cf350bb7d417dbbc394e800981ad7745221c;p=buffer.git IE10 fix: don't pass undefined length to typed array constructor --- diff --git a/index.js b/index.js index 12a7190..83842a2 100644 --- a/index.js +++ b/index.js @@ -252,17 +252,19 @@ function fromArrayBuffer (that, array, byteOffset, length) { throw new RangeError('\'length\' is out of bounds') } + if (length === undefined) { + array = new Uint8Array(array, byteOffset) + } else { + array = new Uint8Array(array, byteOffset, length) + } + if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance - if (length === undefined) { - that = new Uint8Array(array, byteOffset) - } else { - that = new Uint8Array(array, byteOffset, length) - } + that = array that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, new Uint8Array(array, byteOffset, length)) + that = fromArrayLike(that, array) } return that }