| LEFT | RIGHT | 
|    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-present eyeo GmbH |    3  * Copyright (C) 2006-present 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 | 
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  187   JsContext context(*this); |  187   JsContext context(*this); | 
|  188   return JsValue(shared_from_this(), context.GetV8Context()->Global()); |  188   return JsValue(shared_from_this(), context.GetV8Context()->Global()); | 
|  189 } |  189 } | 
|  190  |  190  | 
|  191 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, |  191 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, | 
|  192     const std::string& filename) |  192     const std::string& filename) | 
|  193 { |  193 { | 
|  194   const JsContext context(*this); |  194   const JsContext context(*this); | 
|  195   auto isolate = GetIsolate(); |  195   auto isolate = GetIsolate(); | 
|  196   const v8::TryCatch tryCatch(isolate); |  196   const v8::TryCatch tryCatch(isolate); | 
|  197   auto script = CHECKED_TO_LOCAL( |  197   auto script = CHECKED_TO_LOCAL_WITH_TRY_CATCH( | 
|  198     isolate, CompileScript(isolate, source, filename), tryCatch); |  198     isolate, CompileScript(isolate, source, filename), tryCatch); | 
|  199   auto result = CHECKED_TO_LOCAL( |  199   auto result = CHECKED_TO_LOCAL_WITH_TRY_CATCH( | 
|  200     isolate, script->Run(isolate->GetCurrentContext()), tryCatch); |  200     isolate, script->Run(isolate->GetCurrentContext()), tryCatch); | 
|  201   return JsValue(shared_from_this(), result); |  201   return JsValue(shared_from_this(), result); | 
|  202 } |  202 } | 
|  203  |  203  | 
|  204 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |  204 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, | 
|  205     const AdblockPlus::JsEngine::EventCallback& callback) |  205     const AdblockPlus::JsEngine::EventCallback& callback) | 
|  206 { |  206 { | 
|  207   if (!callback) |  207   if (!callback) | 
|  208   { |  208   { | 
|  209     RemoveEventCallback(eventName); |  209     RemoveEventCallback(eventName); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  235 void AdblockPlus::JsEngine::Gc() |  235 void AdblockPlus::JsEngine::Gc() | 
|  236 { |  236 { | 
|  237   while (!GetIsolate()->IdleNotificationDeadline(1000)); |  237   while (!GetIsolate()->IdleNotificationDeadline(1000)); | 
|  238 } |  238 } | 
|  239  |  239  | 
|  240 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val) |  240 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val) | 
|  241 { |  241 { | 
|  242   const JsContext context(*this); |  242   const JsContext context(*this); | 
|  243   auto isolate = GetIsolate(); |  243   auto isolate = GetIsolate(); | 
|  244   return JsValue(shared_from_this(), |  244   return JsValue(shared_from_this(), | 
|  245     CHECKED_TO_LOCAL_NOTHROW(isolate, Utils::ToV8String(isolate, val))); |  245     CHECKED_TO_LOCAL(isolate, Utils::ToV8String(isolate, val))); | 
|  246 } |  246 } | 
|  247  |  247  | 
|  248 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val) |  248 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val) | 
|  249 { |  249 { | 
|  250   const JsContext context(*this); |  250   const JsContext context(*this); | 
|  251   return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val)); |  251   return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val)); | 
|  252 } |  252 } | 
|  253  |  253  | 
|  254 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val) |  254 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val) | 
|  255 { |  255 { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  268 { |  268 { | 
|  269   const JsContext context(*this); |  269   const JsContext context(*this); | 
|  270   auto isolate = GetIsolate(); |  270   auto isolate = GetIsolate(); | 
|  271   // Note: we are leaking this weak pointer, no obvious way to destroy it when |  271   // Note: we are leaking this weak pointer, no obvious way to destroy it when | 
|  272   // it's no longer used |  272   // it's no longer used | 
|  273   std::weak_ptr<JsEngine>* data = |  273   std::weak_ptr<JsEngine>* data = | 
|  274       new std::weak_ptr<JsEngine>(shared_from_this()); |  274       new std::weak_ptr<JsEngine>(shared_from_this()); | 
|  275   v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, cal
     lback, |  275   v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, cal
     lback, | 
|  276       v8::External::New(isolate, data)); |  276       v8::External::New(isolate, data)); | 
|  277   return JsValue(shared_from_this(), |  277   return JsValue(shared_from_this(), | 
|  278       CHECKED_TO_LOCAL_NOTHROW(isolate, templ->GetFunction(isolate->GetCurrentCo
     ntext()))); |  278       CHECKED_TO_LOCAL(isolate, templ->GetFunction(isolate->GetCurrentContext())
     )); | 
|  279 } |  279 } | 
|  280  |  280  | 
|  281 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Function
     CallbackInfo<v8::Value>& arguments) |  281 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Function
     CallbackInfo<v8::Value>& arguments) | 
|  282 { |  282 { | 
|  283   const v8::Local<const v8::External> external = |  283   const v8::Local<const v8::External> external = | 
|  284       v8::Local<const v8::External>::Cast(arguments.Data()); |  284       v8::Local<const v8::External>::Cast(arguments.Data()); | 
|  285   std::weak_ptr<JsEngine>* data = |  285   std::weak_ptr<JsEngine>* data = | 
|  286       static_cast<std::weak_ptr<JsEngine>*>(external->Value()); |  286       static_cast<std::weak_ptr<JsEngine>*>(external->Value()); | 
|  287   JsEnginePtr result = data->lock(); |  287   JsEnginePtr result = data->lock(); | 
|  288   if (!result) |  288   if (!result) | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  345     list.push_back(JsValue(shared_from_this(), arguments[i])); |  345     list.push_back(JsValue(shared_from_this(), arguments[i])); | 
|  346   return list; |  346   return list; | 
|  347 } |  347 } | 
|  348  |  348  | 
|  349 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |  349 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 
|  350                                               const AdblockPlus::JsValue& value) |  350                                               const AdblockPlus::JsValue& value) | 
|  351 { |  351 { | 
|  352   auto global = GetGlobalObject(); |  352   auto global = GetGlobalObject(); | 
|  353   global.SetProperty(name, value); |  353   global.SetProperty(name, value); | 
|  354 } |  354 } | 
| LEFT | RIGHT |