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

Side by Side Diff: lib/filterClassesNew.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Back to manual approach for API Created Jan. 18, 2016, 12:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/shell.js ('k') | test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 "use strict";
2
3 let compiled = require("./compiled");
4 let {
5 createClass, wrapCall, stringArg, stringResult, defineProperty, defineMethod,
6 defineStringProperty,
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 {
20 let result = createClass(superclass);
21 if (type)
22 Object.defineProperty(result.prototype, "type", {get: () => type, enumerable : true});
23 if (typeId)
24 constructors[typeId] = result;
25 return result;
26 }
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);
OLDNEW
« no previous file with comments | « compiled/shell.js ('k') | test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld