Index: src/WebRequestJsObject.cpp |
=================================================================== |
--- a/src/WebRequestJsObject.cpp |
+++ b/src/WebRequestJsObject.cpp |
@@ -20,17 +20,17 @@ |
#include <AdblockPlus/WebRequest.h> |
#include "JsContext.h" |
-#include "Thread.h" |
#include "Utils.h" |
+#include "Scheduler.h" |
#include "WebRequestJsObject.h" |
namespace |
{ |
- class WebRequestThread : public AdblockPlus::Thread |
+ class WebRequestTask |
{ |
public: |
- WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList& arguments) |
- : Thread(true), jsEngine(jsEngine), url(arguments[0]->AsString()) |
+ WebRequestTask(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList& arguments) |
+ : jsEngine(jsEngine), url(arguments[0]->AsString()) |
{ |
if (!url.length()) |
throw std::runtime_error("Invalid string passed as first argument to GET"); |
@@ -56,7 +56,7 @@ |
throw std::runtime_error("Third argument to GET must be a function"); |
} |
- void Run() |
+ void operator()() |
{ |
AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, headers); |
@@ -89,14 +89,14 @@ |
v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) |
{ |
- WebRequestThread* thread; |
+ std::shared_ptr<WebRequestTask> thread; |
try |
{ |
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); |
AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); |
if (converted.size() != 3u) |
throw std::runtime_error("GET requires exactly 3 arguments"); |
- thread = new WebRequestThread(jsEngine, converted); |
+ thread = std::make_shared<WebRequestTask>(jsEngine, converted); |
} |
catch (const std::exception& e) |
{ |
@@ -104,7 +104,7 @@ |
v8::Isolate* isolate = arguments.GetIsolate(); |
return v8::ThrowException(ToV8String(isolate, e.what())); |
} |
- thread->Start(); |
+ AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeHeapFunction(thread)); |
return v8::Undefined(); |
} |
} |