Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/content/snippets.js

Issue 29995559: Issue 7236 - Handle sub properties in abort-on-property snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Check that the property is configurable. Created Feb. 5, 2019, 7:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
722 {
723 if (currentDescriptor.set && currentDescriptor.set.hasOwnProperty(magic))
724 return true;
725 if (!currentDescriptor.configurable)
726 return false;
727 }
728
729 let v;
730 let setter = a =>
731 {
732 v = a;
733 if (a && typeof a == "object")
734 wrapPropertyAccess(a, property, descriptor, magic);
735 };
736 setter[magic] = undefined;
737 Object.defineProperty(object, name, {get: () => v, set: setter});
708 return true; 738 return true;
709 } 739 }
710 740
711 /** 741 /**
712 * Overrides the <code>onerror</code> handler to discard tagged error messages 742 * Overrides the <code>onerror</code> handler to discard tagged error messages
713 * from our property wrapping. 743 * from our property wrapping.
714 * 744 *
715 * @param {string} magic The magic string that tags the error message. 745 * @param {string} magic The magic string that tags the error message.
716 */ 746 */
717 function overrideOnError(magic) 747 function overrideOnError(magic)
(...skipping 24 matching lines...) Expand all
742 if (!property) 772 if (!property)
743 return; 773 return;
744 774
745 let rid = randomId(); 775 let rid = randomId();
746 776
747 function abort() 777 function abort()
748 { 778 {
749 throw new ReferenceError(rid); 779 throw new ReferenceError(rid);
750 } 780 }
751 781
752 if (wrapPropertyAccess(window, property, {get: abort, set() {}})) 782 if (wrapPropertyAccess(window, property, {get: abort, set() {}}, rid))
753 overrideOnError(rid); 783 overrideOnError(rid);
754 } 784 }
755 785
756 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, 786 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead,
757 wrapPropertyAccess, 787 wrapPropertyAccess,
758 overrideOnError, 788 overrideOnError,
759 randomId); 789 randomId);
760 790
761 /** 791 /**
762 * Patches a property on the window object to abort execution when the 792 * Patches a property on the window object to abort execution when the
(...skipping 11 matching lines...) Expand all
774 if (!property) 804 if (!property)
775 return; 805 return;
776 806
777 let rid = randomId(); 807 let rid = randomId();
778 808
779 function abort() 809 function abort()
780 { 810 {
781 throw new ReferenceError(rid); 811 throw new ReferenceError(rid);
782 } 812 }
783 813
784 if (wrapPropertyAccess(window, property, {set: abort})) 814 if (wrapPropertyAccess(window, property, {set: abort}, rid))
785 overrideOnError(rid); 815 overrideOnError(rid);
786 } 816 }
787 817
788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, 818 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite,
789 wrapPropertyAccess, 819 wrapPropertyAccess,
790 overrideOnError, 820 overrideOnError,
791 randomId); 821 randomId);
792 822
793 /** 823 /**
794 * Aborts the execution of an inline script. 824 * Aborts the execution of an inline script.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 abort(); 867 abort();
838 return currentValue; 868 return currentValue;
839 }, 869 },
840 set(value) 870 set(value)
841 { 871 {
842 abort(); 872 abort();
843 currentValue = value; 873 currentValue = value;
844 } 874 }
845 }; 875 };
846 876
847 if (wrapPropertyAccess(object, name, descriptor)) 877 if (wrapPropertyAccess(object, name, descriptor, rid))
848 overrideOnError(rid); 878 overrideOnError(rid);
849 } 879 }
850 880
851 exports["abort-current-inline-script"] = 881 exports["abort-current-inline-script"] =
852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, 882 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp,
853 overrideOnError, regexEscape, randomId); 883 overrideOnError, regexEscape, randomId);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld