OLD | NEW |
(Empty) | |
| 1 "use strict"; |
| 2 |
| 3 let {_Filter_FromText, _Filter_Normalize, _Filter_get_type} = require("./compile
d"); |
| 4 let {wrapCall, stringArg, stringResult} = require("./compiledTools"); |
| 5 let constructors = Object.create(null); |
| 6 |
| 7 function filterResult(call) |
| 8 { |
| 9 return function() |
| 10 { |
| 11 let result = call.apply(this, arguments); |
| 12 let type = _Filter_get_type(result); |
| 13 if (type in constructors) |
| 14 return new (constructors[type])(result); |
| 15 else |
| 16 throw new Error("Unexpected filter type " + type); |
| 17 }; |
| 18 } |
| 19 |
| 20 function createFilterClass(superclass, type, typeId) |
| 21 { |
| 22 let result = function(pointer) |
| 23 { |
| 24 this._pointer = pointer; |
| 25 }; |
| 26 if (superclass) |
| 27 result.prototype = Object.create(superclass); |
| 28 if (type) |
| 29 Object.defineProperty(result.prototype, "type", {get: () => type, enumerable
: true}); |
| 30 if (typeId) |
| 31 constructors[typeId] = result; |
| 32 return result; |
| 33 } |
| 34 |
| 35 exports.Filter = createFilterClass(); |
| 36 exports.Filter.fromText = wrapCall(filterResult(stringArg(0, _Filter_FromText)))
; |
| 37 exports.Filter.normalize = wrapCall(stringResult(stringArg(0, _Filter_Normalize)
)); |
| 38 |
| 39 exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1); |
| 40 exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2); |
| 41 exports.RegExpFilter = createFilterClass(exports.Filter, "blocking", 3); |
| 42 exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4
); |
| 43 exports.ElemHideBase = createFilterClass(exports.Filter); |
| 44 exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5); |
| 45 exports.ElemHideException = createFilterClass(exports.ElemHideException, "elemhi
deexception", 6); |
| 46 exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty
", 7); |
OLD | NEW |