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

Side by Side Diff: src/FilterEngine.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Patch Set: address comments Created Nov. 25, 2016, 12:02 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
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 else if (className == "ElemHideException") 47 else if (className == "ElemHideException")
48 return TYPE_ELEMHIDE_EXCEPTION; 48 return TYPE_ELEMHIDE_EXCEPTION;
49 else if (className == "CommentFilter") 49 else if (className == "CommentFilter")
50 return TYPE_COMMENT; 50 return TYPE_COMMENT;
51 else 51 else
52 return TYPE_INVALID; 52 return TYPE_INVALID;
53 } 53 }
54 54
55 bool Filter::IsListed() 55 bool Filter::IsListed()
56 { 56 {
57 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); 57 JsContext context(jsEngine);
58 JsValuePtr func = context.GetJsEngine().Evaluate("API.isListedFilter");
58 JsValueList params; 59 JsValueList params;
59 params.push_back(shared_from_this()); 60 params.push_back(shared_from_this());
60 return func->Call(params)->AsBool(); 61 return func->Call(params)->AsBool();
61 } 62 }
62 63
63 void Filter::AddToList() 64 void Filter::AddToList()
64 { 65 {
65 JsValuePtr func = jsEngine->Evaluate("API.addFilterToList"); 66 JsContext context(jsEngine);
67 JsValuePtr func = context.GetJsEngine().Evaluate("API.addFilterToList");
66 JsValueList params; 68 JsValueList params;
67 params.push_back(shared_from_this()); 69 params.push_back(shared_from_this());
68 func->Call(params); 70 func->Call(params);
69 } 71 }
70 72
71 void Filter::RemoveFromList() 73 void Filter::RemoveFromList()
72 { 74 {
73 JsValuePtr func = jsEngine->Evaluate("API.removeFilterFromList"); 75 JsContext context(jsEngine);
76 JsValuePtr func = context.GetJsEngine().Evaluate("API.removeFilterFromList");
74 JsValueList params; 77 JsValueList params;
75 params.push_back(shared_from_this()); 78 params.push_back(shared_from_this());
76 func->Call(params); 79 func->Call(params);
77 } 80 }
78 81
79 bool Filter::operator==(const Filter& filter) const 82 bool Filter::operator==(const Filter& filter) const
80 { 83 {
81 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString (); 84 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString ();
82 } 85 }
83 86
84 Subscription::Subscription(JsValue&& value) 87 Subscription::Subscription(JsValue&& value)
85 : JsValue(std::move(value)) 88 : JsValue(std::move(value))
86 { 89 {
87 if (!IsObject()) 90 if (!IsObject())
88 throw std::runtime_error("JavaScript value is not an object"); 91 throw std::runtime_error("JavaScript value is not an object");
89 } 92 }
90 93
91 bool Subscription::IsListed() 94 bool Subscription::IsListed()
92 { 95 {
93 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); 96 JsContext context(jsEngine);
97 JsValuePtr func = context.GetJsEngine().Evaluate("API.isListedSubscription");
94 JsValueList params; 98 JsValueList params;
95 params.push_back(shared_from_this()); 99 params.push_back(shared_from_this());
96 return func->Call(params)->AsBool(); 100 return func->Call(params)->AsBool();
97 } 101 }
98 102
99 void Subscription::AddToList() 103 void Subscription::AddToList()
100 { 104 {
101 JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList"); 105 JsContext context(jsEngine);
106 JsValuePtr func = context.GetJsEngine().Evaluate("API.addSubscriptionToList");
102 JsValueList params; 107 JsValueList params;
103 params.push_back(shared_from_this()); 108 params.push_back(shared_from_this());
104 func->Call(params); 109 func->Call(params);
105 } 110 }
106 111
107 void Subscription::RemoveFromList() 112 void Subscription::RemoveFromList()
108 { 113 {
109 JsValuePtr func = jsEngine->Evaluate("API.removeSubscriptionFromList"); 114 JsContext context(jsEngine);
115 JsValuePtr func = context.GetJsEngine().Evaluate("API.removeSubscriptionFromLi st");
110 JsValueList params; 116 JsValueList params;
111 params.push_back(shared_from_this()); 117 params.push_back(shared_from_this());
112 func->Call(params); 118 func->Call(params);
113 } 119 }
114 120
115 void Subscription::UpdateFilters() 121 void Subscription::UpdateFilters()
116 { 122 {
117 JsValuePtr func = jsEngine->Evaluate("API.updateSubscription"); 123 JsContext context(jsEngine);
124 JsValuePtr func = context.GetJsEngine().Evaluate("API.updateSubscription");
118 JsValueList params; 125 JsValueList params;
119 params.push_back(shared_from_this()); 126 params.push_back(shared_from_this());
120 func->Call(params); 127 func->Call(params);
121 } 128 }
122 129
123 bool Subscription::IsUpdating() 130 bool Subscription::IsUpdating()
124 { 131 {
125 JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating"); 132 JsContext context(jsEngine);
133 JsValuePtr func = context.GetJsEngine().Evaluate("API.isSubscriptionUpdating") ;
126 JsValueList params; 134 JsValueList params;
127 params.push_back(shared_from_this()); 135 params.push_back(shared_from_this());
128 JsValuePtr result = func->Call(params); 136 JsValuePtr result = func->Call(params);
129 return result->AsBool(); 137 return result->AsBool();
130 } 138 }
131 139
132 bool Subscription::operator==(const Subscription& subscription) const 140 bool Subscription::operator==(const Subscription& subscription) const
133 { 141 {
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); 142 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring();
135 } 143 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 514 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
507 if (filter) 515 if (filter)
508 { 516 {
509 return filter; 517 return filter;
510 } 518 }
511 currentUrl = parentUrl; 519 currentUrl = parentUrl;
512 } 520 }
513 while (urlIterator != documentUrls.end()); 521 while (urlIterator != documentUrls.end());
514 return FilterPtr(); 522 return FilterPtr();
515 } 523 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsContext.h » ('j') | src/JsValue.cpp » ('J')

Powered by Google App Engine
This is Rietveld