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

Powered by Google App Engine
This is Rietveld