/* 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)
  {
  }

  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()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      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()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      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 dom
} // namespace mozilla

#endif // mozilla_dom_EventListenerBinding_h
