You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2 KiB

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