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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 10254076: API cleanup, get rid of JsObject and GetProperty() methods that don`t return JsValue (Closed)
Left Patch Set: Created April 26, 2013, 11:41 a.m.
Right Patch Set: Slightly better Filter/Subscription constructors Created April 26, 2013, 11:51 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 | « shell/src/SubscriptionsCommand.cpp ('k') | src/JsValue.cpp » ('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 #include <algorithm> 1 #include <algorithm>
2 #include <cctype> 2 #include <cctype>
3 #include <functional> 3 #include <functional>
4 4
5 #include <AdblockPlus.h> 5 #include <AdblockPlus.h>
6 6
7 using namespace AdblockPlus; 7 using namespace AdblockPlus;
8 8
9 extern const char* jsSources[]; 9 extern const char* jsSources[];
10 10
11 Filter::Filter(JsValuePtr value) 11 Filter::Filter(JsValuePtr value)
12 : JsValue(value->jsEngine, value->value) 12 : JsValue(value)
13 { 13 {
14 if (!IsObject()) 14 if (!IsObject())
15 throw std::runtime_error("JavaScript value is not an object"); 15 throw std::runtime_error("JavaScript value is not an object");
16 } 16 }
17 17
18 Filter::Type Filter::GetType() 18 Filter::Type Filter::GetType()
19 { 19 {
20 std::string className = GetClassName(); 20 std::string className = GetClassName();
21 if (className == "BlockingFilter") 21 if (className == "BlockingFilter")
22 return TYPE_BLOCKING; 22 return TYPE_BLOCKING;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 params.push_back(shared_from_this()); 55 params.push_back(shared_from_this());
56 func->Call(params); 56 func->Call(params);
57 } 57 }
58 58
59 bool Filter::operator==(const Filter& filter) const 59 bool Filter::operator==(const Filter& filter) const
60 { 60 {
61 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString (); 61 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString ();
62 } 62 }
63 63
64 Subscription::Subscription(JsValuePtr value) 64 Subscription::Subscription(JsValuePtr value)
65 : JsValue(value->jsEngine, value->value) 65 : JsValue(value)
66 { 66 {
67 if (!IsObject()) 67 if (!IsObject())
68 throw std::runtime_error("JavaScript value is not an object"); 68 throw std::runtime_error("JavaScript value is not an object");
69 } 69 }
70 70
71 bool Subscription::IsListed() 71 bool Subscription::IsListed()
72 { 72 {
73 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); 73 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter");
74 JsValueList params; 74 JsValueList params;
75 params.push_back(shared_from_this()); 75 params.push_back(shared_from_this());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 { 186 {
187 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 187 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
188 JsValueList params; 188 JsValueList params;
189 params.push_back(jsEngine->NewValue(domain)); 189 params.push_back(jsEngine->NewValue(domain));
190 JsValueList result = func->Call(params)->AsList(); 190 JsValueList result = func->Call(params)->AsList();
191 std::vector<std::string> selectors; 191 std::vector<std::string> selectors;
192 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 192 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
193 selectors.push_back((*it)->AsString()); 193 selectors.push_back((*it)->AsString());
194 return selectors; 194 return selectors;
195 } 195 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld