Left: | ||
Right: |
OLD | NEW |
---|---|
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 let oldValue = this._disabled; | 120 let oldValue = this._disabled; |
121 this._disabled = value; | 121 this._disabled = value; |
122 filterNotifier.emit("subscription.disabled", this, value, oldValue); | 122 filterNotifier.emit("subscription.disabled", this, value, oldValue); |
123 } | 123 } |
124 return this._disabled; | 124 return this._disabled; |
125 }, | 125 }, |
126 | 126 |
127 /** | 127 /** |
128 * Serializes the subscription to an array of strings for writing | 128 * Serializes the subscription to an array of strings for writing |
129 * out on the disk. | 129 * out on the disk. |
130 * @param {string[]} buffer buffer to push the serialization results into | 130 * @yields {string} |
131 */ | 131 */ |
132 serialize(buffer) | 132 *serialize() |
133 { | 133 { |
134 buffer.push("[Subscription]"); | 134 yield "[Subscription]"; |
Manish Jethani
2018/10/09 15:11:04
Let's extract the values first:
let {url, type,
Jon Sonesen
2018/10/12 03:50:06
Done.
| |
135 buffer.push("url=" + this.url); | 135 yield "url=" + this.url; |
136 | |
136 if (this.type) | 137 if (this.type) |
137 buffer.push("type=" + this.type); | 138 yield "type=" + this.type; |
138 if (this._title) | 139 if (this._title) |
139 buffer.push("title=" + this._title); | 140 yield "title=" + this._title; |
140 if (this._fixedTitle) | 141 if (this._fixedTitle) |
141 buffer.push("fixedTitle=true"); | 142 yield "fixedTitle=true"; |
142 if (this._disabled) | 143 if (this._disabled) |
143 buffer.push("disabled=true"); | 144 yield "disabled=true"; |
144 }, | 145 }, |
145 | 146 |
146 serializeFilters(buffer) | 147 *serializeFilters() |
Manish Jethani
2018/10/04 03:37:12
This might be a good place to introduce a generic
Jon Sonesen
2018/10/06 00:06:34
This most likely will turn into a rather large cha
Manish Jethani
2018/10/09 15:11:04
Acknowledged.
| |
147 { | 148 { |
148 for (let filter of this.filters) | 149 for (let filter of this.filters) |
149 buffer.push(filter.text.replace(/\[/g, "\\[")); | 150 yield filter.text.replace(/\[/g, "\\["); |
150 }, | 151 }, |
151 | 152 |
152 toString() | 153 toString() |
153 { | 154 { |
154 let buffer = []; | 155 return [...this.serialize()].join("\n"); |
155 this.serialize(buffer); | |
156 return buffer.join("\n"); | |
157 } | 156 } |
158 }; | 157 }; |
159 | 158 |
160 /** | 159 /** |
161 * Cache for known filter subscriptions, maps URL to subscription objects. | 160 * Cache for known filter subscriptions, maps URL to subscription objects. |
162 * @type {Map.<string,Subscription>} | 161 * @type {Map.<string,Subscription>} |
163 */ | 162 */ |
164 Subscription.knownSubscriptions = new Map(); | 163 Subscription.knownSubscriptions = new Map(); |
165 | 164 |
166 /** | 165 /** |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 } | 273 } |
275 } | 274 } |
276 | 275 |
277 return false; | 276 return false; |
278 }, | 277 }, |
279 | 278 |
280 /** | 279 /** |
281 * See Subscription.serialize() | 280 * See Subscription.serialize() |
282 * @inheritdoc | 281 * @inheritdoc |
283 */ | 282 */ |
284 serialize(buffer) | 283 *serialize() |
285 { | 284 { |
286 Subscription.prototype.serialize.call(this, buffer); | 285 yield* Subscription.prototype.serialize.call(this); |
Manish Jethani
2018/10/09 15:11:04
Let's extract the values first:
let {defaults,
Jon Sonesen
2018/10/12 03:50:06
Done.
| |
287 if (this.defaults && this.defaults.length) | 286 if (this.defaults && this.defaults.length) |
288 { | 287 { |
289 buffer.push("defaults=" + | 288 yield "defaults=" + |
Manish Jethani
2018/10/04 03:37:12
Nit: Since there is no longer a function call here
Jon Sonesen
2018/10/06 00:06:34
Acknowledged.
| |
290 this.defaults.filter( | 289 this.defaults.filter( |
291 type => SpecialSubscription.defaultsMap.has(type) | 290 type => SpecialSubscription.defaultsMap.has(type) |
292 ).join(" ") | 291 ).join(" ") |
293 ); | 292 ; |
294 } | 293 } |
295 if (this._lastDownload) | 294 if (this._lastDownload) |
296 buffer.push("lastDownload=" + this._lastDownload); | 295 yield "lastDownload=" + this._lastDownload; |
297 } | 296 } |
298 }); | 297 }); |
299 | 298 |
300 SpecialSubscription.defaultsMap = new Map([ | 299 SpecialSubscription.defaultsMap = new Map([ |
301 ["whitelist", WhitelistFilter], | 300 ["whitelist", WhitelistFilter], |
302 ["blocking", BlockingFilter], | 301 ["blocking", BlockingFilter], |
303 ["elemhide", ElemHideBase] | 302 ["elemhide", ElemHideBase] |
304 ]); | 303 ]); |
305 | 304 |
306 /** | 305 /** |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 this._lastDownload = value; | 391 this._lastDownload = value; |
393 filterNotifier.emit("subscription.lastDownload", this, value, oldValue); | 392 filterNotifier.emit("subscription.lastDownload", this, value, oldValue); |
394 } | 393 } |
395 return this._lastDownload; | 394 return this._lastDownload; |
396 }, | 395 }, |
397 | 396 |
398 /** | 397 /** |
399 * See Subscription.serialize() | 398 * See Subscription.serialize() |
400 * @inheritdoc | 399 * @inheritdoc |
401 */ | 400 */ |
402 serialize(buffer) | 401 *serialize() |
403 { | 402 { |
404 Subscription.prototype.serialize.call(this, buffer); | 403 yield* Subscription.prototype.serialize.call(this); |
Manish Jethani
2018/10/09 15:11:04
Same thing, let's extract _homepage and _lastDownl
Jon Sonesen
2018/10/12 03:50:06
Done.
| |
405 if (this._homepage) | 404 if (this._homepage) |
406 buffer.push("homepage=" + this._homepage); | 405 yield "homepage=" + this._homepage; |
407 if (this._lastDownload) | 406 if (this._lastDownload) |
408 buffer.push("lastDownload=" + this._lastDownload); | 407 yield "lastDownload=" + this._lastDownload; |
409 } | 408 } |
410 }); | 409 }); |
411 | 410 |
412 /** | 411 /** |
413 * Class for filter subscriptions updated externally (by other extension) | 412 * Class for filter subscriptions updated externally (by other extension) |
414 * @param {string} url see {@link Subscription Subscription()} | 413 * @param {string} url see {@link Subscription Subscription()} |
415 * @param {string} [title] see {@link Subscription Subscription()} | 414 * @param {string} [title] see {@link Subscription Subscription()} |
416 * @constructor | 415 * @constructor |
417 * @augments RegularSubscription | 416 * @augments RegularSubscription |
418 */ | 417 */ |
419 function ExternalSubscription(url, title) | 418 function ExternalSubscription(url, title) |
420 { | 419 { |
421 RegularSubscription.call(this, url, title); | 420 RegularSubscription.call(this, url, title); |
422 } | 421 } |
423 exports.ExternalSubscription = ExternalSubscription; | 422 exports.ExternalSubscription = ExternalSubscription; |
424 | 423 |
425 ExternalSubscription.prototype = extend(RegularSubscription, { | 424 ExternalSubscription.prototype = extend(RegularSubscription, { |
426 /** | 425 /** |
427 * See Subscription.serialize() | 426 * See Subscription.serialize() |
428 * @inheritdoc | 427 * @inheritdoc |
429 */ | 428 */ |
430 serialize(buffer) | 429 *serialize() |
431 { | 430 { |
432 throw new Error( | 431 yield new Error( |
Manish Jethani
2018/10/04 03:37:12
This would still be a throw.
Manish Jethani
2018/10/04 05:30:00
I see, you're getting an error from ESLint. I hate
Jon Sonesen
2018/10/12 03:50:06
Inline disable ok?
Manish Jethani
2018/10/14 20:05:36
Yeah, that's probably better.
| |
433 "Unexpected call, external subscriptions should not be serialized" | 432 "Unexpected call, external subscriptions should not be serialized" |
434 ); | 433 ); |
435 } | 434 } |
436 }); | 435 }); |
437 | 436 |
438 /** | 437 /** |
439 * Class for filter subscriptions updated externally (by other extension) | 438 * Class for filter subscriptions updated externally (by other extension) |
440 * @param {string} url see {@link Subscription Subscription()} | 439 * @param {string} url see {@link Subscription Subscription()} |
441 * @param {string} [title] see {@link Subscription Subscription()} | 440 * @param {string} [title] see {@link Subscription Subscription()} |
442 * @constructor | 441 * @constructor |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 /** | 544 /** |
546 * Number indicating how often the object was downloaded. | 545 * Number indicating how often the object was downloaded. |
547 * @type {number} | 546 * @type {number} |
548 */ | 547 */ |
549 downloadCount: 0, | 548 downloadCount: 0, |
550 | 549 |
551 /** | 550 /** |
552 * See Subscription.serialize() | 551 * See Subscription.serialize() |
553 * @inheritdoc | 552 * @inheritdoc |
554 */ | 553 */ |
555 serialize(buffer) | 554 *serialize() |
556 { | 555 { |
557 RegularSubscription.prototype.serialize.call(this, buffer); | 556 yield* RegularSubscription.prototype.serialize.call(this); |
Manish Jethani
2018/10/09 15:11:04
Same thing, let's extract all the values of the pr
Jon Sonesen
2018/10/12 03:50:06
Done.
| |
558 if (this.downloadStatus) | 557 if (this.downloadStatus) |
559 buffer.push("downloadStatus=" + this.downloadStatus); | 558 yield "downloadStatus=" + this.downloadStatus; |
560 if (this.lastSuccess) | 559 if (this.lastSuccess) |
561 buffer.push("lastSuccess=" + this.lastSuccess); | 560 yield "lastSuccess=" + this.lastSuccess; |
562 if (this.lastCheck) | 561 if (this.lastCheck) |
563 buffer.push("lastCheck=" + this.lastCheck); | 562 yield "lastCheck=" + this.lastCheck; |
564 if (this.expires) | 563 if (this.expires) |
565 buffer.push("expires=" + this.expires); | 564 yield "expires=" + this.expires; |
566 if (this.softExpiration) | 565 if (this.softExpiration) |
567 buffer.push("softExpiration=" + this.softExpiration); | 566 yield "softExpiration=" + this.softExpiration; |
568 if (this.errors) | 567 if (this.errors) |
569 buffer.push("errors=" + this.errors); | 568 yield "errors=" + this.errors; |
570 if (this.version) | 569 if (this.version) |
571 buffer.push("version=" + this.version); | 570 yield "version=" + this.version; |
572 if (this.requiredVersion) | 571 if (this.requiredVersion) |
573 buffer.push("requiredVersion=" + this.requiredVersion); | 572 yield "requiredVersion=" + this.requiredVersion; |
574 if (this.downloadCount) | 573 if (this.downloadCount) |
575 buffer.push("downloadCount=" + this.downloadCount); | 574 yield "downloadCount=" + this.downloadCount; |
576 } | 575 } |
577 }); | 576 }); |
OLD | NEW |