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

#include "KeyframeAnimationOptionsBinding.h"
#include "MainThreadUtils.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"

namespace mozilla::dom {

namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;


void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningUnrestrictedDoubleOrKeyframeAnimationOptions& aUnion, const char* aName, uint32_t aFlags)
{
  if (aUnion.IsKeyframeAnimationOptions()) {
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsKeyframeAnimationOptions(), "mKeyframeAnimationOptions", aFlags);
  }
}


void
ImplCycleCollectionUnlink(OwningUnrestrictedDoubleOrKeyframeAnimationOptions& aUnion)
{
  aUnion.Uninit();
}


bool
UnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToUnrestrictedDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  tryNext = false;
  { // scope for memberSlot
    double& memberSlot = RawSetAsUnrestrictedDouble();
    if (!ValueToPrimitive<double, eDefault>(cx, value, "Unrestricted double branch of (unrestricted double or KeyframeAnimationOptions)", &memberSlot)) {
      return false;
    }
  }
  return true;
}







bool
UnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToKeyframeAnimationOptions(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  tryNext = false;
  { // scope for memberSlot
    binding_detail::FastKeyframeAnimationOptions& memberSlot = RawSetAsKeyframeAnimationOptions();
    if (!IsConvertibleToDictionary(value)) {
      DestroyKeyframeAnimationOptions();
      tryNext = true;
      return true;
    }
    if (!memberSlot.Init(cx, value, "KeyframeAnimationOptions branch of (unrestricted double or KeyframeAnimationOptions)", passedToJSImpl)) {
      return false;
    }
  }
  return true;
}

bool
UnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToKeyframeAnimationOptions(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  BindingCallContext cx(cx_, nullptr);
  return TrySetToKeyframeAnimationOptions(cx, value, tryNext, passedToJSImpl);
}







bool
UnrestrictedDoubleOrKeyframeAnimationOptions::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
  MOZ_ASSERT(mType == eUninitialized);

  bool done = false, failed = false, tryNext;
  if (!done) {
    done = (failed = !TrySetToKeyframeAnimationOptions(cx, value, tryNext, passedToJSImpl)) || !tryNext;
  }
  if (!done) {
    do {
      done = (failed = !TrySetToUnrestrictedDouble(cx, value, tryNext)) || !tryNext;
      break;
    } while (false);
  }
  if (failed) {
    return false;
  }
  if (!done) {
    cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "KeyframeAnimationOptions");
    return false;
  }
  return true;
}

bool
UnrestrictedDoubleOrKeyframeAnimationOptions::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
  BindingCallContext cx(cx_, nullptr);
  return Init(cx, value, sourceDescription, passedToJSImpl);
}




OwningUnrestrictedDoubleOrKeyframeAnimationOptions::OwningUnrestrictedDoubleOrKeyframeAnimationOptions(OwningUnrestrictedDoubleOrKeyframeAnimationOptions&& aOther)
  : mType(eUninitialized)
{
  switch (aOther.mType) {
    case eUninitialized: {
      MOZ_ASSERT(mType == eUninitialized,
                 "We need to destroy ourselves?");
      break;
    }
    case eUnrestrictedDouble: {
      mType = eUnrestrictedDouble;
      mValue.mUnrestrictedDouble.SetValue(std::move(aOther.mValue.mUnrestrictedDouble.Value()));
      break;
    }
    case eKeyframeAnimationOptions: {
      mType = eKeyframeAnimationOptions;
      mValue.mKeyframeAnimationOptions.SetValue(std::move(aOther.mValue.mKeyframeAnimationOptions.Value()));
      break;
    }
  }
}



bool
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToUnrestrictedDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  tryNext = false;
  { // scope for memberSlot
    double& memberSlot = RawSetAsUnrestrictedDouble();
    if (!ValueToPrimitive<double, eDefault>(cx, value, "Unrestricted double branch of (unrestricted double or KeyframeAnimationOptions)", &memberSlot)) {
      return false;
    }
  }
  return true;
}

[[nodiscard]] double&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::RawSetAsUnrestrictedDouble()
{
  if (mType == eUnrestrictedDouble) {
    return mValue.mUnrestrictedDouble.Value();
  }
  MOZ_ASSERT(mType == eUninitialized);
  mType = eUnrestrictedDouble;
  return mValue.mUnrestrictedDouble.SetValue();
}

[[nodiscard]] double&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::SetAsUnrestrictedDouble()
{
  if (mType == eUnrestrictedDouble) {
    return mValue.mUnrestrictedDouble.Value();
  }
  Uninit();
  mType = eUnrestrictedDouble;
  return mValue.mUnrestrictedDouble.SetValue();
}


void
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::DestroyUnrestrictedDouble()
{
  MOZ_RELEASE_ASSERT(IsUnrestrictedDouble(), "Wrong type!");
  mValue.mUnrestrictedDouble.Destroy();
  mType = eUninitialized;
}



bool
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToKeyframeAnimationOptions(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  tryNext = false;
  { // scope for memberSlot
    KeyframeAnimationOptions& memberSlot = RawSetAsKeyframeAnimationOptions();
    if (!IsConvertibleToDictionary(value)) {
      DestroyKeyframeAnimationOptions();
      tryNext = true;
      return true;
    }
    if (!memberSlot.Init(cx, value, "KeyframeAnimationOptions branch of (unrestricted double or KeyframeAnimationOptions)", passedToJSImpl)) {
      return false;
    }
  }
  return true;
}

bool
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::TrySetToKeyframeAnimationOptions(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
  BindingCallContext cx(cx_, nullptr);
  return TrySetToKeyframeAnimationOptions(cx, value, tryNext, passedToJSImpl);
}

[[nodiscard]] KeyframeAnimationOptions&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::RawSetAsKeyframeAnimationOptions()
{
  if (mType == eKeyframeAnimationOptions) {
    return mValue.mKeyframeAnimationOptions.Value();
  }
  MOZ_ASSERT(mType == eUninitialized);
  mType = eKeyframeAnimationOptions;
  return mValue.mKeyframeAnimationOptions.SetValue();
}

[[nodiscard]] KeyframeAnimationOptions&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::SetAsKeyframeAnimationOptions()
{
  if (mType == eKeyframeAnimationOptions) {
    return mValue.mKeyframeAnimationOptions.Value();
  }
  Uninit();
  mType = eKeyframeAnimationOptions;
  return mValue.mKeyframeAnimationOptions.SetValue();
}


void
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::DestroyKeyframeAnimationOptions()
{
  MOZ_RELEASE_ASSERT(IsKeyframeAnimationOptions(), "Wrong type!");
  mValue.mKeyframeAnimationOptions.Destroy();
  mType = eUninitialized;
}



bool
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
  MOZ_ASSERT(mType == eUninitialized);

  bool done = false, failed = false, tryNext;
  if (!done) {
    done = (failed = !TrySetToKeyframeAnimationOptions(cx, value, tryNext, passedToJSImpl)) || !tryNext;
  }
  if (!done) {
    do {
      done = (failed = !TrySetToUnrestrictedDouble(cx, value, tryNext)) || !tryNext;
      break;
    } while (false);
  }
  if (failed) {
    return false;
  }
  if (!done) {
    cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "KeyframeAnimationOptions");
    return false;
  }
  return true;
}

bool
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
  BindingCallContext cx(cx_, nullptr);
  return Init(cx, value, sourceDescription, passedToJSImpl);
}

void
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::Uninit()
{
  switch (mType) {
    case eUninitialized: {
      break;
    }
    case eUnrestrictedDouble: {
      DestroyUnrestrictedDouble();
      break;
    }
    case eKeyframeAnimationOptions: {
      DestroyKeyframeAnimationOptions();
      break;
    }
  }
}

OwningUnrestrictedDoubleOrKeyframeAnimationOptions&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::operator=(OwningUnrestrictedDoubleOrKeyframeAnimationOptions&& aOther)
{
  this->~OwningUnrestrictedDoubleOrKeyframeAnimationOptions();
  new (this) OwningUnrestrictedDoubleOrKeyframeAnimationOptions (std::move(aOther));
  return *this;
}


OwningUnrestrictedDoubleOrKeyframeAnimationOptions&
OwningUnrestrictedDoubleOrKeyframeAnimationOptions::operator=(const OwningUnrestrictedDoubleOrKeyframeAnimationOptions& aOther)
{
  switch (aOther.mType) {
    case eUninitialized: {
      MOZ_ASSERT(mType == eUninitialized,
                 "We need to destroy ourselves?");
      break;
    }
    case eUnrestrictedDouble: {
      SetAsUnrestrictedDouble() = aOther.GetAsUnrestrictedDouble();
      break;
    }
    case eKeyframeAnimationOptions: {
      SetAsKeyframeAnimationOptions() = aOther.GetAsKeyframeAnimationOptions();
      break;
    }
  }
  return *this;
}


} // namespace mozilla::dom
