/* THIS FILE IS AUTOGENERATED FROM EventListener.webidl BY Codegen.py - DO NOT EDIT */

#ifndef mozilla_dom_EventListenerBinding_h
#define mozilla_dom_EventListenerBinding_h

#include "js/RootingAPI.h"
#include "jspubtd.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackInterface.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/ToJSValue.h"

namespace mozilla {
namespace dom {

class Event;
class EventListener;
struct EventListenerAtoms;
struct NativePropertyHooks;
class ProtoAndIfaceCache;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

class EventListener : public CallbackInterface
{
public:
  explicit inline EventListener(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : CallbackInterface(aCx, aCallback, aIncumbentGlobal)
  {
  }

  explicit inline EventListener(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal, const FastCallbackConstructor& )
    : CallbackInterface(aCx, aCallback, aIncumbentGlobal, FastCallbackConstructor())
  {
  }

  explicit inline EventListener(JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
    : CallbackInterface(aCallback, aAsyncStack, aIncumbentGlobal)
  {
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisVal, Event& event, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "EventListener.handleEvent";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      MOZ_ASSERT(aRv.Failed());
      return;
    }
    JS::Rooted<JS::Value> thisValJS(s.GetContext());
    if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }
    return HandleEvent(s.GetContext(), thisValJS, event, aRv);
  }

  inline void
  HandleEvent(Event& event, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "EventListener.handleEvent";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      MOZ_ASSERT(aRv.Failed());
      return;
    }
    return HandleEvent(s.GetContext(), JS::UndefinedHandleValue, event, aRv);
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisVal, Event& event, const char* aExecutionReason = nullptr)
  {
    IgnoredErrorResult rv;
    return HandleEvent(thisVal, event, rv, aExecutionReason);
  }

  inline void
  HandleEvent(Event& event, const char* aExecutionReason = nullptr)
  {
    IgnoredErrorResult rv;
    return HandleEvent(event, rv, aExecutionReason, eReportExceptions, nullptr);
  }

  inline bool
  operator==(const EventListener& aOther) const
  {
    return CallbackInterface::operator==(aOther);
  }

private:
  void HandleEvent(JSContext* cx, JS::Handle<JS::Value> aThisVal, Event& event, ErrorResult& aRv);

  static bool
  InitIds(JSContext* cx, EventListenerAtoms* atomsCache);
};


namespace binding_detail {
class FastEventListener : public EventListener
{
public:
  explicit inline FastEventListener(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : EventListener(aCx, aCallback, aIncumbentGlobal, FastCallbackConstructor())
  {
  }

  inline void
  Trace(JSTracer* aTracer)
  {
    EventListener::Trace(aTracer);
  }

  inline void
  HoldJSObjectsIfMoreThanOneOwner()
  {
    EventListener::HoldJSObjectsIfMoreThanOneOwner();
  }
};
} // namespace binding_detail


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_EventListenerBinding_h
