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: Address PS4 Comments Created Oct. 22, 2018, 7:28 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 this._subscriptions = [...this._subscriptions][0]; 156 this._subscriptions = [...this._subscriptions][0];
157 } 157 }
158 else if (subscription == this._subscriptions) 158 else if (subscription == this._subscriptions)
159 { 159 {
160 this._subscriptions = null; 160 this._subscriptions = null;
161 } 161 }
162 } 162 }
163 }, 163 },
164 164
165 /** 165 /**
166 * Serializes the filter to an array of strings for writing out on the disk. 166 * Serializes the filter for writing out on disk.
167 * @param {string[]} buffer buffer to push the serialization results into 167 * @yields {string}
168 */ 168 */
169 serialize(buffer) 169 *serialize()
170 { 170 {
171 buffer.push("[Filter]"); 171 let {text} = this;
172 buffer.push("text=" + this.text); 172
173 yield "[Filter]";
174 yield "text=" + text;
173 }, 175 },
174 176
175 toString() 177 toString()
176 { 178 {
177 return this.text; 179 return this.text;
178 } 180 }
179 }; 181 };
180 182
181 /** 183 /**
182 * Cache for known filters, maps string representation to filter objects. 184 * Cache for known filters, maps string representation to filter objects.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 /** 341 /**
340 * Reason why this filter is invalid 342 * Reason why this filter is invalid
341 * @type {string} 343 * @type {string}
342 */ 344 */
343 reason: null, 345 reason: null,
344 346
345 /** 347 /**
346 * See Filter.serialize() 348 * See Filter.serialize()
347 * @inheritdoc 349 * @inheritdoc
348 */ 350 */
349 serialize(buffer) {} 351 *serialize() {}
350 }); 352 });
351 353
352 /** 354 /**
353 * Class for comments 355 * Class for comments
354 * @param {string} text see {@link Filter Filter()} 356 * @param {string} text see {@link Filter Filter()}
355 * @constructor 357 * @constructor
356 * @augments Filter 358 * @augments Filter
357 */ 359 */
358 function CommentFilter(text) 360 function CommentFilter(text)
359 { 361 {
360 Filter.call(this, text); 362 Filter.call(this, text);
361 } 363 }
362 exports.CommentFilter = CommentFilter; 364 exports.CommentFilter = CommentFilter;
363 365
364 CommentFilter.prototype = extend(Filter, { 366 CommentFilter.prototype = extend(Filter, {
365 type: "comment", 367 type: "comment",
366 368
367 /** 369 /**
368 * See Filter.serialize() 370 * See Filter.serialize()
369 * @inheritdoc 371 * @inheritdoc
370 */ 372 */
371 serialize(buffer) {} 373 *serialize() {}
372 }); 374 });
373 375
374 /** 376 /**
375 * Abstract base class for filters that can get hits 377 * Abstract base class for filters that can get hits
376 * @param {string} text 378 * @param {string} text
377 * see {@link Filter Filter()} 379 * see {@link Filter Filter()}
378 * @param {string} [domains] 380 * @param {string} [domains]
379 * Domains that the filter is restricted to separated by domainSeparator 381 * Domains that the filter is restricted to separated by domainSeparator
380 * e.g. "foo.com|bar.com|~baz.com" 382 * e.g. "foo.com|bar.com|~baz.com"
381 * @constructor 383 * @constructor
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 { 646 {
645 let {sitekeys, domains} = this; 647 let {sitekeys, domains} = this;
646 648
647 return !(sitekeys && sitekeys.length) && (!domains || domains.get("")); 649 return !(sitekeys && sitekeys.length) && (!domains || domains.get(""));
648 }, 650 },
649 651
650 /** 652 /**
651 * See Filter.serialize() 653 * See Filter.serialize()
652 * @inheritdoc 654 * @inheritdoc
653 */ 655 */
654 serialize(buffer) 656 *serialize()
655 { 657 {
656 if (this._disabled || this._hitCount || this._lastHit) 658 let {_disabled, _hitCount, _lastHit} = this;
659
660 if (_disabled || _hitCount || _lastHit)
657 { 661 {
658 Filter.prototype.serialize.call(this, buffer); 662 yield* Filter.prototype.serialize.call(this);
659 if (this._disabled) 663 if (_disabled)
660 buffer.push("disabled=true"); 664 yield "disabled=true";
661 if (this._hitCount) 665 if (_hitCount)
662 buffer.push("hitCount=" + this._hitCount); 666 yield "hitCount=" + _hitCount;
663 if (this._lastHit) 667 if (_lastHit)
664 buffer.push("lastHit=" + this._lastHit); 668 yield "lastHit=" + _lastHit;
665 } 669 }
666 } 670 }
667 }); 671 });
668 672
669 /** 673 /**
670 * Abstract base class for RegExp-based filters 674 * Abstract base class for RegExp-based filters
671 * @param {string} text see {@link Filter Filter()} 675 * @param {string} text see {@link Filter Filter()}
672 * @param {string} regexpSource 676 * @param {string} regexpSource
673 * filter part that the regular expression should be build from 677 * filter part that the regular expression should be build from
674 * @param {number} [contentType] 678 * @param {number} [contentType]
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 1340
1337 /** 1341 /**
1338 * Script that should be executed 1342 * Script that should be executed
1339 * @type {string} 1343 * @type {string}
1340 */ 1344 */
1341 get script() 1345 get script()
1342 { 1346 {
1343 return this.body; 1347 return this.body;
1344 } 1348 }
1345 }); 1349 });
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