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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 JsContext context(*this); | 180 JsContext context(*this); |
181 return JsValue(shared_from_this(), context.GetV8Context()->Global()); | 181 return JsValue(shared_from_this(), context.GetV8Context()->Global()); |
182 } | 182 } |
183 | 183 |
184 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, | 184 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, |
185 const std::string& filename) | 185 const std::string& filename) |
186 { | 186 { |
187 const JsContext context(*this); | 187 const JsContext context(*this); |
188 auto isolate = GetIsolate(); | 188 auto isolate = GetIsolate(); |
189 const v8::TryCatch tryCatch(isolate); | 189 const v8::TryCatch tryCatch(isolate); |
190 v8::MaybeLocal<v8::Script> script = CompileScript(isolate, source, filename); | 190 auto script = CHECKED_TO_LOCAL( |
191 v8::MaybeLocal<v8::Value> result = CHECKED_TO_LOCAL( | 191 isolate, CompileScript(isolate, source, filename), tryCatch); |
192 isolate, script, tryCatch)->Run(isolate->GetCurrentContext()); | 192 auto result = CHECKED_TO_LOCAL( |
193 return JsValue(shared_from_this(), CHECKED_TO_LOCAL(isolate, result, tryCatch)
); | 193 isolate, script->Run(isolate->GetCurrentContext()), tryCatch); |
| 194 return JsValue(shared_from_this(), result); |
194 } | 195 } |
195 | 196 |
196 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, | 197 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
197 const AdblockPlus::JsEngine::EventCallback& callback) | 198 const AdblockPlus::JsEngine::EventCallback& callback) |
198 { | 199 { |
199 if (!callback) | 200 if (!callback) |
200 { | 201 { |
201 RemoveEventCallback(eventName); | 202 RemoveEventCallback(eventName); |
202 return; | 203 return; |
203 } | 204 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 list.push_back(JsValue(shared_from_this(), arguments[i])); | 335 list.push_back(JsValue(shared_from_this(), arguments[i])); |
335 return list; | 336 return list; |
336 } | 337 } |
337 | 338 |
338 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 339 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
339 const AdblockPlus::JsValue& value) | 340 const AdblockPlus::JsValue& value) |
340 { | 341 { |
341 auto global = GetGlobalObject(); | 342 auto global = GetGlobalObject(); |
342 global.SetProperty(name, value); | 343 global.SetProperty(name, value); |
343 } | 344 } |
LEFT | RIGHT |