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

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

Issue 29995559: Issue 7236 - Handle sub properties in abort-on-property snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: don't return a value from wrapProperty and unconditionally create error handler. Created March 6, 2019, 9:21 p.m.
Right Patch Set: tweak property names Created March 20, 2019, 4:18 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 | test/browser/_utils.js » ('j') | 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 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 dot = property.indexOf("."); 703 let dotIndex = property.indexOf(".");
Manish Jethani 2019/03/07 14:12:22 Nit: When finding the index of a dot in a string (
hub 2019/03/07 21:32:27 Done.
704 if (dot == -1) 704 if (dotIndex == -1)
705 { 705 {
706 // simple property case. 706 // simple property case.
Manish Jethani 2019/03/07 14:12:22 Nit: I don't know if this comment adds much value,
hub 2019/03/07 21:32:27 Acknowledged.
707 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); 707 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property);
708 if (currentDescriptor && !currentDescriptor.configurable) 708 if (currentDescriptor && !currentDescriptor.configurable)
709 return; 709 return;
710 710
711 Object.defineProperty(object, property, descriptor); 711 Object.defineProperty(object, property, descriptor);
712 return; 712 return;
713 } 713 }
714 let name = property.slice(0, dot); 714
Manish Jethani 2019/03/07 14:12:22 Nit: A blank line after the `if` block would make
hub 2019/03/07 21:32:27 Done.
715 property = property.slice(dot + 1); 715 let name = property.slice(0, dotIndex);
716 property = property.slice(dotIndex + 1);
716 let value = object[name]; 717 let value = object[name];
717 if (value && typeof value == "object") 718 if (value && typeof value == "object")
Manish Jethani 2019/03/07 14:12:22 Suggestion: It might be better if we defined this
hub 2019/03/07 21:32:27 I'll leave it as is
Manish Jethani 2019/03/12 07:00:08 Acknowledged.
718 wrapPropertyAccess(value, property, descriptor); 719 wrapPropertyAccess(value, property, descriptor);
719 720
720 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); 721 let currentDescriptor = Object.getOwnPropertyDescriptor(object, name);
721 if (currentDescriptor && !currentDescriptor.configurable) 722 if (currentDescriptor && !currentDescriptor.configurable)
722 return; 723 return;
723 724
724 let setter = newValue => 725 let setter = newValue =>
725 { 726 {
726 value = newValue; 727 value = newValue;
727 if (newValue && typeof newValue == "object") 728 if (newValue && typeof newValue == "object")
728 wrapPropertyAccess(newValue, property, descriptor); 729 wrapPropertyAccess(newValue, property, descriptor);
729 }; 730 };
731
730 Object.defineProperty(object, name, {get: () => value, set: setter}); 732 Object.defineProperty(object, name, {get: () => value, set: setter});
Manish Jethani 2019/03/07 14:12:23 Nit: Blank line before this would be nice.
hub 2019/03/07 21:32:27 Done.
731 } 733 }
732 734
733 /** 735 /**
734 * Overrides the <code>onerror</code> handler to discard tagged error messages 736 * Overrides the <code>onerror</code> handler to discard tagged error messages
735 * from our property wrapping. 737 * from our property wrapping.
736 * 738 *
737 * @param {string} magic The magic string that tags the error message. 739 * @param {string} magic The magic string that tags the error message.
738 */ 740 */
739 function overrideOnError(magic) 741 function overrideOnError(magic)
740 { 742 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 832
831 833
832 let object = window; 834 let object = window;
833 let path = api.split("."); 835 let path = api.split(".");
834 let name = path.pop(); 836 let name = path.pop();
835 837
836 for (let node of path) 838 for (let node of path)
837 { 839 {
838 object = object[node]; 840 object = object[node];
839 841
840 if (!object || typeof object != "object") 842 if (!object || !(typeof object == "object" || typeof object == "function"))
841 return; 843 return;
842 } 844 }
843 845
844 let currentValue = object[name]; 846 let currentValue = object[name];
845 847
846 let abort = () => 848 let abort = () =>
847 { 849 {
848 let element = document.currentScript; 850 let element = document.currentScript;
849 if (element instanceof HTMLScriptElement && element.src == "" && 851 if (element instanceof HTMLScriptElement && element.src == "" &&
850 element != us && (!re || re.test(element.textContent))) 852 element != us && (!re || re.test(element.textContent)))
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 let url = new URL(source); 898 let url = new URL(source);
897 url.searchParams.delete(name); 899 url.searchParams.delete(name);
898 args[0] = url.href; 900 args[0] = url.href;
899 } 901 }
900 return fetch_.apply(this, args); 902 return fetch_.apply(this, args);
901 }; 903 };
902 } 904 }
903 905
904 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, 906 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter,
905 toRegExp, regexEscape); 907 toRegExp, regexEscape);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld