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: Handle properties being overridden. Created Feb. 22, 2019, 5:35 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 result = true;
715 let name = property.slice(0, dot);
716 property = property.slice(dot + 1);
717 let value = object[name];
718 if (value && typeof value == "object")
719 result = wrapPropertyAccess(value, property, descriptor);
720
721 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name);
704 if (currentDescriptor && !currentDescriptor.configurable) 722 if (currentDescriptor && !currentDescriptor.configurable)
705 return false; 723 return result;
Manish Jethani 2019/03/04 13:28:49 If I understand this correctly, we return the resu
hub 2019/03/05 13:49:13 I should have set `result` to `false` (line 714).
Manish Jethani 2019/03/06 19:07:12 This has the opposite problem though. If we're try
hub 2019/03/06 21:22:03 Silly me, I should just return true at then end si
706 724
707 Object.defineProperty(object, property, descriptor); 725 let setter = a =>
Manish Jethani 2019/03/04 13:28:49 Nit: Instead of `a` this would seem better as `new
hub 2019/03/05 13:49:13 Done.
708 return true; 726 {
727 value = a;
728 if (a && typeof a == "object")
729 wrapPropertyAccess(a, property, descriptor);
730 };
731 Object.defineProperty(object, name, {get: () => value, set: setter});
732 return result;
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)
718 { 742 {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 let url = new URL(source); 898 let url = new URL(source);
875 url.searchParams.delete(name); 899 url.searchParams.delete(name);
876 args[0] = url.href; 900 args[0] = url.href;
877 } 901 }
878 return fetch_.apply(this, args); 902 return fetch_.apply(this, args);
879 }; 903 };
880 } 904 }
881 905
882 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, 906 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter,
883 toRegExp, regexEscape); 907 toRegExp, regexEscape);
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