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 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 currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | 703 let dotIndex = property.indexOf("."); |
| 704 if (dotIndex == -1) |
| 705 { |
| 706 // simple property case. |
| 707 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); |
| 708 if (currentDescriptor && !currentDescriptor.configurable) |
| 709 return; |
| 710 |
| 711 Object.defineProperty(object, property, descriptor); |
| 712 return; |
| 713 } |
| 714 |
| 715 let name = property.slice(0, dotIndex); |
| 716 property = property.slice(dotIndex + 1); |
| 717 let value = object[name]; |
| 718 if (value && typeof value == "object") |
| 719 wrapPropertyAccess(value, property, descriptor); |
| 720 |
| 721 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); |
704 if (currentDescriptor && !currentDescriptor.configurable) | 722 if (currentDescriptor && !currentDescriptor.configurable) |
705 return false; | 723 return; |
706 | 724 |
707 Object.defineProperty(object, property, descriptor); | 725 let setter = newValue => |
708 return true; | 726 { |
| 727 value = newValue; |
| 728 if (newValue && typeof newValue == "object") |
| 729 wrapPropertyAccess(newValue, property, descriptor); |
| 730 }; |
| 731 |
| 732 Object.defineProperty(object, name, {get: () => value, set: setter}); |
709 } | 733 } |
710 | 734 |
711 /** | 735 /** |
712 * Overrides the <code>onerror</code> handler to discard tagged error messages | 736 * Overrides the <code>onerror</code> handler to discard tagged error messages |
713 * from our property wrapping. | 737 * from our property wrapping. |
714 * | 738 * |
715 * @param {string} magic The magic string that tags the error message. | 739 * @param {string} magic The magic string that tags the error message. |
716 */ | 740 */ |
717 function overrideOnError(magic) | 741 function overrideOnError(magic) |
718 { | 742 { |
(...skipping 23 matching lines...) Expand all Loading... |
742 if (!property) | 766 if (!property) |
743 return; | 767 return; |
744 | 768 |
745 let rid = randomId(); | 769 let rid = randomId(); |
746 | 770 |
747 function abort() | 771 function abort() |
748 { | 772 { |
749 throw new ReferenceError(rid); | 773 throw new ReferenceError(rid); |
750 } | 774 } |
751 | 775 |
752 if (wrapPropertyAccess(window, property, {get: abort, set() {}})) | 776 wrapPropertyAccess(window, property, {get: abort, set() {}}); |
753 overrideOnError(rid); | 777 overrideOnError(rid); |
754 } | 778 } |
755 | 779 |
756 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | 780 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, |
757 wrapPropertyAccess, | 781 wrapPropertyAccess, |
758 overrideOnError, | 782 overrideOnError, |
759 randomId); | 783 randomId); |
760 | 784 |
761 /** | 785 /** |
762 * 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 |
763 * property is written. | 787 * property is written. |
(...skipping 10 matching lines...) Expand all Loading... |
774 if (!property) | 798 if (!property) |
775 return; | 799 return; |
776 | 800 |
777 let rid = randomId(); | 801 let rid = randomId(); |
778 | 802 |
779 function abort() | 803 function abort() |
780 { | 804 { |
781 throw new ReferenceError(rid); | 805 throw new ReferenceError(rid); |
782 } | 806 } |
783 | 807 |
784 if (wrapPropertyAccess(window, property, {set: abort})) | 808 wrapPropertyAccess(window, property, {set: abort}); |
785 overrideOnError(rid); | 809 overrideOnError(rid); |
786 } | 810 } |
787 | 811 |
788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, | 812 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, |
789 wrapPropertyAccess, | 813 wrapPropertyAccess, |
790 overrideOnError, | 814 overrideOnError, |
791 randomId); | 815 randomId); |
792 | 816 |
793 /** | 817 /** |
794 * Aborts the execution of an inline script. | 818 * Aborts the execution of an inline script. |
795 * | 819 * |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 abort(); | 861 abort(); |
838 return currentValue; | 862 return currentValue; |
839 }, | 863 }, |
840 set(value) | 864 set(value) |
841 { | 865 { |
842 abort(); | 866 abort(); |
843 currentValue = value; | 867 currentValue = value; |
844 } | 868 } |
845 }; | 869 }; |
846 | 870 |
847 if (wrapPropertyAccess(object, name, descriptor)) | 871 wrapPropertyAccess(object, name, descriptor); |
848 overrideOnError(rid); | 872 overrideOnError(rid); |
849 } | 873 } |
850 | 874 |
851 exports["abort-current-inline-script"] = | 875 exports["abort-current-inline-script"] = |
852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, | 876 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, |
853 overrideOnError, regexEscape, randomId); | 877 overrideOnError, regexEscape, randomId); |
854 | 878 |
855 /** | 879 /** |
856 * Strips a query string parameter from <code>fetch()</code> calls. | 880 * Strips a query string parameter from <code>fetch()</code> calls. |
857 * | 881 * |
858 * @param {string} name The name of the parameter. | 882 * @param {string} name The name of the parameter. |
(...skipping 15 matching lines...) Expand all Loading... |
874 let url = new URL(source); | 898 let url = new URL(source); |
875 url.searchParams.delete(name); | 899 url.searchParams.delete(name); |
876 args[0] = url.href; | 900 args[0] = url.href; |
877 } | 901 } |
878 return fetch_.apply(this, args); | 902 return fetch_.apply(this, args); |
879 }; | 903 }; |
880 } | 904 } |
881 | 905 |
882 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, | 906 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, |
883 toRegExp, regexEscape); | 907 toRegExp, regexEscape); |
OLD | NEW |