-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathint-8-array.polyfill.js
More file actions
43 lines (37 loc) · 1.11 KB
/
int-8-array.polyfill.js
File metadata and controls
43 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Int8Array.prototype.from
* version 0.0.0
* Browser Compatibility:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from#browser_compatibility
*/
if (!Int8Array.prototype.from) {
Int8Array.prototype.from = function (obj, func, thisObj) {
var typedArrayClass = Int8Array.prototype;
if (typeof this !== 'function') {
throw new TypeError('# is not a constructor');
}
if (this.prototype !== typedArrayClass) {
throw new TypeError('this is not a typed array.');
}
func = func || function (elem) {
return elem;
};
if (typeof func !== 'function') {
throw new TypeError('specified argument is not a function');
}
obj = Object(obj);
if (!obj['length']) {
return new this(0);
}
var copy_data = [];
for (var i = 0; i < obj.length; i++) {
copy_data.push(obj[i]);
}
copy_data = copy_data.map(func, thisObj);
var typed_array = new this(copy_data.length);
for (var i = 0; i < typed_array.length; i++) {
typed_array[i] = copy_data[i];
}
return typed_array;
};
}