/* 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 nsIDOMEvent;

class nsIDOMEvent;

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

  template <typename T>
  inline void
  HandleEvent(const T& thisObj, nsIDOMEvent* event, ErrorResult& aRv)
  {
    CallSetup s(mCallback);
    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(nsIDOMEvent* event, ErrorResult& aRv)
  {
    CallSetup s(mCallback);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    return HandleEvent(s.GetContext(), nullptr, event, aRv);
  }

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


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

  template <typename T>
  inline void
  HandleEvent(const T& thisObj, JSObject* event, ErrorResult& aRv)
  {
    CallSetup s(mCallback);
    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)
  {
    CallSetup s(mCallback);
    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__
