| Left: | ||
| Right: |
| 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] | |
|
Manish Jethani
2018/09/24 11:08:35
Since we're not zero-padding the return value, doe
hub
2018/09/25 04:28:52
Modifying the formula so that if Math.random() ret
Manish Jethani
2018/09/25 12:25:22
The updated version looks alright to me, it always
hub
2018/09/25 15:40:43
6 is arbitrary. Long enough to be unique, but stil
| |
| 443 return Math.floor(Math.random() * 2176782336).toString(36); | |
| 444 } | |
| 445 | |
| 446 /** | |
| 447 * Will patch a property on the window object to abort when read. | |
| 448 * It will intercept the onerror callback and block it if tagged. | |
| 449 * | |
| 450 * @todo handle properties of properties. | |
| 451 * | |
| 452 * @param {string} prop the name of the property. | |
| 453 */ | |
| 454 function abortOnPropertyRead(...props) | |
|
Manish Jethani
2018/09/24 11:08:35
The problem with accepting a variable number of ar
hub
2018/09/25 04:28:52
I didn't have uBO compatibility in mind. I just al
Manish Jethani
2018/09/25 12:25:22
The thing is that the moment ABP starts using the
hub
2018/09/25 15:40:43
fair enough. will fix it.
Manish Jethani
2018/10/22 14:21:01
Happy to proceed whenever you're ready.
hub
2018/10/22 14:52:49
This was fixed in Patch Set 5
Manish Jethani
2018/10/22 20:21:54
Sorry, I missed this. I'll look at this patch tomo
| |
| 455 { | |
| 456 if (props.length == 0) | |
| 457 return; | |
| 458 | |
| 459 let magic = randomId(); | |
| 460 | |
| 461 let abort = function() | |
| 462 { | |
| 463 throw new ReferenceError(magic); | |
| 464 }; | |
| 465 | |
| 466 let {onerror} = window; | |
| 467 window.onerror = (msg, ...args) => | |
|
Manish Jethani
2018/09/24 11:08:35
Let's rename this to `message` and `...rest`. Abou
hub
2018/09/25 04:28:51
Done.
| |
| 468 { | |
| 469 if (typeof msg === "string" && msg.indexOf(magic) != -1) | |
|
Manish Jethani
2018/09/24 11:08:35
We could use `String.includes` instead of `String.
Manish Jethani
2018/09/24 11:08:35
Strict equality is unnecessary here.
hub
2018/09/25 04:28:51
Done.
hub
2018/09/25 04:28:52
Done.
| |
| 470 return true; | |
| 471 if (onerror) | |
|
Manish Jethani
2018/09/24 11:08:35
Just to be safe, we should check `typeof onerror =
hub
2018/09/25 04:28:51
Done.
| |
| 472 return onerror(msg, ...args); | |
|
Manish Jethani
2018/09/24 11:08:35
Let's just also set the `this` for this call, so `
hub
2018/09/25 04:28:52
Done.
| |
| 473 }; | |
| 474 | |
| 475 let patch = function(o, p) | |
| 476 { | |
| 477 // simple property | |
| 478 let d = Object.getOwnPropertyDescriptor(o, p); | |
| 479 if (!d || d.get !== abort) | |
|
Manish Jethani
2018/09/24 11:08:35
Strict inequality is unnecessary here.
hub
2018/09/25 04:28:51
Done.
| |
| 480 Object.defineProperty(o, p, {get: abort, set() {}}); | |
| 481 }; | |
| 482 for (let prop of props) | |
| 483 patch(window, prop); | |
| 484 } | |
| 485 | |
| 486 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, randomId); | |
| OLD | NEW |