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

Unified Diff: extensions/renderer/api_binding_hooks.cc

Issue 2609553003: [Extensions Bindings] Allow custom hooks to return values, throw (Closed)
Patch Set: woot Created 4 years 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/api_binding_hooks.cc
diff --git a/extensions/renderer/api_binding_hooks.cc b/extensions/renderer/api_binding_hooks.cc
index 9d479b431636e99c2b8fc65274cbc2fd4076ba42..b4c93ab9eb42654c3cfc4f8f5cd22c0bcba54dcc 100644
--- a/extensions/renderer/api_binding_hooks.cc
+++ b/extensions/renderer/api_binding_hooks.cc
@@ -187,13 +187,14 @@ APIBindingHooks::RequestResult APIBindingHooks::HandleRequest(
v8::Local<v8::Context> context,
const APISignature* signature,
std::vector<v8::Local<v8::Value>>* arguments,
- const ArgumentSpec::RefMap& type_refs) {
+ const ArgumentSpec::RefMap& type_refs,
+ v8::Local<v8::Value>* return_value) {
// Easy case: a native custom hook.
auto request_hooks_iter = request_hooks_.find(method_name);
if (request_hooks_iter != request_hooks_.end()) {
RequestResult result =
request_hooks_iter->second.Run(
- signature, context, arguments, type_refs);
+ signature, context, arguments, type_refs, return_value);
// Right now, it doesn't make sense to register a request handler that
// doesn't handle the request.
DCHECK_NE(RequestResult::NOT_HANDLED, result);
@@ -244,8 +245,15 @@ APIBindingHooks::RequestResult APIBindingHooks::HandleRequest(
if (!success)
return RequestResult::INVALID_INVOCATION;
- run_js_.Run(handle_request, context, parsed_v8_args.size(),
- parsed_v8_args.data());
+ v8::Global<v8::Value> global_result =
+ run_js_.Run(handle_request, context, parsed_v8_args.size(),
+ parsed_v8_args.data());
+ if (try_catch.HasCaught()) {
+ try_catch.ReThrow();
+ return RequestResult::THROWN;
+ }
+ if (!global_result.IsEmpty())
+ *return_value = global_result.Get(isolate);
return RequestResult::HANDLED;
}

Powered by Google App Engine
This is Rietveld 408576698