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: Created Jan. 14, 2016, 4: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
« no previous file with comments | « 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,46 @@
+"use strict";
+
+let {_Filter_FromText, _Filter_Normalize, _Filter_get_type} = require("./compiled");
+let {wrapCall, stringArg, stringResult} = 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 = function(pointer)
+ {
+ this._pointer = pointer;
+ };
+ if (superclass)
+ result.prototype = Object.create(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)));
+
+exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1);
+exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2);
+exports.RegExpFilter = createFilterClass(exports.Filter, "blocking", 3);
+exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4);
+exports.ElemHideBase = createFilterClass(exports.Filter);
+exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5);
+exports.ElemHideException = createFilterClass(exports.ElemHideException, "elemhideexception", 6);
+exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty", 7);
« no previous file with comments | « lib/compiledTools.js ('k') | test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld