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 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 this._subscriptions = new Set(); | 44 this._subscriptions = null; |
45 } | 45 } |
46 exports.Filter = Filter; | 46 exports.Filter = Filter; |
47 | 47 |
48 Filter.prototype = | 48 Filter.prototype = |
49 { | 49 { |
50 /** | 50 /** |
51 * String representation of the filter | 51 * String representation of the filter |
52 * @type {string} | 52 * @type {string} |
53 */ | 53 */ |
54 text: null, | 54 text: null, |
55 | 55 |
56 /** | 56 /** |
57 * Filter type as a string, e.g. "blocking". | 57 * Filter type as a string, e.g. "blocking". |
58 * @type {string} | 58 * @type {string} |
59 */ | 59 */ |
60 get type() | 60 get type() |
61 { | 61 { |
62 throw new Error("Please define filter type in the subclass"); | 62 throw new Error("Please define filter type in the subclass"); |
63 }, | 63 }, |
64 | 64 |
65 /** | 65 /** |
66 * Yields filter subscriptions the filter belongs to | 66 * Yields filter subscriptions the filter belongs to |
67 * @yields {Subscription} | 67 * @yields {Subscription} |
68 */ | 68 */ |
69 *subscriptions() | 69 *subscriptions() |
70 { | 70 { |
71 yield* this._subscriptions; | 71 if (this._subscriptions) |
| 72 { |
| 73 if (this._subscriptions instanceof Set) |
| 74 yield* this._subscriptions; |
| 75 else |
| 76 yield this._subscriptions; |
| 77 } |
72 }, | 78 }, |
73 | 79 |
74 addSubscription(subscription) | 80 addSubscription(subscription) |
75 { | 81 { |
76 this._subscriptions.add(subscription); | 82 if (this._subscriptions) |
| 83 { |
| 84 if (this._subscriptions instanceof Set) |
| 85 this._subscriptions.add(subscription); |
| 86 else if (subscription != this._subscriptions) |
| 87 this._subscriptions = new Set([this._subscriptions, subscription]); |
| 88 } |
| 89 else |
| 90 { |
| 91 this._subscriptions = subscription; |
| 92 } |
77 }, | 93 }, |
78 | 94 |
79 removeSubscription(subscription) | 95 removeSubscription(subscription) |
80 { | 96 { |
81 this._subscriptions.delete(subscription); | 97 if (this._subscriptions) |
| 98 { |
| 99 if (this._subscriptions instanceof Set) |
| 100 { |
| 101 this._subscriptions.delete(subscription); |
| 102 |
| 103 if (this._subscriptions.size == 1) |
| 104 this._subscriptions = [...this._subscriptions][0]; |
| 105 } |
| 106 else if (subscription == this._subscriptions) |
| 107 { |
| 108 this._subscriptions = null; |
| 109 } |
| 110 } |
82 }, | 111 }, |
83 | 112 |
84 /** | 113 /** |
85 * Serializes the filter to an array of strings for writing out on the disk. | 114 * Serializes the filter to an array of strings for writing out on the disk. |
86 * @param {string[]} buffer buffer to push the serialization results into | 115 * @param {string[]} buffer buffer to push the serialization results into |
87 */ | 116 */ |
88 serialize(buffer) | 117 serialize(buffer) |
89 { | 118 { |
90 buffer.push("[Filter]"); | 119 buffer.push("[Filter]"); |
91 buffer.push("text=" + this.text); | 120 buffer.push("text=" + this.text); |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 | 1220 |
1192 /** | 1221 /** |
1193 * Script that should be executed | 1222 * Script that should be executed |
1194 * @type {string} | 1223 * @type {string} |
1195 */ | 1224 */ |
1196 get script() | 1225 get script() |
1197 { | 1226 { |
1198 return this.body; | 1227 return this.body; |
1199 } | 1228 } |
1200 }); | 1229 }); |
OLD | NEW |