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

#ifndef mozilla_dom_EventTargetBinding_h
#define mozilla_dom_EventTargetBinding_h

#include "EventTargetBinding.h"
#include "js/RootingAPI.h"
#include "jspubtd.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/UnionMember.h"

namespace mozilla {
namespace dom {

struct AddEventListenerOptionsAtoms;
struct EventListenerOptionsAtoms;
class EventTarget;
struct EventTargetAtoms;
struct NativePropertyHooks;
class ProtoAndIfaceCache;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

struct EventListenerOptions : public DictionaryBase
{
  bool mCapture;
  bool mMozSystemGroup;

  EventListenerOptions();

  explicit inline EventListenerOptions(const FastDictionaryInitializer& )
  {
    // Do nothing here; this is used by our "Fast" subclass
  }

  explicit inline EventListenerOptions(const EventListenerOptions& aOther)
  {
    *this = aOther;
  }

  bool
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);

  bool
  Init(const nsAString& aJSON);

  bool
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;

  bool
  ToJSON(nsAString& aJSON) const;

  void
  TraceDictionary(JSTracer* trc);

  void
  operator=(const EventListenerOptions& aOther);

private:
  static bool
  InitIds(JSContext* cx, EventListenerOptionsAtoms* atomsCache);
};

namespace binding_detail {
struct FastEventListenerOptions : public EventListenerOptions
{
  inline FastEventListenerOptions()
    : EventListenerOptions(FastDictionaryInitializer())
  {
    // Doesn't matter what int we pass to the parent constructor
  }
};
} // namespace binding_detail


struct AddEventListenerOptions : public EventListenerOptions
{
  bool mOnce;
  bool mPassive;

  AddEventListenerOptions();

  explicit inline AddEventListenerOptions(const FastDictionaryInitializer& )
    : EventListenerOptions(FastDictionaryInitializer())
  {
    // Do nothing here; this is used by our "Fast" subclass
  }

  explicit inline AddEventListenerOptions(const AddEventListenerOptions& aOther)
  {
    *this = aOther;
  }

  bool
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);

  bool
  Init(const nsAString& aJSON);

  bool
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;

  bool
  ToJSON(nsAString& aJSON) const;

  void
  TraceDictionary(JSTracer* trc);

  void
  operator=(const AddEventListenerOptions& aOther);

private:
  static bool
  InitIds(JSContext* cx, AddEventListenerOptionsAtoms* atomsCache);
};

namespace binding_detail {
struct FastAddEventListenerOptions : public AddEventListenerOptions
{
  inline FastAddEventListenerOptions()
    : AddEventListenerOptions(FastDictionaryInitializer())
  {
    // Doesn't matter what int we pass to the parent constructor
  }
};
} // namespace binding_detail


class EventListenerOptionsOrBoolean
{
  friend class EventListenerOptionsOrBooleanArgument;
  enum Type
  {
    eUninitialized,
    eEventListenerOptions,
    eBoolean
  };

  union Value
  {
    UnionMember<binding_detail::FastEventListenerOptions > mEventListenerOptions;
    UnionMember<bool > mBoolean;

  };

  Type mType;
  Value mValue;

  EventListenerOptionsOrBoolean(const EventListenerOptionsOrBoolean&) = delete;
  void operator=(const EventListenerOptionsOrBoolean) = delete;
public:
  explicit inline EventListenerOptionsOrBoolean()
    : mType(eUninitialized)
  {
  }

  inline ~EventListenerOptionsOrBoolean()
  {
    Uninit();
  }

  inline binding_detail::FastEventListenerOptions&
  RawSetAsEventListenerOptions()
  {
    if (mType == eEventListenerOptions) {
      return mValue.mEventListenerOptions.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eEventListenerOptions;
    return mValue.mEventListenerOptions.SetValue();
  }

  inline binding_detail::FastEventListenerOptions&
  SetAsEventListenerOptions()
  {
    if (mType == eEventListenerOptions) {
      return mValue.mEventListenerOptions.Value();
    }
    Uninit();
    mType = eEventListenerOptions;
    return mValue.mEventListenerOptions.SetValue();
  }

  inline bool
  IsEventListenerOptions() const
  {
    return mType == eEventListenerOptions;
  }

  inline binding_detail::FastEventListenerOptions&
  GetAsEventListenerOptions()
  {
    MOZ_ASSERT(IsEventListenerOptions(), "Wrong type!");
    return mValue.mEventListenerOptions.Value();
  }

  inline const EventListenerOptions&
  GetAsEventListenerOptions() const
  {
    MOZ_ASSERT(IsEventListenerOptions(), "Wrong type!");
    return mValue.mEventListenerOptions.Value();
  }

  inline bool&
  RawSetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool&
  SetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    Uninit();
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline void
  Uninit()
  {
    switch (mType) {
      case eUninitialized: {
        break;
      }
      case eEventListenerOptions: {
        DestroyEventListenerOptions();
        break;
      }
      case eBoolean: {
        DestroyBoolean();
        break;
      }
    }
  }

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

private:
  inline void
  DestroyEventListenerOptions()
  {
    MOZ_ASSERT(IsEventListenerOptions(), "Wrong type!");
    mValue.mEventListenerOptions.Destroy();
    mType = eUninitialized;
  }

  inline void
  DestroyBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    mValue.mBoolean.Destroy();
    mType = eUninitialized;
  }
};


class OwningEventListenerOptionsOrBoolean : public AllOwningUnionBase
{
  friend void ImplCycleCollectionUnlink(OwningEventListenerOptionsOrBoolean& aUnion);
  enum Type
  {
    eUninitialized,
    eEventListenerOptions,
    eBoolean
  };

  union Value
  {
    UnionMember<EventListenerOptions > mEventListenerOptions;
    UnionMember<bool > mBoolean;

  };

  Type mType;
  Value mValue;

public:
  explicit inline OwningEventListenerOptionsOrBoolean()
    : mType(eUninitialized)
  {
  }

  explicit inline OwningEventListenerOptionsOrBoolean(const OwningEventListenerOptionsOrBoolean& aOther)
    : mType(eUninitialized)
  {
    *this = aOther;
  }

  inline ~OwningEventListenerOptionsOrBoolean()
  {
    Uninit();
  }

  EventListenerOptions&
  RawSetAsEventListenerOptions();

  EventListenerOptions&
  SetAsEventListenerOptions();

  bool
  TrySetToEventListenerOptions(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsEventListenerOptions() const
  {
    return mType == eEventListenerOptions;
  }

  inline EventListenerOptions&
  GetAsEventListenerOptions()
  {
    MOZ_ASSERT(IsEventListenerOptions(), "Wrong type!");
    return mValue.mEventListenerOptions.Value();
  }

  inline EventListenerOptions const &
  GetAsEventListenerOptions() const
  {
    MOZ_ASSERT(IsEventListenerOptions(), "Wrong type!");
    return mValue.mEventListenerOptions.Value();
  }

  bool&
  RawSetAsBoolean();

  bool&
  SetAsBoolean();

  bool
  TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool const &
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  void
  Uninit();

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

  void
  TraceUnion(JSTracer* trc);

  void
  operator=(const OwningEventListenerOptionsOrBoolean& aOther);

private:
  void
  DestroyEventListenerOptions();

  void
  DestroyBoolean();
};


class AddEventListenerOptionsOrBoolean
{
  friend class AddEventListenerOptionsOrBooleanArgument;
  enum Type
  {
    eUninitialized,
    eAddEventListenerOptions,
    eBoolean
  };

  union Value
  {
    UnionMember<binding_detail::FastAddEventListenerOptions > mAddEventListenerOptions;
    UnionMember<bool > mBoolean;

  };

  Type mType;
  Value mValue;

  AddEventListenerOptionsOrBoolean(const AddEventListenerOptionsOrBoolean&) = delete;
  void operator=(const AddEventListenerOptionsOrBoolean) = delete;
public:
  explicit inline AddEventListenerOptionsOrBoolean()
    : mType(eUninitialized)
  {
  }

  inline ~AddEventListenerOptionsOrBoolean()
  {
    Uninit();
  }

  inline binding_detail::FastAddEventListenerOptions&
  RawSetAsAddEventListenerOptions()
  {
    if (mType == eAddEventListenerOptions) {
      return mValue.mAddEventListenerOptions.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eAddEventListenerOptions;
    return mValue.mAddEventListenerOptions.SetValue();
  }

  inline binding_detail::FastAddEventListenerOptions&
  SetAsAddEventListenerOptions()
  {
    if (mType == eAddEventListenerOptions) {
      return mValue.mAddEventListenerOptions.Value();
    }
    Uninit();
    mType = eAddEventListenerOptions;
    return mValue.mAddEventListenerOptions.SetValue();
  }

  inline bool
  IsAddEventListenerOptions() const
  {
    return mType == eAddEventListenerOptions;
  }

  inline binding_detail::FastAddEventListenerOptions&
  GetAsAddEventListenerOptions()
  {
    MOZ_ASSERT(IsAddEventListenerOptions(), "Wrong type!");
    return mValue.mAddEventListenerOptions.Value();
  }

  inline const AddEventListenerOptions&
  GetAsAddEventListenerOptions() const
  {
    MOZ_ASSERT(IsAddEventListenerOptions(), "Wrong type!");
    return mValue.mAddEventListenerOptions.Value();
  }

  inline bool&
  RawSetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool&
  SetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    Uninit();
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline void
  Uninit()
  {
    switch (mType) {
      case eUninitialized: {
        break;
      }
      case eAddEventListenerOptions: {
        DestroyAddEventListenerOptions();
        break;
      }
      case eBoolean: {
        DestroyBoolean();
        break;
      }
    }
  }

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

private:
  inline void
  DestroyAddEventListenerOptions()
  {
    MOZ_ASSERT(IsAddEventListenerOptions(), "Wrong type!");
    mValue.mAddEventListenerOptions.Destroy();
    mType = eUninitialized;
  }

  inline void
  DestroyBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    mValue.mBoolean.Destroy();
    mType = eUninitialized;
  }
};


class OwningAddEventListenerOptionsOrBoolean : public AllOwningUnionBase
{
  friend void ImplCycleCollectionUnlink(OwningAddEventListenerOptionsOrBoolean& aUnion);
  enum Type
  {
    eUninitialized,
    eAddEventListenerOptions,
    eBoolean
  };

  union Value
  {
    UnionMember<AddEventListenerOptions > mAddEventListenerOptions;
    UnionMember<bool > mBoolean;

  };

  Type mType;
  Value mValue;

public:
  explicit inline OwningAddEventListenerOptionsOrBoolean()
    : mType(eUninitialized)
  {
  }

  explicit inline OwningAddEventListenerOptionsOrBoolean(const OwningAddEventListenerOptionsOrBoolean& aOther)
    : mType(eUninitialized)
  {
    *this = aOther;
  }

  inline ~OwningAddEventListenerOptionsOrBoolean()
  {
    Uninit();
  }

  AddEventListenerOptions&
  RawSetAsAddEventListenerOptions();

  AddEventListenerOptions&
  SetAsAddEventListenerOptions();

  bool
  TrySetToAddEventListenerOptions(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsAddEventListenerOptions() const
  {
    return mType == eAddEventListenerOptions;
  }

  inline AddEventListenerOptions&
  GetAsAddEventListenerOptions()
  {
    MOZ_ASSERT(IsAddEventListenerOptions(), "Wrong type!");
    return mValue.mAddEventListenerOptions.Value();
  }

  inline AddEventListenerOptions const &
  GetAsAddEventListenerOptions() const
  {
    MOZ_ASSERT(IsAddEventListenerOptions(), "Wrong type!");
    return mValue.mAddEventListenerOptions.Value();
  }

  bool&
  RawSetAsBoolean();

  bool&
  SetAsBoolean();

  bool
  TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool const &
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  void
  Uninit();

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

  void
  TraceUnion(JSTracer* trc);

  void
  operator=(const OwningAddEventListenerOptionsOrBoolean& aOther);

private:
  void
  DestroyAddEventListenerOptions();

  void
  DestroyBoolean();
};


namespace EventTargetBinding {

  typedef mozilla::dom::EventTarget NativeType;

  // We declare this as an array so that retrieving a pointer to this
  // binding's property hooks only requires compile/link-time resolvable
  // address arithmetic.  Declaring it as a pointer instead would require
  // doing a run-time load to fetch a pointer to this binding's property
  // hooks.  And then structures which embedded a pointer to this structure
  // would require a run-time load for proper initialization, which would
  // then induce static constructors.  Lots of static constructors.
  extern const NativePropertyHooks sNativePropertyHooks[];

  JSObject*
  DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);

  void
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);

  JS::Handle<JSObject*>
  GetProtoObjectHandle(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

  JSObject*
  GetProtoObject(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

  JS::Handle<JSObject*>
  GetConstructorObjectHandle(JSContext* aCx, JS::Handle<JSObject*> aGlobal, bool aDefineOnGlobal = true);

  JSObject*
  GetConstructorObject(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

} // namespace EventTargetBinding



} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_EventTargetBinding_h
