Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterListener.js

Issue 29807560: Issue 6745 - Prefer strict equality operator (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 14, 2018, 4:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterClasses.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 /** 48 /**
49 * Increases "dirty factor" of the filters and calls 49 * Increases "dirty factor" of the filters and calls
50 * FilterStorage.saveToDisk() if it becomes 1 or more. Save is 50 * FilterStorage.saveToDisk() if it becomes 1 or more. Save is
51 * executed delayed to prevent multiple subsequent calls. If the 51 * executed delayed to prevent multiple subsequent calls. If the
52 * parameter is 0 it forces saving filters if any changes were 52 * parameter is 0 it forces saving filters if any changes were
53 * recorded after the previous save. 53 * recorded after the previous save.
54 * @param {number} factor 54 * @param {number} factor
55 */ 55 */
56 setDirty(factor) 56 setDirty(factor)
57 { 57 {
58 if (factor == 0 && isDirty > 0) 58 if (factor === 0 && isDirty > 0)
59 isDirty = 1; 59 isDirty = 1;
60 else 60 else
61 isDirty += factor; 61 isDirty += factor;
62 if (isDirty >= 1) 62 if (isDirty >= 1)
63 { 63 {
64 isDirty = 0; 64 isDirty = 0;
65 FilterStorage.saveToDisk(); 65 FilterStorage.saveToDisk();
66 } 66 }
67 } 67 }
68 }; 68 };
69 69
70 /** 70 /**
71 * Observer listening to history purge actions. 71 * Observer listening to history purge actions.
72 * @class 72 * @class
73 */ 73 */
74 let HistoryPurgeObserver = { 74 let HistoryPurgeObserver = {
75 observe(subject, topic, data) 75 observe(subject, topic, data)
76 { 76 {
77 if (topic == "browser:purge-session-history" && 77 if (topic === "browser:purge-session-history" &&
78 Prefs.clearStatsOnHistoryPurge) 78 Prefs.clearStatsOnHistoryPurge)
79 { 79 {
80 FilterStorage.resetHitCounts(); 80 FilterStorage.resetHitCounts();
81 FilterListener.setDirty(0); // Force saving to disk 81 FilterListener.setDirty(0); // Force saving to disk
82 82
83 Prefs.recentReports = []; 83 Prefs.recentReports = [];
84 } 84 }
85 }, 85 },
86 QueryInterface: XPCOMUtils.generateQI( 86 QueryInterface: XPCOMUtils.generateQI(
87 [Ci.nsISupportsWeakReference, Ci.nsIObserver] 87 [Ci.nsISupportsWeakReference, Ci.nsIObserver]
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // it. 208 // it.
209 let len = filters.length; 209 let len = filters.length;
210 if (!len) 210 if (!len)
211 return; 211 return;
212 212
213 let current = (Math.random() * len) | 0; 213 let current = (Math.random() * len) | 0;
214 let step; 214 let step;
215 do 215 do
216 { 216 {
217 step = primes[(Math.random() * primes.length) | 0]; 217 step = primes[(Math.random() * primes.length) | 0];
218 } while (len % step == 0); 218 } while (len % step === 0);
219 219
220 for (let i = 0; i < len; i++, current = (current + step) % len) 220 for (let i = 0; i < len; i++, current = (current + step) % len)
221 addFilter(filters[current]); 221 addFilter(filters[current]);
222 } 222 }
223 223
224 function onSubscriptionAdded(subscription) 224 function onSubscriptionAdded(subscription)
225 { 225 {
226 FilterListener.setDirty(1); 226 FilterListener.setDirty(1);
227 227
228 if (!subscription.disabled) 228 if (!subscription.disabled)
229 addFilters(subscription.filters); 229 addFilters(subscription.filters);
230 } 230 }
231 231
232 function onSubscriptionRemoved(subscription) 232 function onSubscriptionRemoved(subscription)
233 { 233 {
234 FilterListener.setDirty(1); 234 FilterListener.setDirty(1);
235 235
236 if (!subscription.disabled) 236 if (!subscription.disabled)
237 subscription.filters.forEach(removeFilter); 237 subscription.filters.forEach(removeFilter);
238 } 238 }
239 239
240 function onSubscriptionDisabled(subscription, newValue) 240 function onSubscriptionDisabled(subscription, newValue)
241 { 241 {
242 FilterListener.setDirty(1); 242 FilterListener.setDirty(1);
243 243
244 if (FilterStorage.knownSubscriptions.has(subscription.url)) 244 if (FilterStorage.knownSubscriptions.has(subscription.url))
245 { 245 {
246 if (newValue == false) 246 if (newValue === false)
247 addFilters(subscription.filters); 247 addFilters(subscription.filters);
248 else 248 else
249 subscription.filters.forEach(removeFilter); 249 subscription.filters.forEach(removeFilter);
250 } 250 }
251 } 251 }
252 252
253 function onSubscriptionUpdated(subscription) 253 function onSubscriptionUpdated(subscription)
254 { 254 {
255 FilterListener.setDirty(1); 255 FilterListener.setDirty(1);
256 256
257 if (!subscription.disabled && 257 if (!subscription.disabled &&
258 FilterStorage.knownSubscriptions.has(subscription.url)) 258 FilterStorage.knownSubscriptions.has(subscription.url))
259 { 259 {
260 subscription.oldFilters.forEach(removeFilter); 260 subscription.oldFilters.forEach(removeFilter);
261 addFilters(subscription.filters); 261 addFilters(subscription.filters);
262 } 262 }
263 } 263 }
264 264
265 function onFilterHitCount(filter, newValue) 265 function onFilterHitCount(filter, newValue)
266 { 266 {
267 if (newValue == 0) 267 if (newValue === 0)
268 FilterListener.setDirty(0); 268 FilterListener.setDirty(0);
269 else 269 else
270 FilterListener.setDirty(0.002); 270 FilterListener.setDirty(0.002);
271 } 271 }
272 272
273 function onFilterLastHit() 273 function onFilterLastHit()
274 { 274 {
275 FilterListener.setDirty(0.002); 275 FilterListener.setDirty(0.002);
276 } 276 }
277 277
(...skipping 10 matching lines...) Expand all
288 FilterListener.setDirty(1); 288 FilterListener.setDirty(1);
289 289
290 if (!filter.disabled) 290 if (!filter.disabled)
291 removeFilter(filter); 291 removeFilter(filter);
292 } 292 }
293 293
294 function onFilterDisabled(filter, newValue) 294 function onFilterDisabled(filter, newValue)
295 { 295 {
296 FilterListener.setDirty(1); 296 FilterListener.setDirty(1);
297 297
298 if (newValue == false) 298 if (newValue === false)
299 addFilter(filter); 299 addFilter(filter);
300 else 300 else
301 removeFilter(filter); 301 removeFilter(filter);
302 } 302 }
303 303
304 function onGenericChange() 304 function onGenericChange()
305 { 305 {
306 FilterListener.setDirty(1); 306 FilterListener.setDirty(1);
307 } 307 }
308 308
309 function onLoad() 309 function onLoad()
310 { 310 {
311 isDirty = 0; 311 isDirty = 0;
312 312
313 defaultMatcher.clear(); 313 defaultMatcher.clear();
314 ElemHide.clear(); 314 ElemHide.clear();
315 ElemHideEmulation.clear(); 315 ElemHideEmulation.clear();
316 for (let subscription of FilterStorage.subscriptions) 316 for (let subscription of FilterStorage.subscriptions)
317 { 317 {
318 if (!subscription.disabled) 318 if (!subscription.disabled)
319 addFilters(subscription.filters); 319 addFilters(subscription.filters);
320 } 320 }
321 } 321 }
322 322
323 function onSave() 323 function onSave()
324 { 324 {
325 isDirty = 0; 325 isDirty = 0;
326 } 326 }
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld