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

Unified Diff: lib/content/elemHideEmulation.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.
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 | « lib/common.js ('k') | lib/downloader.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/content/elemHideEmulation.js
===================================================================
--- a/lib/content/elemHideEmulation.js
+++ b/lib/content/elemHideEmulation.js
@@ -22,33 +22,33 @@
let MIN_INVOCATION_INTERVAL = 3000;
const MAX_SYNCHRONOUS_PROCESSING_TIME = 50;
const abpSelectorRegexp = /:-abp-([\w-]+)\(/i;
function getCachedPropertyValue(object, name, defaultValueFunc = () => {})
{
let value = object[name];
- if (typeof value == "undefined")
+ if (typeof value === "undefined")
Object.defineProperty(object, name, {value: value = defaultValueFunc()});
return value;
}
/** Return position of node from parent.
* @param {Node} node the node to find the position of.
* @return {number} One-based index like for :nth-child(), or 0 on error.
*/
function positionInParent(node)
{
return indexOf(node.parentNode.children, node) + 1;
}
function makeSelector(node, selector = "")
{
- if (node == null)
+ if (!node)
return null;
if (!node.parentElement)
{
let newSelector = ":root";
if (selector)
newSelector += " > " + selector;
return newSelector;
}
@@ -67,34 +67,34 @@
function parseSelectorContent(content, startIndex)
{
let parens = 1;
let quote = null;
let i = startIndex;
for (; i < content.length; i++)
{
let c = content[i];
- if (c == "\\")
+ if (c === "\\")
{
// Ignore escaped characters
i++;
}
else if (quote)
{
- if (c == quote)
+ if (c === quote)
quote = null;
}
- else if (c == "'" || c == '"')
+ else if (c === "'" || c === '"')
quote = c;
- else if (c == "(")
+ else if (c === "(")
parens++;
- else if (c == ")")
+ else if (c === ")")
{
parens--;
- if (parens == 0)
+ if (parens === 0)
break;
}
}
if (parens > 0)
return null;
return {text: content.substring(startIndex, i), end: i};
}
@@ -150,25 +150,25 @@
* Query selector. If it is relative, will try :scope.
* @param {Node} subtree the element to query selector
* @param {string} selector the selector to query
* @param {bool} [all=false] true to perform querySelectorAll()
* @returns {?(Node|NodeList)} result of the query. null in case of error.
*/
function scopedQuerySelector(subtree, selector, all)
{
- if (selector[0] == ">")
+ if (selector[0] === ">")
{
selector = ":scope" + selector;
if (scopeSupported)
{
return all ? subtree.querySelectorAll(selector) :
subtree.querySelector(selector);
}
- if (scopeSupported == null)
+ if (scopeSupported === null)
return tryQuerySelector(subtree, selector, all);
return null;
}
return all ? subtree.querySelectorAll(selector) :
subtree.querySelector(selector);
}
function scopedQuerySelectorAll(subtree, selector)
@@ -350,18 +350,18 @@
}
}
}
};
function PropsSelector(propertyExpression)
{
let regexpString;
- if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
- propertyExpression[propertyExpression.length - 1] == "/")
+ if (propertyExpression.length >= 2 && propertyExpression[0] === "/" &&
+ propertyExpression[propertyExpression.length - 1] === "/")
{
regexpString = propertyExpression.slice(1, -1)
.replace("\\7B ", "{").replace("\\7D ", "}");
}
else
regexpString = filterToRegExp(propertyExpression);
this._regexp = new RegExp(regexpString, "i");
@@ -377,17 +377,17 @@
for (let subSelector of style.subSelectors)
{
if (subSelector.startsWith("*") &&
!incompletePrefixRegexp.test(prefix))
{
subSelector = subSelector.substr(1);
}
let idx = subSelector.lastIndexOf("::");
- if (idx != -1)
+ if (idx !== -1)
subSelector = subSelector.substr(0, idx);
yield prefix + subSelector;
}
},
*getSelectors(prefix, subtree, styles)
{
for (let selector of this.findPropsSelectors(styles, prefix, this._regexp))
@@ -482,17 +482,17 @@
let types = new Set();
for (let mutation of mutations)
{
types.add(mutation.type);
// There are only 3 types of mutations: "attributes", "characterData", and
// "childList".
- if (types.size == 3)
+ if (types.size === 3)
break;
}
return types;
}
function filterPatterns(patterns, {stylesheets, mutations})
{
@@ -527,33 +527,33 @@
this.useInlineStyles = true;
}
ElemHideEmulation.prototype = {
isSameOrigin(stylesheet)
{
try
{
- return new URL(stylesheet.href).origin == this.document.location.origin;
+ return new URL(stylesheet.href).origin === this.document.location.origin;
}
catch (e)
{
// Invalid URL, assume that it is first-party.
return true;
}
},
/** Parse the selector
* @param {string} selector the selector to parse
* @return {Array} selectors is an array of objects,
* or null in case of errors.
*/
parseSelector(selector)
{
- if (selector.length == 0)
+ if (selector.length === 0)
return [];
let match = abpSelectorRegexp.exec(selector);
if (!match)
return [new PlainSelector(selector)];
let selectors = [];
if (match.index > 0)
@@ -563,43 +563,43 @@
let content = parseSelectorContent(selector, startIndex);
if (!content)
{
console.error(new SyntaxError("Failed to parse Adblock Plus " +
`selector ${selector} ` +
"due to unmatched parentheses."));
return null;
}
- if (match[1] == "properties")
+ if (match[1] === "properties")
selectors.push(new PropsSelector(content.text));
- else if (match[1] == "has")
+ else if (match[1] === "has")
{
let hasSelectors = this.parseSelector(content.text);
- if (hasSelectors == null)
+ if (hasSelectors === null)
return null;
selectors.push(new HasSelector(hasSelectors));
}
- else if (match[1] == "contains")
+ else if (match[1] === "contains")
selectors.push(new ContainsSelector(content.text));
else
{
// this is an error, can't parse selector.
console.error(new SyntaxError("Failed to parse Adblock Plus " +
`selector ${selector}, invalid ` +
`pseudo-class :-abp-${match[1]}().`));
return null;
}
let suffix = this.parseSelector(selector.substr(content.end + 1));
- if (suffix == null)
+ if (suffix === null)
return null;
selectors.push(...suffix);
- if (selectors.length == 1 && selectors[0] instanceof ContainsSelector)
+ if (selectors.length === 1 && selectors[0] instanceof ContainsSelector)
{
console.error(new SyntaxError("Failed to parse Adblock Plus " +
`selector ${selector}, can't ` +
"have a lonely :-abp-contains()."));
return null;
}
return selectors;
},
@@ -666,17 +666,17 @@
continue;
}
if (!rules)
continue;
for (let rule of rules)
{
- if (rule.type != rule.STYLE_RULE)
+ if (rule.type !== rule.STYLE_RULE)
continue;
cssStyles.push(stringifyStyle(rule));
}
}
let pattern = null;
let generator = null;
@@ -688,29 +688,29 @@
if (!pattern)
{
if (!patterns.length)
{
if (selectors.length > 0)
this.addSelectorsFunc(selectors, selectorFilters);
if (elements.length > 0)
this.hideElemsFunc(elements, elementFilters);
- if (typeof done == "function")
+ if (typeof done === "function")
done();
return;
}
pattern = patterns.shift();
generator = evaluate(pattern.selectors, 0, "",
this.document, cssStyles);
}
for (let selector of generator)
{
- if (selector != null)
+ if (selector !== null)
{
if (!this.useInlineStyles)
{
selectors.push(selector);
selectorFilters.push(pattern.text);
}
else
{
@@ -807,17 +807,17 @@
{
let params = Object.assign({}, this._scheduledProcessing);
this._filteringInProgress = true;
this._scheduledProcessing = null;
this._addSelectors(params.stylesheets, params.mutations, completion);
},
MIN_INVOCATION_INTERVAL - (performance.now() - this._lastInvocation));
}
- else if (this.document.readyState == "loading")
+ else if (this.document.readyState === "loading")
{
this._scheduledProcessing = {stylesheets, mutations};
let handler = () =>
{
this.document.removeEventListener("DOMContentLoaded", handler);
let params = Object.assign({}, this._scheduledProcessing);
this._filteringInProgress = true;
this._scheduledProcessing = null;
@@ -845,17 +845,17 @@
},
apply(patterns)
{
this.patterns = [];
for (let pattern of patterns)
{
let selectors = this.parseSelector(pattern.selector);
- if (selectors != null && selectors.length > 0)
+ if (selectors !== null && selectors.length > 0)
this.patterns.push(new Pattern(selectors, pattern.text));
}
if (this.patterns.length > 0)
{
this.queueFiltering();
this.observer.observe(
this.document,
« no previous file with comments | « lib/common.js ('k') | lib/downloader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld