| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * This file is part of Adblock Plus <https://adblockplus.org/>, |    2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
|    3  * Copyright (C) 2006-2016 Eyeo GmbH |    3  * Copyright (C) 2006-2016 Eyeo GmbH | 
|    4  * |    4  * | 
|    5  * Adblock Plus is free software: you can redistribute it and/or modify |    5  * Adblock Plus is free software: you can redistribute it and/or modify | 
|    6  * it under the terms of the GNU General Public License version 3 as |    6  * it under the terms of the GNU General Public License version 3 as | 
|    7  * published by the Free Software Foundation. |    7  * published by the Free Software Foundation. | 
|    8  * |    8  * | 
|    9  * Adblock Plus is distributed in the hope that it will be useful, |    9  * Adblock Plus is distributed in the hope that it will be useful, | 
|   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of |   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|   12  * GNU General Public License for more details. |   12  * GNU General Public License for more details. | 
|   13  * |   13  * | 
|   14  * You should have received a copy of the GNU General Public License |   14  * You should have received a copy of the GNU General Public License | 
|   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. |   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
|   16  */ |   16  */ | 
|   17  |   17  | 
|   18 #include <AdblockPlus.h> |   18 #include <AdblockPlus.h> | 
|   19 #include "FileSystemJsObject.h" |   19 #include "FileSystemJsObject.h" | 
|   20 #include "GlobalJsObject.h" |   20 #include "GlobalJsObject.h" | 
|   21 #include "JsContext.h" |   21 #include "JsContext.h" | 
|   22 #include "JsEngineInternal.h" |   22 #include "JsEngineInternal.h" | 
|   23 #include "JsEngineTransition.h" |   23 #include "JsEngineTransition.h" | 
|   24 #include "JsError.h" |   24 #include "JsError.h" | 
|   25 #include "Scheduler.h" |  | 
|   26 #include "Utils.h" |   25 #include "Utils.h" | 
|   27 #include "WebRequestJsObject.h" |   26 #include "WebRequestJsObject.h" | 
|   28  |   27  | 
|   29 const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseT
     hread = {}; |   28 const ImmediateSingleUseThreadType ImmediateSingleUseThread = {}; | 
|   30  |  | 
|   31 class AdblockPlus::JsEngine::SchedulerImpl |  | 
|   32   : public SchedulerT<SingleUseWorker> |  | 
|   33 { |  | 
|   34 public: |  | 
|   35   SchedulerImpl() {} // = default; |  | 
|   36 }; |  | 
|   37  |   29  | 
|   38 namespace |   30 namespace | 
|   39 { |   31 { | 
|   40   v8::Handle<v8::Script> CompileScript(v8::Isolate* isolate, |   32   v8::Handle<v8::Script> CompileScript(v8::Isolate* isolate, | 
|   41     const std::string& source, const std::string& filename) |   33     const std::string& source, const std::string& filename) | 
|   42   { |   34   { | 
|   43     using AdblockPlus::Utils::ToV8String; |   35     using AdblockPlus::Utils::ToV8String; | 
|   44     const v8::Handle<v8::String> v8Source = ToV8String(isolate, source); |   36     const v8::Handle<v8::String> v8Source = ToV8String(isolate, source); | 
|   45     if (filename.length()) |   37     if (filename.length()) | 
|   46     { |   38     { | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   91   isolate = v8::Isolate::New(); |   83   isolate = v8::Isolate::New(); | 
|   92 } |   84 } | 
|   93  |   85  | 
|   94 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() |   86 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() | 
|   95 { |   87 { | 
|   96   isolate->Dispose(); |   88   isolate->Dispose(); | 
|   97   isolate = nullptr; |   89   isolate = nullptr; | 
|   98 } |   90 } | 
|   99  |   91  | 
|  100 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) |   92 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) | 
|  101   : isolate(isolate), |   93   : isolate(isolate) | 
|  102   scheduler(new SchedulerImpl()) // TODO: make_unique once available |  | 
|  103 {} |   94 {} | 
|  104  |   95  | 
|  105 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat
     e) |   96 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat
     e) | 
|  106   : AdblockPlus::JsEngine(isolate), |   97   : AdblockPlus::JsEngine(isolate), | 
|  107   context(isolate->Get(),v8::Context::New(isolate->Get())) |   98   context(isolate->Get(),v8::Context::New(isolate->Get())) | 
|  108 { |   99 { | 
|  109   /* |  100   /* | 
|  110    * Enter v8 scope for our context so that we can initialize its global object. |  101    * Enter v8 scope for our context so that we can initialize its global object. | 
|  111    */ |  102    */ | 
|  112   const v8::Context::Scope contextScope(GetContextAsLocal()); |  103   const v8::Context::Scope contextScope(GetContextAsLocal()); | 
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  375 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,  |  366 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,  | 
|  376                                               AdblockPlus::JsValuePtr value) |  367                                               AdblockPlus::JsValuePtr value) | 
|  377 { |  368 { | 
|  378   JsContext jsContext(shared_from_this()); |  369   JsContext jsContext(shared_from_this()); | 
|  379   auto global = GetGlobalObject(); |  370   auto global = GetGlobalObject(); | 
|  380   if (!global) |  371   if (!global) | 
|  381     throw std::runtime_error("Global object cannot be null"); |  372     throw std::runtime_error("Global object cannot be null"); | 
|  382   global->SetProperty(name, value); |  373   global->SetProperty(name, value); | 
|  383 } |  374 } | 
|  384  |  375  | 
|  385 void AdblockPlus::JsEngine::Schedule(std::function<void()> task, |  376 void JsEngineInternal::ScheduleTaskInternal(std::shared_ptr<TaskFunctionInterfac
     e>&& body) | 
|  386                                      AdblockPlus::ImmediateSingleUseThreadType) |  | 
|  387 { |  377 { | 
|  388   // The present version of the scheduler only does immediate and single-use |  378   // The present version of the scheduler only does immediate and single-use | 
|  389   // It does not, however, detach threads like the legacy thread behavior did. |  379   // It does not, however, detach threads like the legacy thread behavior did. | 
|  390   scheduler->Run(task); |  380   scheduler.Run(Task(this, std::move(body))); | 
|  391 } |  381 } | 
|  392  |  382  | 
|  393 void AdblockPlus::JsEngine::WaitForQuietScheduler() |  383 void JsEngineInternal::WaitForQuietScheduler() | 
|  394 { |  384 { | 
|  395   scheduler->JoinAll(); |  385   scheduler.JoinAll(); | 
|  396 } |  386 } | 
|  397  |  387  | 
|  398 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p) |  388 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p) | 
|  399 { |  389 { | 
|  400   return static_cast<JsEngineInternal*>(p.get()); |  390   return static_cast<JsEngineInternal*>(p.get()); | 
|  401 } |  391 } | 
|  402  |  392  | 
|  403 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p) |  393 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p) | 
|  404 { |  394 { | 
|  405   return static_cast<JsEngineInternal*>(p); |  395   return static_cast<JsEngineInternal*>(p); | 
|  406 } |  396 } | 
| OLD | NEW |