Index: src/WebRequestJsObject.cpp |
=================================================================== |
--- a/src/WebRequestJsObject.cpp |
+++ b/src/WebRequestJsObject.cpp |
@@ -30,6 +30,7 @@ |
namespace |
{ |
class WebRequestTask |
+ : public TaskFunctionInterface |
{ |
public: |
WebRequestTask( |
@@ -38,13 +39,12 @@ |
AdblockPlus::HeaderList headers, |
V8PersistentNG<v8::Function> callbackFunction |
) |
- : jsEngine(engine->shared_from_this()), |
+ : engine(engine), |
url(url), headers(headers), callbackFunction(callbackFunction) |
{} |
- void operator()() |
+ void operator()() override |
{ |
- auto engine = ToInternal(jsEngine); // temporary statement while task keeps its own engine alive |
/* |
* Synchronous HTTP GET request is arbitrary-duration and not interruptible |
*/ |
@@ -77,7 +77,7 @@ |
/** |
* Engine pointer keeps engine in existence across thread boundary |
*/ |
- AdblockPlus::JsEnginePtr jsEngine; |
+ JsEngineInternal *engine; |
std::string url; |
AdblockPlus::HeaderList headers; |
V8PersistentNG<v8::Function> callbackFunction; |
@@ -107,7 +107,6 @@ |
/* |
* Factory block for WebRequest tasks. |
*/ |
- std::shared_ptr<WebRequestTask> task; |
try |
{ |
std::string url; |
@@ -152,8 +151,13 @@ |
{ |
throw std::runtime_error("Third argument to GET must be a function"); |
} |
- task = std::make_shared<WebRequestTask>(engine, url, headers, |
+ WebRequestTask task(engine, url, headers, |
V8PersistentNG<v8::Function>(engine->GetIsolate(), v8::Local<v8::Function>::Cast(arguments[2]))); |
+ /* |
+ * Run the task |
+ */ |
+ engine->ScheduleTask(std::move(task), ImmediateSingleUseThread); |
+ return v8::Undefined(); |
} |
catch (const std::exception& e) |
{ |
@@ -161,9 +165,4 @@ |
v8::Isolate* isolate = arguments.GetIsolate(); |
return v8::ThrowException(ToV8String(isolate, e.what())); |
} |
- /* |
- * Run the task |
- */ |
- engine->Schedule(AdblockPlus::MakeHeapFunction(task), AdblockPlus::ImmediateSingleUseThread); |
- return v8::Undefined(); |
} |