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: Now passing all filter matching tests (without filter options) Created Jan. 18, 2016, 6:12 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 compiled = require("./compiled"); 3 let compiled = require("compiled");
4 let { 4 for (let cls of ["Filter", "InvalidFilter", "CommentFilter", "ActiveFilter",
5 createClass, wrapCall, stringArg, stringResult, defineProperty, defineMethod, 5 "RegExpFilter", "BlockingFilter", "WhitelistFilter", "ElemHideBase",
6 defineStringProperty, 6 "ElemHideFilter", "ElemHideException", "CSSPropertyFilter"])
7 _CreatePointer, _DeletePointer,
8 _Filter_GetType, _Filter_GetText, _Filter_FromText, _Filter_Normalize,
9 _InvalidFilter_GetReason,
10 _ActiveFilter_GetDisabled, _ActiveFilter_SetDisabled,
11 _ActiveFilter_GetHitCount, _ActiveFilter_SetHitCount,
12 _ActiveFilter_GetLastHit, _ActiveFilter_SetLastHit,
13 _RegExpFilter_Matches
14 } = compiled;
15
16 let constructors = Object.create(null);
17
18 function createFilterClass(superclass, type, typeId)
19 { 7 {
20 let result = createClass(superclass); 8 exports[cls] = compiled[cls];
21 if (type)
22 Object.defineProperty(result.prototype, "type", {get: () => type, enumerable : true});
23 if (typeId)
24 constructors[typeId] = result;
25 return result;
26 } 9 }
27
28 function filterResult(call)
29 {
30 return function()
31 {
32 let pointer = _CreatePointer();
33 try
34 {
35 let params = Array.slice(arguments);
36 params.unshift(pointer);
37
38 call.apply(this, params);
39 let type = _Filter_GetType(pointer);
40 if (type in constructors)
41 return new (constructors[type])(pointer);
42 else
43 throw new Error("Unexpected filter type " + type);
44 }
45 catch (e)
46 {
47 _DeletePointer(pointer);
48 throw e;
49 }
50 };
51 }
52
53 exports.Filter = createFilterClass();
54 exports.Filter.fromText = wrapCall(stringArg(0, filterResult(_Filter_FromText))) ;
55 exports.Filter.normalize = wrapCall(stringArg(0, stringResult(_Filter_Normalize) ));
56 defineStringProperty(exports.Filter, "text", _Filter_GetText);
57
58 exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1);
59 defineStringProperty(exports.InvalidFilter, "reason", _InvalidFilter_GetReason);
60
61 exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2);
62
63 exports.ActiveFilter = createFilterClass(exports.Filter);
64 defineProperty(exports.ActiveFilter, "disabled", _ActiveFilter_GetDisabled, _Act iveFilter_SetDisabled);
65 defineProperty(exports.ActiveFilter, "hitCount", _ActiveFilter_GetHitCount, _Act iveFilter_SetHitCount);
66 defineProperty(exports.ActiveFilter, "lastHit", _ActiveFilter_GetLastHit, _Activ eFilter_SetLastHit);
67
68 exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3);
69 defineMethod(exports.RegExpFilter, "matches", stringArg(1, _RegExpFilter_Matches ));
70
71 exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4 );
72 exports.ElemHideBase = createFilterClass(exports.ActiveFilter);
73 exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5);
74 exports.ElemHideException = createFilterClass(exports.ElemHideBase, "elemhideexc eption", 6);
75 exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty ", 7);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld