blob: fa259312cb58e46fab7488bb7a0a0444d52ea89c [file] [log] [blame]
{% 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 %}
{% if is_legacy_callback_interface %}
{{exported}}extern const WrapperTypeInfo {{snake_case_v8_class}}_wrapper_type_info;
{% endif %}
class {{exported}}{{v8_class}} final : public CallbackInterfaceBase {
public:
{% if is_legacy_callback_interface %}
// Support of "legacy callback interface"
static v8::Local<v8::FunctionTemplate> DomTemplate(v8::Isolate*, const DOMWrapperWorld&);
static constexpr const WrapperTypeInfo* GetWrapperTypeInfo() {
return &{{snake_case_v8_class}}_wrapper_type_info;
}
// Constants
{% for constant in constants %}
static constexpr {{constant.cpp_type}} {{constant.name}} = {{constant.value}};
{% endfor %}
{% endif %}
static {{v8_class}}* Create(v8::Local<v8::Object> callback_object) {
return MakeGarbageCollected<{{v8_class}}>(callback_object);
}
{% set single_operation_enum_value =
'kSingleOperation' if is_single_operation_callback_interface else
'kNotSingleOperation' %}
explicit {{v8_class}}(v8::Local<v8::Object> callback_object)
: CallbackInterfaceBase(callback_object,
{{single_operation_enum_value}}) {}
~{{v8_class}}() override = default;
// NameClient overrides:
const char* NameInHeapSnapshot() const override;
{% for method in methods %}
// Performs "call a user object's operation".
// https://heycam.github.io/webidl/#call-a-user-objects-operation
v8::Maybe<{{method.cpp_type}}> {{method.name}}({{method.argument_declarations | join(', ')}}) WARN_UNUSED_RESULT;
{% endfor %}
{% if methods|length == 1 and methods[0].idl_type == 'void' %}
// Performs "call a user object's operation", and then reports an exception,
// if any, to the global error handler such as DevTools' console.
void InvokeAndReportException({{methods[0].argument_declarations | join(', ')}});
{% endif %}
{% if interface_name == 'EventListener' %}
// 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 "call a user object's operation" for '{{methods[0].name}}' without
// checking the runnability check, which must be done prior to this call by
// |IsRunnableOrThrowException|.
// https://heycam.github.io/webidl/#call-a-user-objects-operation
// This function may throw unlike InvokeAndReportException.
v8::Maybe<{{methods[0].cpp_type}}> InvokeWithoutRunnabilityCheck({{methods[0].argument_declarations | join(', ')}}) WARN_UNUSED_RESULT;
{% endif %}
};
template <>
class V8PersistentCallbackInterface<{{v8_class}}> final : public V8PersistentCallbackInterfaceBase {
using V8CallbackInterface = {{v8_class}};
public:
explicit V8PersistentCallbackInterface(V8CallbackInterface* callback_interface)
: V8PersistentCallbackInterfaceBase(callback_interface) {}
~V8PersistentCallbackInterface() override = default;
{% for method in methods %}
{{exported}}v8::Maybe<{{method.cpp_type}}> {{method.name}}({{method.argument_declarations | join(', ')}}) WARN_UNUSED_RESULT;
{% endfor %}
{% if methods|length == 1 and methods[0].idl_type == 'void' %}
{{exported}}void InvokeAndReportException({{methods[0].argument_declarations | join(', ')}});
{% endif %}
private:
V8CallbackInterface* Proxy() {
return As<V8CallbackInterface>();
}
template <typename V8CallbackInterface>
friend V8PersistentCallbackInterface<V8CallbackInterface>*
ToV8PersistentCallbackInterface(V8CallbackInterface*);
};
// {{v8_class}} is designed to be used with wrapper-tracing.
// As blink::Persistent does not perform wrapper-tracing, use of
// |WrapPersistent| for callback interfaces is likely (if not always) misuse.
// Thus, this code prohibits such a use case. The call sites should explicitly
// use WrapPersistent(V8PersistentCallbackInterface<T>*).
Persistent<{{v8_class}}> WrapPersistent({{v8_class}}*) = delete;
} // namespace blink
#endif // {{header_guard}}
{% endfilter %}{# format_blink_cpp_source_code #}