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

Side by Side Diff: src/JsEngine.cpp

Issue 29408747: Issue 5013 - Mark more method as const (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 10, 2017, 3: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
« include/AdblockPlus/JsEngine.h ('K') | « src/FilterEngine.cpp ('k') | no next file » | 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
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 JsConstValueList callbackArgs; 119 JsConstValueList callbackArgs;
120 for (int i = 2; i < timerTaskIterator->arguments.size(); i++) 120 for (int i = 2; i < timerTaskIterator->arguments.size(); i++)
121 callbackArgs.emplace_back(new JsValue(shared_from_this(), 121 callbackArgs.emplace_back(new JsValue(shared_from_this(),
122 v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i]))); 122 v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i])));
123 callback.Call(callbackArgs); 123 callback.Call(callbackArgs);
124 timerTasks.erase(timerTaskIterator); 124 timerTasks.erase(timerTaskIterator);
125 } 125 }
126 126
127 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr time r) 127 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr time r)
128 : isolate(isolate) 128 : isolate(isolate)
129 , fileSystem(new DefaultFileSystem())
130 , webRequest(new DefaultWebRequest())
131 , logSystem(new DefaultLogSystem())
129 , timer(std::move(timer)) 132 , timer(std::move(timer))
130 { 133 {
131 } 134 }
132 135
133 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, 136 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
134 TimerPtr timer, 137 TimerPtr timer,
135 const ScopedV8IsolatePtr& isolate) 138 const ScopedV8IsolatePtr& isolate)
136 { 139 {
137 JsEnginePtr result(new JsEngine(isolate, std::move(timer))); 140 JsEnginePtr result(new JsEngine(isolate, std::move(timer)));
138 141
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 258
256 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum ents& arguments) 259 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum ents& arguments)
257 { 260 {
258 const JsContext context(shared_from_this()); 261 const JsContext context(shared_from_this());
259 JsValueList list; 262 JsValueList list;
260 for (int i = 0; i < arguments.Length(); i++) 263 for (int i = 0; i < arguments.Length(); i++)
261 list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); 264 list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i])));
262 return list; 265 return list;
263 } 266 }
264 267
265 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() 268 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const
266 { 269 {
267 if (!fileSystem)
268 fileSystem.reset(new DefaultFileSystem());
269 return fileSystem; 270 return fileSystem;
270 } 271 }
271 272
272 void AdblockPlus::JsEngine::SetFileSystem(AdblockPlus::FileSystemPtr val) 273 void AdblockPlus::JsEngine::SetFileSystem(AdblockPlus::FileSystemPtr val)
273 { 274 {
274 if (!val) 275 if (!val)
275 throw std::runtime_error("FileSystem cannot be null"); 276 throw std::runtime_error("FileSystem cannot be null");
276 277
277 fileSystem = val; 278 fileSystem = val;
278 } 279 }
279 280
280 AdblockPlus::WebRequestPtr AdblockPlus::JsEngine::GetWebRequest() 281 AdblockPlus::WebRequestPtr AdblockPlus::JsEngine::GetWebRequest() const
281 { 282 {
282 if (!webRequest)
283 webRequest.reset(new DefaultWebRequest());
284 return webRequest; 283 return webRequest;
285 } 284 }
286 285
287 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val) 286 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val)
288 { 287 {
289 if (!val) 288 if (!val)
290 throw std::runtime_error("WebRequest cannot be null"); 289 throw std::runtime_error("WebRequest cannot be null");
291 290
292 webRequest = val; 291 webRequest = val;
293 } 292 }
294 293
295 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll owedCallback& callback) 294 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll owedCallback& callback)
296 { 295 {
297 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex); 296 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
298 isConnectionAllowed = callback; 297 isConnectionAllowed = callback;
299 } 298 }
300 299
301 bool AdblockPlus::JsEngine::IsConnectionAllowed() 300 bool AdblockPlus::JsEngine::IsConnectionAllowed() const
302 { 301 {
303 // The call of isConnectionAllowed can be very expensive and it makes a 302 // The call of isConnectionAllowed can be very expensive and it makes a
304 // little sense to block execution of JavaScript for it. Currently this 303 // little sense to block execution of JavaScript for it. Currently this
305 // method is called from a thread of web request, so let only this thread be 304 // method is called from a thread of web request, so let only this thread be
306 // blocked by the call of the callback. 305 // blocked by the call of the callback.
307 IsConnectionAllowedCallback localCopy; 306 IsConnectionAllowedCallback localCopy;
308 { 307 {
309 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex); 308 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
310 localCopy = isConnectionAllowed; 309 localCopy = isConnectionAllowed;
311 } 310 }
312 return !localCopy || localCopy(); 311 return !localCopy || localCopy();
313 } 312 }
314 313
315 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() 314 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const
316 { 315 {
317 if (!logSystem)
318 logSystem.reset(new DefaultLogSystem());
319 return logSystem; 316 return logSystem;
320 } 317 }
321 318
322 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) 319 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
323 { 320 {
324 if (!val) 321 if (!val)
325 throw std::runtime_error("LogSystem cannot be null"); 322 throw std::runtime_error("LogSystem cannot be null");
326 323
327 logSystem = val; 324 logSystem = val;
328 } 325 }
329 326
330 327
331 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 328 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
332 AdblockPlus::JsValuePtr value) 329 AdblockPlus::JsValuePtr value)
333 { 330 {
334 auto global = GetGlobalObject(); 331 auto global = GetGlobalObject();
335 if (!global) 332 if (!global)
336 throw std::runtime_error("Global object cannot be null"); 333 throw std::runtime_error("Global object cannot be null");
337 global->SetProperty(name, value); 334 global->SetProperty(name, value);
338 } 335 }
OLDNEW
« include/AdblockPlus/JsEngine.h ('K') | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld