Left: | ||
Right: |
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 11 matching lines...) Expand all Loading... | |
22 #include "Utils.h" | 22 #include "Utils.h" |
23 #include <libplatform/libplatform.h> | 23 #include <libplatform/libplatform.h> |
24 #include <AdblockPlus/Platform.h> | 24 #include <AdblockPlus/Platform.h> |
25 | 25 |
26 namespace | 26 namespace |
27 { | 27 { |
28 v8::MaybeLocal<v8::Script> CompileScript(v8::Isolate* isolate, | 28 v8::MaybeLocal<v8::Script> CompileScript(v8::Isolate* isolate, |
29 const std::string& source, const std::string& filename) | 29 const std::string& source, const std::string& filename) |
30 { | 30 { |
31 using AdblockPlus::Utils::ToV8String; | 31 using AdblockPlus::Utils::ToV8String; |
32 const v8::Local<v8::String> v8Source = ToV8String(isolate, source); | 32 auto maybeV8Source = ToV8String(isolate, source); |
33 if (maybeV8Source.IsEmpty()) | |
34 return v8::MaybeLocal<v8::Script>(); | |
35 const v8::Local<v8::String> v8Source = maybeV8Source.ToLocalChecked(); | |
33 if (filename.length()) | 36 if (filename.length()) |
34 { | 37 { |
35 const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename); | 38 auto maybeV8Filename = ToV8String(isolate, filename); |
36 v8::ScriptOrigin scriptOrigin(v8Filename); | 39 if (maybeV8Filename.IsEmpty()) |
40 return v8::MaybeLocal<v8::Script>(); | |
41 v8::ScriptOrigin scriptOrigin(maybeV8Filename.ToLocalChecked()); | |
37 return v8::Script::Compile(isolate->GetCurrentContext(), v8Source, &script Origin); | 42 return v8::Script::Compile(isolate->GetCurrentContext(), v8Source, &script Origin); |
38 } | 43 } |
39 else | 44 else |
40 return v8::Script::Compile(isolate->GetCurrentContext(), v8Source); | 45 return v8::Script::Compile(isolate->GetCurrentContext(), v8Source); |
41 } | 46 } |
42 | 47 |
43 class V8Initializer | 48 class V8Initializer |
44 { | 49 { |
45 V8Initializer() | 50 V8Initializer() |
46 : platform{nullptr} | 51 : platform{nullptr} |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 } | 230 } |
226 | 231 |
227 void AdblockPlus::JsEngine::Gc() | 232 void AdblockPlus::JsEngine::Gc() |
228 { | 233 { |
229 while (!GetIsolate()->IdleNotificationDeadline(1000)); | 234 while (!GetIsolate()->IdleNotificationDeadline(1000)); |
230 } | 235 } |
231 | 236 |
232 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val) | 237 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val) |
233 { | 238 { |
234 const JsContext context(*this); | 239 const JsContext context(*this); |
235 return JsValue(shared_from_this(), Utils::ToV8String(GetIsolate(), val)); | 240 auto maybeValue = Utils::ToV8String(GetIsolate(), val); |
241 if (maybeValue.IsEmpty()) | |
242 return JsValue(shared_from_this(), v8::Undefined(GetIsolate())); | |
hub
2018/06/22 00:34:31
This is where I think we should break APIs to some
sergei
2018/06/22 06:57:46
Let's just use CHECKED_TO_LOCAL.
hub
2018/06/22 15:50:56
Done.
| |
243 return JsValue(shared_from_this(), maybeValue.ToLocalChecked()); | |
236 } | 244 } |
237 | 245 |
238 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val) | 246 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val) |
239 { | 247 { |
240 const JsContext context(*this); | 248 const JsContext context(*this); |
241 return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val)); | 249 return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val)); |
242 } | 250 } |
243 | 251 |
244 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val) | 252 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val) |
245 { | 253 { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 list.push_back(JsValue(shared_from_this(), arguments[i])); | 342 list.push_back(JsValue(shared_from_this(), arguments[i])); |
335 return list; | 343 return list; |
336 } | 344 } |
337 | 345 |
338 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 346 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
339 const AdblockPlus::JsValue& value) | 347 const AdblockPlus::JsValue& value) |
340 { | 348 { |
341 auto global = GetGlobalObject(); | 349 auto global = GetGlobalObject(); |
342 global.SetProperty(name, value); | 350 global.SetProperty(name, value); |
343 } | 351 } |
OLD | NEW |