Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsEngine.cpp

Issue 29812649: Issue 6526 - *ToV8String() return MaybeLocal<> and check Call() return value (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Introduce CHECKED_TO_LOCAL_NOTHROW and use it. Created June 22, 2018, 3:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 isolate = GetIsolate();
241 return JsValue(shared_from_this(),
242 CHECKED_TO_LOCAL_NOTHROW(isolate, Utils::ToV8String(isolate, val)));
236 } 243 }
237 244
238 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val) 245 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val)
239 { 246 {
240 const JsContext context(*this); 247 const JsContext context(*this);
241 return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val)); 248 return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val));
242 } 249 }
243 250
244 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val) 251 AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val)
245 { 252 {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 list.push_back(JsValue(shared_from_this(), arguments[i])); 341 list.push_back(JsValue(shared_from_this(), arguments[i]));
335 return list; 342 return list;
336 } 343 }
337 344
338 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 345 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
339 const AdblockPlus::JsValue& value) 346 const AdblockPlus::JsValue& value)
340 { 347 {
341 auto global = GetGlobalObject(); 348 auto global = GetGlobalObject();
342 global.SetProperty(name, value); 349 global.SetProperty(name, value);
343 } 350 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsValue.cpp » ('j') | src/Utils.h » ('J')

Powered by Google App Engine
This is Rietveld