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

Side by Side Diff: compiled/bindings/main.cpp

Issue 29410617: Issue 5131 - [emscripten] Clean separation of bindings code and runtime code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Rebased Created April 13, 2017, 1:08 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/bindings/generator.cpp ('k') | compiled/bindings/runtime_utils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "bindings.ipp" 18 #include <exception>
19 #include "filter/Filter.h" 19 #include <emscripten.h>
20 #include "filter/InvalidFilter.h"
21 #include "filter/CommentFilter.h"
22 #include "filter/ActiveFilter.h"
23 #include "filter/RegExpFilter.h"
24 #include "filter/BlockingFilter.h"
25 #include "filter/WhitelistFilter.h"
26 #include "filter/ElemHideBase.h"
27 #include "filter/ElemHideFilter.h"
28 #include "filter/ElemHideException.h"
29 #include "filter/ElemHideEmulationFilter.h"
30 #include "subscription/Subscription.h"
31 #include "subscription/DownloadableSubscription.h"
32 #include "subscription/UserDefinedSubscription.h"
33 #include "FilterNotifier.h"
34 20
35 EMSCRIPTEN_BINDINGS 21 #include "generator.h"
22 #include "../filter/Filter.h"
23 #include "../filter/InvalidFilter.h"
24 #include "../filter/CommentFilter.h"
25 #include "../filter/ActiveFilter.h"
26 #include "../filter/RegExpFilter.h"
27 #include "../filter/BlockingFilter.h"
28 #include "../filter/WhitelistFilter.h"
29 #include "../filter/ElemHideBase.h"
30 #include "../filter/ElemHideFilter.h"
31 #include "../filter/ElemHideException.h"
32 #include "../filter/ElemHideEmulationFilter.h"
33 #include "../subscription/Subscription.h"
34 #include "../subscription/DownloadableSubscription.h"
35 #include "../subscription/UserDefinedSubscription.h"
36 #include "../FilterNotifier.h"
37
38 int main()
36 { 39 {
37 class_<Filter>("Filter") 40 try
38 .property("text", &Filter::GetText) 41 {
39 .function("serialize", &Filter::Serialize) 42 class_<Filter>("Filter")
40 .class_function("fromText", &Filter::FromText) 43 .property("text", &Filter::GetText)
41 .subclass_differentiator(&Filter::mType, { 44 .function("serialize", &Filter::Serialize)
42 {Filter::Type::INVALID, "InvalidFilter"}, 45 .class_function("fromText", &Filter::FromText)
43 {Filter::Type::COMMENT, "CommentFilter"}, 46 .subclass_differentiator(&Filter::mType, {
44 {Filter::Type::BLOCKING, "BlockingFilter"}, 47 {Filter::Type::INVALID, "InvalidFilter"},
45 {Filter::Type::WHITELIST, "WhitelistFilter"}, 48 {Filter::Type::COMMENT, "CommentFilter"},
46 {Filter::Type::ELEMHIDE, "ElemHideFilter"}, 49 {Filter::Type::BLOCKING, "BlockingFilter"},
47 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"}, 50 {Filter::Type::WHITELIST, "WhitelistFilter"},
48 {Filter::Type::ELEMHIDEEMULATION, "ElemHideEmulationFilter"}, 51 {Filter::Type::ELEMHIDE, "ElemHideFilter"},
49 }); 52 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"},
53 {Filter::Type::ELEMHIDEEMULATION, "ElemHideEmulationFilter"},
54 });
50 55
51 class_<InvalidFilter,Filter>("InvalidFilter") 56 class_<InvalidFilter,Filter>("InvalidFilter")
52 .class_property("type", "'invalid'") 57 .class_property("type", "'invalid'")
53 .property("reason", &InvalidFilter::GetReason); 58 .property("reason", &InvalidFilter::GetReason);
54 59
55 class_<CommentFilter,Filter>("CommentFilter") 60 class_<CommentFilter,Filter>("CommentFilter")
56 .class_property("type", "'comment'"); 61 .class_property("type", "'comment'");
57 62
58 class_<ActiveFilter,Filter>("ActiveFilter") 63 class_<ActiveFilter,Filter>("ActiveFilter")
59 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabl ed) 64 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisa bled)
60 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCou nt) 65 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitC ount)
61 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit) 66 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHi t)
62 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain) 67 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain)
63 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain) 68 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain)
64 .function("isGeneric", &ActiveFilter::IsGeneric) 69 .function("isGeneric", &ActiveFilter::IsGeneric)
65 .function("serialize", &ActiveFilter::Serialize); 70 .function("serialize", &ActiveFilter::Serialize);
66 71
67 class_<RegExpFilter,ActiveFilter>("RegExpFilter") 72 class_<RegExpFilter,ActiveFilter>("RegExpFilter")
68 .function("matches", &RegExpFilter::Matches); 73 .function("matches", &RegExpFilter::Matches);
69 74
70 custom_generator(&RegExpFilter::GenerateCustomBindings); 75 custom_generator(&RegExpFilter::GenerateCustomBindings);
71 76
72 class_<BlockingFilter,RegExpFilter>("BlockingFilter") 77 class_<BlockingFilter,RegExpFilter>("BlockingFilter")
73 .class_property("type", "'blocking'"); 78 .class_property("type", "'blocking'");
74 79
75 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter") 80 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter")
76 .class_property("type", "'whitelist'"); 81 .class_property("type", "'whitelist'");
77 82
78 class_<ElemHideBase,ActiveFilter>("ElemHideBase") 83 class_<ElemHideBase,ActiveFilter>("ElemHideBase")
79 .property("selector", &ElemHideBase::GetSelector) 84 .property("selector", &ElemHideBase::GetSelector)
80 .property("selectorDomain", &ElemHideBase::GetSelectorDomain); 85 .property("selectorDomain", &ElemHideBase::GetSelectorDomain);
81 86
82 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter") 87 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter")
83 .class_property("type", "'elemhide'"); 88 .class_property("type", "'elemhide'");
84 89
85 class_<ElemHideException,ElemHideBase>("ElemHideException") 90 class_<ElemHideException,ElemHideBase>("ElemHideException")
86 .class_property("type", "'elemhideexception'"); 91 .class_property("type", "'elemhideexception'");
87 92
88 class_<ElemHideEmulationFilter,ElemHideBase>("ElemHideEmulationFilter") 93 class_<ElemHideEmulationFilter,ElemHideBase>("ElemHideEmulationFilter")
89 .class_property("type", "'elemhideemulation'"); 94 .class_property("type", "'elemhideemulation'");
90 95
91 class_<Subscription>("Subscription") 96 class_<Subscription>("Subscription")
92 .property("url", &Subscription::GetID) 97 .property("url", &Subscription::GetID)
93 .property("title", &Subscription::GetTitle, &Subscription::SetTitle) 98 .property("title", &Subscription::GetTitle, &Subscription::SetTitle)
94 .property("disabled", &Subscription::GetDisabled, &Subscription::SetDisabl ed) 99 .property("disabled", &Subscription::GetDisabled, &Subscription::SetDisa bled)
95 .property("filterCount", &Subscription::GetFilterCount) 100 .property("filterCount", &Subscription::GetFilterCount)
96 .function("filterAt", &Subscription::FilterAt) 101 .function("filterAt", &Subscription::FilterAt)
97 .function("indexOfFilter", &Subscription::IndexOfFilter) 102 .function("indexOfFilter", &Subscription::IndexOfFilter)
98 .function("serialize", &Subscription::Serialize) 103 .function("serialize", &Subscription::Serialize)
99 .function("serializeFilters", &Subscription::SerializeFilters) 104 .function("serializeFilters", &Subscription::SerializeFilters)
100 .class_function("fromURL", &Subscription::FromID) 105 .class_function("fromURL", &Subscription::FromID)
101 .subclass_differentiator(&Subscription::mType, { 106 .subclass_differentiator(&Subscription::mType, {
102 {Subscription::Type::USERDEFINED, "SpecialSubscription"}, 107 {Subscription::Type::USERDEFINED, "SpecialSubscription"},
103 {Subscription::Type::DOWNLOADABLE, "DownloadableSubscription"}, 108 {Subscription::Type::DOWNLOADABLE, "DownloadableSubscription"},
104 }); 109 });
105 110
106 class_<UserDefinedSubscription,Subscription>("SpecialSubscription") 111 class_<UserDefinedSubscription,Subscription>("SpecialSubscription")
107 .function("isDefaultFor", &UserDefinedSubscription::IsDefaultFor) 112 .function("isDefaultFor", &UserDefinedSubscription::IsDefaultFor)
108 .function("makeDefaultFor", &UserDefinedSubscription::MakeDefaultFor) 113 .function("makeDefaultFor", &UserDefinedSubscription::MakeDefaultFor)
109 .function("insertFilterAt", &UserDefinedSubscription::InsertFilterAt) 114 .function("insertFilterAt", &UserDefinedSubscription::InsertFilterAt)
110 .function("removeFilterAt", &UserDefinedSubscription::RemoveFilterAt) 115 .function("removeFilterAt", &UserDefinedSubscription::RemoveFilterAt)
111 .function("serialize", &UserDefinedSubscription::Serialize); 116 .function("serialize", &UserDefinedSubscription::Serialize);
112 117
113 class_<DownloadableSubscription,Subscription>("DownloadableSubscription") 118 class_<DownloadableSubscription,Subscription>("DownloadableSubscription")
114 .property("fixedTitle", &DownloadableSubscription::GetFixedTitle, &Downloa dableSubscription::SetFixedTitle) 119 .property("fixedTitle", &DownloadableSubscription::GetFixedTitle, &Downl oadableSubscription::SetFixedTitle)
115 .property("homepage", &DownloadableSubscription::GetHomepage, &Downloadabl eSubscription::SetHomepage) 120 .property("homepage", &DownloadableSubscription::GetHomepage, &Downloada bleSubscription::SetHomepage)
116 .property("lastCheck", &DownloadableSubscription::GetLastCheck, &Downloada bleSubscription::SetLastCheck) 121 .property("lastCheck", &DownloadableSubscription::GetLastCheck, &Downloa dableSubscription::SetLastCheck)
117 .property("expires", &DownloadableSubscription::GetHardExpiration, &Downlo adableSubscription::SetHardExpiration) 122 .property("expires", &DownloadableSubscription::GetHardExpiration, &Down loadableSubscription::SetHardExpiration)
118 .property("softExpiration", &DownloadableSubscription::GetSoftExpiration, &DownloadableSubscription::SetSoftExpiration) 123 .property("softExpiration", &DownloadableSubscription::GetSoftExpiration , &DownloadableSubscription::SetSoftExpiration)
119 .property("lastDownload", &DownloadableSubscription::GetLastDownload, &Dow nloadableSubscription::SetLastDownload) 124 .property("lastDownload", &DownloadableSubscription::GetLastDownload, &D ownloadableSubscription::SetLastDownload)
120 .property("downloadStatus", &DownloadableSubscription::GetDownloadStatus, &DownloadableSubscription::SetDownloadStatus) 125 .property("downloadStatus", &DownloadableSubscription::GetDownloadStatus , &DownloadableSubscription::SetDownloadStatus)
121 .property("lastSuccess", &DownloadableSubscription::GetLastSuccess, &Downl oadableSubscription::SetLastSuccess) 126 .property("lastSuccess", &DownloadableSubscription::GetLastSuccess, &Dow nloadableSubscription::SetLastSuccess)
122 .property("errors", &DownloadableSubscription::GetErrorCount, &Downloadabl eSubscription::SetErrorCount) 127 .property("errors", &DownloadableSubscription::GetErrorCount, &Downloada bleSubscription::SetErrorCount)
123 .property("version", &DownloadableSubscription::GetDataRevision, &Download ableSubscription::SetDataRevision) 128 .property("version", &DownloadableSubscription::GetDataRevision, &Downlo adableSubscription::SetDataRevision)
124 .property("requiredVersion", &DownloadableSubscription::GetRequiredVersion , &DownloadableSubscription::SetRequiredVersion) 129 .property("requiredVersion", &DownloadableSubscription::GetRequiredVersi on, &DownloadableSubscription::SetRequiredVersion)
125 .property("downloadCount", &DownloadableSubscription::GetDownloadCount, &D ownloadableSubscription::SetDownloadCount) 130 .property("downloadCount", &DownloadableSubscription::GetDownloadCount, &DownloadableSubscription::SetDownloadCount)
126 .function("serialize", &DownloadableSubscription::Serialize); 131 .function("serialize", &DownloadableSubscription::Serialize);
127 132
128 custom_generator(&FilterNotifier::GenerateCustomBindings); 133 custom_generator(&FilterNotifier::GenerateCustomBindings);
134
135 printBindings();
136 return 0;
137 }
138 catch (const std::exception& e)
139 {
140 EM_ASM_ARGS(
141 console.error("Error occurred generating JavaScript bindings: " +
142 Module.AsciiToString($0)), e.what()
143 );
144 return 1;
145 }
129 } 146 }
OLDNEW
« no previous file with comments | « compiled/bindings/generator.cpp ('k') | compiled/bindings/runtime_utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld