| {% filter format_blink_cpp_source_code %} |
| |
| {% include 'copyright_block.txt' %} |
| #ifndef {{header_guard}} |
| #define {{header_guard}} |
| |
| {% for filename in header_includes %} |
| #include "{{filename}}" |
| {% endfor %} |
| |
| namespace blink { |
| |
| {% for forward_declaration in forward_declarations %} |
| class {{forward_declaration}}; |
| {% endfor %} |
| |
| class {{exported}}{{cpp_class}} final : public CallbackFunctionBase { |
| public: |
| static {{cpp_class}}* Create( |
| {%- if is_treat_non_object_as_null %}v8::Local<v8::Object> |
| {%- else %}v8::Local<v8::Function>{% endif %} callback_function) { |
| return MakeGarbageCollected<{{cpp_class}}>(callback_function); |
| } |
| |
| explicit {{cpp_class}}( |
| {%- if is_treat_non_object_as_null %}v8::Local<v8::Object> |
| {%- else %}v8::Local<v8::Function>{% endif %} callback_function) |
| : CallbackFunctionBase(callback_function) {} |
| ~{{cpp_class}}() override = default; |
| |
| // NameClient overrides: |
| const char* NameInHeapSnapshot() const override; |
| |
| // Performs "invoke". |
| // https://heycam.github.io/webidl/#es-invoking-callback-functions |
| v8::Maybe<{{return_cpp_type}}> Invoke({{argument_declarations | join(', ')}}) WARN_UNUSED_RESULT; |
| |
| {# Web IDL does not distinguish callback constructors from callback functions. |
| If the return type is 'any', then it\'s likely to be used as a callback |
| constructor. #} |
| {% if idl_type == 'any' %} |
| // Performs "construct". |
| // https://heycam.github.io/webidl/#construct-a-callback-function |
| v8::Maybe<{{return_cpp_type}}> Construct({{argument_declarations[1:] | join(', ')}}) WARN_UNUSED_RESULT; |
| {% endif %} |
| |
| {# 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(', ')}}); |
| {% endif %} |
| |
| {% if callback_function_name == 'EventHandlerNonNull' %} |
| // Returns true if the callback is runnable, otherwise returns false and |
| // throws an exception. 'beforeunload' event need to have priority over pause |
| // of execution contexts. |
| enum class IgnorePause { kDontIgnore, kIgnore }; |
| bool IsRunnableOrThrowException(IgnorePause); |
| |
| // Performs "invoke" without checking the runnability check, which must be |
| // done prior to this call by |IsRunnableOrThrowException|. |
| // https://heycam.github.io/webidl/#es-invoking-callback-functions |
| // This function may throw unlike InvokeAndReportException. |
| v8::Maybe<{{return_cpp_type}}> InvokeWithoutRunnabilityCheck({{argument_declarations | join(', ')}}) WARN_UNUSED_RESULT; |
| {% endif %} |
| }; |
| |
| } // namespace blink |
| |
| #endif // {{header_guard}} |
| |
| {% endfilter %}{# format_blink_cpp_source_code #} |