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

Unified Diff: src/WebRequestJsObject.cpp

Issue 29370568: Issue #4692 - Move responsibility for engine reference from tasks to scheduler
Patch Set: Created Dec. 31, 2016, 10:37 p.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/Scheduler.h ('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
===================================================================
--- 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();
}
« no previous file with comments | « src/Scheduler.h ('k') | test/BaseJsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld