| Index: src/JsEngine.cpp |
| =================================================================== |
| --- a/src/JsEngine.cpp |
| +++ b/src/JsEngine.cpp |
| @@ -19,8 +19,18 @@ |
| #include "GlobalJsObject.h" |
| #include "JsContext.h" |
| #include "JsError.h" |
| +#include "Scheduler.h" |
| #include "Utils.h" |
| +const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseThread = {}; |
| + |
| +class AdblockPlus::JsEngine::SchedulerImpl |
| + : public SchedulerT<SingleUseWorker> |
| +{ |
| +public: |
| + SchedulerImpl() {} // = default; |
|
sergei
2017/01/20 13:08:13
We don't need this line.
|
| +}; |
| + |
| namespace |
| { |
| v8::Handle<v8::Script> CompileScript(v8::Isolate* isolate, |
| @@ -77,9 +87,9 @@ |
| } |
| AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) |
| - : isolate(isolate) |
| -{ |
| -} |
| + : isolate(isolate), |
| + scheduler(new SchedulerImpl()) // use std::make_unique after we upgrade out of VS2012 |
|
sergei
2017/01/20 13:08:13
We don't need this comment about std::make_unique
Eric
2017/03/30 17:16:58
Is that because we're planning never to upgrade fr
sergei
2017/04/03 15:35:31
Maybe, though I think that std::make_shared are mu
|
| +{} |
| AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, const ScopedV8IsolatePtr& isolate) |
| { |
| @@ -95,10 +105,10 @@ |
| return result; |
| } |
| -AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject() |
| -{ |
| - JsContext context(shared_from_this()); |
| - return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Global())); |
| +AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject() |
| +{ |
| + JsContext context(shared_from_this()); |
| + return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Global())); |
| } |
| AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source, |
| @@ -252,3 +262,16 @@ |
| throw std::runtime_error("Global object cannot be null"); |
| global->SetProperty(name, value); |
| } |
| + |
| +void AdblockPlus::JsEngine::Schedule(std::function<void()> task, |
| + AdblockPlus::ImmediateSingleUseThreadType) |
| +{ |
| + // The present version of the scheduler only does immediate and single-use |
| + // It does not, however, detach threads like the legacy thread behavior did. |
| + scheduler->Run(task); |
| +} |
| + |
| +void AdblockPlus::JsEngine::WaitForQuietScheduler() |
| +{ |
| + scheduler->JoinAll(); |
| +} |