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; |