aboutsummaryrefslogtreecommitdiff
path: root/js/polyfill.js
blob: 9ff59cc440ef31b4d8685048e49e11e4cc3f7bac (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
if (!Int32Array.__proto__.from) {
  Object.defineProperty(Int32Array.__proto__, 'from', {
    value: function(obj) {
      obj = Object(obj);
      if (!obj['length']) {
        return new this(0);
      }
      let typed_array = new this(obj.length);
      for (let i = 0; i < typed_array.length; i++) {
        typed_array[i] = obj[i];
      }
      return typed_array;
    }
  });
}

if (!Array.prototype.copyWithin) {
  Array.prototype.copyWithin = function(target, start, end) {
    let O = Object(this);
    let len = O.length >>> 0;
    let to = target | 0;
    let from = start | 0;
    let count = Math.min(Math.min(end | 0, len) - from, len - to);
    let direction = 1;
    if (from < to && to < (from + count)) {
      direction = -1;
      from += count - 1;
      to += count - 1;
    }
    while (count > 0) {
      O[to] = O[from];
      from += direction;
      to += direction;
      count--;
    }
    return O;
  };
}

if (!Array.prototype.fill) {
  Object.defineProperty(Array.prototype, 'fill', {
    value: function(value, start, end) {
      end = end | 0;
      let O = Object(this);
      let k = start | 0;
      while (k < end) {
        O[k] = value;
        k++;
      }
      return O;
    }
  });
}

if (!Int8Array.prototype.copyWithin) {
  Int8Array.prototype.copyWithin = Array.prototype.copyWithin;
}

if (!Int8Array.prototype.fill) {
  Int8Array.prototype.fill = Array.prototype.fill;
}

if (!Int32Array.prototype.fill) {
  Int32Array.prototype.fill = Array.prototype.fill;
}

if (!Int8Array.prototype.slice) {
  Object.defineProperty(Int8Array.prototype, 'slice', {
    value: function(begin, end) {
      return new Int8Array(Array.prototype.slice.call(this, begin, end));
    }
  });
}