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

Unified Diff: lib/elemHide.js

Issue 29356018: Issue 4450 - Prevent ElemHide filters with empty domains (Closed)
Patch Set: Addressed feedback Created Oct. 6, 2016, 8:50 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
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
diff --git a/lib/elemHide.js b/lib/elemHide.js
index b9d34e3064d0f7a76252505a8a670d3ed55f8d92..948f62aaa1c8b0af54dd57ef4b31008a03aff729 100644
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -43,23 +43,22 @@ var keyByFilter = Object.create(null);
var filtersByDomain = Object.create(null);
/**
- * Lookup table, filter keys by selector. (Only contains filters that have a
- * selector that is unconditionally matched for all domains.)
+ * Lookup table, filter key by selector. (Only used for selectors that are
+ * unconditionally matched for all domains.)
*/
-var filterKeysBySelector = Object.create(null);
+var filterKeyBySelector = Object.create(null);
/**
- * This array caches the keys of filterKeysBySelector table (selectors which
+ * This array caches the keys of filterKeyBySelector table (selectors which
* unconditionally apply on all domains). It will be null if the cache needs to
* be rebuilt.
*/
var unconditionalSelectors = null;
/**
- * This array caches the values of filterKeysBySelector table (filterIds for
+ * This array caches the values of filterKeyBySelector table (filterIds for
* selectors which unconditionally apply on all domains). It will be null if the
- * cache needs to be rebuilt. Note: Only the first filter key for each selector
- * is cached.
+ * cache needs to be rebuilt.
*/
var unconditionalFilterKeys = null;
@@ -95,7 +94,7 @@ var ElemHide = exports.ElemHide =
filterByKey = [];
keyByFilter = Object.create(null);
filtersByDomain = Object.create(null);
- filterKeysBySelector = Object.create(null);
+ filterKeyBySelector = Object.create(null);
unconditionalSelectors = unconditionalFilterKeys = null;
knownExceptions = Object.create(null);
exceptions = Object.create(null);
@@ -137,12 +136,11 @@ var ElemHide = exports.ElemHide =
// If this is the first exception for a previously unconditionally
// applied element hiding selector we need to take care to update the
// lookups.
- let filterKeys = filterKeysBySelector[selector];
- if (filterKeys)
+ let filterKey = filterKeyBySelector[selector];
+ if (filterKey)
{
- for (let filterKey of filterKeys)
- this._addToFiltersByDomain(filterKey, filterByKey[filterKey]);
- delete filterKeysBySelector[selector];
+ this._addToFiltersByDomain(filterKey, filterByKey[filterKey]);
+ delete filterKeyBySelector[selector];
unconditionalSelectors = unconditionalFilterKeys = null;
}
@@ -159,16 +157,8 @@ var ElemHide = exports.ElemHide =
if (!(filter.domains || filter.selector in exceptions))
{
// The new filter's selector is unconditionally applied to all domains
- let filterKeys = filterKeysBySelector[filter.selector];
- if (filterKeys)
- {
- filterKeys.push(key);
- }
- else
- {
- filterKeysBySelector[filter.selector] = [key];
- unconditionalSelectors = unconditionalFilterKeys = null;
- }
+ filterKeyBySelector[filter.selector] = key;
+ unconditionalSelectors = unconditionalFilterKeys = null;
}
else
{
@@ -182,25 +172,11 @@ var ElemHide = exports.ElemHide =
_removeFilterKey: function(key, filter)
{
- let filterKeys = filterKeysBySelector[filter.selector];
- if (filterKeys)
+ if (filterKeyBySelector[filter.selector] == key)
{
- let index = filterKeys.indexOf(key);
- if (index >= 0)
- {
- if (filterKeys.length > 1)
- {
- filterKeys.splice(index, 1);
- if (index == 0)
- unconditionalFilterKeys = null;
- }
- else
- {
- delete filterKeysBySelector[filter.selector];
- unconditionalSelectors = unconditionalFilterKeys = null;
- }
- return;
- }
+ delete filterKeyBySelector[filter.selector];
+ unconditionalSelectors = unconditionalFilterKeys = null;
+ return;
}
// We haven't found this filter in unconditional filters, look in
@@ -304,7 +280,7 @@ var ElemHide = exports.ElemHide =
getUnconditionalSelectors: function()
{
if (!unconditionalSelectors)
- unconditionalSelectors = Object.keys(filterKeysBySelector);
+ unconditionalSelectors = Object.keys(filterKeyBySelector);
return unconditionalSelectors.slice();
},
@@ -320,7 +296,7 @@ var ElemHide = exports.ElemHide =
let selectors = this.getUnconditionalSelectors();
unconditionalFilterKeys = [];
for (let selector of selectors)
- unconditionalFilterKeys.push(filterKeysBySelector[selector][0]);
+ unconditionalFilterKeys.push(filterKeyBySelector[selector]);
}
return unconditionalFilterKeys.slice();
},
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld