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

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

Issue 29979555: Issue 7207 - Implement abort-on-property-write snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
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:
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 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
763 * property is written.
764 *
765 * No error is printed to the console.
766 *
767 * The idea originates from
768 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1671 uBlock Origin}.
769 *
770 * @param {string} property The name of the property.
771 */
772 function abortOnPropertyWrite(property)
773 {
774 if (!property)
775 return;
776
777 let rid = randomId();
778
779 function abort()
780 {
781 throw new ReferenceError(rid);
782 }
783
784 if (wrapPropertyAccess(window, property, {set: abort}))
785 overrideOnError(rid);
786 }
787
788 exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite,
789 wrapPropertyAccess,
790 overrideOnError,
791 randomId);
792
793 /**
762 * Aborts the execution of an inline script. 794 * Aborts the execution of an inline script.
763 * 795 *
764 * @param {string} api API function or property name to anchor on. 796 * @param {string} api API function or property name to anchor on.
765 * @param {?string} [search] If specified, only scripts containing the given 797 * @param {?string} [search] If specified, only scripts containing the given
766 * string are prevented from executing. If the string begins and ends with a 798 * string are prevented from executing. If the string begins and ends with a
767 * slash (<code>/</code>), the text in between is treated as a regular 799 * slash (<code>/</code>), the text in between is treated as a regular
768 * expression. 800 * expression.
769 */ 801 */
770 function abortCurrentInlineScript(api, search = null) 802 function abortCurrentInlineScript(api, search = null)
771 { 803 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 } 844 }
813 }; 845 };
814 846
815 if (wrapPropertyAccess(object, name, descriptor)) 847 if (wrapPropertyAccess(object, name, descriptor))
816 overrideOnError(rid); 848 overrideOnError(rid);
817 } 849 }
818 850
819 exports["abort-current-inline-script"] = 851 exports["abort-current-inline-script"] =
820 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, 852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp,
821 overrideOnError, regexEscape, randomId); 853 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