Index: lib/filterClassesNew.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/filterClassesNew.js |
@@ -0,0 +1,75 @@ |
+"use strict"; |
+ |
+let compiled = require("./compiled"); |
+let { |
+ createClass, wrapCall, stringArg, stringResult, defineProperty, defineMethod, |
+ defineStringProperty, |
+ _CreatePointer, _DeletePointer, |
+ _Filter_GetType, _Filter_GetText, _Filter_FromText, _Filter_Normalize, |
+ _InvalidFilter_GetReason, |
+ _ActiveFilter_GetDisabled, _ActiveFilter_SetDisabled, |
+ _ActiveFilter_GetHitCount, _ActiveFilter_SetHitCount, |
+ _ActiveFilter_GetLastHit, _ActiveFilter_SetLastHit, |
+ _RegExpFilter_Matches |
+} = compiled; |
+ |
+let constructors = Object.create(null); |
+ |
+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; |
+} |
+ |
+function filterResult(call) |
+{ |
+ return function() |
+ { |
+ let pointer = _CreatePointer(); |
+ try |
+ { |
+ let params = Array.slice(arguments); |
+ params.unshift(pointer); |
+ |
+ call.apply(this, params); |
+ let type = _Filter_GetType(pointer); |
+ if (type in constructors) |
+ return new (constructors[type])(pointer); |
+ else |
+ throw new Error("Unexpected filter type " + type); |
+ } |
+ catch (e) |
+ { |
+ _DeletePointer(pointer); |
+ throw e; |
+ } |
+ }; |
+} |
+ |
+exports.Filter = createFilterClass(); |
+exports.Filter.fromText = wrapCall(stringArg(0, filterResult(_Filter_FromText))); |
+exports.Filter.normalize = wrapCall(stringArg(0, stringResult(_Filter_Normalize))); |
+defineStringProperty(exports.Filter, "text", _Filter_GetText); |
+ |
+exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1); |
+defineStringProperty(exports.InvalidFilter, "reason", _InvalidFilter_GetReason); |
+ |
+exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2); |
+ |
+exports.ActiveFilter = createFilterClass(exports.Filter); |
+defineProperty(exports.ActiveFilter, "disabled", _ActiveFilter_GetDisabled, _ActiveFilter_SetDisabled); |
+defineProperty(exports.ActiveFilter, "hitCount", _ActiveFilter_GetHitCount, _ActiveFilter_SetHitCount); |
+defineProperty(exports.ActiveFilter, "lastHit", _ActiveFilter_GetLastHit, _ActiveFilter_SetLastHit); |
+ |
+exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3); |
+defineMethod(exports.RegExpFilter, "matches", stringArg(1, _RegExpFilter_Matches)); |
+ |
+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); |