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: Almost complete implementation, missing CSS property filters Created Jan. 20, 2016, 12:04 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_Serialize, _Filter_FromText,
9 _Filter_Normalize,
10 _InvalidFilter_GetReason,
11 _ActiveFilter_GetDisabled, _ActiveFilter_SetDisabled,
12 _ActiveFilter_GetHitCount, _ActiveFilter_SetHitCount,
13 _ActiveFilter_GetLastHit, _ActiveFilter_SetLastHit,
14 _ActiveFilter_IsActiveOnDomain, _ActiveFilter_IsActiveOnlyOnDomain,
15 _ActiveFilter_IsGeneric,
16 RegExpFilter_typeMap, _RegExpFilter_InitJSTypes, _RegExpFilter_Matches,
17 _ElemHideBase_GetSelector, _ElemHideBase_GetSelectorDomain
18 } = compiled;
19
20 let constructors = Object.create(null);
21
22 function createFilterClass(superclass, type, typeId)
23 { 7 {
24 let result = createClass(superclass); 8 exports[cls] = compiled[cls];
25 if (type)
26 Object.defineProperty(result.prototype, "type", {get: () => type, enumerable : true});
27 if (typeId)
28 constructors[typeId] = result;
29 return result;
30 } 9 }
31
32 function pointerToFilter(pointer)
33 {
34 let type = _Filter_GetType(pointer);
35 if (type in constructors)
36 return new (constructors[type])(pointer);
37 else
38 throw new Error("Unexpected filter type " + type);
39 }
40 exports.pointerToFilter = pointerToFilter;
41
42 function filterResult(call)
43 {
44 return function()
45 {
46 let pointer = _CreatePointer();
47 try
48 {
49 let params = Array.slice(arguments);
50 params.unshift(pointer);
51
52 call.apply(this, params);
53 return pointerToFilter(pointer);
54 }
55 catch (e)
56 {
57 _DeletePointer(pointer);
58 throw e;
59 }
60 };
61 }
62
63 exports.Filter = createFilterClass();
64 defineStringProperty(exports.Filter, "text", _Filter_GetText);
65 defineMethod(exports.Filter, "serialize", stringResult(_Filter_Serialize));
66 exports.Filter.fromText = wrapCall(stringArg(0, filterResult(_Filter_FromText))) ;
67 exports.Filter.normalize = wrapCall(stringArg(0, stringResult(_Filter_Normalize) ));
68
69 exports.InvalidFilter = createFilterClass(exports.Filter, "invalid", 1);
70 defineStringProperty(exports.InvalidFilter, "reason", _InvalidFilter_GetReason);
71
72 exports.CommentFilter = createFilterClass(exports.Filter, "comment", 2);
73
74 exports.ActiveFilter = createFilterClass(exports.Filter);
75 defineProperty(exports.ActiveFilter, "disabled", _ActiveFilter_GetDisabled, _Act iveFilter_SetDisabled);
76 defineProperty(exports.ActiveFilter, "hitCount", _ActiveFilter_GetHitCount, _Act iveFilter_SetHitCount);
77 defineProperty(exports.ActiveFilter, "lastHit", _ActiveFilter_GetLastHit, _Activ eFilter_SetLastHit);
78 defineMethod(exports.ActiveFilter, "isActiveOnDomain", stringArg(1, stringArg(2, _ActiveFilter_IsActiveOnDomain)));
79 defineMethod(exports.ActiveFilter, "isActiveOnlyOnDomain", stringArg(1, _ActiveF ilter_IsActiveOnlyOnDomain));
80 defineMethod(exports.ActiveFilter, "isGeneric", _ActiveFilter_IsGeneric);
81
82 exports.RegExpFilter = createFilterClass(exports.ActiveFilter, "blocking", 3);
83 defineMethod(exports.RegExpFilter, "matches", stringArg(1, stringArg(3, stringAr g(5, _RegExpFilter_Matches))));
84
85 _RegExpFilter_InitJSTypes();
86 exports.RegExpFilter.typeMap = RegExpFilter_typeMap;
87
88 exports.WhiteListFilter = createFilterClass(exports.RegExpFilter, "whitelist", 4 );
89
90 exports.ElemHideBase = createFilterClass(exports.ActiveFilter);
91 defineStringProperty(exports.ElemHideBase, "selector", _ElemHideBase_GetSelector );
92 defineStringProperty(exports.ElemHideBase, "selectorDomain", _ElemHideBase_GetSe lectorDomain);
93
94 exports.ElemHideFilter = createFilterClass(exports.ElemHideBase, "elemhide", 5);
95 exports.ElemHideException = createFilterClass(exports.ElemHideBase, "elemhideexc eption", 6);
96 exports.CSSPropertyFilter = createFilterClass(exports.ElemHideBase, "cssproperty ", 7);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld