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 PS2 Comments Created Oct. 12, 2018, 3:46 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
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | lib/subscriptionClasses.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.
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/14 20:05:36 This should be: let {text} = this; It's workin
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 { 608 {
608 let {sitekeys, domains} = this; 609 let {sitekeys, domains} = this;
609 610
610 return !(sitekeys && sitekeys.length) && (!domains || domains.get("")); 611 return !(sitekeys && sitekeys.length) && (!domains || domains.get(""));
611 }, 612 },
612 613
613 /** 614 /**
614 * See Filter.serialize() 615 * See Filter.serialize()
615 * @inheritdoc 616 * @inheritdoc
616 */ 617 */
617 serialize(buffer) 618 *serialize()
618 { 619 {
619 if (this._disabled || this._hitCount || this._lastHit) 620 let {_disabled, _hitCount, _lastHit} = this;
621 if (_disabled || _hitCount || _lastHit)
620 { 622 {
621 Filter.prototype.serialize.call(this, buffer); 623 yield* Filter.prototype.serialize.call(this);
622 if (this._disabled) 624 if (this._disabled)
Manish Jethani 2018/10/14 20:05:36 We extracted the values first so we would use them
623 buffer.push("disabled=true"); 625 yield "disabled=true";
624 if (this._hitCount) 626 if (this._hitCount)
625 buffer.push("hitCount=" + this._hitCount); 627 yield "hitCount=" + this._hitCount;
626 if (this._lastHit) 628 if (this._lastHit)
627 buffer.push("lastHit=" + this._lastHit); 629 yield "lastHit=" + this._lastHit;
628 } 630 }
629 } 631 }
630 }); 632 });
631 633
632 /** 634 /**
633 * Abstract base class for RegExp-based filters 635 * Abstract base class for RegExp-based filters
634 * @param {string} text see {@link Filter Filter()} 636 * @param {string} text see {@link Filter Filter()}
635 * @param {string} regexpSource 637 * @param {string} regexpSource
636 * filter part that the regular expression should be build from 638 * filter part that the regular expression should be build from
637 * @param {number} [contentType] 639 * @param {number} [contentType]
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1239
1238 /** 1240 /**
1239 * Script that should be executed 1241 * Script that should be executed
1240 * @type {string} 1242 * @type {string}
1241 */ 1243 */
1242 get script() 1244 get script()
1243 { 1245 {
1244 return this.body; 1246 return this.body;
1245 } 1247 }
1246 }); 1248 });
OLDNEW
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | lib/subscriptionClasses.js » ('J')

Powered by Google App Engine
This is Rietveld