| 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-2017 eyeo GmbH | 3  * Copyright (C) 2006-2017 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 179   std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 179   std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 
| 180   eventCallbacks[eventName] = callback; | 180   eventCallbacks[eventName] = callback; | 
| 181 } | 181 } | 
| 182 | 182 | 
| 183 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) | 183 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) | 
| 184 { | 184 { | 
| 185   std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 185   std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 
| 186   eventCallbacks.erase(eventName); | 186   eventCallbacks.erase(eventName); | 
| 187 } | 187 } | 
| 188 | 188 | 
| 189 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, const Adb
     lockPlus::JsValueList& params) | 189 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, const Adb
     lockPlus::JsConstValueList& params) | 
| 190 { | 190 { | 
| 191   EventCallback callback; | 191   EventCallback callback; | 
| 192   { | 192   { | 
| 193     std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 193     std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 
| 194     auto it = eventCallbacks.find(eventName); | 194     auto it = eventCallbacks.find(eventName); | 
| 195     if (it == eventCallbacks.end()) | 195     if (it == eventCallbacks.end()) | 
| 196       return; | 196       return; | 
| 197     callback = it->second; | 197     callback = it->second; | 
| 198   } | 198   } | 
| 199   callback(params); | 199   callback(params); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249   const v8::Local<const v8::External> external = | 249   const v8::Local<const v8::External> external = | 
| 250       v8::Local<const v8::External>::Cast(arguments.Data()); | 250       v8::Local<const v8::External>::Cast(arguments.Data()); | 
| 251   std::weak_ptr<JsEngine>* data = | 251   std::weak_ptr<JsEngine>* data = | 
| 252       static_cast<std::weak_ptr<JsEngine>*>(external->Value()); | 252       static_cast<std::weak_ptr<JsEngine>*>(external->Value()); | 
| 253   JsEnginePtr result = data->lock(); | 253   JsEnginePtr result = data->lock(); | 
| 254   if (!result) | 254   if (!result) | 
| 255     throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?")
     ; | 255     throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?")
     ; | 
| 256   return result; | 256   return result; | 
| 257 } | 257 } | 
| 258 | 258 | 
| 259 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
     ents& arguments) | 259 AdblockPlus::JsConstValueList AdblockPlus::JsEngine::ConvertArguments(const v8::
     Arguments& arguments) | 
| 260 { | 260 { | 
| 261   const JsContext context(shared_from_this()); | 261   const JsContext context(shared_from_this()); | 
| 262   JsValueList list; | 262   JsConstValueList list; | 
| 263   for (int i = 0; i < arguments.Length(); i++) | 263   for (int i = 0; i < arguments.Length(); i++) | 
| 264     list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); | 264     list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); | 
| 265   return list; | 265   return list; | 
| 266 } | 266 } | 
| 267 | 267 | 
| 268 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const | 268 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const | 
| 269 { | 269 { | 
| 270   return fileSystem; | 270   return fileSystem; | 
| 271 } | 271 } | 
| 272 | 272 | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 326 | 326 | 
| 327 | 327 | 
| 328 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 328 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 
| 329                                               const AdblockPlus::JsValuePtr& val
     ue) | 329                                               const AdblockPlus::JsValuePtr& val
     ue) | 
| 330 { | 330 { | 
| 331   auto global = GetGlobalObject(); | 331   auto global = GetGlobalObject(); | 
| 332   if (!global) | 332   if (!global) | 
| 333     throw std::runtime_error("Global object cannot be null"); | 333     throw std::runtime_error("Global object cannot be null"); | 
| 334   global->SetProperty(name, value); | 334   global->SetProperty(name, value); | 
| 335 } | 335 } | 
| OLD | NEW | 
|---|