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

Side by Side Diff: lib/filterClasses.js

Issue 29907586: Issue 6994 - Use shortcut matching for location only filters (Closed)
Patch Set: Address PS1 Comments Created Oct. 20, 2018, 11:07 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 | lib/matcher.js » ('j') | lib/matcher.js » ('J')
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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 { 765 {
766 sitekeys = this.sitekeySource.split("|"); 766 sitekeys = this.sitekeySource.split("|");
767 this.sitekeySource = null; 767 this.sitekeySource = null;
768 } 768 }
769 769
770 Object.defineProperty( 770 Object.defineProperty(
771 this, "sitekeys", {value: sitekeys, enumerable: true} 771 this, "sitekeys", {value: sitekeys, enumerable: true}
772 ); 772 );
773 return this.sitekeys; 773 return this.sitekeys;
774 }, 774 },
775 /**
776 * Tests whether the filter only has location.
777 */
778 get isLocationOnly()
779 {
780 return this.contentType == RegExpFilter.prototype.contentType &&
781 this.thirdParty == null && !this.domains && !this.sitekeys;
782 },
775 783
776 /** 784 /**
777 * Tests whether the URL matches this filter 785 * Tests whether the URL matches this filter
778 * @param {string} location URL to be tested 786 * @param {string} location URL to be tested
779 * @param {number} typeMask bitmask of content / request types to match 787 * @param {number} typeMask bitmask of content / request types to match
780 * @param {string} [docDomain] domain name of the document that loads the URL 788 * @param {string} [docDomain] domain name of the document that loads the URL
781 * @param {boolean} [thirdParty] should be true if the URL is a third-party 789 * @param {boolean} [thirdParty] should be true if the URL is a third-party
782 * request 790 * request
783 * @param {string} [sitekey] public key provided by the document 791 * @param {string} [sitekey] public key provided by the document
784 * @return {boolean} true in case of a match 792 * @return {boolean} true in case of a match
785 */ 793 */
786 matches(location, typeMask, docDomain, thirdParty, sitekey) 794 matches(location, typeMask, docDomain, thirdParty, sitekey)
787 { 795 {
788 return (this.contentType & typeMask) != 0 && 796 return (this.contentType & typeMask) != 0 &&
789 (this.thirdParty == null || this.thirdParty == thirdParty) && 797 (this.thirdParty == null || this.thirdParty == thirdParty) &&
790 this.isActiveOnDomain(docDomain, sitekey) && 798 this.isActiveOnDomain(docDomain, sitekey) &&
791 this.regexp.test(location); 799 this.regexp.test(location);
800 },
801 matchesLocation(location)
802 {
803 return RegExp(location).test(this.regexp);
Jon Sonesen 2018/10/20 23:09:48 My bad, thought I added doc strings here.
792 } 804 }
793 }); 805 });
794 806
795 /** 807 /**
796 * Yields the filter itself (required to optimize {@link Matcher}). 808 * Yields the filter itself (required to optimize {@link Matcher}).
797 * @yields {RegExpFilter} 809 * @yields {RegExpFilter}
798 */ 810 */
799 RegExpFilter.prototype[Symbol.iterator] = function*() 811 RegExpFilter.prototype[Symbol.iterator] = function*()
800 { 812 {
801 yield this; 813 yield this;
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 1288
1277 /** 1289 /**
1278 * Script that should be executed 1290 * Script that should be executed
1279 * @type {string} 1291 * @type {string}
1280 */ 1292 */
1281 get script() 1293 get script()
1282 { 1294 {
1283 return this.body; 1295 return this.body;
1284 } 1296 }
1285 }); 1297 });
OLDNEW
« no previous file with comments | « no previous file | lib/matcher.js » ('j') | lib/matcher.js » ('J')

Powered by Google App Engine
This is Rietveld