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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 { | 429 { |
430 for (let i = 0; i < times; i++) | 430 for (let i = 0; i < times; i++) |
431 object + ""; | 431 object + ""; |
432 | 432 |
433 if (typeof dir == "function") | 433 if (typeof dir == "function") |
434 dir.call(this, object); | 434 dir.call(this, object); |
435 }; | 435 }; |
436 } | 436 } |
437 | 437 |
438 exports["dir-string"] = makeInjector(dirString); | 438 exports["dir-string"] = makeInjector(dirString); |
| 439 |
| 440 function randomId() |
| 441 { |
| 442 // 2176782336 is 36^6 which mean 6 chars [a-z0-9] |
| 443 // 60466176 is 36^5 |
| 444 // 2176782336 - 60466176 = 2116316160. This ensure always 6 chars |
| 445 // for when Math.random() returns 0.0 |
| 446 return Math.floor(Math.random() * 2116316160 + 60466176).toString(36); |
| 447 } |
| 448 |
| 449 /** |
| 450 * Will patch a property on the window object to abort when read. |
| 451 * It will intercept the onerror callback and block it if tagged. |
| 452 * |
| 453 * @todo handle properties of properties. |
| 454 * |
| 455 * @param {string} prop the name of the property. |
| 456 */ |
| 457 function abortOnPropertyRead(prop) |
| 458 { |
| 459 if (!prop) |
| 460 return; |
| 461 |
| 462 let magic = randomId(); |
| 463 |
| 464 let abort = function() |
| 465 { |
| 466 throw new ReferenceError(magic); |
| 467 }; |
| 468 |
| 469 let {onerror} = window; |
| 470 window.onerror = (message, ...rest) => |
| 471 { |
| 472 if (typeof message == "string" && message.includes(magic)) |
| 473 return true; |
| 474 if (onerror && typeof onerro == "function") |
| 475 return onerror(this, message, ...rest); |
| 476 }; |
| 477 |
| 478 (function(o, p) |
| 479 { |
| 480 // simple property |
| 481 let d = Object.getOwnPropertyDescriptor(o, p); |
| 482 if (!d || d.get != abort) |
| 483 Object.defineProperty(o, p, {get: abort, set() {}}); |
| 484 })(window, prop); |
| 485 } |
| 486 |
| 487 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, randomId); |
OLD | NEW |