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: Fixed some bugs and exposed/tested more properties Created Jan. 15, 2016, 3:40 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
« compiled/Filter.cpp ('K') | « lib/compiledTools.js ('k') | test.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,61 @@
+"use strict";
+
+let {
+ _Filter_FromText, _Filter_Normalize, _Filter_get_text, _Filter_get_type,
+ _InvalidFilter_get_reason,
+ _ActiveFilter_get_disabled, _ActiveFilter_set_disabled,
+ _ActiveFilter_get_hitCount, _ActiveFilter_set_hitCount,
+ _ActiveFilter_get_lastHit, _ActiveFilter_set_lastHit
+} = require("./compiled");
+
+let {
+ createClass, wrapCall, stringArg, stringResult, defineProperty,
+ defineStringProperty
+} = 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 = createClass(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)));
+defineStringProperty(exports.Filter, "text", _Filter_get_text);
+
+exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1);
+defineStringProperty(exports.InvalidFilter, "text", _InvalidFilter_get_reason);
+
+exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2);
+
+exports.ActiveFilter = createFilterClass(exports.Filter);
+defineProperty(exports.ActiveFilter, "disabled", _ActiveFilter_get_disabled, _ActiveFilter_set_disabled);
+defineProperty(exports.ActiveFilter, "hitCount", _ActiveFilter_get_hitCount, _ActiveFilter_set_hitCount);
+defineProperty(exports.ActiveFilter, "lastHit", _ActiveFilter_get_lastHit, _ActiveFilter_set_lastHit);
+
+exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3);
+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);
« compiled/Filter.cpp ('K') | « lib/compiledTools.js ('k') | test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld