/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */

#ifndef mozilla_dom_EventListenerBinding_h__
#define mozilla_dom_EventListenerBinding_h__

#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/CallbackInterface.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/DOMJSProxyHandler.h"

class XPCWrappedNativeScope;
class nsDOMEvent;

class nsDOMEvent;

class JSObject;

class JSObject;


namespace mozilla {
namespace dom {

class EventListener : public CallbackInterface
{
public:
  inline EventListener(JSContext* cx, JSObject* aOwner, JSObject* aCallback, bool* aInited)
    : CallbackInterface(cx, aOwner, aCallback, aInited)
  {
  }

  explicit inline EventListener(JSObject* aCallback)
    : CallbackInterface(aCallback)
  {
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisObj, nsDOMEvent& event, ErrorResult& aRv, ExceptionHandling aExceptionHandling = eReportExceptions)
  {
    CallSetup s(mCallback, aRv, aExceptionHandling);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    JSObject* thisObjJS = WrapCallThisObject(s.GetContext(), mCallback, thisObj);
    if (!thisObjJS) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }
    return HandleEvent(s.GetContext(), thisObjJS, event, aRv);
  }

  inline void
  HandleEvent(nsDOMEvent& event, ErrorResult& aRv, ExceptionHandling aExceptionHandling = eReportExceptions)
  {
    CallSetup s(mCallback, aRv, aExceptionHandling);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    return HandleEvent(s.GetContext(), nullptr, event, aRv);
  }

private:
  void HandleEvent(JSContext* cx, JSObject* aThisObj, nsDOMEvent& event, ErrorResult& aRv);
};


class EventListenerWorkers : public CallbackInterface
{
public:
  inline EventListenerWorkers(JSContext* cx, JSObject* aOwner, JSObject* aCallback, bool* aInited)
    : CallbackInterface(cx, aOwner, aCallback, aInited)
  {
  }

  explicit inline EventListenerWorkers(JSObject* aCallback)
    : CallbackInterface(aCallback)
  {
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisObj, JSObject& event, ErrorResult& aRv, ExceptionHandling aExceptionHandling = eReportExceptions)
  {
    CallSetup s(mCallback, aRv, aExceptionHandling);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    JSObject* thisObjJS = WrapCallThisObject(s.GetContext(), mCallback, thisObj);
    if (!thisObjJS) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }
    return HandleEvent(s.GetContext(), thisObjJS, event, aRv);
  }

  inline void
  HandleEvent(JSObject& event, ErrorResult& aRv, ExceptionHandling aExceptionHandling = eReportExceptions)
  {
    CallSetup s(mCallback, aRv, aExceptionHandling);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    return HandleEvent(s.GetContext(), nullptr, event, aRv);
  }

private:
  void HandleEvent(JSContext* cx, JSObject* aThisObj, JSObject& event, ErrorResult& aRv);
};


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_EventListenerBinding_h__
