LEFT | RIGHT |
1 "use strict"; | 1 "use strict"; |
2 | 2 |
3 let {_Filter_FromText, _Filter_Normalize, _Filter_get_type} = require("./compile
d"); | 3 let compiled = require("compiled"); |
4 let {wrapCall, stringArg, stringResult} = require("./compiledTools"); | 4 for (let cls of ["Filter", "InvalidFilter", "CommentFilter", "ActiveFilter", |
5 let constructors = Object.create(null); | 5 "RegExpFilter", "BlockingFilter", "WhitelistFilter", "ElemHideBase", |
6 | 6 "ElemHideFilter", "ElemHideException", "CSSPropertyFilter"]) |
7 function filterResult(call) | |
8 { | 7 { |
9 return function() | 8 exports[cls] = compiled[cls]; |
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 } | 9 } |
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); | |
LEFT | RIGHT |