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