| 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 25 matching lines...) Expand all Loading... |
| 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 /** | 44 /** |
| 45 * Subscriptions to which this filter belongs. | 45 * Subscriptions to which this filter belongs. |
| 46 * @type {Set.<Subscription>} | 46 * @type {(Subscription|Set.<Subscription>)?} |
| 47 * @private | 47 * @private |
| 48 */ | 48 */ |
| 49 this._subscriptions = new Set(); | 49 this._subscriptions = null; |
| 50 } | 50 } |
| 51 exports.Filter = Filter; | 51 exports.Filter = Filter; |
| 52 | 52 |
| 53 Filter.prototype = | 53 Filter.prototype = |
| 54 { | 54 { |
| 55 /** | 55 /** |
| 56 * String representation of the filter | 56 * String representation of the filter |
| 57 * @type {string} | 57 * @type {string} |
| 58 */ | 58 */ |
| 59 text: null, | 59 text: null, |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Filter type as a string, e.g. "blocking". | 62 * Filter type as a string, e.g. "blocking". |
| 63 * @type {string} | 63 * @type {string} |
| 64 */ | 64 */ |
| 65 get type() | 65 get type() |
| 66 { | 66 { |
| 67 throw new Error("Please define filter type in the subclass"); | 67 throw new Error("Please define filter type in the subclass"); |
| 68 }, | 68 }, |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Yields subscriptions to which the filter belongs. | 71 * Yields subscriptions to which the filter belongs. |
| 72 * @yields {Subscription} | 72 * @yields {Subscription} |
| 73 */ | 73 */ |
| 74 *subscriptions() | 74 *subscriptions() |
| 75 { | 75 { |
| 76 yield* this._subscriptions; | 76 if (this._subscriptions) |
| 77 { |
| 78 if (this._subscriptions instanceof Set) |
| 79 yield* this._subscriptions; |
| 80 else |
| 81 yield this._subscriptions; |
| 82 } |
| 77 }, | 83 }, |
| 78 | 84 |
| 79 /** | 85 /** |
| 80 * The number of subscriptions to which the filter belongs. | 86 * The number of subscriptions to which the filter belongs. |
| 81 * @type {number} | 87 * @type {number} |
| 82 */ | 88 */ |
| 83 get subscriptionCount() | 89 get subscriptionCount() |
| 84 { | 90 { |
| 85 return this._subscriptions.size; | 91 if (this._subscriptions instanceof Set) |
| 92 return this._subscriptions.size; |
| 93 |
| 94 return this._subscriptions ? 1 : 0; |
| 86 }, | 95 }, |
| 87 | 96 |
| 88 /** | 97 /** |
| 89 * Adds a subscription to the set of subscriptions to which the filter | 98 * Adds a subscription to the set of subscriptions to which the filter |
| 90 * belongs. | 99 * belongs. |
| 91 * @param {Subscription} subscription | 100 * @param {Subscription} subscription |
| 92 */ | 101 */ |
| 93 addSubscription(subscription) | 102 addSubscription(subscription) |
| 94 { | 103 { |
| 95 this._subscriptions.add(subscription); | 104 if (this._subscriptions) |
| 105 { |
| 106 if (this._subscriptions instanceof Set) |
| 107 this._subscriptions.add(subscription); |
| 108 else if (subscription != this._subscriptions) |
| 109 this._subscriptions = new Set([this._subscriptions, subscription]); |
| 110 } |
| 111 else |
| 112 { |
| 113 this._subscriptions = subscription; |
| 114 } |
| 96 }, | 115 }, |
| 97 | 116 |
| 98 /** | 117 /** |
| 99 * Removes a subscription from the set of subscriptions to which the filter | 118 * Removes a subscription from the set of subscriptions to which the filter |
| 100 * belongs. | 119 * belongs. |
| 101 * @param {Subscription} subscription | 120 * @param {Subscription} subscription |
| 102 */ | 121 */ |
| 103 removeSubscription(subscription) | 122 removeSubscription(subscription) |
| 104 { | 123 { |
| 105 this._subscriptions.delete(subscription); | 124 if (this._subscriptions) |
| 125 { |
| 126 if (this._subscriptions instanceof Set) |
| 127 { |
| 128 this._subscriptions.delete(subscription); |
| 129 |
| 130 if (this._subscriptions.size == 1) |
| 131 this._subscriptions = [...this._subscriptions][0]; |
| 132 } |
| 133 else if (subscription == this._subscriptions) |
| 134 { |
| 135 this._subscriptions = null; |
| 136 } |
| 137 } |
| 106 }, | 138 }, |
| 107 | 139 |
| 108 /** | 140 /** |
| 109 * Serializes the filter to an array of strings for writing out on the disk. | 141 * Serializes the filter to an array of strings for writing out on the disk. |
| 110 * @param {string[]} buffer buffer to push the serialization results into | 142 * @param {string[]} buffer buffer to push the serialization results into |
| 111 */ | 143 */ |
| 112 serialize(buffer) | 144 serialize(buffer) |
| 113 { | 145 { |
| 114 buffer.push("[Filter]"); | 146 buffer.push("[Filter]"); |
| 115 buffer.push("text=" + this.text); | 147 buffer.push("text=" + this.text); |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 | 1247 |
| 1216 /** | 1248 /** |
| 1217 * Script that should be executed | 1249 * Script that should be executed |
| 1218 * @type {string} | 1250 * @type {string} |
| 1219 */ | 1251 */ |
| 1220 get script() | 1252 get script() |
| 1221 { | 1253 { |
| 1222 return this.body; | 1254 return this.body; |
| 1223 } | 1255 } |
| 1224 }); | 1256 }); |
| OLD | NEW |