|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -var callBind = require('call-bind'); |
4 |
| -var callBound = require('call-bind/callBound'); |
5 |
| - |
6 |
| -var $toString = callBound('Object.prototype.toString'); |
7 |
| -var $strSlice = callBound('String.prototype.slice'); |
8 |
| - |
9 | 3 | var implementation = require('./implementation');
|
10 | 4 |
|
11 |
| -var ownSlice = null; |
12 |
| -if (typeof Uint8Array === 'function' && !Uint8Array.prototype.slice && new Uint8Array(0).slice) { |
13 |
| - // node < 0.12 has typed arrays but only an own slice, that's specific for each type |
14 |
| - var map = { |
15 |
| - $Float32Array: callBind(new Float32Array(0).slice), |
16 |
| - $Float64Array: callBind(new Float64Array(0).slice), |
17 |
| - $Int8Array: callBind(new Int8Array(0).slice), |
18 |
| - $Int16Array: callBind(new Int16Array(0).slice), |
19 |
| - $Int32Array: callBind(new Int32Array(0).slice), |
20 |
| - $Uint8Array: callBind(new Uint8Array(0).slice), |
21 |
| - $Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' && callBind(new Uint8ClampedArray(0).slice), // node 0.6 lacks Uint8ClampedArray |
22 |
| - $Uint16Array: callBind(new Uint16Array(0).slice), |
23 |
| - $Uint32Array: callBind(new Uint32Array(0).slice), |
24 |
| - __proto__: null |
25 |
| - }; |
26 |
| - var dispatch = function dispatchSlice(fn, arr, args) { |
27 |
| - if (args.length < 2) { |
28 |
| - return fn(arr, args.length > 0 ? args[0] : 0); |
29 |
| - } |
30 |
| - return fn(arr, args[0], args[1]); |
31 |
| - }; |
32 |
| - // eslint-disable-next-line no-unused-vars |
33 |
| - ownSlice = function slice(start, end) { |
34 |
| - var fn = map['$' + $strSlice($toString(this), 8, -1)]; |
35 |
| - if (!fn) { |
36 |
| - /* eslint max-depth: 0 */ |
37 |
| - try { |
38 |
| - return dispatch(map.$Float32Array, this, arguments); |
39 |
| - } catch (e) { |
40 |
| - try { |
41 |
| - return dispatch(map.$Float64Array, this, arguments); |
42 |
| - } catch (e1) { |
43 |
| - try { |
44 |
| - return dispatch(map.$Int8Array, this, arguments); |
45 |
| - } catch (e2) { |
46 |
| - try { |
47 |
| - return dispatch(map.$Uint8Array, this, arguments); |
48 |
| - } catch (e3) { |
49 |
| - try { |
50 |
| - return dispatch(map.$Uint8ClampedArray, this, arguments); |
51 |
| - } catch (e4) { |
52 |
| - try { |
53 |
| - return dispatch(map.$Int16Array, this, arguments); |
54 |
| - } catch (e5) { |
55 |
| - try { |
56 |
| - return dispatch(map.$Uint16Array, this, arguments); |
57 |
| - } catch (e6) { |
58 |
| - try { |
59 |
| - return dispatch(map.$Int32Array, this, arguments); |
60 |
| - } catch (e7) { |
61 |
| - return dispatch(map.$Uint32Array, this, arguments); |
62 |
| - } |
63 |
| - } |
64 |
| - } |
65 |
| - } |
66 |
| - } |
67 |
| - } |
68 |
| - } |
69 |
| - } |
70 |
| - } |
71 |
| - /* eslint no-invalid-this: 0 */ |
72 |
| - return dispatch(fn, this, arguments); |
73 |
| - }; |
74 |
| -} |
75 |
| - |
76 | 5 | module.exports = function getPolyfill() {
|
77 |
| - return (typeof Uint8Array === 'function' && Uint8Array.prototype.slice) |
78 |
| - || ownSlice |
79 |
| - || implementation; |
| 6 | + return (typeof Uint8Array === 'function' && Uint8Array.prototype.slice) || implementation; |
80 | 7 | };
|
0 commit comments