| 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 "GlobalJsObject.h" | 20 #include "GlobalJsObject.h" | 
| 20 #include "JsContext.h" | 21 #include "JsContext.h" | 
| 21 #include "JsEngineInternal.h" | 22 #include "JsEngineInternal.h" | 
| 22 #include "JsEngineTransition.h" | 23 #include "JsEngineTransition.h" | 
| 23 #include "JsError.h" | 24 #include "JsError.h" | 
| 24 #include "Scheduler.h" | 25 #include "Scheduler.h" | 
| 25 #include "Utils.h" | 26 #include "Utils.h" | 
| 26 #include "WebRequestJsObject.h" | 27 #include "WebRequestJsObject.h" | 
| 27 | 28 | 
| 28 const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseT
     hread = {}; | 29 const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseT
     hread = {}; | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 104 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat
     e) | 105 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat
     e) | 
| 105   : AdblockPlus::JsEngine(isolate), | 106   : AdblockPlus::JsEngine(isolate), | 
| 106   context(isolate->Get(),v8::Context::New(isolate->Get())) | 107   context(isolate->Get(),v8::Context::New(isolate->Get())) | 
| 107 { | 108 { | 
| 108   /* | 109   /* | 
| 109    * Enter v8 scope for our context so that we can initialize its global object. | 110    * Enter v8 scope for our context so that we can initialize its global object. | 
| 110    */ | 111    */ | 
| 111   const v8::Context::Scope contextScope(GetContextAsLocal()); | 112   const v8::Context::Scope contextScope(GetContextAsLocal()); | 
| 112   auto globalObject = GetGlobalObject(); | 113   auto globalObject = GetGlobalObject(); | 
| 113   // Timeout | 114   // Timeout | 
| 114   auto propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "setTimeout")
     ; | 115   globalObject->Set(ToV8String("setTimeout"), MakeCallback(::CallbackForSetTimeo
     ut)); | 
| 115   globalObject->Set(propertyName, MakeCallback(::CallbackForSetTimeout)); |  | 
| 116   // Web request | 116   // Web request | 
| 117   auto auxiliaryObject = v8::Object::New(); | 117   auto auxiliaryObject = v8::Object::New(); | 
| 118   propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "GET"); | 118   auxiliaryObject->Set(ToV8String("GET"), MakeCallback(::GETCallback)); | 
| 119   auxiliaryObject->Set(propertyName, MakeCallback(::GETCallback)); | 119   globalObject->Set(ToV8String("_webRequest"), auxiliaryObject); | 
| 120   propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "_webRequest"); | 120   // File system I/O | 
| 121   globalObject->Set(propertyName, auxiliaryObject); | 121   auxiliaryObject = v8::Object::New(); | 
|  | 122   auxiliaryObject->Set(ToV8String("read"), MakeCallback(::ReadCallback)); | 
|  | 123   auxiliaryObject->Set(ToV8String("write"), MakeCallback(::WriteCallback)); | 
|  | 124   auxiliaryObject->Set(ToV8String("move"), MakeCallback(::MoveCallback)); | 
|  | 125   auxiliaryObject->Set(ToV8String("remove"), MakeCallback(::RemoveCallback)); | 
|  | 126   auxiliaryObject->Set(ToV8String("stat"), MakeCallback(::StatCallback)); | 
|  | 127   auxiliaryObject->Set(ToV8String("resolve"), MakeCallback(::ResolveCallback)); | 
|  | 128   globalObject->Set(ToV8String("_fileSystem"), auxiliaryObject); | 
|  | 129 | 
| 122   // TODO: Move the rest of the global object initializations here | 130   // TODO: Move the rest of the global object initializations here | 
| 123 } | 131 } | 
| 124 | 132 | 
| 125 /** | 133 /** | 
| 126  * \par Design Notes | 134  * \par Design Notes | 
| 127  * It is technically necessary to construct JsEngine instances *only* within a f
     actory. | 135  * It is technically necessary to construct JsEngine instances *only* within a f
     actory. | 
| 128  * Initialization requires that certain transient v8 scopes be set up | 136  * Initialization requires that certain transient v8 scopes be set up | 
| 129  *   before initialization and torn down afterwards. | 137  *   before initialization and torn down afterwards. | 
| 130  * C++ has no syntax to use anything like a sentry object in the constructor its
     elf. | 138  * C++ has no syntax to use anything like a sentry object in the constructor its
     elf. | 
| 131  * Thus we need to establish v8 scope within every C++ scope that constructs an 
     object. | 139  * Thus we need to establish v8 scope within every C++ scope that constructs an 
     object. | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 298 v8::Local<v8::Function> JsEngineInternal::MakeCallback(v8::InvocationCallback ca
     llback) | 306 v8::Local<v8::Function> JsEngineInternal::MakeCallback(v8::InvocationCallback ca
     llback) | 
| 299 { | 307 { | 
| 300   return v8::FunctionTemplate::New(callback, v8::External::New(this))->GetFuncti
     on(); | 308   return v8::FunctionTemplate::New(callback, v8::External::New(this))->GetFuncti
     on(); | 
| 301 } | 309 } | 
| 302 | 310 | 
| 303 JsEngineInternal* JsEngineInternal::ExtractEngine(const v8::Arguments& arguments
     ) | 311 JsEngineInternal* JsEngineInternal::ExtractEngine(const v8::Arguments& arguments
     ) | 
| 304 { | 312 { | 
| 305   return static_cast<JsEngineInternal*>(v8::Local<v8::External>::Cast(arguments.
     Data())->Value()); | 313   return static_cast<JsEngineInternal*>(v8::Local<v8::External>::Cast(arguments.
     Data())->Value()); | 
| 306 } | 314 } | 
| 307 | 315 | 
|  | 316 v8::Local<v8::String> JsEngineInternal::ToV8String(const std::string& s) | 
|  | 317 { | 
|  | 318   return AdblockPlus::Utils::ToV8String(GetIsolate(), s); | 
|  | 319 } | 
|  | 320 | 
| 308 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
     ents& arguments) | 321 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
     ents& arguments) | 
| 309 { | 322 { | 
| 310   const JsContext context(shared_from_this()); | 323   const JsContext context(shared_from_this()); | 
| 311   JsValueList list; | 324   JsValueList list; | 
| 312   for (int i = 0; i < arguments.Length(); i++) | 325   for (int i = 0; i < arguments.Length(); i++) | 
| 313     list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); | 326     list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); | 
| 314   return list; | 327   return list; | 
| 315 } | 328 } | 
| 316 | 329 | 
| 317 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() | 330 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 384 | 397 | 
| 385 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p) | 398 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p) | 
| 386 { | 399 { | 
| 387   return static_cast<JsEngineInternal*>(p.get()); | 400   return static_cast<JsEngineInternal*>(p.get()); | 
| 388 } | 401 } | 
| 389 | 402 | 
| 390 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p) | 403 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p) | 
| 391 { | 404 { | 
| 392   return static_cast<JsEngineInternal*>(p); | 405   return static_cast<JsEngineInternal*>(p); | 
| 393 } | 406 } | 
| OLD | NEW | 
|---|