Index: lib/filterClassesNew.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/filterClassesNew.js |
@@ -0,0 +1,61 @@ |
+"use strict"; |
+ |
+let { |
+ _Filter_FromText, _Filter_Normalize, _Filter_get_text, _Filter_get_type, |
+ _InvalidFilter_get_reason, |
+ _ActiveFilter_get_disabled, _ActiveFilter_set_disabled, |
+ _ActiveFilter_get_hitCount, _ActiveFilter_set_hitCount, |
+ _ActiveFilter_get_lastHit, _ActiveFilter_set_lastHit |
+} = require("./compiled"); |
+ |
+let { |
+ createClass, wrapCall, stringArg, stringResult, defineProperty, |
+ defineStringProperty |
+} = require("./compiledTools"); |
+ |
+let constructors = Object.create(null); |
+ |
+function filterResult(call) |
+{ |
+ return function() |
+ { |
+ let result = call.apply(this, arguments); |
+ let type = _Filter_get_type(result); |
+ if (type in constructors) |
+ return new (constructors[type])(result); |
+ else |
+ throw new Error("Unexpected filter type " + type); |
+ }; |
+} |
+ |
+function createFilterClass(superclass, type, typeId) |
+{ |
+ let result = createClass(superclass); |
+ if (type) |
+ Object.defineProperty(result.prototype, "type", {get: () => type, enumerable: true}); |
+ if (typeId) |
+ constructors[typeId] = result; |
+ return result; |
+} |
+ |
+exports.Filter = createFilterClass(); |
+exports.Filter.fromText = wrapCall(filterResult(stringArg(0, _Filter_FromText))); |
+exports.Filter.normalize = wrapCall(stringResult(stringArg(0, _Filter_Normalize))); |
+defineStringProperty(exports.Filter, "text", _Filter_get_text); |
+ |
+exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1); |
+defineStringProperty(exports.InvalidFilter, "text", _InvalidFilter_get_reason); |
+ |
+exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2); |
+ |
+exports.ActiveFilter = createFilterClass(exports.Filter); |
+defineProperty(exports.ActiveFilter, "disabled", _ActiveFilter_get_disabled, _ActiveFilter_set_disabled); |
+defineProperty(exports.ActiveFilter, "hitCount", _ActiveFilter_get_hitCount, _ActiveFilter_set_hitCount); |
+defineProperty(exports.ActiveFilter, "lastHit", _ActiveFilter_get_lastHit, _ActiveFilter_set_lastHit); |
+ |
+exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3); |
+exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4); |
+exports.ElemHideBase = createFilterClass(exports.ActiveFilter); |
+exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5); |
+exports.ElemHideException = createFilterClass(exports.ElemHideBase, "elemhideexception", 6); |
+exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty", 7); |