]> zoso.dev Git - buffer.git/commitdiff
IE10 fix: don't pass undefined length to typed array constructor
authorFeross Aboukhadijeh <feross@feross.org>
Wed, 20 Apr 2016 05:48:28 +0000 (22:48 -0700)
committerFeross Aboukhadijeh <feross@feross.org>
Wed, 20 Apr 2016 05:48:28 +0000 (22:48 -0700)
index.js

index 12a7190bd501cd0f3c803cff837c040ed9c350d0..83842a2de9bfc83a9240971f9ae1dc7ea0058ecd 100644 (file)
--- 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
 }