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

Unified Diff: src/JsEngine.cpp

Issue 29408747: Issue 5013 - Mark more method as const (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Isolate::Get() and JsEngine::GetIsolate() should be non-const Created April 11, 2017, 11:39 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -121,16 +121,19 @@
callbackArgs.emplace_back(new JsValue(shared_from_this(),
v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i])));
callback.Call(callbackArgs);
timerTasks.erase(timerTaskIterator);
}
AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer)
: isolate(isolate)
+ , fileSystem(new DefaultFileSystem())
+ , webRequest(new DefaultWebRequest())
+ , logSystem(new DefaultLogSystem())
, timer(std::move(timer))
{
}
AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
TimerPtr timer,
const ScopedV8IsolatePtr& isolate)
{
@@ -257,35 +260,31 @@
{
const JsContext context(shared_from_this());
JsValueList list;
for (int i = 0; i < arguments.Length(); i++)
list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i])));
return list;
}
-AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem()
+AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const
{
- if (!fileSystem)
- fileSystem.reset(new DefaultFileSystem());
return fileSystem;
}
void AdblockPlus::JsEngine::SetFileSystem(AdblockPlus::FileSystemPtr val)
{
if (!val)
throw std::runtime_error("FileSystem cannot be null");
fileSystem = val;
}
-AdblockPlus::WebRequestPtr AdblockPlus::JsEngine::GetWebRequest()
+AdblockPlus::WebRequestPtr AdblockPlus::JsEngine::GetWebRequest() const
{
- if (!webRequest)
- webRequest.reset(new DefaultWebRequest());
return webRequest;
}
void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val)
{
if (!val)
throw std::runtime_error("WebRequest cannot be null");
@@ -293,46 +292,44 @@
}
void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callback)
{
std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
isConnectionAllowed = callback;
}
-bool AdblockPlus::JsEngine::IsConnectionAllowed()
+bool AdblockPlus::JsEngine::IsConnectionAllowed() const
{
// The call of isConnectionAllowed can be very expensive and it makes a
// little sense to block execution of JavaScript for it. Currently this
// method is called from a thread of web request, so let only this thread be
// blocked by the call of the callback.
IsConnectionAllowedCallback localCopy;
{
std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
localCopy = isConnectionAllowed;
}
return !localCopy || localCopy();
}
-AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem()
+AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const
{
- if (!logSystem)
- logSystem.reset(new DefaultLogSystem());
return logSystem;
}
void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
{
if (!val)
throw std::runtime_error("LogSystem cannot be null");
logSystem = val;
}
-void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
+void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
AdblockPlus::JsValuePtr value)
{
auto global = GetGlobalObject();
if (!global)
throw std::runtime_error("Global object cannot be null");
global->SetProperty(name, value);
}
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld