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

Unified Diff: src/Platform.cpp

Issue 29508569: Issue 5450 - don't expose std::shared_ptr<JsEngine> (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 7, 2017, 8: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') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/Platform.cpp
diff --git a/src/Platform.cpp b/src/Platform.cpp
index 9369d0c78988445ea3869bbfd8e4ebe9dea6681d..ede0dca6b0af370648a1a9b3fb5e80c09431e745 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -72,32 +72,33 @@ void Platform::SetUpJsEngine(const AppInfo& appInfo)
jsEngine = JsEngine::New(appInfo, *this);
}
-std::shared_ptr<JsEngine> Platform::GetJsEngine()
+JsEngine& Platform::GetJsEngine()
{
SetUpJsEngine();
- return jsEngine;
+ return *jsEngine;
}
-void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& parameters,
- const OnFilterEngineCreatedCallback& onCreated)
-{
- std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise;
- {
+void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& parameters,
+ const OnFilterEngineCreatedCallback& onCreated)
+{
+ std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise;
+ {
std::lock_guard<std::mutex> lock(modulesMutex);
if (filterEngine.valid())
return;
filterEnginePromise = std::make_shared<std::promise<FilterEnginePtr>>();
- filterEngine = filterEnginePromise->get_future();
- }
+ filterEngine = filterEnginePromise->get_future();
+ }
- FilterEngine::CreateAsync(GetJsEngine(), [this, onCreated, filterEnginePromise](const FilterEnginePtr& filterEngine)
- {
+ GetJsEngine(); // ensures that JsEngine is instantiated
+ FilterEngine::CreateAsync(jsEngine, [this, onCreated, filterEnginePromise](const FilterEnginePtr& filterEngine)
+ {
filterEnginePromise->set_value(filterEngine);
- if (onCreated)
- onCreated(filterEngine);
- }, parameters);
-}
-
+ if (onCreated)
+ onCreated(filterEngine);
+ }, parameters);
+}
+
FilterEnginePtr Platform::GetFilterEngine()
{
CreateFilterEngineAsync();
« no previous file with comments | « src/FilterEngine.cpp ('k') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld