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: Added tests. Renamed CHECKED_TO_LOCAL. Created July 11, 2018, 2:10 a.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/Utils.h » ('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
{
@@ -181,19 +186,19 @@
}
AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
const JsContext context(*this);
auto isolate = GetIsolate();
const v8::TryCatch tryCatch(isolate);
- auto script = CHECKED_TO_LOCAL(
+ auto script = CHECKED_TO_LOCAL_WITH_TRY_CATCH(
isolate, CompileScript(isolate, source, filename), tryCatch);
- auto result = CHECKED_TO_LOCAL(
+ auto result = CHECKED_TO_LOCAL_WITH_TRY_CATCH(
isolate, script->Run(isolate->GetCurrentContext()), tryCatch);
return JsValue(shared_from_this(), result);
}
void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
const AdblockPlus::JsEngine::EventCallback& callback)
{
if (!callback)
@@ -227,17 +232,19 @@
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 isolate = GetIsolate();
+ return JsValue(shared_from_this(),
+ CHECKED_TO_LOCAL(isolate, Utils::ToV8String(isolate, val)));
}
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/Utils.h » ('J')

Powered by Google App Engine
This is Rietveld