polyfill.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*******************************************************************************
  2. ηMatrix - a browser extension to black/white list requests.
  3. Copyright (C) 2017-2019 Raymond Hill
  4. Copyright (C) 2019-2022 Alessio Vanni
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see {http://www.gnu.org/licenses/}.
  15. Home: https://gitlab.com/vannilla/ematrix
  16. uMatrix Home: https://github.com/gorhill/uMatrix
  17. This file has been originally imported from:
  18. https://github.com/gorhill/uBlock/tree/master/platform/chromium
  19. */
  20. // For background page or non-background pages
  21. /* exported objectAssign */
  22. 'use strict';
  23. /******************************************************************************/
  24. /******************************************************************************/
  25. // As per MDN, Object.assign appeared first in Firefox 34.
  26. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility
  27. var objectAssign = Object.assign || function(target, source) {
  28. var keys = Object.keys(source);
  29. for ( var i = 0, n = keys.length, key; i < n; i++ ) {
  30. key = keys[i];
  31. target[key] = source[key];
  32. }
  33. return target;
  34. };
  35. /******************************************************************************/
  36. // Patching for Pale Moon which does not implement ES6 Set/Map.
  37. // Test for non-ES6 Set/Map: check if property `iterator` is present.
  38. // The code is strictly to satisfy uBO's core, not to be an accurate
  39. // implementation of ES6.
  40. if ( self.Set.prototype.iterator instanceof Function ) {
  41. //console.log('Patching non-ES6 Set() to be more ES6-like.');
  42. self.Set.prototype._values = self.Set.prototype.values;
  43. self.Set.prototype.values = function() {
  44. this._valueIter = this._values();
  45. this.value = undefined;
  46. this.done = false;
  47. return this;
  48. };
  49. self.Set.prototype.next = function() {
  50. try {
  51. this.value = this._valueIter.next();
  52. } catch (ex) {
  53. this._valueIter = undefined;
  54. this.value = undefined;
  55. this.done = true;
  56. }
  57. return this;
  58. };
  59. }
  60. if ( self.Map.prototype.iterator instanceof Function ) {
  61. //console.log('Patching non-ES6 Map() to be more ES6-like.');
  62. self.Map.prototype._entries = self.Map.prototype.entries;
  63. self.Map.prototype.entries = function() {
  64. this._entryIter = this._entries();
  65. this.value = undefined;
  66. this.done = false;
  67. return this;
  68. };
  69. self.Map.prototype.next = function() {
  70. try {
  71. this.value = this._entryIter.next();
  72. } catch (ex) {
  73. this._entryIter = undefined;
  74. this.value = undefined;
  75. this.done = true;
  76. }
  77. return this;
  78. };
  79. }