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

Side by Side Diff: lib/filterClasses.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
Patch Set: Actually Address PS2 Comments Created Oct. 21, 2018, 5:25 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/filterStorage.js » ('j') | lib/filterStorage.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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 this._subscriptions = [...this._subscriptions][0]; 136 this._subscriptions = [...this._subscriptions][0];
137 } 137 }
138 else if (subscription == this._subscriptions) 138 else if (subscription == this._subscriptions)
139 { 139 {
140 this._subscriptions = null; 140 this._subscriptions = null;
141 } 141 }
142 } 142 }
143 }, 143 },
144 144
145 /** 145 /**
146 * Serializes the filter to an array of strings for writing out on the disk. 146 * Generates serialized filter.
Manish Jethani 2018/10/21 21:51:43 I like the previous comment, I think we could just
Jon Sonesen 2018/10/22 19:27:47 Acknowledged. Yeah I like that better
147 * @param {string[]} buffer buffer to push the serialization results into 147 * @yields {string}
148 */ 148 */
149 serialize(buffer) 149 *serialize()
150 { 150 {
151 buffer.push("[Filter]"); 151 let {text} = this;
Manish Jethani 2018/10/21 21:52:55 Nit: I would leave a line after this just to be co
Jon Sonesen 2018/10/22 19:27:47 Yeah good catch
152 buffer.push("text=" + this.text); 152 yield "[Filter]";
153 yield "text=" + text;
153 }, 154 },
154 155
155 toString() 156 toString()
156 { 157 {
157 return this.text; 158 return this.text;
158 } 159 }
159 }; 160 };
160 161
161 /** 162 /**
162 * Cache for known filters, maps string representation to filter objects. 163 * Cache for known filters, maps string representation to filter objects.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 /** 320 /**
320 * Reason why this filter is invalid 321 * Reason why this filter is invalid
321 * @type {string} 322 * @type {string}
322 */ 323 */
323 reason: null, 324 reason: null,
324 325
325 /** 326 /**
326 * See Filter.serialize() 327 * See Filter.serialize()
327 * @inheritdoc 328 * @inheritdoc
328 */ 329 */
329 serialize(buffer) {} 330 *serialize() {}
330 }); 331 });
331 332
332 /** 333 /**
333 * Class for comments 334 * Class for comments
334 * @param {string} text see {@link Filter Filter()} 335 * @param {string} text see {@link Filter Filter()}
335 * @constructor 336 * @constructor
336 * @augments Filter 337 * @augments Filter
337 */ 338 */
338 function CommentFilter(text) 339 function CommentFilter(text)
339 { 340 {
340 Filter.call(this, text); 341 Filter.call(this, text);
341 } 342 }
342 exports.CommentFilter = CommentFilter; 343 exports.CommentFilter = CommentFilter;
343 344
344 CommentFilter.prototype = extend(Filter, { 345 CommentFilter.prototype = extend(Filter, {
345 type: "comment", 346 type: "comment",
346 347
347 /** 348 /**
348 * See Filter.serialize() 349 * See Filter.serialize()
349 * @inheritdoc 350 * @inheritdoc
350 */ 351 */
351 serialize(buffer) {} 352 *serialize() {}
352 }); 353 });
353 354
354 /** 355 /**
355 * Abstract base class for filters that can get hits 356 * Abstract base class for filters that can get hits
356 * @param {string} text 357 * @param {string} text
357 * see {@link Filter Filter()} 358 * see {@link Filter Filter()}
358 * @param {string} [domains] 359 * @param {string} [domains]
359 * Domains that the filter is restricted to separated by domainSeparator 360 * Domains that the filter is restricted to separated by domainSeparator
360 * e.g. "foo.com|bar.com|~baz.com" 361 * e.g. "foo.com|bar.com|~baz.com"
361 * @constructor 362 * @constructor
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 { 625 {
625 let {sitekeys, domains} = this; 626 let {sitekeys, domains} = this;
626 627
627 return !(sitekeys && sitekeys.length) && (!domains || domains.get("")); 628 return !(sitekeys && sitekeys.length) && (!domains || domains.get(""));
628 }, 629 },
629 630
630 /** 631 /**
631 * See Filter.serialize() 632 * See Filter.serialize()
632 * @inheritdoc 633 * @inheritdoc
633 */ 634 */
634 serialize(buffer) 635 *serialize()
635 { 636 {
636 if (this._disabled || this._hitCount || this._lastHit) 637 let {_disabled, _hitCount, _lastHit} = this;
638
639 if (_disabled || _hitCount || _lastHit)
637 { 640 {
638 Filter.prototype.serialize.call(this, buffer); 641 yield* Filter.prototype.serialize.call(this);
639 if (this._disabled) 642 if (_disabled)
640 buffer.push("disabled=true"); 643 yield "disabled=true";
641 if (this._hitCount) 644 if (_hitCount)
642 buffer.push("hitCount=" + this._hitCount); 645 yield "hitCount=" + _hitCount;
643 if (this._lastHit) 646 if (_lastHit)
644 buffer.push("lastHit=" + this._lastHit); 647 yield "lastHit=" + _lastHit;
645 } 648 }
646 } 649 }
647 }); 650 });
648 651
649 /** 652 /**
650 * Abstract base class for RegExp-based filters 653 * Abstract base class for RegExp-based filters
651 * @param {string} text see {@link Filter Filter()} 654 * @param {string} text see {@link Filter Filter()}
652 * @param {string} regexpSource 655 * @param {string} regexpSource
653 * filter part that the regular expression should be build from 656 * filter part that the regular expression should be build from
654 * @param {number} [contentType] 657 * @param {number} [contentType]
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 1279
1277 /** 1280 /**
1278 * Script that should be executed 1281 * Script that should be executed
1279 * @type {string} 1282 * @type {string}
1280 */ 1283 */
1281 get script() 1284 get script()
1282 { 1285 {
1283 return this.body; 1286 return this.body;
1284 } 1287 }
1285 }); 1288 });
OLDNEW
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | lib/filterStorage.js » ('J')

Powered by Google App Engine
This is Rietveld