Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: extensions/renderer/bindings/api_request_handler.cc

Issue 2961103002: [Extensions Bindings] Add an ExceptionHandler class (Closed)
Patch Set: jbroman's Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/bindings/api_request_handler.cc
diff --git a/extensions/renderer/bindings/api_request_handler.cc b/extensions/renderer/bindings/api_request_handler.cc
index e13c9e58aae3dd3c4e88f31d7228f30a4361d07f..396798322a8f5cc588aa7b653deb846c5cd2e1df 100644
--- a/extensions/renderer/bindings/api_request_handler.cc
+++ b/extensions/renderer/bindings/api_request_handler.cc
@@ -9,6 +9,7 @@
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "content/public/child/v8_value_converter.h"
+#include "extensions/renderer/bindings/exception_handler.h"
#include "gin/converter.h"
#include "gin/data_object_builder.h"
#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
@@ -43,10 +44,12 @@ APIRequestHandler::PendingRequest& APIRequestHandler::PendingRequest::operator=(
APIRequestHandler::APIRequestHandler(const SendRequestMethod& send_request,
const CallJSFunction& call_js,
- APILastError last_error)
+ APILastError last_error,
+ ExceptionHandler* exception_handler)
: send_request_(send_request),
call_js_(call_js),
- last_error_(std::move(last_error)) {}
+ last_error_(std::move(last_error)),
+ exception_handler_(exception_handler) {}
APIRequestHandler::~APIRequestHandler() {}
@@ -140,10 +143,19 @@ void APIRequestHandler::CompleteRequest(int request_id,
if (!error.empty())
last_error_.SetError(context, error);
+ v8::TryCatch try_catch(isolate);
// args.size() is converted to int, but args is controlled by chrome and is
// never close to std::numeric_limits<int>::max.
call_js_.Run(pending_request.callback.Get(isolate), context, args.size(),
args.data());
+ if (try_catch.HasCaught()) {
+ v8::Local<v8::Message> v8_message = try_catch.Message();
+ base::Optional<std::string> message;
+ if (!v8_message.IsEmpty())
+ message = gin::V8ToString(v8_message->Get());
+ exception_handler_->HandleException(context, "Error handling response",
+ &try_catch);
+ }
if (!error.empty())
last_error_.ClearError(context, true);

Powered by Google App Engine
This is Rietveld 408576698