From: Feross Aboukhadijeh Date: Mon, 26 Sep 2016 19:37:27 +0000 (-0700) Subject: clean up typed array support detection X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=62fc25c37f859799597910f57df77f5bb65dbb92;p=buffer.git clean up typed array support detection --- diff --git a/index.js b/index.js index 5112d22..1c28c58 100644 --- a/index.js +++ b/index.js @@ -27,16 +27,10 @@ exports.kMaxLength = K_MAX_LENGTH * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * - * Sometimes we report that the browser does not support typed arrays, if there - * exist extreme bugs in the implemetation. For example: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. */ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() @@ -47,12 +41,11 @@ if (!Buffer.TYPED_ARRAY_SUPPORT) { } function typedArraySupport () { + // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + return arr.foo() === 42 } catch (e) { return false }