Index: lib/filterClassesNew.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/filterClassesNew.js |
@@ -0,0 +1,46 @@ |
+"use strict"; |
+ |
+let {_Filter_FromText, _Filter_Normalize, _Filter_get_type} = require("./compiled"); |
+let {wrapCall, stringArg, stringResult} = 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 = function(pointer) |
+ { |
+ this._pointer = pointer; |
+ }; |
+ if (superclass) |
+ result.prototype = Object.create(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))); |
+ |
+exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1); |
+exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2); |
+exports.RegExpFilter = createFilterClass(exports.Filter, "blocking", 3); |
+exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4); |
+exports.ElemHideBase = createFilterClass(exports.Filter); |
+exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5); |
+exports.ElemHideException = createFilterClass(exports.ElemHideException, "elemhideexception", 6); |
+exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty", 7); |