chromium/third_party/blink/renderer/bindings/core/v8/callback_invoke_helper.h

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_CALLBACK_INVOKE_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_CALLBACK_INVOKE_HELPER_H_

#include <optional>

#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_value_or_script_wrappable_adapter.h"
#include "third_party/blink/renderer/platform/scheduler/public/task_attribution_tracker.h"
#include "v8/include/v8.h"

namespace blink {

class CallbackFunctionBase;
class CallbackFunctionWithTaskAttributionBase;
class CallbackInterfaceBase;

namespace bindings {

enum class CallbackInvokeHelperMode {};

enum class CallbackReturnTypeIsPromise {};

// This class helps implement the generated Blink-V8 bindings of IDL callback
// functions and IDL callback interfaces.  This class implements the following
// algorithms of Web IDL.
//
// https://webidl.spec.whatwg.org/#call-a-user-objects-operation
// 3.11. Callback interfaces
// To call a user object's operation
//
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
// 3.12. Invoking callback functions
// To invoke a callback function type value
//
// https://webidl.spec.whatwg.org/#construct-a-callback-function
// 3.12. Invoking callback functions
// To construct a callback functions type value
template <class CallbackBase,
          CallbackInvokeHelperMode mode = CallbackInvokeHelperMode::kDefault,
          CallbackReturnTypeIsPromise return_type_is_promise =
              CallbackReturnTypeIsPromise::kNo>
class CallbackInvokeHelper final {};

extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionBase,
                         CallbackInvokeHelperMode::kDefault>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionBase,
                         CallbackInvokeHelperMode::kDefault,
                         CallbackReturnTypeIsPromise::kYes>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionBase,
                         CallbackInvokeHelperMode::kConstructorCall>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionBase,
                         CallbackInvokeHelperMode::kConstructorCall,
                         CallbackReturnTypeIsPromise::kYes>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionBase,
                         CallbackInvokeHelperMode::kLegacyTreatNonObjectAsNull>;

extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionWithTaskAttributionBase,
                         CallbackInvokeHelperMode::kDefault>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionWithTaskAttributionBase,
                         CallbackInvokeHelperMode::kDefault,
                         CallbackReturnTypeIsPromise::kYes>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionWithTaskAttributionBase,
                         CallbackInvokeHelperMode::kConstructorCall>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionWithTaskAttributionBase,
                         CallbackInvokeHelperMode::kConstructorCall,
                         CallbackReturnTypeIsPromise::kYes>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackFunctionWithTaskAttributionBase,
                         CallbackInvokeHelperMode::kLegacyTreatNonObjectAsNull>;

extern template class CORE_EXTERN_TEMPLATE_EXPORT
    CallbackInvokeHelper<CallbackInterfaceBase>;

}  // namespace bindings

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_CALLBACK_INVOKE_HELPER_H_