Index: lib/coreUtils.js
diff --git a/lib/coreUtils.js b/lib/coreUtils.js
new file mode 100644
index 0000000000000000000000000000000000000000..b9e9a2f050252ae0ac6d4d7d1a1919ff812c1d7a
--- /dev/null
+++ b/lib/coreUtils.js
@@ -0,0 +1,34 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+function desc(properties)
+{
+ let descriptor = {};
+ let keys = Object.keys(properties);
+
+ for (let key of keys)
+ descriptor[key] = Object.getOwnPropertyDescriptor(properties, key);
+
+ return descriptor;
+}
+exports.desc = desc;
+
+function extend(cls, properties)
+{
+ return Object.create(cls.prototype, desc(properties));
+}
+exports.extend = extend;
Index: lib/filterClasses.js
diff --git a/lib/filterClasses.js b/lib/filterClasses.js
index 5a8ac6d77bf116ace79ceebbbf3df1b02dc11fc6..ddf9aff8ec82a7e1abdb8f81465bc53af9acb881 100644
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -20,6 +20,7 @@
*/
let {FilterNotifier} = require("filterNotifier");
+let {extend} = require("coreUtils");
/**
* Abstract base class for filters
@@ -210,10 +211,7 @@ function InvalidFilter(text, reason)
}
exports.InvalidFilter = InvalidFilter;
-InvalidFilter.prototype =
-{
- __proto__: Filter.prototype,
-
+InvalidFilter.prototype = extend(Filter, {
type: "invalid",
/**
@@ -226,7 +224,7 @@ InvalidFilter.prototype =
* See Filter.serialize()
*/
serialize: function(buffer) {}
-};
+});
/**
* Class for comments
@@ -240,17 +238,14 @@ function CommentFilter(text)
}
exports.CommentFilter = CommentFilter;
-CommentFilter.prototype =
-{
- __proto__: Filter.prototype,
-
+CommentFilter.prototype = extend(Filter, {
type: "comment",
/**
* See Filter.serialize()
*/
serialize: function(buffer) {}
-};
+});
/**
* Abstract base class for filters that can get hits
@@ -267,10 +262,7 @@ function ActiveFilter(text, domains)
}
exports.ActiveFilter = ActiveFilter;
-ActiveFilter.prototype =
-{
- __proto__: Filter.prototype,
-
+ActiveFilter.prototype = extend(Filter, {
_disabled: false,
_hitCount: 0,
_lastHit: 0,
@@ -515,7 +507,7 @@ ActiveFilter.prototype =
buffer.push("lastHit=" + this._lastHit);
}
}
-};
+});
/**
* Abstract base class for RegExp-based filters
@@ -556,10 +548,7 @@ function RegExpFilter(text, regexpSource, contentType, matchCase, domains, third
}
exports.RegExpFilter = RegExpFilter;
-RegExpFilter.prototype =
-{
- __proto__: ActiveFilter.prototype,
-
+RegExpFilter.prototype = extend(ActiveFilter, {
/**
* @see ActiveFilter.domainSourceIsUpperCase
*/
@@ -664,7 +653,7 @@ RegExpFilter.prototype =
return false;
}
-};
+});
// Required to optimize Matcher, see also RegExpFilter.prototype.length
Object.defineProperty(RegExpFilter.prototype, "0",
@@ -810,10 +799,7 @@ function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thi
}
exports.BlockingFilter = BlockingFilter;
-BlockingFilter.prototype =
-{
- __proto__: RegExpFilter.prototype,
-
+BlockingFilter.prototype = extend(RegExpFilter, {
type: "blocking",
/**
@@ -821,7 +807,7 @@ BlockingFilter.prototype =
* @type Boolean
*/
collapse: null
-};
+});
/**
* Class for whitelist filters
@@ -841,12 +827,9 @@ function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
}
exports.WhitelistFilter = WhitelistFilter;
-WhitelistFilter.prototype =
-{
- __proto__: RegExpFilter.prototype,
-
+WhitelistFilter.prototype = extend(RegExpFilter, {
type: "whitelist"
-};
+});
/**
* Base class for element hiding filters
@@ -866,10 +849,7 @@ function ElemHideBase(text, domains, selector)
}
exports.ElemHideBase = ElemHideBase;
-ElemHideBase.prototype =
-{
- __proto__: ActiveFilter.prototype,
-
+ElemHideBase.prototype = extend(ActiveFilter, {
/**
* @see ActiveFilter.domainSeparator
*/
@@ -890,7 +870,7 @@ ElemHideBase.prototype =
* @type String
*/
selector: null
-};
+});
/**
* Creates an element hiding filter from a pre-parsed text representation
@@ -975,12 +955,9 @@ function ElemHideFilter(text, domains, selector)
}
exports.ElemHideFilter = ElemHideFilter;
-ElemHideFilter.prototype =
-{
- __proto__: ElemHideBase.prototype,
-
+ElemHideFilter.prototype = extend(ElemHideBase, {
type: "elemhide"
-};
+});
/**
* Class for element hiding exceptions
@@ -996,12 +973,9 @@ function ElemHideException(text, domains, selector)
}
exports.ElemHideException = ElemHideException;
-ElemHideException.prototype =
-{
- __proto__: ElemHideBase.prototype,
-
+ElemHideException.prototype = extend(ElemHideBase, {
type: "elemhideexception"
-};
+});
/**
* Class for CSS property filters
@@ -1025,10 +999,7 @@ function CSSPropertyFilter(text, domains, selector, regexpSource,
}
exports.CSSPropertyFilter = CSSPropertyFilter;
-CSSPropertyFilter.prototype =
-{
- __proto__: ElemHideBase.prototype,
-
+CSSPropertyFilter.prototype = extend(ElemHideBase, {
type: "cssproperty",
/**
@@ -1067,4 +1038,4 @@ CSSPropertyFilter.prototype =
Object.defineProperty(this, "regexpString", {value: regexp});
return regexp;
}
-};
+});
Index: lib/filterNotifier.js
diff --git a/lib/filterNotifier.js b/lib/filterNotifier.js
index 8e24ff70e7307173ad5e929ee5d12dddc451100b..624b2bf48d3c0fa5e8008a5690800b471fa846ab 100644
--- a/lib/filterNotifier.js
+++ b/lib/filterNotifier.js
@@ -21,6 +21,7 @@
*/
let {EventEmitter} = require("events");
+let {desc} = require("coreUtils");
const CATCH_ALL = "__all";
@@ -28,10 +29,7 @@ const CATCH_ALL = "__all";
* This class allows registering and triggering listeners for filter events.
* @class
*/
-exports.FilterNotifier =
-{
- __proto__: new EventEmitter(),
-
+exports.FilterNotifier = Object.create(new EventEmitter(), desc({
/**
* Adds a listener
*
@@ -71,4 +69,4 @@ exports.FilterNotifier =
this.emit(action, item, param1, param2, param3);
this.emit(CATCH_ALL, action, item, param1, param2, param3);
}
-};
+}));
Index: lib/subscriptionClasses.js
diff --git a/lib/subscriptionClasses.js b/lib/subscriptionClasses.js
index f559cb3937f42a8caff29135c7799e90c598183f..a154e7fb603ed1bac727349b6b9b9e13c2654996 100644
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -21,6 +21,7 @@
let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("filterClasses");
let {FilterNotifier} = require("filterNotifier");
+let {desc, extend} = require("coreUtils");
/**
* Abstract base class for filter subscriptions
@@ -229,10 +230,7 @@ function SpecialSubscription(url, title)
}
exports.SpecialSubscription = SpecialSubscription;
-SpecialSubscription.prototype =
-{
- __proto__: Subscription.prototype,
-
+SpecialSubscription.prototype = extend(Subscription, {
/**
* Filter types that should be added to this subscription by default
* (entries should correspond to keys in SpecialSubscription.defaultsMap).
@@ -272,14 +270,13 @@ SpecialSubscription.prototype =
if (this._lastDownload)
buffer.push("lastDownload=" + this._lastDownload);
}
-};
+});
-SpecialSubscription.defaultsMap = {
- __proto__: null,
+SpecialSubscription.defaultsMap = Object.create(null, desc({
"whitelist": WhitelistFilter,
"blocking": BlockingFilter,
"elemhide": ElemHideBase
-};
+}));
/**
* Creates a new user-defined filter group.
@@ -327,10 +324,7 @@ function RegularSubscription(url, title)
}
exports.RegularSubscription = RegularSubscription;
-RegularSubscription.prototype =
-{
- __proto__: Subscription.prototype,
-
+RegularSubscription.prototype = extend(Subscription, {
_homepage: null,
_lastDownload: 0,
@@ -383,7 +377,7 @@ RegularSubscription.prototype =
if (this._lastDownload)
buffer.push("lastDownload=" + this._lastDownload);
}
-};
+});
/**
* Class for filter subscriptions updated externally (by other extension)
@@ -398,10 +392,7 @@ function ExternalSubscription(url, title)
}
exports.ExternalSubscription = ExternalSubscription;
-ExternalSubscription.prototype =
-{
- __proto__: RegularSubscription.prototype,
-
+ExternalSubscription.prototype = extend(RegularSubscription, {
/**
* See Subscription.serialize()
*/
@@ -409,7 +400,7 @@ ExternalSubscription.prototype =
{
throw new Error("Unexpected call, external subscriptions should not be serialized");
}
-};
+});
/**
* Class for filter subscriptions updated externally (by other extension)
@@ -424,10 +415,7 @@ function DownloadableSubscription(url, title)
}
exports.DownloadableSubscription = DownloadableSubscription;
-DownloadableSubscription.prototype =
-{
- __proto__: RegularSubscription.prototype,
-
+DownloadableSubscription.prototype = extend(RegularSubscription, {
_downloadStatus: null,
_lastCheck: 0,
_errors: 0,
@@ -549,4 +537,4 @@ DownloadableSubscription.prototype =
if (this.downloadCount)
buffer.push("downloadCount=" + this.downloadCount);
}
-};
+});