| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 34 /** | 34 /** |
| 35 * Abstract base class for filters | 35 * Abstract base class for filters |
| 36 * | 36 * |
| 37 * @param {string} text string representation of the filter | 37 * @param {string} text string representation of the filter |
| 38 * @constructor | 38 * @constructor |
| 39 */ | 39 */ |
| 40 function Filter(text) | 40 function Filter(text) |
| 41 { | 41 { |
| 42 this.text = text; | 42 this.text = text; |
| 43 | 43 |
| 44 /** | |
| 45 * Subscriptions to which this filter belongs. | |
| 46 * @type {(Subscription|Set.<Subscription>)?} | |
| 47 * @private | |
| 48 */ | |
| 44 this._subscriptions = null; | 49 this._subscriptions = null; |
| 45 } | 50 } |
| 46 exports.Filter = Filter; | 51 exports.Filter = Filter; |
| 47 | 52 |
| 48 Filter.prototype = | 53 Filter.prototype = |
| 49 { | 54 { |
| 50 /** | 55 /** |
| 51 * String representation of the filter | 56 * String representation of the filter |
| 52 * @type {string} | 57 * @type {string} |
| 53 */ | 58 */ |
| 54 text: null, | 59 text: null, |
| 55 | 60 |
| 56 /** | 61 /** |
| 57 * Filter type as a string, e.g. "blocking". | 62 * Filter type as a string, e.g. "blocking". |
| 58 * @type {string} | 63 * @type {string} |
| 59 */ | 64 */ |
| 60 get type() | 65 get type() |
| 61 { | 66 { |
| 62 throw new Error("Please define filter type in the subclass"); | 67 throw new Error("Please define filter type in the subclass"); |
| 63 }, | 68 }, |
| 64 | 69 |
| 65 /** | 70 /** |
| 66 * Yields filter subscriptions the filter belongs to | 71 * Yields subscriptions to which the filter belongs. |
| 67 * @yields {Subscription} | 72 * @yields {Subscription} |
|
Jon Sonesen
2018/09/02 17:22:50
Should this be {(Subscription|Set.<Subscription>)?
Manish Jethani
2018/09/03 19:03:42
No, the function only ever yields a single Subscri
| |
| 68 */ | 73 */ |
| 69 *subscriptions() | 74 *subscriptions() |
| 70 { | 75 { |
| 71 if (this._subscriptions) | 76 if (this._subscriptions) |
| 72 { | 77 { |
| 73 if (this._subscriptions instanceof Set) | 78 if (this._subscriptions instanceof Set) |
| 74 yield* this._subscriptions; | 79 yield* this._subscriptions; |
| 75 else | 80 else |
| 76 yield this._subscriptions; | 81 yield this._subscriptions; |
| 77 } | 82 } |
| 78 }, | 83 }, |
| 79 | 84 |
| 85 /** | |
| 86 * The number of subscriptions to which the filter belongs. | |
| 87 * @type {number} | |
| 88 */ | |
| 89 get subscriptionCount() | |
| 90 { | |
| 91 if (this._subscriptions instanceof Set) | |
| 92 return this._subscriptions.size; | |
| 93 | |
| 94 return this._subscriptions ? 1 : 0; | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 98 * Adds a subscription to the set of subscriptions to which the filter | |
| 99 * belongs. | |
| 100 * @param {Subscription} subscription | |
| 101 */ | |
| 80 addSubscription(subscription) | 102 addSubscription(subscription) |
| 81 { | 103 { |
| 104 // Since we use truthy checks in our logic, we must avoid adding a | |
| 105 // subscription that isn't a non-null object. | |
|
Jon Sonesen
2018/09/02 17:22:50
the double negative in the comment is sort of conf
Manish Jethani
2018/09/03 19:03:42
The non-null part is a bit of a distraction: the p
| |
| 106 if (subscription === null || typeof subscription != "object") | |
| 107 return; | |
| 108 | |
| 82 if (this._subscriptions) | 109 if (this._subscriptions) |
| 83 { | 110 { |
| 84 if (this._subscriptions instanceof Set) | 111 if (this._subscriptions instanceof Set) |
| 85 this._subscriptions.add(subscription); | 112 this._subscriptions.add(subscription); |
| 86 else if (subscription != this._subscriptions) | 113 else if (subscription != this._subscriptions) |
| 87 this._subscriptions = new Set([this._subscriptions, subscription]); | 114 this._subscriptions = new Set([this._subscriptions, subscription]); |
| 88 } | 115 } |
| 89 else | 116 else |
| 90 { | 117 { |
| 91 this._subscriptions = subscription; | 118 this._subscriptions = subscription; |
| 92 } | 119 } |
| 93 }, | 120 }, |
| 94 | 121 |
| 122 /** | |
| 123 * Removes a subscription from the set of subscriptions to which the filter | |
| 124 * belongs. | |
| 125 * @param {Subscription} subscription | |
| 126 */ | |
| 95 removeSubscription(subscription) | 127 removeSubscription(subscription) |
| 96 { | 128 { |
| 97 if (this._subscriptions) | 129 if (this._subscriptions) |
| 98 { | 130 { |
| 99 if (this._subscriptions instanceof Set) | 131 if (this._subscriptions instanceof Set) |
| 100 { | 132 { |
| 101 this._subscriptions.delete(subscription); | 133 this._subscriptions.delete(subscription); |
| 102 | 134 |
| 103 if (this._subscriptions.size == 1) | 135 if (this._subscriptions.size == 1) |
| 104 this._subscriptions = [...this._subscriptions][0]; | 136 this._subscriptions = [...this._subscriptions][0]; |
|
Jon Sonesen
2018/09/02 17:22:50
Just asking, not so much a comment but this line
Manish Jethani
2018/09/03 19:03:42
Yes, that's exactly what it does. We can't do `thi
| |
| 105 } | 137 } |
| 106 else if (subscription == this._subscriptions) | 138 else if (subscription == this._subscriptions) |
| 107 { | 139 { |
| 108 this._subscriptions = null; | 140 this._subscriptions = null; |
| 109 } | 141 } |
| 110 } | 142 } |
| 111 }, | 143 }, |
| 112 | 144 |
| 113 /** | 145 /** |
| 114 * Serializes the filter to an array of strings for writing out on the disk. | 146 * Serializes the filter to an array of strings for writing out on the disk. |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 | 1252 |
| 1221 /** | 1253 /** |
| 1222 * Script that should be executed | 1254 * Script that should be executed |
| 1223 * @type {string} | 1255 * @type {string} |
| 1224 */ | 1256 */ |
| 1225 get script() | 1257 get script() |
| 1226 { | 1258 { |
| 1227 return this.body; | 1259 return this.body; |
| 1228 } | 1260 } |
| 1229 }); | 1261 }); |
| LEFT | RIGHT |