blob: fdc3536587731a4fc4b51089cd80e9c4a6e9ad88 [file] [log] [blame]
{% filter format_blink_cpp_source_code %}
{% include 'copyright_block.txt' %}
#ifndef {{v8_class}}_h
#define {{v8_class}}_h
{% for filename in header_includes %}
#include "{{filename}}"
{% endfor %}
namespace blink {
{% for forward_declaration in forward_declarations %}
class {{forward_declaration}};
{% endfor %}
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 const WrapperTypeInfo wrapperTypeInfo;
// Constants
{% for constant in constants %}
static constexpr {{constant.cpp_type}} {{constant.name}} = {{constant.value}};
{% endfor %}
{% endif %}
// Creates and returns a new instance. Returns nullptr when |callback_object|
// is an object in a remote context (e.g. cross origin window object). The
// call sites may want to throw a SecurityError in the case.
// See also crbug.com/886588
static {{v8_class}}* CreateOrNull(v8::Local<v8::Object> callback_object);
~{{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 %}
private:
{% set single_operation_enum_value =
'kSingleOperation' if is_single_operation_callback_interface else
'kNotSingleOperation' %}
explicit {{v8_class}}(
v8::Local<v8::Object> callback_object,
v8::Local<v8::Context> callback_object_creation_context)
: CallbackInterfaceBase(callback_object, callback_object_creation_context,
{{single_operation_enum_value}}) {}
};
template <>
class V8PersistentCallbackInterface<{{v8_class}}> final : public V8PersistentCallbackInterfaceBase {
using V8CallbackInterface = {{v8_class}};
public:
~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:
explicit V8PersistentCallbackInterface(V8CallbackInterface* callback_interface)
: V8PersistentCallbackInterfaceBase(callback_interface) {}
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 // {{v8_class}}_h
{% endfilter %}{# format_blink_cpp_source_code #}