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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 * Filter type as a string, e.g. "blocking". | 75 * Filter type as a string, e.g. "blocking". |
76 * @type {string} | 76 * @type {string} |
77 */ | 77 */ |
78 get type() | 78 get type() |
79 { | 79 { |
80 throw new Error("Please define filter type in the subclass"); | 80 throw new Error("Please define filter type in the subclass"); |
81 }, | 81 }, |
82 | 82 |
83 /** | 83 /** |
84 * Subscriptions to which this filter belongs. | 84 * Subscriptions to which this filter belongs. |
85 * @type {(Subscription|Set.<Subscription>)?} | 85 * @type {?(Subscription|Set.<Subscription>)} |
86 * @private | 86 * @private |
87 */ | 87 */ |
88 _subscriptions: null, | 88 _subscriptions: null, |
89 | 89 |
90 /** | 90 /** |
91 * Whether the filter's subscriptions have already been added to the filter. | 91 * Whether the filter's subscriptions have already been added to the filter. |
92 * @type {boolean} | 92 * @type {boolean} |
93 * @package | 93 * @package |
94 */ | 94 */ |
95 get subscriptionsAdded() | 95 get subscriptionsAdded() |
96 { | 96 { |
97 return this.hasOwnProperty("_subscriptions"); | 97 return this.hasOwnProperty("_subscriptions"); |
98 }, | 98 }, |
99 set subscriptionsAdded(value) | 99 set subscriptionsAdded(value) |
100 { | 100 { |
101 this._subscriptions = this._subscriptions; | 101 // Once set to true, this cannot be set back to false even if all |
| 102 // subscriptions are removed. |
| 103 if (value) |
| 104 this._subscriptions = this._subscriptions; |
102 }, | 105 }, |
103 | 106 |
104 /** | 107 /** |
105 * Yields subscriptions to which the filter belongs. | 108 * Yields subscriptions to which the filter belongs. |
106 * @yields {Subscription} | 109 * @yields {Subscription} |
| 110 * @package |
107 */ | 111 */ |
108 *subscriptions() | 112 *subscriptions() |
109 { | 113 { |
110 if (this._subscriptions) | 114 if (this._subscriptions) |
111 { | 115 { |
112 if (this._subscriptions instanceof Set) | 116 if (this._subscriptions instanceof Set) |
113 yield* this._subscriptions; | 117 yield* this._subscriptions; |
114 else | 118 else |
115 yield this._subscriptions; | 119 yield this._subscriptions; |
116 } | 120 } |
117 }, | 121 }, |
118 | 122 |
119 /** | 123 /** |
120 * The number of subscriptions to which the filter belongs. | 124 * The number of subscriptions to which the filter belongs. |
121 * @type {number} | 125 * @type {number} |
| 126 * @package |
122 */ | 127 */ |
123 get subscriptionCount() | 128 get subscriptionCount() |
124 { | 129 { |
125 if (this._subscriptions instanceof Set) | 130 if (this._subscriptions instanceof Set) |
126 return this._subscriptions.size; | 131 return this._subscriptions.size; |
127 | 132 |
128 return this._subscriptions ? 1 : 0; | 133 return this._subscriptions ? 1 : 0; |
129 }, | 134 }, |
130 | 135 |
131 /** | 136 /** |
132 * Adds a subscription to the set of subscriptions to which the filter | 137 * Adds a subscription to the set of subscriptions to which the filter |
133 * belongs. | 138 * belongs. |
134 * @param {Subscription} subscription | 139 * @param {Subscription} subscription |
| 140 * @package |
135 */ | 141 */ |
136 addSubscription(subscription) | 142 addSubscription(subscription) |
137 { | 143 { |
138 // Since we use truthy checks in our logic, we must avoid adding a | 144 // Since we use truthy checks in our logic, we must avoid adding a |
139 // subscription that isn't a non-null object. | 145 // subscription that isn't a non-null object. |
140 if (subscription === null || typeof subscription != "object") | 146 if (subscription === null || typeof subscription != "object") |
141 return; | 147 return; |
142 | 148 |
143 if (this._subscriptions) | 149 if (this._subscriptions) |
144 { | 150 { |
145 if (this._subscriptions instanceof Set) | 151 if (this._subscriptions instanceof Set) |
146 this._subscriptions.add(subscription); | 152 this._subscriptions.add(subscription); |
147 else if (subscription != this._subscriptions) | 153 else if (subscription != this._subscriptions) |
148 this._subscriptions = new Set([this._subscriptions, subscription]); | 154 this._subscriptions = new Set([this._subscriptions, subscription]); |
149 } | 155 } |
150 else | 156 else |
151 { | 157 { |
152 this._subscriptions = subscription; | 158 this._subscriptions = subscription; |
153 } | 159 } |
154 }, | 160 }, |
155 | 161 |
156 /** | 162 /** |
157 * Removes a subscription from the set of subscriptions to which the filter | 163 * Removes a subscription from the set of subscriptions to which the filter |
158 * belongs. | 164 * belongs. |
159 * @param {Subscription} subscription | 165 * @param {Subscription} subscription |
| 166 * @package |
160 */ | 167 */ |
161 removeSubscription(subscription) | 168 removeSubscription(subscription) |
162 { | 169 { |
163 if (this._subscriptions) | 170 if (this._subscriptions) |
164 { | 171 { |
165 if (this._subscriptions instanceof Set) | 172 if (this._subscriptions instanceof Set) |
166 { | 173 { |
167 this._subscriptions.delete(subscription); | 174 this._subscriptions.delete(subscription); |
168 | 175 |
169 if (this._subscriptions.size == 1) | 176 if (this._subscriptions.size == 1) |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 | 1374 |
1368 /** | 1375 /** |
1369 * Script that should be executed | 1376 * Script that should be executed |
1370 * @type {string} | 1377 * @type {string} |
1371 */ | 1378 */ |
1372 get script() | 1379 get script() |
1373 { | 1380 { |
1374 return this.body; | 1381 return this.body; |
1375 } | 1382 } |
1376 }); | 1383 }); |
LEFT | RIGHT |