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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 /** | 54 /** |
55 * Abstract base class for filters | 55 * Abstract base class for filters |
56 * | 56 * |
57 * @param {string} text string representation of the filter | 57 * @param {string} text string representation of the filter |
58 * @constructor | 58 * @constructor |
59 */ | 59 */ |
60 function Filter(text) | 60 function Filter(text) |
61 { | 61 { |
62 this.text = text; | 62 this.text = text; |
63 | |
64 /** | |
65 * Subscriptions to which this filter belongs. | |
66 * @type {(Subscription|Set.<Subscription>)?} | |
67 * @private | |
68 */ | |
69 this._subscriptions = null; | |
70 } | 63 } |
71 exports.Filter = Filter; | 64 exports.Filter = Filter; |
72 | 65 |
73 Filter.prototype = | 66 Filter.prototype = |
74 { | 67 { |
75 /** | 68 /** |
76 * String representation of the filter | 69 * String representation of the filter |
77 * @type {string} | 70 * @type {string} |
78 */ | 71 */ |
79 text: null, | 72 text: null, |
80 | 73 |
81 /** | 74 /** |
82 * Filter type as a string, e.g. "blocking". | 75 * Filter type as a string, e.g. "blocking". |
83 * @type {string} | 76 * @type {string} |
84 */ | 77 */ |
85 get type() | 78 get type() |
86 { | 79 { |
87 throw new Error("Please define filter type in the subclass"); | 80 throw new Error("Please define filter type in the subclass"); |
88 }, | 81 }, |
89 | 82 |
90 /** | 83 /** |
| 84 * Subscriptions to which this filter belongs. |
| 85 * @type {?(Subscription|Set.<Subscription>)} |
| 86 * @private |
| 87 */ |
| 88 _subscriptions: null, |
| 89 |
| 90 /** |
| 91 * Whether the filter's subscriptions have already been added to the filter. |
| 92 * @type {boolean} |
| 93 * @package |
| 94 */ |
| 95 get subscriptionsAdded() |
| 96 { |
| 97 return this.hasOwnProperty("_subscriptions"); |
| 98 }, |
| 99 set subscriptionsAdded(value) |
| 100 { |
| 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; |
| 105 }, |
| 106 |
| 107 /** |
91 * Yields subscriptions to which the filter belongs. | 108 * Yields subscriptions to which the filter belongs. |
92 * @yields {Subscription} | 109 * @yields {Subscription} |
| 110 * @package |
93 */ | 111 */ |
94 *subscriptions() | 112 *subscriptions() |
95 { | 113 { |
96 if (this._subscriptions) | 114 if (this._subscriptions) |
97 { | 115 { |
98 if (this._subscriptions instanceof Set) | 116 if (this._subscriptions instanceof Set) |
99 yield* this._subscriptions; | 117 yield* this._subscriptions; |
100 else | 118 else |
101 yield this._subscriptions; | 119 yield this._subscriptions; |
102 } | 120 } |
103 }, | 121 }, |
104 | 122 |
105 /** | 123 /** |
106 * The number of subscriptions to which the filter belongs. | 124 * The number of subscriptions to which the filter belongs. |
107 * @type {number} | 125 * @type {number} |
| 126 * @package |
108 */ | 127 */ |
109 get subscriptionCount() | 128 get subscriptionCount() |
110 { | 129 { |
111 if (this._subscriptions instanceof Set) | 130 if (this._subscriptions instanceof Set) |
112 return this._subscriptions.size; | 131 return this._subscriptions.size; |
113 | 132 |
114 return this._subscriptions ? 1 : 0; | 133 return this._subscriptions ? 1 : 0; |
115 }, | 134 }, |
116 | 135 |
117 /** | 136 /** |
118 * 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 |
119 * belongs. | 138 * belongs. |
120 * @param {Subscription} subscription | 139 * @param {Subscription} subscription |
| 140 * @package |
121 */ | 141 */ |
122 addSubscription(subscription) | 142 addSubscription(subscription) |
123 { | 143 { |
124 // 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 |
125 // subscription that isn't a non-null object. | 145 // subscription that isn't a non-null object. |
126 if (subscription === null || typeof subscription != "object") | 146 if (subscription === null || typeof subscription != "object") |
127 return; | 147 return; |
128 | 148 |
129 if (this._subscriptions) | 149 if (this._subscriptions) |
130 { | 150 { |
131 if (this._subscriptions instanceof Set) | 151 if (this._subscriptions instanceof Set) |
132 this._subscriptions.add(subscription); | 152 this._subscriptions.add(subscription); |
133 else if (subscription != this._subscriptions) | 153 else if (subscription != this._subscriptions) |
134 this._subscriptions = new Set([this._subscriptions, subscription]); | 154 this._subscriptions = new Set([this._subscriptions, subscription]); |
135 } | 155 } |
136 else | 156 else |
137 { | 157 { |
138 this._subscriptions = subscription; | 158 this._subscriptions = subscription; |
139 } | 159 } |
140 }, | 160 }, |
141 | 161 |
142 /** | 162 /** |
143 * 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 |
144 * belongs. | 164 * belongs. |
145 * @param {Subscription} subscription | 165 * @param {Subscription} subscription |
| 166 * @package |
146 */ | 167 */ |
147 removeSubscription(subscription) | 168 removeSubscription(subscription) |
148 { | 169 { |
149 if (this._subscriptions) | 170 if (this._subscriptions) |
150 { | 171 { |
151 if (this._subscriptions instanceof Set) | 172 if (this._subscriptions instanceof Set) |
152 { | 173 { |
153 this._subscriptions.delete(subscription); | 174 this._subscriptions.delete(subscription); |
154 | 175 |
155 if (this._subscriptions.size == 1) | 176 if (this._subscriptions.size == 1) |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 | 1374 |
1354 /** | 1375 /** |
1355 * Script that should be executed | 1376 * Script that should be executed |
1356 * @type {string} | 1377 * @type {string} |
1357 */ | 1378 */ |
1358 get script() | 1379 get script() |
1359 { | 1380 { |
1360 return this.body; | 1381 return this.body; |
1361 } | 1382 } |
1362 }); | 1383 }); |
OLD | NEW |