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

Side by Side Diff: compiled/api.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Call parameters in JS wrappers generated statically Created Jan. 28, 2016, 9:26 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/api.h ('k') | compiled/debug.h » ('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 #include <exception>
2
3 #include <emscripten.h>
4 #include <emscripten/trace.h>
5
6 #include "Filter.h"
7 #include "InvalidFilter.h"
8 #include "ActiveFilter.h"
9 #include "RegExpFilter.h"
10 #include "ElemHideBase.h"
11 #include "CSSPropertyFilter.h"
12 #include "String.h"
13
14 #define DO_PRAGMA(pragma) _Pragma(#pragma)
15 #define INSERT_MESSAGE(m) DO_PRAGMA(comment(m))
16
17 #define CLASS(name) \
18 extern "C"\
19 INSERT_MESSAGE(class name)
20
21 #define AUGMENTS(name) INSERT_MESSAGE(augments name)
22 #define CLASS_INIT(func) INSERT_MESSAGE(class_init func)
23
24 #define METHOD(name, impl) INSERT_MESSAGE(method name impl)
25 #define CLASS_METHOD(name, impl) INSERT_MESSAGE(class_method name impl)
26 #define STRING_ARG(pos) INSERT_MESSAGE(string_arg pos)
27 #define RETURNS_STRING INSERT_MESSAGE(string_result)
28 #define RETURNS_POINTER(cls) INSERT_MESSAGE(pointer_result cls)
29
30 #define READONLY_PROPERTY(name, getter) INSERT_MESSAGE(property name getter)
31 #define PROPERTY(name, getter, setter) INSERT_MESSAGE(property name getter sette r)
32 #define READONLY_STRING_PROPERTY(name, getter) INSERT_MESSAGE(string_property na me getter)
33 #define STRING_PROPERTY(name, getter, setter) INSERT_MESSAGE(string_property nam e getter setter)
34 #define STATIC_PROPERTY(name, value) INSERT_MESSAGE(static_property name value)
35
36 #define DIFFERENTIATOR(cls, func) INSERT_MESSAGE(differentiator cls func)
37 #define ASSOCIATE(value, cls) INSERT_MESSAGE(differentiator_mapping value cls)
38
39 #if defined(__EMSCRIPTEN_TRACING__)
40 struct InitTracing
41 {
42 InitTracing()
43 {
44 emscripten_trace_configure("http://127.0.0.1:5000/", "MyApplication");
45 }
46
47 ~InitTracing()
48 {
49 emscripten_trace_close();
50 }
51 };
52
53 InitTracing foo;
54 #endif
55
56 #define EXPOSE_FILTER_PROPERTY(class, type, name, getter, setter) \
57 type EMSCRIPTEN_KEEPALIVE class##_##getter(const class* filter)\
58 {\
59 return filter->getter();\
60 }\
61 void EMSCRIPTEN_KEEPALIVE class##_##setter(\
62 class* filter, type value)\
63 {\
64 filter->setter(value);\
65 }\
66 PROPERTY(name, class##_##getter, class##_##setter)
67
68 #pragma clang diagnostic push
69 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
70
71 extern "C"
72 {
73 size_t EMSCRIPTEN_KEEPALIVE GetSizeofString()
74 {
75 return sizeof(String);
76 }
77
78 void EMSCRIPTEN_KEEPALIVE InitString(String* str, String::value_type* data,
79 String::size_type len)
80 {
81 // String is already allocated on stack, we merely need to call constructor.
82 new (str) String(data, len);
83 }
84
85 void EMSCRIPTEN_KEEPALIVE DestroyString(String* str)
86 {
87 // Stack memory will be freed automatically, we need to call destructor
88 // explicitly however.
89 str->~String();
90 }
91
92 String::size_type EMSCRIPTEN_KEEPALIVE GetStringLength(const String& str)
93 {
94 return str.length();
95 }
96
97 const String::value_type* EMSCRIPTEN_KEEPALIVE GetStringData(const String& str )
98 {
99 return str.data();
100 }
101
102 void EMSCRIPTEN_KEEPALIVE DeletePointer(Filter* ptr)
103 {
104 ptr->ReleaseRef();
105 }
106 }
107
108 DIFFERENTIATOR(Filter, Filter_GetType)
109 ASSOCIATE(1, InvalidFilter)
110 ASSOCIATE(2, CommentFilter)
111 ASSOCIATE(3, RegExpFilter)
112 ASSOCIATE(4, WhitelistFilter)
113 ASSOCIATE(5, ElemHideFilter)
114 ASSOCIATE(6, ElemHideException)
115 ASSOCIATE(7, CSSPropertyFilter)
116
117 CLASS(Filter)
118 {
119 String EMSCRIPTEN_KEEPALIVE Filter_GetText(const Filter* filter)
120 {
121 return filter->GetText();
122 }
123 READONLY_STRING_PROPERTY(text, Filter_GetText)
124
125 Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const Filter* filter)
126 {
127 return filter->GetType();
128 }
129
130 String EMSCRIPTEN_KEEPALIVE Filter_Serialize(const Filter* filter)
131 {
132 return filter->Serialize();
133 }
134 METHOD(serialize, Filter_Serialize) RETURNS_STRING
135
136 Filter* EMSCRIPTEN_KEEPALIVE Filter_FromText(String& text)
137 {
138 Filter* filter = Filter::FromText(text);
139 filter->AddRef();
140 return filter;
141 }
142 CLASS_METHOD(fromText, Filter_FromText) STRING_ARG(0) RETURNS_POINTER(Filter)
143
144 String EMSCRIPTEN_KEEPALIVE Filter_Normalize(String& text)
145 {
146 return Filter::Normalize(text);
147 }
148 CLASS_METHOD(normalize, Filter_Normalize) STRING_ARG(0) RETURNS_STRING
149 }
150
151 CLASS(InvalidFilter)
152 {
153 AUGMENTS(Filter)
154 STATIC_PROPERTY(type, "invalid")
155
156 String EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const InvalidFilter* filte r)
157 {
158 return filter->GetReason();
159 }
160 READONLY_STRING_PROPERTY(reason, InvalidFilter_GetReason)
161 }
162
163 CLASS(CommentFilter)
164 {
165 AUGMENTS(Filter)
166 STATIC_PROPERTY(type, "comment")
167 }
168
169 CLASS(ActiveFilter)
170 {
171 AUGMENTS(Filter)
172
173 EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, disabled, GetDisabled, SetDisabled) ;
174 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, hitCount, GetHitCount, SetH itCount);
175 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, lastHit, GetLastHit, SetLas tHit);
176
177 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnDomain(
178 const ActiveFilter* filter, String& domain, String& sitekey)
179 {
180 return filter->IsActiveOnDomain(domain, sitekey);
181 }
182 METHOD(isActiveOnDomain, ActiveFilter_IsActiveOnDomain) STRING_ARG(0) STRING_A RG(1)
183
184 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnlyOnDomain(
185 const ActiveFilter* filter, String& domain)
186 {
187 return filter->IsActiveOnlyOnDomain(domain);
188 }
189 METHOD(isActiveOnlyOnDomain, ActiveFilter_IsActiveOnlyOnDomain) STRING_ARG(0)
190
191 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsGeneric(const ActiveFilter* filter)
192 {
193 return filter->IsGeneric();
194 }
195 METHOD(isGeneric, ActiveFilter_IsGeneric)
196 }
197
198 CLASS(RegExpFilter)
199 {
200 AUGMENTS(ActiveFilter)
201 STATIC_PROPERTY(type, "blocking")
202
203 bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const RegExpFilter* filter,
204 String& location, int typeMask, String& docDomain, bool thirdParty,
205 String& sitekey)
206 {
207 return filter->Matches(location, typeMask, docDomain, thirdParty, sitekey);
208 }
209 METHOD(matches, RegExpFilter_Matches) STRING_ARG(0) STRING_ARG(2) STRING_ARG(4 )
210
211 void EMSCRIPTEN_KEEPALIVE RegExpFilter_InitJSTypes()
212 {
213 RegExpFilter::InitJSTypes();
214 }
215 CLASS_INIT(RegExpFilter_InitJSTypes)
216 }
217
218 CLASS(WhitelistFilter)
219 {
220 AUGMENTS(RegExpFilter)
221 STATIC_PROPERTY(type, "whitelist")
222 }
223
224 CLASS(ElemHideBase)
225 {
226 AUGMENTS(ActiveFilter)
227
228 String EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelector(
229 const ElemHideBase* filter)
230 {
231 return filter->GetSelector();
232 }
233 READONLY_STRING_PROPERTY(selector, ElemHideBase_GetSelector)
234
235 String EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelectorDomain(
236 const ElemHideBase* filter)
237 {
238 return filter->GetSelectorDomain();
239 }
240 READONLY_STRING_PROPERTY(selectorDomain, ElemHideBase_GetSelectorDomain)
241 }
242
243 CLASS(ElemHideFilter)
244 {
245 AUGMENTS(ElemHideBase)
246 STATIC_PROPERTY(type, "elemhide")
247 }
248
249 CLASS(ElemHideException)
250 {
251 AUGMENTS(ElemHideBase)
252 STATIC_PROPERTY(type, "elemhideexception")
253 }
254
255 CLASS(CSSPropertyFilter)
256 {
257 AUGMENTS(ElemHideBase)
258 STATIC_PROPERTY(type, "cssproperty")
259
260 String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetRegExpString(
261 const CSSPropertyFilter* filter)
262 {
263 return filter->GetRegExpString();
264 }
265 READONLY_STRING_PROPERTY(regexpString, CSSPropertyFilter_GetRegExpString)
266
267 String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorPrefix(
268 const CSSPropertyFilter* filter)
269 {
270 return filter->GetSelectorPrefix();
271 }
272 READONLY_STRING_PROPERTY(selectorPrefix, CSSPropertyFilter_GetSelectorPrefix)
273
274 String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorSuffix(
275 const CSSPropertyFilter* filter)
276 {
277 return filter->GetSelectorSuffix();
278 }
279 READONLY_STRING_PROPERTY(selectorSuffix, CSSPropertyFilter_GetSelectorSuffix)
280 }
281
282 #pragma clang diagnostic pop
OLDNEW
« no previous file with comments | « compiled/api.h ('k') | compiled/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld