Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/filterClassesNew.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Almost complete implementation, missing CSS property filters Created Jan. 20, 2016, 12:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/shell.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClassesNew.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/filterClassesNew.js
@@ -0,0 +1,96 @@
+"use strict";
+
+let compiled = require("compiled");
+let {
+ createClass, wrapCall, stringArg, stringResult, defineProperty, defineMethod,
+ defineStringProperty,
+ _CreatePointer, _DeletePointer,
+ _Filter_GetType, _Filter_GetText, _Filter_Serialize, _Filter_FromText,
+ _Filter_Normalize,
+ _InvalidFilter_GetReason,
+ _ActiveFilter_GetDisabled, _ActiveFilter_SetDisabled,
+ _ActiveFilter_GetHitCount, _ActiveFilter_SetHitCount,
+ _ActiveFilter_GetLastHit, _ActiveFilter_SetLastHit,
+ _ActiveFilter_IsActiveOnDomain, _ActiveFilter_IsActiveOnlyOnDomain,
+ _ActiveFilter_IsGeneric,
+ RegExpFilter_typeMap, _RegExpFilter_InitJSTypes, _RegExpFilter_Matches,
+ _ElemHideBase_GetSelector, _ElemHideBase_GetSelectorDomain
+} = 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 pointerToFilter(pointer)
+{
+ let type = _Filter_GetType(pointer);
+ if (type in constructors)
+ return new (constructors[type])(pointer);
+ else
+ throw new Error("Unexpected filter type " + type);
+}
+exports.pointerToFilter = pointerToFilter;
+
+function filterResult(call)
+{
+ return function()
+ {
+ let pointer = _CreatePointer();
+ try
+ {
+ let params = Array.slice(arguments);
+ params.unshift(pointer);
+
+ call.apply(this, params);
+ return pointerToFilter(pointer);
+ }
+ catch (e)
+ {
+ _DeletePointer(pointer);
+ throw e;
+ }
+ };
+}
+
+exports.Filter = createFilterClass();
+defineStringProperty(exports.Filter, "text", _Filter_GetText);
+defineMethod(exports.Filter, "serialize", stringResult(_Filter_Serialize));
+exports.Filter.fromText = wrapCall(stringArg(0, filterResult(_Filter_FromText)));
+exports.Filter.normalize = wrapCall(stringArg(0, stringResult(_Filter_Normalize)));
+
+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);
+defineMethod(exports.ActiveFilter, "isActiveOnDomain", stringArg(1, stringArg(2, _ActiveFilter_IsActiveOnDomain)));
+defineMethod(exports.ActiveFilter, "isActiveOnlyOnDomain", stringArg(1, _ActiveFilter_IsActiveOnlyOnDomain));
+defineMethod(exports.ActiveFilter, "isGeneric", _ActiveFilter_IsGeneric);
+
+exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3);
+defineMethod(exports.RegExpFilter, "matches", stringArg(1, stringArg(3, stringArg(5, _RegExpFilter_Matches))));
+
+_RegExpFilter_InitJSTypes();
+exports.RegExpFilter.typeMap = RegExpFilter_typeMap;
+
+exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4);
+
+exports.ElemHideBase = createFilterClass(exports.ActiveFilter);
+defineStringProperty(exports.ElemHideBase, "selector", _ElemHideBase_GetSelector);
+defineStringProperty(exports.ElemHideBase, "selectorDomain", _ElemHideBase_GetSelectorDomain);
+
+exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5);
+exports.ElemHideException = createFilterClass(exports.ElemHideBase, "elemhideexception", 6);
+exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty", 7);
« no previous file with comments | « compiled/shell.js ('k') | lib/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld