| 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 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 filename); | 110 filename); |
| 111 CheckTryCatch(tryCatch); | 111 CheckTryCatch(tryCatch); |
| 112 v8::Local<v8::Value> result = script->Run(); | 112 v8::Local<v8::Value> result = script->Run(); |
| 113 CheckTryCatch(tryCatch); | 113 CheckTryCatch(tryCatch); |
| 114 return JsValuePtr(new JsValue(shared_from_this(), result)); | 114 return JsValuePtr(new JsValue(shared_from_this(), result)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, | 117 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
| 118 AdblockPlus::JsEngine::EventCallback callback) | 118 AdblockPlus::JsEngine::EventCallback callback) |
| 119 { | 119 { |
| 120 if (!callback) |
| 121 { |
| 122 RemoveEventCallback(eventName); |
| 123 return; |
| 124 } |
| 120 std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 125 std::lock_guard<std::mutex> lock(eventCallbacksMutex); |
| 121 eventCallbacks[eventName] = callback; | 126 eventCallbacks[eventName] = callback; |
| 122 } | 127 } |
| 123 | 128 |
| 124 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) | 129 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) |
| 125 { | 130 { |
| 126 std::lock_guard<std::mutex> lock(eventCallbacksMutex); | 131 std::lock_guard<std::mutex> lock(eventCallbacksMutex); |
| 127 eventCallbacks.erase(eventName); | 132 eventCallbacks.erase(eventName); |
| 128 } | 133 } |
| 129 | 134 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 278 |
| 274 | 279 |
| 275 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 280 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 276 AdblockPlus::JsValuePtr value) | 281 AdblockPlus::JsValuePtr value) |
| 277 { | 282 { |
| 278 auto global = GetGlobalObject(); | 283 auto global = GetGlobalObject(); |
| 279 if (!global) | 284 if (!global) |
| 280 throw std::runtime_error("Global object cannot be null"); | 285 throw std::runtime_error("Global object cannot be null"); |
| 281 global->SetProperty(name, value); | 286 global->SetProperty(name, value); |
| 282 } | 287 } |
| OLD | NEW |