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: Remove the magic from the setter. Created Feb. 19, 2019, 8:54 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 | test/browser/snippets.js » ('j') | 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(".");
704 if (dot == -1)
705 {
706 // simple property case.
707 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property);
708 if (currentDescriptor && !currentDescriptor.configurable)
709 return false;
710
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);
719
720 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name);
704 if (currentDescriptor && !currentDescriptor.configurable) 721 if (currentDescriptor && !currentDescriptor.configurable)
705 return false; 722 return false;
706 723
707 Object.defineProperty(object, property, descriptor); 724 let v;
Manish Jethani 2019/02/20 06:20:46 There are two things missing in this implementatio
Manish Jethani 2019/02/20 06:28:53 Let me elaborate a little ...
hub 2019/02/22 17:36:19 Fixed them.
725 let setter = a =>
726 {
727 v = a;
728 if (a && typeof a == "object")
729 wrapPropertyAccess(a, property, descriptor);
730 };
731 Object.defineProperty(object, name, {get: () => v, set: setter});
708 return true; 732 return true;
709 } 733 }
710 734
711 /** 735 /**
712 * Overrides the <code>onerror</code> handler to discard tagged error messages 736 * Overrides the <code>onerror</code> handler to discard tagged error messages
713 * from our property wrapping. 737 * from our property wrapping.
714 * 738 *
715 * @param {string} magic The magic string that tags the error message. 739 * @param {string} magic The magic string that tags the error message.
716 */ 740 */
717 function overrideOnError(magic) 741 function overrideOnError(magic)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 } 868 }
845 }; 869 };
846 870
847 if (wrapPropertyAccess(object, name, descriptor)) 871 if (wrapPropertyAccess(object, name, descriptor))
848 overrideOnError(rid); 872 overrideOnError(rid);
849 } 873 }
850 874
851 exports["abort-current-inline-script"] = 875 exports["abort-current-inline-script"] =
852 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp, 876 makeInjector(abortCurrentInlineScript, wrapPropertyAccess, toRegExp,
853 overrideOnError, regexEscape, randomId); 877 overrideOnError, regexEscape, randomId);
OLDNEW
« no previous file with comments | « no previous file | test/browser/snippets.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld