Chromium Code Reviews| Index: extensions/renderer/api_binding.cc |
| diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc |
| index 163858dbc6503b311b05aaf14e20f6b44b196a14..da71ba458b2852dd44c40a5fb6bededa07f5c41b 100644 |
| --- a/extensions/renderer/api_binding.cc |
| +++ b/extensions/renderer/api_binding.cc |
| @@ -188,20 +188,48 @@ 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: |
| + std::vector<v8::Local<v8::Value>> argument_list; |
| + { |
| + v8::TryCatch try_catch(isolate); |
| + if (arguments->Length() > 0 && |
| + !arguments->GetRemaining(&argument_list)) { |
| + if (try_catch.HasCaught()) { |
| + try_catch.ReThrow(); |
| + return; |
| + } |
| arguments->ThrowTypeError("Invalid invocation"); |
|
jbroman
2016/12/23 22:37:06
Isn't this caught by the v8::TryCatch a few lines
Devlin
2016/12/28 19:02:39
Right you are! Fixed.
|
| return; |
| - case APIBindingHooks::RequestResult::HANDLED: |
| - return; // Our work here is done. |
| - case APIBindingHooks::RequestResult::NOT_HANDLED: |
| - break; // Handle in the default manner. |
| + } |
| + } |
| + |
| + 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; |
| @@ -210,7 +238,8 @@ void APIBinding::HandleCall(const std::string& name, |
| { |
| v8::TryCatch try_catch(isolate); |
| conversion_success = signature->ParseArgumentsToJSON( |
| - arguments, *type_refs_, &converted_arguments, &callback, &error); |
| + context, argument_list, *type_refs_, |
| + &converted_arguments, &callback, &error); |
| if (try_catch.HasCaught()) { |
| DCHECK(!converted_arguments); |
| try_catch.ReThrow(); |