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

Delta Between Two Patch Sets: lib/filterClassesNew.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Created Jan. 14, 2016, 4:40 p.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterClasses.js ('k') | lib/filterNotifier.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld