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

Unified Diff: src/WebRequestJsObject.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Patch Set: temporary workaround for race condition Created Dec. 1, 2016, 10:26 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
« src/JsValue.cpp ('K') | « src/Utils.cpp ('k') | test/BaseJsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/WebRequestJsObject.cpp
diff --git a/src/WebRequestJsObject.cpp b/src/WebRequestJsObject.cpp
index 48a703709053895845a5bb83e4036158b9b094f9..b3bf1c2282689bc9c55190527a9af4987cf62413 100644
--- a/src/WebRequestJsObject.cpp
+++ b/src/WebRequestJsObject.cpp
@@ -58,16 +58,16 @@ namespace
void Run()
{
- AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, headers);
-
+ // Don't keep a strong reference to JsEngine while request is being executed.
+ auto webRequest = AdblockPlus::Utils::lockJsEngine(jsEngine)->GetWebRequest();
+ auto result = webRequest->GET(url, headers);
AdblockPlus::JsContext context(jsEngine);
-
- AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject();
+ AdblockPlus::JsValuePtr resultObject = context.GetJsEngine().NewObject();
resultObject->SetProperty("status", result.status);
resultObject->SetProperty("responseStatus", result.responseStatus);
resultObject->SetProperty("responseText", result.responseText);
- AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject();
+ AdblockPlus::JsValuePtr headersObject = context.GetJsEngine().NewObject();
for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin();
it != result.responseHeaders.end(); ++it)
{
@@ -81,7 +81,7 @@ namespace
}
private:
- AdblockPlus::JsEnginePtr jsEngine;
+ std::weak_ptr<AdblockPlus::JsEngine> jsEngine;
std::string url;
AdblockPlus::HeaderList headers;
AdblockPlus::JsValuePtr callback;
« src/JsValue.cpp ('K') | « src/Utils.cpp ('k') | test/BaseJsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld