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

Unified Diff: lib/elemHide.js

Issue 29778572: Noissue - Make private functions inaccessible via ElemHide object (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fix JSDoc comment error Created May 11, 2018, 12:25 p.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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -61,16 +61,48 @@
/**
* Lookup table, lists of element hiding exceptions by selector
* @type {Map.<string,Filter>}
*/
let exceptions = new Map();
/**
+ * Adds a filter to the lookup table of filters by domain.
+ * @param {Filter} filter
+ */
+function addToFiltersByDomain(filter)
+{
+ let domains = filter.domains || defaultDomains;
+ for (let [domain, isIncluded] of domains)
+ {
+ // There's no need to note that a filter is generically disabled.
+ if (!isIncluded && domain == "")
+ continue;
+
+ let filters = filtersByDomain.get(domain);
+ if (!filters)
+ filtersByDomain.set(domain, filters = new Map());
+ filters.set(filter, isIncluded);
+ }
+}
+
+/**
+ * Returns a list of selectors that apply on each website unconditionally.
+ * @returns {string[]}
+ */
+function getUnconditionalSelectors()
+{
+ if (!unconditionalSelectors)
+ unconditionalSelectors = [...filterBySelector.keys()];
+
+ return unconditionalSelectors.slice();
+}
+
+/**
* Container for element hiding filters
* @class
*/
let ElemHide = exports.ElemHide = {
/**
* Removes all known filters
*/
clear()
@@ -79,32 +111,16 @@
knownFilters, exceptions])
{
collection.clear();
}
unconditionalSelectors = null;
FilterNotifier.emit("elemhideupdate");
},
- _addToFiltersByDomain(filter)
- {
- let domains = filter.domains || defaultDomains;
- for (let [domain, isIncluded] of domains)
- {
- // There's no need to note that a filter is generically disabled.
- if (!isIncluded && domain == "")
- continue;
-
- let filters = filtersByDomain.get(domain);
- if (!filters)
- filtersByDomain.set(domain, filters = new Map());
- filters.set(filter, isIncluded);
- }
- },
-
/**
* Add a new element hiding filter
* @param {ElemHideBase} filter
*/
add(filter)
{
if (knownFilters.has(filter))
return;
@@ -119,31 +135,31 @@
exceptions.set(selector, [filter]);
// If this is the first exception for a previously unconditionally
// applied element hiding selector we need to take care to update the
// lookups.
let unconditionalFilterForSelector = filterBySelector.get(selector);
if (unconditionalFilterForSelector)
{
- this._addToFiltersByDomain(unconditionalFilterForSelector);
+ addToFiltersByDomain(unconditionalFilterForSelector);
filterBySelector.delete(selector);
unconditionalSelectors = null;
}
}
else if (!(filter.domains || exceptions.has(filter.selector)))
{
// The new filter's selector is unconditionally applied to all domains
filterBySelector.set(filter.selector, filter);
unconditionalSelectors = null;
}
else
{
// The new filter's selector only applies to some domains
- this._addToFiltersByDomain(filter);
+ addToFiltersByDomain(filter);
}
knownFilters.add(filter);
FilterNotifier.emit("elemhideupdate");
},
/**
* Removes an element hiding filter
@@ -202,27 +218,16 @@
if (list[i].isActiveOnDomain(docDomain))
return list[i];
}
return null;
},
/**
- * Returns a list of selectors that apply on each website unconditionally.
- * @returns {string[]}
- */
- getUnconditionalSelectors()
- {
- if (!unconditionalSelectors)
- unconditionalSelectors = [...filterBySelector.keys()];
- return unconditionalSelectors.slice();
- },
-
- /**
* Constant used by getSelectorsForDomain to return all selectors applying to
* a particular hostname.
* @type {number}
* @const
*/
ALL_MATCHING: 0,
/**
@@ -251,17 +256,17 @@
* @returns {string[]}
* List of selectors.
*/
getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING)
{
let selectors = [];
if (criteria < ElemHide.NO_UNCONDITIONAL)
- selectors = this.getUnconditionalSelectors();
+ selectors = getUnconditionalSelectors();
let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
let excluded = new Set();
let currentDomain = domain ? domain.toUpperCase() : "";
// This code is a performance hot-spot, which is why we've made certain
// micro-optimisations. Please be careful before making changes.
while (true)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld