OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 notificationCallbacks: {}, | 436 notificationCallbacks: {}, |
437 loadFlags: 0, | 437 loadFlags: 0, |
438 INHIBIT_CACHING: 0, | 438 INHIBIT_CACHING: 0, |
439 VALIDATE_ALWAYS: 0, | 439 VALIDATE_ALWAYS: 0, |
440 QueryInterface: function() | 440 QueryInterface: function() |
441 { | 441 { |
442 return this; | 442 return this; |
443 } | 443 } |
444 } | 444 } |
445 }; | 445 }; |
| 446 |
| 447 |
| 448 // Polyfill Array.prototype.find |
| 449 // from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Ob
jects/Array/find |
| 450 // https://tc39.github.io/ecma262/#sec-array.prototype.find |
| 451 if (!Array.prototype.find) { |
| 452 Object.defineProperty(Array.prototype, 'find', { |
| 453 value: function (predicate) { |
| 454 // 1. Let O be ? ToObject(this value). |
| 455 if (this == null) { |
| 456 throw new TypeError('"this" is null or not defined'); |
| 457 } |
| 458 |
| 459 var o = Object(this); |
| 460 |
| 461 // 2. Let len be ? ToLength(? Get(O, "length")). |
| 462 var len = o.length >>> 0; |
| 463 |
| 464 // 3. If IsCallable(predicate) is false, throw a TypeError exception. |
| 465 if (typeof predicate !== 'function') { |
| 466 throw new TypeError('predicate must be a function'); |
| 467 } |
| 468 |
| 469 // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. |
| 470 var thisArg = arguments[1]; |
| 471 |
| 472 // 5. Let k be 0. |
| 473 var k = 0; |
| 474 |
| 475 // 6. Repeat, while k < len |
| 476 while (k < len) { |
| 477 // a. Let Pk be ! ToString(k). |
| 478 // b. Let kValue be ? Get(O, Pk). |
| 479 // c. Let testResult be ToBoolean(? Call(predicate, T, "kValue, k, O")). |
| 480 // d. If testResult is true, return kValue. |
| 481 var kValue = o[k]; |
| 482 if (predicate.call(thisArg, kValue, k, o)) { |
| 483 return kValue; |
| 484 } |
| 485 // e. Increase k by 1. |
| 486 k++; |
| 487 } |
| 488 } |
| 489 }); |
| 490 } |
OLD | NEW |