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

Unified Diff: src/JsEngine.cpp

Issue 29810586: Issue 6526 - Use the maybe version of Compile() and Run() (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: r-value CheckedToLocal Created June 21, 2018, 1:04 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 | « no previous file | src/JsError.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -20,34 +20,29 @@
#include "JsContext.h"
#include "JsError.h"
#include "Utils.h"
#include <libplatform/libplatform.h>
#include <AdblockPlus/Platform.h>
namespace
{
- v8::Local<v8::Script> CompileScript(v8::Isolate* isolate,
+ 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);
if (filename.length())
{
const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename);
- return v8::Script::Compile(v8Source, v8Filename);
+ v8::ScriptOrigin scriptOrigin(v8Filename);
+ return v8::Script::Compile(isolate->GetCurrentContext(), v8Source, &scriptOrigin);
}
else
- return v8::Script::Compile(v8Source);
- }
-
- void CheckTryCatch(v8::Isolate* isolate, const v8::TryCatch& tryCatch)
- {
- if (tryCatch.HasCaught())
- throw AdblockPlus::JsError(isolate, tryCatch.Exception(), tryCatch.Message());
+ return v8::Script::Compile(isolate->GetCurrentContext(), v8Source);
}
class V8Initializer
{
V8Initializer()
: platform{nullptr}
{
std::string cmd = "--use_strict";
@@ -187,21 +182,20 @@
}
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);
- const v8::Local<v8::Script> script = CompileScript(isolate, source,
- filename);
- CheckTryCatch(isolate, tryCatch);
- v8::Local<v8::Value> result = script->Run();
- CheckTryCatch(isolate, tryCatch);
+ auto script = CHECKED_TO_LOCAL(
+ isolate, CompileScript(isolate, source, filename), tryCatch);
+ auto result = CHECKED_TO_LOCAL(
+ 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)
{
« no previous file with comments | « no previous file | src/JsError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld