| {% from 'callback_invoke.cc.tmpl' import callback_invoke %} |
| {% filter format_blink_cpp_source_code %} |
| |
| {% include 'copyright_block.txt' %} |
| |
| #include "{{this_include_header_path}}" |
| |
| {% for filename in cpp_includes %} |
| #include "{{filename}}" |
| {% endfor %} |
| |
| namespace blink { |
| |
| const char* {{cpp_class}}::NameInHeapSnapshot() const { |
| return "{{cpp_class}}"; |
| } |
| |
| v8::Maybe<{{return_cpp_type}}> {{cpp_class}}::Invoke({{argument_declarations | join(', ')}}) { |
| {{callback_invoke( |
| 'callback function', 'invoke', |
| return_cpp_type, native_value_traits_tag, arguments, |
| is_treat_non_object_as_null, False, |
| callback_function_name, 'invoke')}} |
| } |
| |
| {% if idl_type == 'any' %} |
| v8::Maybe<{{return_cpp_type}}> {{cpp_class}}::Construct({{argument_declarations[1:] | join(', ')}}) { |
| {{callback_invoke( |
| 'callback function', 'construct', |
| return_cpp_type, native_value_traits_tag, arguments, |
| is_treat_non_object_as_null, False, |
| callback_function_name, 'construct')}} |
| } |
| {% endif %} |
| |
| {% 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<{{return_cpp_type}}> maybe_result = |
| Invoke({{ |
| (['callback_this_value'] + |
| (arguments|map(attribute='name')|list) |
| )|join(', ') |
| }}); |
| // An exception if any is killed with the v8::TryCatch above. |
| ALLOW_UNUSED_LOCAL(maybe_result); |
| } |
| {% endif %} |
| |
| {% if callback_function_name == 'EventHandlerNonNull' %} |
| bool {{cpp_class}}::IsRunnableOrThrowException(IgnorePause ignore_pause) { |
| ScriptState* callback_relevant_script_state = |
| CallbackRelevantScriptState(); |
| |
| bool is_runnable = |
| ignore_pause == IgnorePause::kIgnore ? |
| IsCallbackFunctionRunnableIgnoringPause( |
| callback_relevant_script_state, IncumbentScriptState()) : |
| IsCallbackFunctionRunnable( |
| callback_relevant_script_state, IncumbentScriptState()); |
| if (is_runnable) |
| return true; |
| |
| // Wrapper-tracing for the callback function makes the function object and |
| // its creation context alive. Thus it's safe to use the creation context |
| // of the callback function here. |
| ScriptState::Scope scope(callback_relevant_script_state); |
| V8ThrowException::ThrowError( |
| GetIsolate(), |
| ExceptionMessages::FailedToExecute( |
| "invoke", |
| "{{callback_function_name}}", |
| "The provided callback is no longer runnable.")); |
| return false; |
| } |
| |
| v8::Maybe<{{return_cpp_type}}> {{cpp_class}}::InvokeWithoutRunnabilityCheck({{argument_declarations | join(', ')}}) { |
| {{callback_invoke( |
| 'callback function', 'invoke', |
| return_cpp_type, native_value_traits_tag, arguments, |
| is_treat_non_object_as_null, True, |
| callback_function_name, 'invoke')}} |
| } |
| {% endif %} |
| |
| v8::Maybe<{{return_cpp_type}}> V8PersistentCallbackFunction<{{cpp_class}}>::Invoke({{argument_declarations | join(', ')}}) { |
| return Proxy()->Invoke( |
| {{ |
| (['callback_this_value'] + |
| (arguments|map(attribute='name')|list) |
| )|join(', ') |
| }}); |
| } |
| |
| {% if idl_type == 'void' or callback_function_name == 'Function' %} |
| void V8PersistentCallbackFunction<{{cpp_class}}>::InvokeAndReportException({{argument_declarations | join(', ')}}) { |
| Proxy()->InvokeAndReportException( |
| {{ |
| (['callback_this_value'] + |
| (arguments|map(attribute='name')|list) |
| )|join(', ') |
| }}); |
| } |
| {% endif %} |
| |
| } // namespace blink |
| |
| {% endfilter %}{# format_blink_cpp_source_code #} |