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

#ifndef mozilla_dom_DOMMobileMessageErrorBinding_h
#define mozilla_dom_DOMMobileMessageErrorBinding_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 {

class DOMMobileMessageError;
struct DOMMobileMessageErrorAtoms;
class MmsMessage;
struct NativePropertyHooks;
class OwningSmsMessageOrMmsMessage;
class ProtoAndIfaceCache;
class SmsMessage;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningSmsMessageOrMmsMessage& aUnion, const char* aName, uint32_t aFlags = 0);


void
ImplCycleCollectionUnlink(OwningSmsMessageOrMmsMessage& aUnion);


class SmsMessageOrMmsMessage
{
  friend class SmsMessageOrMmsMessageArgument;
  enum Type
  {
    eUninitialized,
    eSmsMessage,
    eMmsMessage
  };

  union Value
  {
    UnionMember<NonNull<mozilla::dom::SmsMessage> > mSmsMessage;
    UnionMember<NonNull<mozilla::dom::MmsMessage> > mMmsMessage;

  };

  Type mType;
  Value mValue;

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

  inline ~SmsMessageOrMmsMessage()
  {
    Uninit();
  }

  inline NonNull<mozilla::dom::SmsMessage>&
  RawSetAsSmsMessage()
  {
    if (mType == eSmsMessage) {
      return mValue.mSmsMessage.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eSmsMessage;
    return mValue.mSmsMessage.SetValue();
  }

  inline NonNull<mozilla::dom::SmsMessage>&
  SetAsSmsMessage()
  {
    if (mType == eSmsMessage) {
      return mValue.mSmsMessage.Value();
    }
    Uninit();
    mType = eSmsMessage;
    return mValue.mSmsMessage.SetValue();
  }

  inline bool
  IsSmsMessage() const
  {
    return mType == eSmsMessage;
  }

  inline NonNull<mozilla::dom::SmsMessage>&
  GetAsSmsMessage()
  {
    MOZ_ASSERT(IsSmsMessage(), "Wrong type!");
    return mValue.mSmsMessage.Value();
  }

  inline mozilla::dom::SmsMessage&
  GetAsSmsMessage() const
  {
    MOZ_ASSERT(IsSmsMessage(), "Wrong type!");
    return mValue.mSmsMessage.Value();
  }

  inline NonNull<mozilla::dom::MmsMessage>&
  RawSetAsMmsMessage()
  {
    if (mType == eMmsMessage) {
      return mValue.mMmsMessage.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eMmsMessage;
    return mValue.mMmsMessage.SetValue();
  }

  inline NonNull<mozilla::dom::MmsMessage>&
  SetAsMmsMessage()
  {
    if (mType == eMmsMessage) {
      return mValue.mMmsMessage.Value();
    }
    Uninit();
    mType = eMmsMessage;
    return mValue.mMmsMessage.SetValue();
  }

  inline bool
  IsMmsMessage() const
  {
    return mType == eMmsMessage;
  }

  inline NonNull<mozilla::dom::MmsMessage>&
  GetAsMmsMessage()
  {
    MOZ_ASSERT(IsMmsMessage(), "Wrong type!");
    return mValue.mMmsMessage.Value();
  }

  inline mozilla::dom::MmsMessage&
  GetAsMmsMessage() const
  {
    MOZ_ASSERT(IsMmsMessage(), "Wrong type!");
    return mValue.mMmsMessage.Value();
  }

  inline void
  Uninit()
  {
    switch (mType) {
      case eUninitialized: {
        break;
      }
      case eSmsMessage: {
        DestroySmsMessage();
        break;
      }
      case eMmsMessage: {
        DestroyMmsMessage();
        break;
      }
    }
  }

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

private:
  inline void
  DestroySmsMessage()
  {
    MOZ_ASSERT(IsSmsMessage(), "Wrong type!");
    mValue.mSmsMessage.Destroy();
    mType = eUninitialized;
  }

  inline void
  DestroyMmsMessage()
  {
    MOZ_ASSERT(IsMmsMessage(), "Wrong type!");
    mValue.mMmsMessage.Destroy();
    mType = eUninitialized;
  }
};


class OwningSmsMessageOrMmsMessage : public AllOwningUnionBase
{
  friend void ImplCycleCollectionUnlink(OwningSmsMessageOrMmsMessage& aUnion);
  enum Type
  {
    eUninitialized,
    eSmsMessage,
    eMmsMessage
  };

  union Value
  {
    UnionMember<OwningNonNull<mozilla::dom::SmsMessage> > mSmsMessage;
    UnionMember<OwningNonNull<mozilla::dom::MmsMessage> > mMmsMessage;

  };

  Type mType;
  Value mValue;

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

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

  inline ~OwningSmsMessageOrMmsMessage()
  {
    Uninit();
  }

  OwningNonNull<mozilla::dom::SmsMessage>&
  RawSetAsSmsMessage();

  OwningNonNull<mozilla::dom::SmsMessage>&
  SetAsSmsMessage();

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

  inline bool
  IsSmsMessage() const
  {
    return mType == eSmsMessage;
  }

  inline OwningNonNull<mozilla::dom::SmsMessage>&
  GetAsSmsMessage()
  {
    MOZ_ASSERT(IsSmsMessage(), "Wrong type!");
    return mValue.mSmsMessage.Value();
  }

  inline OwningNonNull<mozilla::dom::SmsMessage> const &
  GetAsSmsMessage() const
  {
    MOZ_ASSERT(IsSmsMessage(), "Wrong type!");
    return mValue.mSmsMessage.Value();
  }

  OwningNonNull<mozilla::dom::MmsMessage>&
  RawSetAsMmsMessage();

  OwningNonNull<mozilla::dom::MmsMessage>&
  SetAsMmsMessage();

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

  inline bool
  IsMmsMessage() const
  {
    return mType == eMmsMessage;
  }

  inline OwningNonNull<mozilla::dom::MmsMessage>&
  GetAsMmsMessage()
  {
    MOZ_ASSERT(IsMmsMessage(), "Wrong type!");
    return mValue.mMmsMessage.Value();
  }

  inline OwningNonNull<mozilla::dom::MmsMessage> const &
  GetAsMmsMessage() const
  {
    MOZ_ASSERT(IsMmsMessage(), "Wrong type!");
    return mValue.mMmsMessage.Value();
  }

  void
  Uninit();

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

  void
  TraceUnion(JSTracer* trc);

  void
  operator=(const OwningSmsMessageOrMmsMessage& aOther);

private:
  void
  DestroySmsMessage();

  void
  DestroyMmsMessage();
};


namespace DOMMobileMessageErrorBinding {

  typedef mozilla::dom::DOMMobileMessageError 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);

  bool
  ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);

  const JSClass*
  GetJSClass();

  bool
  Wrap(JSContext* aCx, mozilla::dom::DOMMobileMessageError* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);

  template <class T>
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
  {
    JS::Rooted<JSObject*> reflector(aCx);
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
  }

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

  JS::Handle<JSObject*>
  GetProtoObjectHandle(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 DOMMobileMessageErrorBinding



} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_DOMMobileMessageErrorBinding_h
