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: Remove unelated change Created Oct. 3, 2018, 11:51 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.
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 yield "[Filter]";
Manish Jethani 2018/10/09 15:11:03 Let's extract the value of the text property first
Jon Sonesen 2018/10/12 03:50:05 Done.
152 buffer.push("text=" + this.text); 152 yield "text=" + this.text;
153 }, 153 },
154 154
155 toString() 155 toString()
156 { 156 {
157 return this.text; 157 return this.text;
158 } 158 }
159 }; 159 };
160 160
161 /** 161 /**
162 * Cache for known filters, maps string representation to filter objects. 162 * Cache for known filters, maps string representation to filter objects.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 /** 319 /**
320 * Reason why this filter is invalid 320 * Reason why this filter is invalid
321 * @type {string} 321 * @type {string}
322 */ 322 */
323 reason: null, 323 reason: null,
324 324
325 /** 325 /**
326 * See Filter.serialize() 326 * See Filter.serialize()
327 * @inheritdoc 327 * @inheritdoc
328 */ 328 */
329 serialize(buffer) {} 329 *serialize() {}
330 }); 330 });
331 331
332 /** 332 /**
333 * Class for comments 333 * Class for comments
334 * @param {string} text see {@link Filter Filter()} 334 * @param {string} text see {@link Filter Filter()}
335 * @constructor 335 * @constructor
336 * @augments Filter 336 * @augments Filter
337 */ 337 */
338 function CommentFilter(text) 338 function CommentFilter(text)
339 { 339 {
340 Filter.call(this, text); 340 Filter.call(this, text);
341 } 341 }
342 exports.CommentFilter = CommentFilter; 342 exports.CommentFilter = CommentFilter;
343 343
344 CommentFilter.prototype = extend(Filter, { 344 CommentFilter.prototype = extend(Filter, {
345 type: "comment", 345 type: "comment",
346 346
347 /** 347 /**
348 * See Filter.serialize() 348 * See Filter.serialize()
349 * @inheritdoc 349 * @inheritdoc
350 */ 350 */
351 serialize(buffer) {} 351 *serialize() {}
352 }); 352 });
353 353
354 /** 354 /**
355 * Abstract base class for filters that can get hits 355 * Abstract base class for filters that can get hits
356 * @param {string} text 356 * @param {string} text
357 * see {@link Filter Filter()} 357 * see {@link Filter Filter()}
358 * @param {string} [domains] 358 * @param {string} [domains]
359 * Domains that the filter is restricted to separated by domainSeparator 359 * Domains that the filter is restricted to separated by domainSeparator
360 * e.g. "foo.com|bar.com|~baz.com" 360 * e.g. "foo.com|bar.com|~baz.com"
361 * @constructor 361 * @constructor
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 { 607 {
608 let {sitekeys, domains} = this; 608 let {sitekeys, domains} = this;
609 609
610 return !(sitekeys && sitekeys.length) && (!domains || domains.get("")); 610 return !(sitekeys && sitekeys.length) && (!domains || domains.get(""));
611 }, 611 },
612 612
613 /** 613 /**
614 * See Filter.serialize() 614 * See Filter.serialize()
615 * @inheritdoc 615 * @inheritdoc
616 */ 616 */
617 serialize(buffer) 617 *serialize()
618 { 618 {
619 if (this._disabled || this._hitCount || this._lastHit) 619 if (this._disabled || this._hitCount || this._lastHit)
Manish Jethani 2018/10/09 15:11:03 Similarly, let's extract the values here first:
Jon Sonesen 2018/10/12 03:50:05 Done.
620 { 620 {
621 Filter.prototype.serialize.call(this, buffer); 621 yield* Filter.prototype.serialize.call(this);
622 if (this._disabled) 622 if (this._disabled)
623 buffer.push("disabled=true"); 623 yield "disabled=true";
624 if (this._hitCount) 624 if (this._hitCount)
625 buffer.push("hitCount=" + this._hitCount); 625 yield "hitCount=" + this._hitCount;
626 if (this._lastHit) 626 if (this._lastHit)
627 buffer.push("lastHit=" + this._lastHit); 627 yield "lastHit=" + this._lastHit;
628 } 628 }
629 } 629 }
630 }); 630 });
631 631
632 /** 632 /**
633 * Abstract base class for RegExp-based filters 633 * Abstract base class for RegExp-based filters
634 * @param {string} text see {@link Filter Filter()} 634 * @param {string} text see {@link Filter Filter()}
635 * @param {string} regexpSource 635 * @param {string} regexpSource
636 * filter part that the regular expression should be build from 636 * filter part that the regular expression should be build from
637 * @param {number} [contentType] 637 * @param {number} [contentType]
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1237
1238 /** 1238 /**
1239 * Script that should be executed 1239 * Script that should be executed
1240 * @type {string} 1240 * @type {string}
1241 */ 1241 */
1242 get script() 1242 get script()
1243 { 1243 {
1244 return this.body; 1244 return this.body;
1245 } 1245 }
1246 }); 1246 });
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