Skip to content

Commit

Permalink
v8binding: Supports InvokeAndReportException for type Function.
Browse files Browse the repository at this point in the history
Web IDL type Function (= any (any...)) is a sort of "arbitrary
function", and used very widely in the web standards.  Its
return value is often discarded, as if its return type is void.

So, this patch supports InvokeAndReportException for type
Function.

Bug: 871208
Change-Id: Icbe56560585c402271363e7c8294d3b0c96b1562
Reviewed-on: https://chromium-review.googlesource.com/1173931
Reviewed-by: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582843}
  • Loading branch information
yuki3 authored and Commit Bot committed Aug 14, 2018
1 parent 8437185 commit 3f2c0c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ v8::Maybe<{{return_cpp_type}}> {{cpp_class}}::Invoke({{argument_declarations | j
{% endif %}
}

{% if idl_type == 'void' %}
{% if idl_type == 'void' or callback_function_name == 'Function' %}
void {{cpp_class}}::InvokeAndReportException({{argument_declarations | join(', ')}}) {
v8::TryCatch try_catch(GetIsolate());
try_catch.SetVerbose(true);

v8::Maybe<void> maybe_result =
v8::Maybe<{{return_cpp_type}}> maybe_result =
Invoke({{
(['callback_this_value'] +
(arguments|map(attribute='name')|list)
Expand All @@ -171,7 +171,7 @@ v8::Maybe<{{return_cpp_type}}> V8PersistentCallbackFunction<{{cpp_class}}>::Invo
}});
}

{% if idl_type == 'void' %}
{% if idl_type == 'void' or callback_function_name == 'Function' %}
void V8PersistentCallbackFunction<{{cpp_class}}>::InvokeAndReportException({{argument_declarations | join(', ')}}) {
Proxy()->InvokeAndReportException(
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class {{exported}}{{cpp_class}} final : public CallbackFunctionBase {
// https://heycam.github.io/webidl/#es-invoking-callback-functions
v8::Maybe<{{return_cpp_type}}> Invoke({{argument_declarations | join(', ')}}) WARN_UNUSED_RESULT;

{% if idl_type == 'void' %}
{# Type Function is often used as a sort of wild cards, and its return value is
often discarded. So, this provides some convenience. #}
{% if idl_type == 'void' or callback_function_name == 'Function' %}
// Performs "invoke", and then reports an exception, if any, to the global
// error handler such as DevTools' console.
void InvokeAndReportException({{argument_declarations | join(', ')}});
Expand All @@ -52,7 +54,7 @@ class V8PersistentCallbackFunction<{{cpp_class}}> final : public V8PersistentCal
V8CallbackFunction* ToNonV8Persistent() { return Proxy(); }

v8::Maybe<{{return_cpp_type}}> Invoke({{argument_declarations | join(', ')}}) WARN_UNUSED_RESULT;
{% if idl_type == 'void' %}
{% if idl_type == 'void' or callback_function_name == 'Function' %}
{{exported}}void InvokeAndReportException({{argument_declarations | join(', ')}});
{% endif %}

Expand Down

0 comments on commit 3f2c0c0

Please sign in to comment.