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

Delta Between Two Patch Sets: lib/content/snippets.js

Issue 29979555: Issue 7207 - Implement abort-on-property-write snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Jan. 11, 2019, 2:39 p.m.
Right Patch Set: Addressed comment typo Created Jan. 15, 2019, 4:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 return true; 723 return true;
724 if (typeof onerror == "function") 724 if (typeof onerror == "function")
725 return (() => {}).call.call(onerror, this, message, ...rest); 725 return (() => {}).call.call(onerror, this, message, ...rest);
726 }; 726 };
727 } 727 }
728 728
729 /** 729 /**
730 * Patches a property on the window object to abort execution when the 730 * Patches a property on the window object to abort execution when the
731 * property is read. 731 * property is read.
732 * 732 *
733 * No error is be printed to the console. 733 * No error is printed to the console.
734 * 734 *
735 * The idea originates from 735 * The idea originates from
736 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1703 uBlock Origin}. 736 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1703 uBlock Origin}.
737 * 737 *
738 * @param {string} property The name of the property. 738 * @param {string} property The name of the property.
739 */ 739 */
740 function abortOnPropertyRead(property) 740 function abortOnPropertyRead(property)
741 { 741 {
742 if (!property) 742 if (!property)
743 return; 743 return;
744 744
745 let rid = randomId(); 745 let rid = randomId();
746 746
747 function abort() 747 function abort()
748 { 748 {
749 throw new ReferenceError(rid); 749 throw new ReferenceError(rid);
750 } 750 }
751 751
752 if (wrapPropertyAccess(window, property, {get: abort, set() {}})) 752 if (wrapPropertyAccess(window, property, {get: abort, set() {}}))
753 overrideOnError(rid); 753 overrideOnError(rid);
754 } 754 }
755 755
756 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, 756 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead,
757 wrapPropertyAccess, 757 wrapPropertyAccess,
758 overrideOnError, 758 overrideOnError,
759 randomId); 759 randomId);
760 760
761 /** 761 /**
762 * Patches a property on the window object to abort execution when the 762 * Patches a property on the window object to abort execution when the
763 * property is written (set). 763 * property is written.
Manish Jethani 2019/01/15 14:13:29 Nit: I don't think "(set)" is necessary, but it's
hub 2019/01/15 16:40:29 I ought it clarify, but then I don't for "read" so
764 * 764 *
765 * No error is be printed to the console. 765 * No error is printed to the console.
Manish Jethani 2019/01/15 14:13:30 Correction: No error is printed to the console. W
hub 2019/01/15 16:40:29 Done. BTW it is a cut&paste error that is found i
766 * 766 *
767 * The idea originates from 767 * The idea originates from
768 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1671 uBlock Origin}. 768 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1671 uBlock Origin}.
769 * 769 *
770 * @param {string} property The name of the property. 770 * @param {string} property The name of the property.
771 */ 771 */
772 function abortOnPropertyWrite(property) 772 function abortOnPropertyWrite(property)
773 { 773 {
774 if (!property) 774 if (!property)
775 return; 775 return;
776 776
777 let rid = randomId(); 777 let rid = randomId();
778 778
779 function abort() 779 function abort()
780 { 780 {
781 throw new ReferenceError(rid); 781 throw new ReferenceError(rid);
782 } 782 }
783 783
784 if (wrapPropertyAccess(window, property, {set: abort})) 784 if (wrapPropertyAccess(window, property, {set: abort}))
Manish Jethani 2019/01/15 14:13:29 Do we need a getter here?
hub 2019/01/15 16:40:30 We don't.
Manish Jethani 2019/01/15 17:24:16 Acknowledged.
785 overrideOnError(rid); 785 overrideOnError(rid);
786 } 786 }
787 787
788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, 788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite,
789 wrapPropertyAccess, 789 wrapPropertyAccess,
790 overrideOnError, 790 overrideOnError,
791 randomId); 791 randomId);
792 792
793 /** 793 /**
794 * Aborts the execution of an inline script. 794 * Aborts the execution of an inline script.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 } 844 }
845 }; 845 };
846 846
847 if (wrapPropertyAccess(object, name, descriptor)) 847 if (wrapPropertyAccess(object, name, descriptor))
848 overrideOnError(rid); 848 overrideOnError(rid);
849 } 849 }
850 850
851 exports["abort-current-inline-script"] = 851 exports["abort-current-inline-script"] =
852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, 852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp,
853 overrideOnError, regexEscape, randomId); 853 overrideOnError, regexEscape, randomId);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld