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

Unified 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: Created June 21, 2018, 11:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsValue.cpp » ('j') | src/JsValue.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -24,21 +24,26 @@
#include <AdblockPlus/Platform.h>
namespace
{
v8::MaybeLocal<v8::Script> CompileScript(v8::Isolate* isolate,
const std::string& source, const std::string& filename)
{
using AdblockPlus::Utils::ToV8String;
- const v8::Local<v8::String> v8Source = ToV8String(isolate, source);
+ auto maybeV8Source = ToV8String(isolate, source);
+ if (maybeV8Source.IsEmpty())
+ return v8::MaybeLocal<v8::Script>();
+ const v8::Local<v8::String> v8Source = maybeV8Source.ToLocalChecked();
if (filename.length())
{
- const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename);
- v8::ScriptOrigin scriptOrigin(v8Filename);
+ auto maybeV8Filename = ToV8String(isolate, filename);
+ if (maybeV8Filename.IsEmpty())
+ return v8::MaybeLocal<v8::Script>();
+ v8::ScriptOrigin scriptOrigin(maybeV8Filename.ToLocalChecked());
return v8::Script::Compile(isolate->GetCurrentContext(), v8Source, &scriptOrigin);
}
else
return v8::Script::Compile(isolate->GetCurrentContext(), v8Source);
}
class V8Initializer
{
@@ -227,17 +232,20 @@
void AdblockPlus::JsEngine::Gc()
{
while (!GetIsolate()->IdleNotificationDeadline(1000));
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val)
{
const JsContext context(*this);
- return JsValue(shared_from_this(), Utils::ToV8String(GetIsolate(), val));
+ auto maybeValue = Utils::ToV8String(GetIsolate(), val);
+ if (maybeValue.IsEmpty())
+ 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.
+ return JsValue(shared_from_this(), maybeValue.ToLocalChecked());
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val)
{
const JsContext context(*this);
return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val));
}
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsValue.cpp » ('j') | src/JsValue.cpp » ('J')

Powered by Google App Engine
This is Rietveld