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

Unified Diff: lib/filterClasses.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/events.js ('k') | lib/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -131,17 +131,17 @@
return Filter.fromText(`${match[1]}#?#` +
`${prefix}:-abp-properties(${expression})${suffix}`);
}
filter = ElemHideBase.fromText(
text, match[1], match[2], match[3]
);
}
- else if (text[0] == "!")
+ else if (text[0] === "!")
filter = new CommentFilter(text);
else
filter = RegExpFilter.fromText(text);
Filter.knownFilters.set(filter.text, filter);
return filter;
};
@@ -152,17 +152,17 @@
* @return {Filter} filter or null if the filter couldn't be created
*/
Filter.fromObject = function(obj)
{
let filter = Filter.fromText(obj.text);
if (filter instanceof ActiveFilter)
{
if ("disabled" in obj)
- filter._disabled = (obj.disabled == "true");
+ filter._disabled = (obj.disabled === "true");
if ("hitCount" in obj)
filter._hitCount = parseInt(obj.hitCount, 10) || 0;
if ("lastHit" in obj)
filter._lastHit = parseInt(obj.lastHit, 10) || 0;
}
return filter;
};
@@ -207,17 +207,17 @@
let beforeOptions = strippedText.substring(0, optionsMatch.index);
let strippedDollarIndex = -1;
let dollarIndex = -1;
do
{
strippedDollarIndex = beforeOptions.indexOf("$", strippedDollarIndex + 1);
dollarIndex = text.indexOf("$", dollarIndex + 1);
}
- while (strippedDollarIndex != -1);
+ while (strippedDollarIndex !== -1);
let optionsText = text.substr(dollarIndex + 1);
// Then we can normalize spaces in the options part safely
let options = optionsText.split(",");
for (let i = 0; i < options.length; i++)
{
let option = options[i];
let cspMatch = /^ *c *s *p *=/i.exec(option);
@@ -320,17 +320,17 @@
* @type {boolean}
*/
get disabled()
{
return this._disabled;
},
set disabled(value)
{
- if (value != this._disabled)
+ if (value !== this._disabled)
{
let oldValue = this._disabled;
this._disabled = value;
FilterNotifier.triggerListeners("filter.disabled", this, value, oldValue);
}
return this._disabled;
},
@@ -339,17 +339,17 @@
* @type {number}
*/
get hitCount()
{
return this._hitCount;
},
set hitCount(value)
{
- if (value != this._hitCount)
+ if (value !== this._hitCount)
{
let oldValue = this._hitCount;
this._hitCount = value;
FilterNotifier.triggerListeners("filter.hitCount", this, value, oldValue);
}
return this._hitCount;
},
@@ -359,17 +359,17 @@
* @type {number}
*/
get lastHit()
{
return this._lastHit;
},
set lastHit(value)
{
- if (value != this._lastHit)
+ if (value !== this._lastHit)
{
let oldValue = this._lastHit;
this._lastHit = value;
FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue);
}
return this._lastHit;
},
@@ -406,32 +406,32 @@
{
let source = this.domainSource;
if (!this.domainSourceIsUpperCase)
{
// RegExpFilter already have uppercase domains
source = source.toUpperCase();
}
let list = source.split(this.domainSeparator);
- if (list.length == 1 && list[0][0] != "~")
+ if (list.length === 1 && list[0][0] !== "~")
{
// Fast track for the common one-domain scenario
domains = new Map([["", false], [list[0], true]]);
}
else
{
let hasIncludes = false;
for (let i = 0; i < list.length; i++)
{
let domain = list[i];
- if (domain == "")
+ if (domain === "")
continue;
let include;
- if (domain[0] == "~")
+ if (domain[0] === "~")
{
include = false;
domain = domain.substr(1);
}
else
{
include = true;
hasIncludes = true;
@@ -485,17 +485,17 @@
if (!docDomain)
return this.domains.get("");
docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
while (true)
{
let isDomainIncluded = this.domains.get(docDomain);
- if (typeof isDomainIncluded != "undefined")
+ if (typeof isDomainIncluded !== "undefined")
return isDomainIncluded;
let nextDot = docDomain.indexOf(".");
if (nextDot < 0)
break;
docDomain = docDomain.substr(nextDot + 1);
}
return this.domains.get("");
@@ -510,17 +510,17 @@
{
if (!docDomain || !this.domains || this.domains.get(""))
return false;
docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
for (let [domain, isIncluded] of this.domains)
{
- if (isIncluded && domain != docDomain)
+ if (isIncluded && domain !== docDomain)
{
if (domain.length <= docDomain.length)
return false;
if (!domain.endsWith("." + docDomain))
return false;
}
}
@@ -578,28 +578,28 @@
* @constructor
* @augments ActiveFilter
*/
function RegExpFilter(text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys)
{
ActiveFilter.call(this, text, domains, sitekeys);
- if (contentType != null)
+ if (contentType !== null)
this.contentType = contentType;
if (matchCase)
this.matchCase = matchCase;
- if (thirdParty != null)
+ if (thirdParty !== null)
this.thirdParty = thirdParty;
- if (sitekeys != null)
+ if (sitekeys !== null)
this.sitekeySource = sitekeys;
if (regexpSource.length >= 2 &&
- regexpSource[0] == "/" &&
- regexpSource[regexpSource.length - 1] == "/")
+ regexpSource[0] === "/" &&
+ regexpSource[regexpSource.length - 1] === "/")
{
// The filter is a regular expression - convert it immediately to
// catch syntax errors
let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2),
this.matchCase ? "" : "i");
Object.defineProperty(this, "regexp", {value: regexp});
}
else
@@ -698,17 +698,17 @@
* @param {boolean} [thirdParty] should be true if the URL is a third-party
* request
* @param {string} [sitekey] public key provided by the document
* @return {boolean} true in case of a match
*/
matches(location, typeMask, docDomain, thirdParty, sitekey)
{
if (this.contentType & typeMask &&
- (this.thirdParty == null || this.thirdParty == thirdParty) &&
+ (this.thirdParty === null || this.thirdParty === thirdParty) &&
this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
{
return true;
}
return false;
}
});
@@ -721,17 +721,17 @@
* Creates a RegExp filter from its text representation
* @param {string} text same as in Filter()
* @return {Filter}
*/
RegExpFilter.fromText = function(text)
{
let blocking = true;
let origText = text;
- if (text[0] == "@" && text[1] == "@")
+ if (text[0] === "@" && text[1] === "@")
{
blocking = false;
text = text.substr(2);
}
let contentType = null;
let matchCase = null;
let domains = null;
@@ -755,53 +755,53 @@
value = option.substr(separatorIndex + 1);
option = option.substr(0, separatorIndex);
}
option = option.replace(/-/, "_").toUpperCase();
if (option in RegExpFilter.typeMap)
{
contentType |= RegExpFilter.typeMap[option];
- if (option == "CSP" && value)
+ if (option === "CSP" && value)
csp = value;
}
- else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap)
+ else if (option[0] === "~" && option.substr(1) in RegExpFilter.typeMap)
{
- if (contentType == null)
+ if (contentType === null)
({contentType} = RegExpFilter.prototype);
contentType &= ~RegExpFilter.typeMap[option.substr(1)];
}
- else if (option == "MATCH_CASE")
+ else if (option === "MATCH_CASE")
matchCase = true;
- else if (option == "~MATCH_CASE")
+ else if (option === "~MATCH_CASE")
matchCase = false;
- else if (option == "DOMAIN" && value)
+ else if (option === "DOMAIN" && value)
domains = value.toUpperCase();
- else if (option == "THIRD_PARTY")
+ else if (option === "THIRD_PARTY")
thirdParty = true;
- else if (option == "~THIRD_PARTY")
+ else if (option === "~THIRD_PARTY")
thirdParty = false;
- else if (option == "COLLAPSE")
+ else if (option === "COLLAPSE")
collapse = true;
- else if (option == "~COLLAPSE")
+ else if (option === "~COLLAPSE")
collapse = false;
- else if (option == "SITEKEY" && value)
+ else if (option === "SITEKEY" && value)
sitekeys = value.toUpperCase();
- else if (option == "REWRITE" && value)
+ else if (option === "REWRITE" && value)
rewrite = value;
else
return new InvalidFilter(origText, "filter_unknown_option");
}
}
// For security reasons, never match $rewrite filters
// against requests that might load any code to be executed.
- if (rewrite != null)
+ if (rewrite !== null)
{
- if (contentType == null)
+ if (contentType === null)
({contentType} = RegExpFilter.prototype);
contentType &= ~(RegExpFilter.typeMap.SCRIPT |
RegExpFilter.typeMap.SUBDOCUMENT |
RegExpFilter.typeMap.OBJECT |
RegExpFilter.typeMap.OBJECT_SUBREQUEST);
}
try
@@ -882,23 +882,23 @@
* @augments RegExpFilter
*/
function BlockingFilter(text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys, collapse, csp, rewrite)
{
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys);
- if (collapse != null)
+ if (collapse !== null)
this.collapse = collapse;
- if (csp != null)
+ if (csp !== null)
this.csp = csp;
- if (rewrite != null)
+ if (rewrite !== null)
this.rewrite = rewrite;
}
exports.BlockingFilter = BlockingFilter;
BlockingFilter.prototype = extend(RegExpFilter, {
type: "blocking",
/**
@@ -926,17 +926,17 @@
* @param {string} url the URL to rewrite
* @return {string} the rewritten URL, or the original in case of failure
*/
rewriteUrl(url)
{
try
{
let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url);
- if (rewrittenUrl.origin == new URL(url).origin)
+ if (rewrittenUrl.origin === new URL(url).origin)
return rewrittenUrl.href;
}
catch (e)
{
}
return url;
}
@@ -1013,20 +1013,20 @@
ElemHideBase.fromText = function(text, domains, type, selector)
{
// We don't allow ElemHide filters which have any empty domains.
// Note: The ElemHide.prototype.domainSeparator is duplicated here, if that
// changes this must be changed too.
if (domains && /(^|,)~?(,|$)/.test(domains))
return new InvalidFilter(text, "filter_invalid_domain");
- if (type == "@")
+ if (type === "@")
return new ElemHideException(text, domains, selector);
- if (type == "?")
+ if (type === "?")
{
// Element hiding emulation filters are inefficient so we need to make sure
// that they're only applied if they specify active domains
if (!/,[^~][^,.]*\.[^,]/.test("," + domains))
return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
return new ElemHideEmulationFilter(text, domains, selector);
}
« no previous file with comments | « lib/events.js ('k') | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld