/* 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 JSObject;
class nsDOMEvent;
class nsIDOMEventListener;

namespace mozilla {
namespace dom {

class EventListener : public CallbackInterface
{
public:
  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;
    }
    JS::Rooted<JSObject*> thisObjJS(s.GetContext(),
      WrapCallThisObject(s.GetContext(), CallbackPreserveColor(), 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(), JS::NullPtr(), event, aRv);
  }

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


class EventListenerWorkers : public CallbackInterface
{
public:
  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;
    }
    JS::Rooted<JSObject*> thisObjJS(s.GetContext(),
      WrapCallThisObject(s.GetContext(), CallbackPreserveColor(), 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(), JS::NullPtr(), event, aRv);
  }

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


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_EventListenerBinding_h__
