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-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 21 matching lines...) Expand all Loading... |
32 const v8::Local<v8::String> v8Source = ToV8String(isolate, source); | 32 const v8::Local<v8::String> v8Source = ToV8String(isolate, source); |
33 if (filename.length()) | 33 if (filename.length()) |
34 { | 34 { |
35 const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename); | 35 const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename); |
36 return v8::Script::Compile(v8Source, v8Filename); | 36 return v8::Script::Compile(v8Source, v8Filename); |
37 } | 37 } |
38 else | 38 else |
39 return v8::Script::Compile(v8Source); | 39 return v8::Script::Compile(v8Source); |
40 } | 40 } |
41 | 41 |
42 void CheckTryCatch(const v8::TryCatch& tryCatch) | 42 void CheckTryCatch(v8::Isolate* isolate, const v8::TryCatch& tryCatch) |
43 { | 43 { |
44 if (tryCatch.HasCaught()) | 44 if (tryCatch.HasCaught()) |
45 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); | 45 throw AdblockPlus::JsError(isolate, tryCatch.Exception(), tryCatch.Message
()); |
46 } | 46 } |
47 | 47 |
48 class V8Initializer | 48 class V8Initializer |
49 { | 49 { |
50 V8Initializer() | 50 V8Initializer() |
51 : platform{nullptr} | 51 : platform{nullptr} |
52 { | 52 { |
53 std::string cmd = "--use_strict"; | 53 std::string cmd = "--use_strict"; |
54 v8::V8::SetFlagsFromString(cmd.c_str(), cmd.length()); | 54 v8::V8::SetFlagsFromString(cmd.c_str(), cmd.length()); |
55 platform = v8::platform::CreateDefaultPlatform(); | 55 platform = v8::platform::CreateDefaultPlatform(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 AdblockPlus::JsValue AdblockPlus::JsEngine::GetGlobalObject() | 183 AdblockPlus::JsValue AdblockPlus::JsEngine::GetGlobalObject() |
184 { | 184 { |
185 JsContext context(*this); | 185 JsContext context(*this); |
186 return JsValue(shared_from_this(), context.GetV8Context()->Global()); | 186 return JsValue(shared_from_this(), context.GetV8Context()->Global()); |
187 } | 187 } |
188 | 188 |
189 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, | 189 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, |
190 const std::string& filename) | 190 const std::string& filename) |
191 { | 191 { |
192 const JsContext context(*this); | 192 const JsContext context(*this); |
193 const v8::TryCatch tryCatch(GetIsolate()); | 193 auto isolate = GetIsolate(); |
194 const v8::Local<v8::Script> script = CompileScript(GetIsolate(), source, | 194 const v8::TryCatch tryCatch(isolate); |
| 195 const v8::Local<v8::Script> script = CompileScript(isolate, source, |
195 filename); | 196 filename); |
196 CheckTryCatch(tryCatch); | 197 CheckTryCatch(isolate, tryCatch); |
197 v8::Local<v8::Value> result = script->Run(); | 198 v8::Local<v8::Value> result = script->Run(); |
198 CheckTryCatch(tryCatch); | 199 CheckTryCatch(isolate, tryCatch); |
199 return JsValue(shared_from_this(), result); | 200 return JsValue(shared_from_this(), result); |
200 } | 201 } |
201 | 202 |
202 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, | 203 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
203 const AdblockPlus::JsEngine::EventCallback& callback) | 204 const AdblockPlus::JsEngine::EventCallback& callback) |
204 { | 205 { |
205 if (!callback) | 206 if (!callback) |
206 { | 207 { |
207 RemoveEventCallback(eventName); | 208 RemoveEventCallback(eventName); |
208 return; | 209 return; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 list.push_back(JsValue(shared_from_this(), arguments[i])); | 341 list.push_back(JsValue(shared_from_this(), arguments[i])); |
341 return list; | 342 return list; |
342 } | 343 } |
343 | 344 |
344 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 345 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
345 const AdblockPlus::JsValue& value) | 346 const AdblockPlus::JsValue& value) |
346 { | 347 { |
347 auto global = GetGlobalObject(); | 348 auto global = GetGlobalObject(); |
348 global.SetProperty(name, value); | 349 global.SetProperty(name, value); |
349 } | 350 } |
OLD | NEW |