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

Unified Diff: lib/filterClasses.js

Issue 29746555: Issue 6564 - Replace desc and extend with __proto__ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created April 8, 2018, 8:57 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 | « lib/coreUtils.js ('k') | lib/filterNotifier.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
@@ -17,17 +17,16 @@
"use strict";
/**
* @fileOverview Definition of Filter class and its subclasses.
*/
const {FilterNotifier} = require("./filterNotifier");
-const {extend} = require("./coreUtils");
const {filterToRegExp} = require("./common");
/**
* Abstract base class for filters
*
* @param {string} text string representation of the filter
* @constructor
*/
@@ -248,53 +247,57 @@
function InvalidFilter(text, reason)
{
Filter.call(this, text);
this.reason = reason;
}
exports.InvalidFilter = InvalidFilter;
-InvalidFilter.prototype = extend(Filter, {
+InvalidFilter.prototype = {
+ __proto__: Filter.prototype,
+
type: "invalid",
/**
* Reason why this filter is invalid
* @type {string}
*/
reason: null,
/**
* See Filter.serialize()
* @inheritdoc
*/
serialize(buffer) {}
-});
+};
/**
* Class for comments
* @param {string} text see Filter()
* @constructor
* @augments Filter
*/
function CommentFilter(text)
{
Filter.call(this, text);
}
exports.CommentFilter = CommentFilter;
-CommentFilter.prototype = extend(Filter, {
+CommentFilter.prototype = {
+ __proto__: Filter.prototype,
+
type: "comment",
/**
* See Filter.serialize()
* @inheritdoc
*/
serialize(buffer) {}
-});
+};
/**
* Abstract base class for filters that can get hits
* @param {string} text
* see Filter()
* @param {string} [domains]
* Domains that the filter is restricted to separated by domainSeparator
* e.g. "foo.com|bar.com|~baz.com"
@@ -304,17 +307,19 @@
function ActiveFilter(text, domains)
{
Filter.call(this, text);
this.domainSource = domains;
}
exports.ActiveFilter = ActiveFilter;
-ActiveFilter.prototype = extend(Filter, {
+ActiveFilter.prototype = {
+ __proto__: Filter.prototype,
+
_disabled: false,
_hitCount: 0,
_lastHit: 0,
/**
* Defines whether the filter is disabled
* @type {boolean}
*/
@@ -570,17 +575,17 @@
if (this._disabled)
buffer.push("disabled=true");
if (this._hitCount)
buffer.push("hitCount=" + this._hitCount);
if (this._lastHit)
buffer.push("lastHit=" + this._lastHit);
}
}
-});
+};
/**
* Abstract base class for RegExp-based filters
* @param {string} text see Filter()
* @param {string} regexpSource
* filter part that the regular expression should be build from
* @param {number} [contentType]
* Content types the filter applies to, combination of values from
@@ -625,17 +630,19 @@
else
{
// No need to convert this filter to regular expression yet, do it on demand
this.regexpSource = regexpSource;
}
}
exports.RegExpFilter = RegExpFilter;
-RegExpFilter.prototype = extend(ActiveFilter, {
+RegExpFilter.prototype = {
+ __proto__: ActiveFilter.prototype,
+
/**
* @see ActiveFilter.domainSourceIsUpperCase
*/
domainSourceIsUpperCase: true,
/**
* Number of filters contained, will always be 1 (required to
* optimize Matcher).
@@ -737,17 +744,17 @@
if (this.contentType & typeMask &&
(this.thirdParty == null || this.thirdParty == thirdParty) &&
this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
{
return true;
}
return false;
}
-});
+};
// Required to optimize Matcher, see also RegExpFilter.prototype.length
Object.defineProperty(RegExpFilter.prototype, "0", {
get() { return this; }
});
/**
* Creates a RegExp filter from its text representation
@@ -903,32 +910,34 @@
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys);
this.collapse = collapse;
this.csp = csp;
}
exports.BlockingFilter = BlockingFilter;
-BlockingFilter.prototype = extend(RegExpFilter, {
+BlockingFilter.prototype = {
+ __proto__: RegExpFilter.prototype,
+
type: "blocking",
/**
* Defines whether the filter should collapse blocked content.
* Can be null (use the global preference).
* @type {boolean}
*/
collapse: null,
/**
* Content Security Policy to inject for matching requests.
* @type {string}
*/
csp: null
-});
+};
/**
* Class for whitelist filters
* @param {string} text see Filter()
* @param {string} regexpSource see RegExpFilter()
* @param {number} contentType see RegExpFilter()
* @param {boolean} matchCase see RegExpFilter()
* @param {string} domains see RegExpFilter()
@@ -940,19 +949,20 @@
function WhitelistFilter(text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys)
{
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
thirdParty, sitekeys);
}
exports.WhitelistFilter = WhitelistFilter;
-WhitelistFilter.prototype = extend(RegExpFilter, {
+WhitelistFilter.prototype = {
+ __proto__: RegExpFilter.prototype,
type: "whitelist"
-});
+};
/**
* Base class for element hiding filters
* @param {string} text see Filter()
* @param {string} [domains] Host names or domains the filter should be
* restricted to
* @param {string} selector CSS selector for the HTML elements that should be
* hidden
@@ -969,17 +979,19 @@
.replace(/^~[^,]+,?/, "").toLowerCase();
}
// Braces are being escaped to prevent CSS rule injection.
this.selector = selector.replace("{", "\\7B ").replace("}", "\\7D ");
}
exports.ElemHideBase = ElemHideBase;
-ElemHideBase.prototype = extend(ActiveFilter, {
+ElemHideBase.prototype = {
+ __proto__: ActiveFilter.prototype,
+
/**
* @see ActiveFilter.domainSeparator
*/
domainSeparator: ",",
/**
* @see ActiveFilter.ignoreTrailingDot
*/
@@ -991,17 +1003,17 @@
* @type {string}
*/
selectorDomain: null,
/**
* CSS selector for the HTML elements that should be hidden
* @type {string}
*/
selector: null
-});
+};
/**
* Creates an element hiding filter from a pre-parsed text representation
*
* @param {string} text same as in Filter()
* @param {string?} domain
* domain part of the text representation
* @param {string?} type
@@ -1043,47 +1055,50 @@
* @augments ElemHideBase
*/
function ElemHideFilter(text, domains, selector)
{
ElemHideBase.call(this, text, domains, selector);
}
exports.ElemHideFilter = ElemHideFilter;
-ElemHideFilter.prototype = extend(ElemHideBase, {
+ElemHideFilter.prototype = {
+ __proto__: ElemHideBase.prototype,
type: "elemhide"
-});
+};
/**
* Class for element hiding exceptions
* @param {string} text see Filter()
* @param {string} domains see ElemHideBase()
* @param {string} selector see ElemHideBase()
* @constructor
* @augments ElemHideBase
*/
function ElemHideException(text, domains, selector)
{
ElemHideBase.call(this, text, domains, selector);
}
exports.ElemHideException = ElemHideException;
-ElemHideException.prototype = extend(ElemHideBase, {
+ElemHideException.prototype = {
+ __proto__: ElemHideBase.prototype,
type: "elemhideexception"
-});
+};
/**
* Class for element hiding emulation filters
* @param {string} text see Filter()
* @param {string} domains see ElemHideBase()
* @param {string} selector see ElemHideBase()
* @constructor
* @augments ElemHideBase
*/
function ElemHideEmulationFilter(text, domains, selector)
{
ElemHideBase.call(this, text, domains, selector);
}
exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
-ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
+ElemHideEmulationFilter.prototype = {
+ __proto__: ElemHideBase.prototype,
type: "elemhideemulation"
-});
+};
« no previous file with comments | « lib/coreUtils.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld