polyfill.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. if (!Int32Array.__proto__.from) {
  2. Object.defineProperty(Int32Array.__proto__, 'from', {
  3. value: function(obj) {
  4. obj = Object(obj);
  5. if (!obj['length']) {
  6. return new this(0);
  7. }
  8. var typed_array = new this(obj.length);
  9. for(var i = 0; i < typed_array.length; i++) {
  10. typed_array[i] = obj[i];
  11. }
  12. return typed_array;
  13. }
  14. });
  15. }
  16. if (!Array.prototype.copyWithin) {
  17. Array.prototype.copyWithin = function(target, start, end) {
  18. var O = Object(this);
  19. var len = O.length >>> 0;
  20. var to = target | 0;
  21. var from = start | 0;
  22. var count = Math.min(Math.min(end | 0, len) - from, len - to);
  23. var direction = 1;
  24. if (from < to && to < (from + count)) {
  25. direction = -1;
  26. from += count - 1;
  27. to += count - 1;
  28. }
  29. while (count > 0) {
  30. O[to] = O[from];
  31. from += direction;
  32. to += direction;
  33. count--;
  34. }
  35. return O;
  36. };
  37. }
  38. if (!Array.prototype.fill) {
  39. Object.defineProperty(Array.prototype, 'fill', {
  40. value: function(value, start, end) {
  41. end = end | 0;
  42. var O = Object(this);
  43. var k = start | 0;
  44. while (k < end) {
  45. O[k] = value;
  46. k++;
  47. }
  48. return O;
  49. }
  50. });
  51. }
  52. if (!Int8Array.prototype.copyWithin) {
  53. Int8Array.prototype.copyWithin = Array.prototype.copyWithin;
  54. }
  55. if (!Int8Array.prototype.fill) {
  56. Int8Array.prototype.fill = Array.prototype.fill;
  57. }
  58. if (!Int32Array.prototype.fill) {
  59. Int32Array.prototype.fill = Array.prototype.fill;
  60. }