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

Unified Diff: lib/filterListener.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Patch Set: Created Feb. 20, 2017, 10:02 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/filterListener.js
diff --git a/lib/filterListener.js b/lib/filterListener.js
index d56e82545b8fa0562ffa1681a5273c51e737837d..2d0f44d5429afc6d32fef5957e2a8d812ba7cb70 100644
--- a/lib/filterListener.js
+++ b/lib/filterListener.js
@@ -15,12 +15,15 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-/**
- * @fileOverview Component synchronizing filter storage with Matcher instances and ElemHide.
- */
+/* globals Services, XPCOMUtils */
Sebastian Noack 2017/02/20 13:14:51 Aren't these universally available? If so, please
kzar 2017/02/21 06:13:59 Done.
"use strict";
+/**
+ * @fileOverview Component synchronizing filter storage with Matcher
+ * instances and ElemHide.
+ */
+
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@@ -35,7 +38,7 @@ let {Prefs} = require("prefs");
/**
* Increases on filter changes, filters will be saved if it exceeds 1.
- * @type Integer
+ * @type {Integer}
*/
let isDirty = 0;
@@ -43,15 +46,16 @@ let isDirty = 0;
* This object can be used to change properties of the filter change listeners.
* @class
*/
-let FilterListener =
-{
+let FilterListener = {
/**
- * Increases "dirty factor" of the filters and calls FilterStorage.saveToDisk()
- * if it becomes 1 or more. Save is executed delayed to prevent multiple
- * subsequent calls. If the parameter is 0 it forces saving filters if any
- * changes were recorded after the previous save.
+ * Increases "dirty factor" of the filters and calls
+ * FilterStorage.saveToDisk() if it becomes 1 or more. Save is
+ * executed delayed to prevent multiple subsequent calls. If the
+ * parameter is 0 it forces saving filters if any changes were
+ * recorded after the previous save.
+ * @param {Integer} factor
*/
- setDirty: function(/**Integer*/ factor)
+ setDirty(factor)
{
if (factor == 0 && isDirty > 0)
isDirty = 1;
@@ -69,11 +73,11 @@ let FilterListener =
* Observer listening to history purge actions.
* @class
*/
-let HistoryPurgeObserver =
-{
- observe: function(subject, topic, data)
+let HistoryPurgeObserver = {
+ observe(subject, topic, data)
{
- if (topic == "browser:purge-session-history" && Prefs.clearStatsOnHistoryPurge)
+ if (topic == "browser:purge-session-history" &&
+ Prefs.clearStatsOnHistoryPurge)
{
FilterStorage.resetHitCounts();
FilterListener.setDirty(0); // Force saving to disk
@@ -81,7 +85,9 @@ let HistoryPurgeObserver =
Prefs.recentReports = [];
}
},
- QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
+ QueryInterface: XPCOMUtils.generateQI(
+ [Ci.nsISupportsWeakReference, Ci.nsIObserver]
+ )
};
/**
@@ -113,10 +119,12 @@ function init()
FilterStorage.loadFromDisk();
- Services.obs.addObserver(HistoryPurgeObserver, "browser:purge-session-history", true);
- onShutdown.add(function()
+ Services.obs.addObserver(HistoryPurgeObserver,
+ "browser:purge-session-history", true);
+ onShutdown.add(() =>
{
- Services.obs.removeObserver(HistoryPurgeObserver, "browser:purge-session-history");
+ Services.obs.removeObserver(HistoryPurgeObserver,
+ "browser:purge-session-history");
});
}
init();
@@ -133,8 +141,10 @@ function addFilter(filter)
let hasEnabled = false;
for (let i = 0; i < filter.subscriptions.length; i++)
+ {
if (!filter.subscriptions[i].disabled)
hasEnabled = true;
+ }
if (!hasEnabled)
return;
@@ -163,8 +173,10 @@ function removeFilter(filter)
{
let hasEnabled = false;
for (let i = 0; i < filter.subscriptions.length; i++)
+ {
if (!filter.subscriptions[i].disabled)
hasEnabled = true;
+ }
if (hasEnabled)
return;
}
@@ -197,9 +209,8 @@ function addFilters(filters)
let current = (Math.random() * len) | 0;
let step;
do
- {
step = primes[(Math.random() * primes.length) | 0];
- } while (len % step == 0);
+ while (len % step == 0);
for (let i = 0; i < len; i++, current = (current + step) % len)
addFilter(filters[current]);
@@ -298,8 +309,10 @@ function onLoad()
ElemHide.clear();
ElemHideEmulation.clear();
for (let subscription of FilterStorage.subscriptions)
+ {
if (!subscription.disabled)
addFilters(subscription.filters);
+ }
}
function onSave()

Powered by Google App Engine
This is Rietveld