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

Side by Side Diff: compiled/bindings.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Reworked JS binding generation Created Feb. 1, 2016, 9:14 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
OLDNEW
(Empty)
1 #include <emscripten.h>
2
3 #include "bindings.h"
4 #include "String.h"
5 #include "intrusive_ptr.h"
6 #include "Filter.h"
7 #include "InvalidFilter.h"
8 #include "CommentFilter.h"
9 #include "ActiveFilter.h"
10 #include "RegExpFilter.h"
11 #include "WhitelistFilter.h"
12 #include "ElemHideBase.h"
13 #include "ElemHideFilter.h"
14 #include "ElemHideException.h"
15 #include "CSSPropertyFilter.h"
16
17 extern "C"
18 {
19 void EMSCRIPTEN_KEEPALIVE InitString(String* str, String::value_type* data,
20 String::size_type len)
21 {
22 // String is already allocated on stack, we merely need to call constructor.
23 new (str) String(data, len);
24 }
25
26 void EMSCRIPTEN_KEEPALIVE DestroyString(String* str)
27 {
28 // Stack memory will be freed automatically, we need to call destructor
29 // explicitly however.
30 str->~String();
31 }
32
33 String::size_type EMSCRIPTEN_KEEPALIVE GetStringLength(const String& str)
34 {
35 return str.length();
36 }
37
38 const String::value_type* EMSCRIPTEN_KEEPALIVE GetStringData(const String& str )
39 {
40 return str.data();
41 }
42
43 void EMSCRIPTEN_KEEPALIVE AddRef(ref_counted* ptr)
44 {
45 ptr->AddRef();
46 }
47
48 void EMSCRIPTEN_KEEPALIVE ReleaseRef(ref_counted* ptr)
49 {
50 ptr->ReleaseRef();
51 }
52 }
53
54 #if defined(PRINT_BINDINGS)
55 EMSCRIPTEN_BINDINGS(api)
56 {
57 class_<Filter>("Filter")
58 .property("text", &Filter::GetText)
59 .function("serialize", &Filter::Serialize)
60 .class_function("fromText", &Filter::FromText)
61 .class_function("normalize", &Filter::Normalize)
62 .subclass_differentiator(&Filter::GetType, {
63 {Filter::Type::INVALID, "InvalidFilter"},
64 {Filter::Type::COMMENT, "CommentFilter"},
65 {Filter::Type::BLOCKING, "RegExpFilter"},
66 {Filter::Type::WHITELIST, "WhitelistFilter"},
67 {Filter::Type::ELEMHIDE, "ElemHideFilter"},
68 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"},
69 {Filter::Type::CSSPROPERTY, "CSSPropertyFilter"},
70 });
71
72 class_<InvalidFilter,Filter>("InvalidFilter")
73 .class_property("type", "'invalid'")
74 .property("reason", &InvalidFilter::GetReason);
75
76 class_<CommentFilter,Filter>("CommentFilter")
77 .class_property("type", "'comment'");
78
79 class_<ActiveFilter,Filter>("ActiveFilter")
80 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabl ed)
81 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCou nt)
82 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit)
83 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain)
84 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain)
85 .function("isGeneric", &ActiveFilter::IsGeneric)
86 .function("serialize", &ActiveFilter::Serialize);
87
88 class_<RegExpFilter,ActiveFilter>("RegExpFilter")
89 .class_property("type", "'blocking'")
90 .function("matches", &RegExpFilter::Matches)
91 .class_initializer(&RegExpFilter::InitJSTypes);
92
93 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter")
94 .class_property("type", "'whitelist'");
95
96 class_<ElemHideBase,ActiveFilter>("ElemHideBase")
97 .property("selector", &ElemHideBase::GetSelector)
98 .property("selectorDomain", &ElemHideBase::GetSelectorDomain);
99
100 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter")
101 .class_property("type", "'elemhide'");
102
103 class_<ElemHideException,ElemHideBase>("ElemHideException")
104 .class_property("type", "'elemhideexception'");
105
106 class_<CSSPropertyFilter,ElemHideBase>("CSSPropertyFilter")
107 .class_property("type", "'cssproperty'")
108 .property("regexpString", &CSSPropertyFilter::GetRegExpString)
109 .property("selectorPrefix", &CSSPropertyFilter::GetSelectorPrefix)
110 .property("selectorSuffix", &CSSPropertyFilter::GetSelectorSuffix);
111 }
112 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld