| LEFT | RIGHT | 
|---|
| 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 693   // 2176782336 is 36^6 which mean 6 chars [a-z0-9] | 693   // 2176782336 is 36^6 which mean 6 chars [a-z0-9] | 
| 694   // 60466176 is 36^5 | 694   // 60466176 is 36^5 | 
| 695   // 2176782336 - 60466176 = 2116316160. This ensure to always have 6 | 695   // 2176782336 - 60466176 = 2116316160. This ensure to always have 6 | 
| 696   // chars even if Math.random() returns its minimum value 0.0 | 696   // chars even if Math.random() returns its minimum value 0.0 | 
| 697   // | 697   // | 
| 698   return Math.floor(Math.random() * 2116316160 + 60466176).toString(36); | 698   return Math.floor(Math.random() * 2116316160 + 60466176).toString(36); | 
| 699 } | 699 } | 
| 700 | 700 | 
| 701 function wrapPropertyAccess(object, property, descriptor) | 701 function wrapPropertyAccess(object, property, descriptor) | 
| 702 { | 702 { | 
| 703   let dot = property.indexOf("."); | 703   let dotIndex = property.indexOf("."); | 
| 704   if (dot == -1) | 704   if (dotIndex == -1) | 
| 705   { | 705   { | 
| 706     // simple property case. | 706     // simple property case. | 
| 707     let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | 707     let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | 
| 708     if (currentDescriptor && !currentDescriptor.configurable) | 708     if (currentDescriptor && !currentDescriptor.configurable) | 
| 709       return false; | 709       return; | 
| 710 | 710 | 
| 711     Object.defineProperty(object, property, descriptor); | 711     Object.defineProperty(object, property, descriptor); | 
| 712     return true; | 712     return; | 
| 713   } | 713   } | 
| 714   let result = false; | 714 | 
| 715   let name = property.slice(0, dot); | 715   let name = property.slice(0, dotIndex); | 
| 716   property = property.slice(dot + 1); | 716   property = property.slice(dotIndex + 1); | 
| 717   let value = object[name]; | 717   let value = object[name]; | 
| 718   if (value && typeof value == "object") | 718   if (value && typeof value == "object") | 
| 719     result = wrapPropertyAccess(value, property, descriptor); | 719     wrapPropertyAccess(value, property, descriptor); | 
| 720 | 720 | 
| 721   let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); | 721   let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); | 
| 722   if (currentDescriptor && !currentDescriptor.configurable) | 722   if (currentDescriptor && !currentDescriptor.configurable) | 
| 723     return result; | 723     return; | 
| 724 | 724 | 
| 725   let setter = newValue => | 725   let setter = newValue => | 
| 726   { | 726   { | 
| 727     value = newValue; | 727     value = newValue; | 
| 728     if (newValue && typeof newValue == "object") | 728     if (newValue && typeof newValue == "object") | 
| 729       wrapPropertyAccess(newValue, property, descriptor); | 729       wrapPropertyAccess(newValue, property, descriptor); | 
| 730   }; | 730   }; | 
|  | 731 | 
| 731   Object.defineProperty(object, name, {get: () => value, set: setter}); | 732   Object.defineProperty(object, name, {get: () => value, set: setter}); | 
| 732   return result; |  | 
| 733 } | 733 } | 
| 734 | 734 | 
| 735 /** | 735 /** | 
| 736  * Overrides the <code>onerror</code> handler to discard tagged error messages | 736  * Overrides the <code>onerror</code> handler to discard tagged error messages | 
| 737  * from our property wrapping. | 737  * from our property wrapping. | 
| 738  * | 738  * | 
| 739  * @param {string} magic The magic string that tags the error message. | 739  * @param {string} magic The magic string that tags the error message. | 
| 740  */ | 740  */ | 
| 741 function overrideOnError(magic) | 741 function overrideOnError(magic) | 
| 742 { | 742 { | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 766   if (!property) | 766   if (!property) | 
| 767     return; | 767     return; | 
| 768 | 768 | 
| 769   let rid = randomId(); | 769   let rid = randomId(); | 
| 770 | 770 | 
| 771   function abort() | 771   function abort() | 
| 772   { | 772   { | 
| 773     throw new ReferenceError(rid); | 773     throw new ReferenceError(rid); | 
| 774   } | 774   } | 
| 775 | 775 | 
| 776   if (wrapPropertyAccess(window, property, {get: abort, set() {}})) | 776   wrapPropertyAccess(window, property, {get: abort, set() {}}); | 
| 777     overrideOnError(rid); | 777   overrideOnError(rid); | 
| 778 } | 778 } | 
| 779 | 779 | 
| 780 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | 780 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | 
| 781                                                  wrapPropertyAccess, | 781                                                  wrapPropertyAccess, | 
| 782                                                  overrideOnError, | 782                                                  overrideOnError, | 
| 783                                                  randomId); | 783                                                  randomId); | 
| 784 | 784 | 
| 785 /** | 785 /** | 
| 786  * Patches a property on the window object to abort execution when the | 786  * Patches a property on the window object to abort execution when the | 
| 787  * property is written. | 787  * property is written. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 798   if (!property) | 798   if (!property) | 
| 799     return; | 799     return; | 
| 800 | 800 | 
| 801   let rid = randomId(); | 801   let rid = randomId(); | 
| 802 | 802 | 
| 803   function abort() | 803   function abort() | 
| 804   { | 804   { | 
| 805     throw new ReferenceError(rid); | 805     throw new ReferenceError(rid); | 
| 806   } | 806   } | 
| 807 | 807 | 
| 808   if (wrapPropertyAccess(window, property, {set: abort})) | 808   wrapPropertyAccess(window, property, {set: abort}); | 
| 809     overrideOnError(rid); | 809   overrideOnError(rid); | 
| 810 } | 810 } | 
| 811 | 811 | 
| 812 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, | 812 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, | 
| 813                                                   wrapPropertyAccess, | 813                                                   wrapPropertyAccess, | 
| 814                                                   overrideOnError, | 814                                                   overrideOnError, | 
| 815                                                   randomId); | 815                                                   randomId); | 
| 816 | 816 | 
| 817 /** | 817 /** | 
| 818  * Aborts the execution of an inline script. | 818  * Aborts the execution of an inline script. | 
| 819  * | 819  * | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 832 | 832 | 
| 833 | 833 | 
| 834   let object = window; | 834   let object = window; | 
| 835   let path = api.split("."); | 835   let path = api.split("."); | 
| 836   let name = path.pop(); | 836   let name = path.pop(); | 
| 837 | 837 | 
| 838   for (let node of path) | 838   for (let node of path) | 
| 839   { | 839   { | 
| 840     object = object[node]; | 840     object = object[node]; | 
| 841 | 841 | 
| 842     if (!object || typeof object != "object") | 842     if (!object || !(typeof object == "object" || typeof object == "function")) | 
| 843       return; | 843       return; | 
| 844   } | 844   } | 
| 845 | 845 | 
| 846   let currentValue = object[name]; | 846   let currentValue = object[name]; | 
| 847 | 847 | 
| 848   let abort = () => | 848   let abort = () => | 
| 849   { | 849   { | 
| 850     let element = document.currentScript; | 850     let element = document.currentScript; | 
| 851     if (element instanceof HTMLScriptElement && element.src == "" && | 851     if (element instanceof HTMLScriptElement && element.src == "" && | 
| 852         element != us && (!re || re.test(element.textContent))) | 852         element != us && (!re || re.test(element.textContent))) | 
| 853     { | 853     { | 
| 854       throw new ReferenceError(rid); | 854       throw new ReferenceError(rid); | 
| 855     } | 855     } | 
| 856   }; | 856   }; | 
| 857 | 857 | 
| 858   let descriptor = { | 858   let descriptor = { | 
| 859     get() | 859     get() | 
| 860     { | 860     { | 
| 861       abort(); | 861       abort(); | 
| 862       return currentValue; | 862       return currentValue; | 
| 863     }, | 863     }, | 
| 864     set(value) | 864     set(value) | 
| 865     { | 865     { | 
| 866       abort(); | 866       abort(); | 
| 867       currentValue = value; | 867       currentValue = value; | 
| 868     } | 868     } | 
| 869   }; | 869   }; | 
| 870 | 870 | 
| 871   if (wrapPropertyAccess(object, name, descriptor)) | 871   wrapPropertyAccess(object, name, descriptor); | 
| 872     overrideOnError(rid); | 872   overrideOnError(rid); | 
| 873 } | 873 } | 
| 874 | 874 | 
| 875 exports["abort-current-inline-script"] = | 875 exports["abort-current-inline-script"] = | 
| 876   makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, | 876   makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, | 
| 877                overrideOnError, regexEscape, randomId); | 877                overrideOnError, regexEscape, randomId); | 
| 878 | 878 | 
| 879 /** | 879 /** | 
| 880  * Strips a query string parameter from <code>fetch()</code> calls. | 880  * Strips a query string parameter from <code>fetch()</code> calls. | 
| 881  * | 881  * | 
| 882  * @param {string} name The name of the parameter. | 882  * @param {string} name The name of the parameter. | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 898       let url = new URL(source); | 898       let url = new URL(source); | 
| 899       url.searchParams.delete(name); | 899       url.searchParams.delete(name); | 
| 900       args[0] = url.href; | 900       args[0] = url.href; | 
| 901     } | 901     } | 
| 902     return fetch_.apply(this, args); | 902     return fetch_.apply(this, args); | 
| 903   }; | 903   }; | 
| 904 } | 904 } | 
| 905 | 905 | 
| 906 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, | 906 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, | 
| 907                                                       toRegExp, regexEscape); | 907                                                       toRegExp, regexEscape); | 
| LEFT | RIGHT | 
|---|