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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 function randomId() | 691 function randomId() |
692 { | 692 { |
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, magic) |
702 { | 702 { |
703 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | 703 let dot = property.indexOf("."); |
704 if (currentDescriptor && !currentDescriptor.configurable) | 704 if (dot == -1) |
705 return false; | 705 { |
706 // simple property case. | |
707 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | |
708 if (currentDescriptor && !currentDescriptor.configurable) | |
709 return false; | |
706 | 710 |
707 Object.defineProperty(object, property, descriptor); | 711 Object.defineProperty(object, property, descriptor); |
712 return true; | |
713 } | |
714 let name = property.slice(0, dot); | |
715 property = property.slice(dot + 1); | |
716 let value = object[name]; | |
717 if (value && typeof value == "object") | |
718 return wrapPropertyAccess(value, property, descriptor, magic); | |
719 | |
720 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); | |
721 if (currentDescriptor && currentDescriptor.set && | |
722 currentDescriptor.set.hasOwnProperty(magic)) | |
723 { | |
724 return true; | |
725 } | |
726 | |
727 let v; | |
728 let setter = a => | |
729 { | |
730 v = a; | |
731 if (a && typeof a == "object") | |
732 wrapPropertyAccess(a, property, descriptor, magic); | |
733 }; | |
734 setter[magic] = undefined; | |
735 Object.defineProperty(object, name, {get: () => v, set: setter}); | |
Manish Jethani
2019/02/05 15:39:08
What if object.name is non-configurable? Similar t
hub
2019/02/05 19:22:26
Exception will be thrown. I'll address this.
| |
708 return true; | 736 return true; |
709 } | 737 } |
710 | 738 |
711 /** | 739 /** |
712 * Overrides the <code>onerror</code> handler to discard tagged error messages | 740 * Overrides the <code>onerror</code> handler to discard tagged error messages |
713 * from our property wrapping. | 741 * from our property wrapping. |
714 * | 742 * |
715 * @param {string} magic The magic string that tags the error message. | 743 * @param {string} magic The magic string that tags the error message. |
716 */ | 744 */ |
717 function overrideOnError(magic) | 745 function overrideOnError(magic) |
(...skipping 24 matching lines...) Expand all Loading... | |
742 if (!property) | 770 if (!property) |
743 return; | 771 return; |
744 | 772 |
745 let rid = randomId(); | 773 let rid = randomId(); |
746 | 774 |
747 function abort() | 775 function abort() |
748 { | 776 { |
749 throw new ReferenceError(rid); | 777 throw new ReferenceError(rid); |
750 } | 778 } |
751 | 779 |
752 if (wrapPropertyAccess(window, property, {get: abort, set() {}})) | 780 if (wrapPropertyAccess(window, property, {get: abort, set() {}}, rid)) |
753 overrideOnError(rid); | 781 overrideOnError(rid); |
754 } | 782 } |
755 | 783 |
756 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | 784 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, |
757 wrapPropertyAccess, | 785 wrapPropertyAccess, |
758 overrideOnError, | 786 overrideOnError, |
759 randomId); | 787 randomId); |
760 | 788 |
761 /** | 789 /** |
762 * Patches a property on the window object to abort execution when the | 790 * Patches a property on the window object to abort execution when the |
(...skipping 11 matching lines...) Expand all Loading... | |
774 if (!property) | 802 if (!property) |
775 return; | 803 return; |
776 | 804 |
777 let rid = randomId(); | 805 let rid = randomId(); |
778 | 806 |
779 function abort() | 807 function abort() |
780 { | 808 { |
781 throw new ReferenceError(rid); | 809 throw new ReferenceError(rid); |
782 } | 810 } |
783 | 811 |
784 if (wrapPropertyAccess(window, property, {set: abort})) | 812 if (wrapPropertyAccess(window, property, {set: abort}, rid)) |
785 overrideOnError(rid); | 813 overrideOnError(rid); |
786 } | 814 } |
787 | 815 |
788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, | 816 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, |
789 wrapPropertyAccess, | 817 wrapPropertyAccess, |
790 overrideOnError, | 818 overrideOnError, |
791 randomId); | 819 randomId); |
792 | 820 |
793 /** | 821 /** |
794 * Aborts the execution of an inline script. | 822 * Aborts the execution of an inline script. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 abort(); | 865 abort(); |
838 return currentValue; | 866 return currentValue; |
839 }, | 867 }, |
840 set(value) | 868 set(value) |
841 { | 869 { |
842 abort(); | 870 abort(); |
843 currentValue = value; | 871 currentValue = value; |
844 } | 872 } |
845 }; | 873 }; |
846 | 874 |
847 if (wrapPropertyAccess(object, name, descriptor)) | 875 if (wrapPropertyAccess(object, name, descriptor, rid)) |
848 overrideOnError(rid); | 876 overrideOnError(rid); |
849 } | 877 } |
850 | 878 |
851 exports["abort-current-inline-script"] = | 879 exports["abort-current-inline-script"] = |
852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, | 880 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, |
853 overrideOnError, regexEscape, randomId); | 881 overrideOnError, regexEscape, randomId); |
OLD | NEW |