|
19 | 19 | // Save the previous value of the `_` variable.
|
20 | 20 | var previousUnderscore = root._;
|
21 | 21 |
|
22 |
| - // not every runtime supports ArrayBuffer |
23 |
| - var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined'; |
24 |
| - |
25 | 22 | // Save bytes in the minified (but not gzipped) version:
|
26 | 23 | var ArrayProto = Array.prototype, ObjProto = Object.prototype;
|
27 | 24 | var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
|
|
48 | 45 | this._wrapped = obj;
|
49 | 46 | };
|
50 | 47 |
|
| 48 | + // not every runtime supports ArrayBuffer |
| 49 | + var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined'; |
| 50 | + // list from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays |
| 51 | + var typedArrayNames = [ |
| 52 | + '[object Int8Array]', |
| 53 | + '[object Int16Array]', |
| 54 | + '[object Int32Array]', |
| 55 | + '[object Uint8Array]', |
| 56 | + '[object Uint8ClampedArray]', |
| 57 | + '[object Uint16Array]', |
| 58 | + '[object Uint32Array]', |
| 59 | + '[object Float32Array]', |
| 60 | + '[object Float64Array]' |
| 61 | + ]; |
| 62 | + var isTypedArray = function(a) { |
| 63 | + // second check is from the above whitelist, but the first check is more future proof |
| 64 | + // since new typed arrays may arrive |
| 65 | + return (supportsArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(a) && !(a instanceof DataView)) |
| 66 | + || _.contains(typedArrayNames, toString.call(a)); |
| 67 | + }; |
| 68 | + |
51 | 69 | // Export the Underscore object for **Node.js**, with
|
52 | 70 | // backwards-compatibility for their old module API. If we're in
|
53 | 71 | // the browser, add `_` as a global object.
|
|
1208 | 1226 | if (className !== toString.call(b)) return false;
|
1209 | 1227 |
|
1210 | 1228 | // isView returns true when it's a typed array or DataView
|
1211 |
| - if (supportsArrayBuffer && ArrayBuffer.isView(a) && !(a instanceof DataView)) { |
| 1229 | + if (isTypedArray(a)) { |
1212 | 1230 | // If a and b are of the same typed array, we compare them as DataView
|
1213 | 1231 | return deepEq(new DataView(a.buffer), new DataView(b.buffer), aStack, bStack);
|
1214 | 1232 | }
|
|
0 commit comments