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

Unified Diff: extensions/renderer/api_binding.cc

Issue 2598123002: [Extensions Bindings] Add support for updateArgumentsPreValidate (Closed)
Patch Set: jbroman II Created 3 years, 11 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
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | extensions/renderer/api_binding_hooks.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding.cc
diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc
index 163858dbc6503b311b05aaf14e20f6b44b196a14..1c1c0f902f30601f3441c36042dff11b714e7905 100644
--- a/extensions/renderer/api_binding.cc
+++ b/extensions/renderer/api_binding.cc
@@ -188,36 +188,56 @@ void APIBinding::HandleCall(const std::string& name,
// GetCurrentContext() should always be correct.
v8::Local<v8::Context> context = isolate->GetCurrentContext();
- APIBindingHooks::RequestResult hooks_result =
- APIBindingHooks::RequestResult::NOT_HANDLED;
- hooks_result = binding_hooks_->HandleRequest(api_name_, name, context,
- signature, arguments,
- *type_refs_);
-
- switch (hooks_result) {
- case APIBindingHooks::RequestResult::INVALID_INVOCATION:
- arguments->ThrowTypeError("Invalid invocation");
- return;
- case APIBindingHooks::RequestResult::HANDLED:
- return; // Our work here is done.
- case APIBindingHooks::RequestResult::NOT_HANDLED:
- break; // Handle in the default manner.
+ std::vector<v8::Local<v8::Value>> argument_list;
+ if (arguments->Length() > 0) {
+ // Just copying handles should never fail.
+ CHECK(arguments->GetRemaining(&argument_list));
+ }
+
+ bool invalid_invocation = false;
+ {
+ v8::TryCatch try_catch(isolate);
+ APIBindingHooks::RequestResult hooks_result =
+ APIBindingHooks::RequestResult::NOT_HANDLED;
+ hooks_result = binding_hooks_->HandleRequest(api_name_, name, context,
+ signature, &argument_list,
+ *type_refs_);
+
+ switch (hooks_result) {
+ case APIBindingHooks::RequestResult::INVALID_INVOCATION:
+ invalid_invocation = true;
+ // Throw a type error below so that it's not caught by our try-catch.
+ break;
+ case APIBindingHooks::RequestResult::THROWN:
+ DCHECK(try_catch.HasCaught());
+ try_catch.ReThrow();
+ return;
+ case APIBindingHooks::RequestResult::HANDLED:
+ return; // Our work here is done.
+ case APIBindingHooks::RequestResult::NOT_HANDLED:
+ break; // Handle in the default manner.
+ }
+ }
+
+ if (invalid_invocation) {
+ arguments->ThrowTypeError("Invalid invocation");
+ return;
}
std::unique_ptr<base::ListValue> converted_arguments;
v8::Local<v8::Function> callback;
- bool conversion_success = false;
{
v8::TryCatch try_catch(isolate);
- conversion_success = signature->ParseArgumentsToJSON(
- arguments, *type_refs_, &converted_arguments, &callback, &error);
+ invalid_invocation = !signature->ParseArgumentsToJSON(
+ context, argument_list, *type_refs_,
+ &converted_arguments, &callback, &error);
if (try_catch.HasCaught()) {
DCHECK(!converted_arguments);
try_catch.ReThrow();
return;
}
}
- if (!conversion_success) {
+ if (invalid_invocation) {
arguments->ThrowTypeError("Invalid invocation");
return;
}
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | extensions/renderer/api_binding_hooks.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698