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

Side by Side Diff: lib/filterClasses.js

Issue 29350382: Issue 4353 - Remove deprecated __proto__ syntax (Closed)
Patch Set: Make use of Object.getOwnPropertyDescriptor Created Sept. 2, 2016, 11:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Definition of Filter class and its subclasses. 19 * @fileOverview Definition of Filter class and its subclasses.
20 */ 20 */
21 21
22 let {FilterNotifier} = require("filterNotifier"); 22 let {FilterNotifier} = require("filterNotifier");
23 let {desc} = require("coreUtils");
23 24
24 /** 25 /**
25 * Abstract base class for filters 26 * Abstract base class for filters
26 * 27 *
27 * @param {String} text string representation of the filter 28 * @param {String} text string representation of the filter
28 * @constructor 29 * @constructor
29 */ 30 */
30 function Filter(text) 31 function Filter(text)
31 { 32 {
32 this.text = text; 33 this.text = text;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 * @augments Filter 204 * @augments Filter
204 */ 205 */
205 function InvalidFilter(text, reason) 206 function InvalidFilter(text, reason)
206 { 207 {
207 Filter.call(this, text); 208 Filter.call(this, text);
208 209
209 this.reason = reason; 210 this.reason = reason;
210 } 211 }
211 exports.InvalidFilter = InvalidFilter; 212 exports.InvalidFilter = InvalidFilter;
212 213
213 InvalidFilter.prototype = 214 InvalidFilter.prototype = Object.create(Filter.prototype, desc({
214 {
215 __proto__: Filter.prototype,
216
217 type: "invalid", 215 type: "invalid",
218 216
219 /** 217 /**
220 * Reason why this filter is invalid 218 * Reason why this filter is invalid
221 * @type String 219 * @type String
222 */ 220 */
223 reason: null, 221 reason: null,
224 222
225 /** 223 /**
226 * See Filter.serialize() 224 * See Filter.serialize()
227 */ 225 */
228 serialize: function(buffer) {} 226 serialize: function(buffer) {}
229 }; 227 }));
230 228
231 /** 229 /**
232 * Class for comments 230 * Class for comments
233 * @param {String} text see Filter() 231 * @param {String} text see Filter()
234 * @constructor 232 * @constructor
235 * @augments Filter 233 * @augments Filter
236 */ 234 */
237 function CommentFilter(text) 235 function CommentFilter(text)
238 { 236 {
239 Filter.call(this, text); 237 Filter.call(this, text);
240 } 238 }
241 exports.CommentFilter = CommentFilter; 239 exports.CommentFilter = CommentFilter;
242 240
243 CommentFilter.prototype = 241 CommentFilter.prototype = Object.create(Filter.prototype, desc({
244 {
245 __proto__: Filter.prototype,
246
247 type: "comment", 242 type: "comment",
248 243
249 /** 244 /**
250 * See Filter.serialize() 245 * See Filter.serialize()
251 */ 246 */
252 serialize: function(buffer) {} 247 serialize: function(buffer) {}
253 }; 248 }));
254 249
255 /** 250 /**
256 * Abstract base class for filters that can get hits 251 * Abstract base class for filters that can get hits
257 * @param {String} text see Filter() 252 * @param {String} text see Filter()
258 * @param {String} [domains] Domains that the filter is restricted to separated by domainSeparator e.g. "foo.com|bar.com|~baz.com" 253 * @param {String} [domains] Domains that the filter is restricted to separated by domainSeparator e.g. "foo.com|bar.com|~baz.com"
259 * @constructor 254 * @constructor
260 * @augments Filter 255 * @augments Filter
261 */ 256 */
262 function ActiveFilter(text, domains) 257 function ActiveFilter(text, domains)
263 { 258 {
264 Filter.call(this, text); 259 Filter.call(this, text);
265 260
266 this.domainSource = domains; 261 this.domainSource = domains;
267 } 262 }
268 exports.ActiveFilter = ActiveFilter; 263 exports.ActiveFilter = ActiveFilter;
269 264
270 ActiveFilter.prototype = 265 ActiveFilter.prototype = Object.create(Filter.prototype, desc({
271 {
272 __proto__: Filter.prototype,
273
274 _disabled: false, 266 _disabled: false,
275 _hitCount: 0, 267 _hitCount: 0,
276 _lastHit: 0, 268 _lastHit: 0,
277 269
278 /** 270 /**
279 * Defines whether the filter is disabled 271 * Defines whether the filter is disabled
280 * @type Boolean 272 * @type Boolean
281 */ 273 */
282 get disabled() 274 get disabled()
283 { 275 {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 { 500 {
509 Filter.prototype.serialize.call(this, buffer); 501 Filter.prototype.serialize.call(this, buffer);
510 if (this._disabled) 502 if (this._disabled)
511 buffer.push("disabled=true"); 503 buffer.push("disabled=true");
512 if (this._hitCount) 504 if (this._hitCount)
513 buffer.push("hitCount=" + this._hitCount); 505 buffer.push("hitCount=" + this._hitCount);
514 if (this._lastHit) 506 if (this._lastHit)
515 buffer.push("lastHit=" + this._lastHit); 507 buffer.push("lastHit=" + this._lastHit);
516 } 508 }
517 } 509 }
518 }; 510 }));
519 511
520 /** 512 /**
521 * Abstract base class for RegExp-based filters 513 * Abstract base class for RegExp-based filters
522 * @param {String} text see Filter() 514 * @param {String} text see Filter()
523 * @param {String} regexpSource filter part that the regular expression should b e build from 515 * @param {String} regexpSource filter part that the regular expression should b e build from
524 * @param {Number} [contentType] Content types the filter applies to, combinatio n of values from RegExpFilter.typeMap 516 * @param {Number} [contentType] Content types the filter applies to, combinatio n of values from RegExpFilter.typeMap
525 * @param {Boolean} [matchCase] Defines whether the filter should distinguish be tween lower and upper case letters 517 * @param {Boolean} [matchCase] Defines whether the filter should distinguish be tween lower and upper case letters
526 * @param {String} [domains] Domains that the filter is restricted to, e.g. "foo .com|bar.com|~baz.com" 518 * @param {String} [domains] Domains that the filter is restricted to, e.g. "foo .com|bar.com|~baz.com"
527 * @param {Boolean} [thirdParty] Defines whether the filter should apply to thir d-party or first-party content only 519 * @param {Boolean} [thirdParty] Defines whether the filter should apply to thir d-party or first-party content only
528 * @param {String} [sitekeys] Public keys of websites that this filter should ap ply to 520 * @param {String} [sitekeys] Public keys of websites that this filter should ap ply to
(...skipping 20 matching lines...) Expand all
549 Object.defineProperty(this, "regexp", {value: regexp}); 541 Object.defineProperty(this, "regexp", {value: regexp});
550 } 542 }
551 else 543 else
552 { 544 {
553 // No need to convert this filter to regular expression yet, do it on demand 545 // No need to convert this filter to regular expression yet, do it on demand
554 this.regexpSource = regexpSource; 546 this.regexpSource = regexpSource;
555 } 547 }
556 } 548 }
557 exports.RegExpFilter = RegExpFilter; 549 exports.RegExpFilter = RegExpFilter;
558 550
559 RegExpFilter.prototype = 551 RegExpFilter.prototype = Object.create(ActiveFilter.prototype, desc({
560 {
561 __proto__: ActiveFilter.prototype,
562
563 /** 552 /**
564 * @see ActiveFilter.domainSourceIsUpperCase 553 * @see ActiveFilter.domainSourceIsUpperCase
565 */ 554 */
566 domainSourceIsUpperCase: true, 555 domainSourceIsUpperCase: true,
567 556
568 /** 557 /**
569 * Number of filters contained, will always be 1 (required to optimize Matcher ). 558 * Number of filters contained, will always be 1 (required to optimize Matcher ).
570 * @type Integer 559 * @type Integer
571 */ 560 */
572 length: 1, 561 length: 1,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 { 646 {
658 if (this.contentType & typeMask && 647 if (this.contentType & typeMask &&
659 (this.thirdParty == null || this.thirdParty == thirdParty) && 648 (this.thirdParty == null || this.thirdParty == thirdParty) &&
660 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) 649 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
661 { 650 {
662 return true; 651 return true;
663 } 652 }
664 653
665 return false; 654 return false;
666 } 655 }
667 }; 656 }));
668 657
669 // Required to optimize Matcher, see also RegExpFilter.prototype.length 658 // Required to optimize Matcher, see also RegExpFilter.prototype.length
670 Object.defineProperty(RegExpFilter.prototype, "0", 659 Object.defineProperty(RegExpFilter.prototype, "0",
671 { 660 {
672 get: function() { return this; } 661 get: function() { return this; }
673 }); 662 });
674 663
675 /** 664 /**
676 * Creates a RegExp filter from its text representation 665 * Creates a RegExp filter from its text representation
677 * @param {String} text same as in Filter() 666 * @param {String} text same as in Filter()
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 * @augments RegExpFilter 792 * @augments RegExpFilter
804 */ 793 */
805 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thi rdParty, sitekeys, collapse) 794 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thi rdParty, sitekeys, collapse)
806 { 795 {
807 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t hirdParty, sitekeys); 796 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t hirdParty, sitekeys);
808 797
809 this.collapse = collapse; 798 this.collapse = collapse;
810 } 799 }
811 exports.BlockingFilter = BlockingFilter; 800 exports.BlockingFilter = BlockingFilter;
812 801
813 BlockingFilter.prototype = 802 BlockingFilter.prototype = Object.create(RegExpFilter.prototype, desc({
814 {
815 __proto__: RegExpFilter.prototype,
816
817 type: "blocking", 803 type: "blocking",
818 804
819 /** 805 /**
820 * Defines whether the filter should collapse blocked content. Can be null (us e the global preference). 806 * Defines whether the filter should collapse blocked content. Can be null (us e the global preference).
821 * @type Boolean 807 * @type Boolean
822 */ 808 */
823 collapse: null 809 collapse: null
824 }; 810 }));
825 811
826 /** 812 /**
827 * Class for whitelist filters 813 * Class for whitelist filters
828 * @param {String} text see Filter() 814 * @param {String} text see Filter()
829 * @param {String} regexpSource see RegExpFilter() 815 * @param {String} regexpSource see RegExpFilter()
830 * @param {Number} contentType see RegExpFilter() 816 * @param {Number} contentType see RegExpFilter()
831 * @param {Boolean} matchCase see RegExpFilter() 817 * @param {Boolean} matchCase see RegExpFilter()
832 * @param {String} domains see RegExpFilter() 818 * @param {String} domains see RegExpFilter()
833 * @param {Boolean} thirdParty see RegExpFilter() 819 * @param {Boolean} thirdParty see RegExpFilter()
834 * @param {String} sitekeys see RegExpFilter() 820 * @param {String} sitekeys see RegExpFilter()
835 * @constructor 821 * @constructor
836 * @augments RegExpFilter 822 * @augments RegExpFilter
837 */ 823 */
838 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th irdParty, sitekeys) 824 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th irdParty, sitekeys)
839 { 825 {
840 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t hirdParty, sitekeys); 826 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t hirdParty, sitekeys);
841 } 827 }
842 exports.WhitelistFilter = WhitelistFilter; 828 exports.WhitelistFilter = WhitelistFilter;
843 829
844 WhitelistFilter.prototype = 830 WhitelistFilter.prototype = Object.create(RegExpFilter.prototype, desc({
845 {
846 __proto__: RegExpFilter.prototype,
847
848 type: "whitelist" 831 type: "whitelist"
849 }; 832 }));
850 833
851 /** 834 /**
852 * Base class for element hiding filters 835 * Base class for element hiding filters
853 * @param {String} text see Filter() 836 * @param {String} text see Filter()
854 * @param {String} [domains] Host names or domains the filter should be restrict ed to 837 * @param {String} [domains] Host names or domains the filter should be restrict ed to
855 * @param {String} selector CSS selector for the HTML elements that should be hidden 838 * @param {String} selector CSS selector for the HTML elements that should be hidden
856 * @constructor 839 * @constructor
857 * @augments ActiveFilter 840 * @augments ActiveFilter
858 */ 841 */
859 function ElemHideBase(text, domains, selector) 842 function ElemHideBase(text, domains, selector)
860 { 843 {
861 ActiveFilter.call(this, text, domains || null); 844 ActiveFilter.call(this, text, domains || null);
862 845
863 if (domains) 846 if (domains)
864 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase(); 847 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase();
865 this.selector = selector; 848 this.selector = selector;
866 } 849 }
867 exports.ElemHideBase = ElemHideBase; 850 exports.ElemHideBase = ElemHideBase;
868 851
869 ElemHideBase.prototype = 852 ElemHideBase.prototype = Object.create(ActiveFilter.prototype, desc({
870 {
871 __proto__: ActiveFilter.prototype,
872
873 /** 853 /**
874 * @see ActiveFilter.domainSeparator 854 * @see ActiveFilter.domainSeparator
875 */ 855 */
876 domainSeparator: ",", 856 domainSeparator: ",",
877 857
878 /** 858 /**
879 * @see ActiveFilter.ignoreTrailingDot 859 * @see ActiveFilter.ignoreTrailingDot
880 */ 860 */
881 ignoreTrailingDot: false, 861 ignoreTrailingDot: false,
882 862
883 /** 863 /**
884 * Host name or domain the filter should be restricted to (can be null for no restriction) 864 * Host name or domain the filter should be restricted to (can be null for no restriction)
885 * @type String 865 * @type String
886 */ 866 */
887 selectorDomain: null, 867 selectorDomain: null,
888 /** 868 /**
889 * CSS selector for the HTML elements that should be hidden 869 * CSS selector for the HTML elements that should be hidden
890 * @type String 870 * @type String
891 */ 871 */
892 selector: null 872 selector: null
893 }; 873 }));
894 874
895 /** 875 /**
896 * Creates an element hiding filter from a pre-parsed text representation 876 * Creates an element hiding filter from a pre-parsed text representation
897 * 877 *
898 * @param {String} text same as in Filter() 878 * @param {String} text same as in Filter()
899 * @param {String} domain domain part of the text representation (can be e mpty) 879 * @param {String} domain domain part of the text representation (can be e mpty)
900 * @param {Boolean} isException exception rule indicator 880 * @param {Boolean} isException exception rule indicator
901 * @param {String} tagName tag name part (can be empty) 881 * @param {String} tagName tag name part (can be empty)
902 * @param {String} attrRules attribute matching rules (can be empty) 882 * @param {String} attrRules attribute matching rules (can be empty)
903 * @param {String} selector raw CSS selector (can be empty) 883 * @param {String} selector raw CSS selector (can be empty)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 * @param {String} selector see ElemHideBase() 948 * @param {String} selector see ElemHideBase()
969 * @constructor 949 * @constructor
970 * @augments ElemHideBase 950 * @augments ElemHideBase
971 */ 951 */
972 function ElemHideFilter(text, domains, selector) 952 function ElemHideFilter(text, domains, selector)
973 { 953 {
974 ElemHideBase.call(this, text, domains, selector); 954 ElemHideBase.call(this, text, domains, selector);
975 } 955 }
976 exports.ElemHideFilter = ElemHideFilter; 956 exports.ElemHideFilter = ElemHideFilter;
977 957
978 ElemHideFilter.prototype = 958 ElemHideFilter.prototype = Object.create(ElemHideBase.prototype, desc({
979 {
980 __proto__: ElemHideBase.prototype,
981
982 type: "elemhide" 959 type: "elemhide"
983 }; 960 }));
984 961
985 /** 962 /**
986 * Class for element hiding exceptions 963 * Class for element hiding exceptions
987 * @param {String} text see Filter() 964 * @param {String} text see Filter()
988 * @param {String} domains see ElemHideBase() 965 * @param {String} domains see ElemHideBase()
989 * @param {String} selector see ElemHideBase() 966 * @param {String} selector see ElemHideBase()
990 * @constructor 967 * @constructor
991 * @augments ElemHideBase 968 * @augments ElemHideBase
992 */ 969 */
993 function ElemHideException(text, domains, selector) 970 function ElemHideException(text, domains, selector)
994 { 971 {
995 ElemHideBase.call(this, text, domains, selector); 972 ElemHideBase.call(this, text, domains, selector);
996 } 973 }
997 exports.ElemHideException = ElemHideException; 974 exports.ElemHideException = ElemHideException;
998 975
999 ElemHideException.prototype = 976 ElemHideException.prototype = Object.create(ElemHideBase.prototype, desc({
1000 {
1001 __proto__: ElemHideBase.prototype,
1002
1003 type: "elemhideexception" 977 type: "elemhideexception"
1004 }; 978 }));
1005 979
1006 /** 980 /**
1007 * Class for CSS property filters 981 * Class for CSS property filters
1008 * @param {String} text see Filter() 982 * @param {String} text see Filter()
1009 * @param {String} domains see ElemHideBase() 983 * @param {String} domains see ElemHideBase()
1010 * @param {String} selector see ElemHideBase() 984 * @param {String} selector see ElemHideBase()
1011 * @param {String} regexpSource see CSSPropertyFilter.regexpSource 985 * @param {String} regexpSource see CSSPropertyFilter.regexpSource
1012 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix 986 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix
1013 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix 987 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix
1014 * @constructor 988 * @constructor
1015 * @augments ElemHideBase 989 * @augments ElemHideBase
1016 */ 990 */
1017 function CSSPropertyFilter(text, domains, selector, regexpSource, 991 function CSSPropertyFilter(text, domains, selector, regexpSource,
1018 selectorPrefix, selectorSuffix) 992 selectorPrefix, selectorSuffix)
1019 { 993 {
1020 ElemHideBase.call(this, text, domains, selector); 994 ElemHideBase.call(this, text, domains, selector);
1021 995
1022 this.regexpSource = regexpSource; 996 this.regexpSource = regexpSource;
1023 this.selectorPrefix = selectorPrefix; 997 this.selectorPrefix = selectorPrefix;
1024 this.selectorSuffix = selectorSuffix; 998 this.selectorSuffix = selectorSuffix;
1025 } 999 }
1026 exports.CSSPropertyFilter = CSSPropertyFilter; 1000 exports.CSSPropertyFilter = CSSPropertyFilter;
1027 1001
1028 CSSPropertyFilter.prototype = 1002 CSSPropertyFilter.prototype = Object.create(ElemHideBase.prototype, desc({
1029 {
1030 __proto__: ElemHideBase.prototype,
1031
1032 type: "cssproperty", 1003 type: "cssproperty",
1033 1004
1034 /** 1005 /**
1035 * Expression from which a regular expression should be generated for matching 1006 * Expression from which a regular expression should be generated for matching
1036 * CSS properties - for delayed creation of the regexpString property 1007 * CSS properties - for delayed creation of the regexpString property
1037 * @type String 1008 * @type String
1038 */ 1009 */
1039 regexpSource: null, 1010 regexpSource: null,
1040 /** 1011 /**
1041 * Substring of CSS selector before properties for the HTML elements that 1012 * Substring of CSS selector before properties for the HTML elements that
(...skipping 18 matching lines...) Expand all
1060 // Despite this property being cached, the getter is called 1031 // Despite this property being cached, the getter is called
1061 // several times on Safari, due to WebKit bug 132872 1032 // several times on Safari, due to WebKit bug 132872
1062 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1033 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1063 if (prop) 1034 if (prop)
1064 return prop.value; 1035 return prop.value;
1065 1036
1066 let regexp = Filter.toRegExp(this.regexpSource); 1037 let regexp = Filter.toRegExp(this.regexpSource);
1067 Object.defineProperty(this, "regexpString", {value: regexp}); 1038 Object.defineProperty(this, "regexpString", {value: regexp});
1068 return regexp; 1039 return regexp;
1069 } 1040 }
1070 }; 1041 }));
OLDNEW
« lib/coreUtils.js ('K') | « lib/coreUtils.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld