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

#ifndef mozilla_dom_FetchObserverBinding_h
#define mozilla_dom_FetchObserverBinding_h

#include "js/RootingAPI.h"
#include "jspubtd.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackInterface.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/ToJSValue.h"

namespace mozilla {
namespace dom {

class FetchObserver;
struct FetchObserverAtoms;
struct NativePropertyHooks;
class ObserverCallback;
struct ObserverCallbackAtoms;
class ProtoAndIfaceCache;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

enum class FetchState : uint32_t {
  Requesting,
  Responding,
  Aborted,
  Errored,
  Complete,
  EndGuard_
};

namespace FetchStateValues {
extern const EnumEntry strings[6];
} // namespace FetchStateValues

bool
ToJSValue(JSContext* aCx, FetchState aArgument, JS::MutableHandle<JS::Value> aValue);


namespace FetchObserverBinding {

  typedef mozilla::dom::FetchObserver NativeType;

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

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

  const JSClass*
  GetJSClass();

  bool
  Wrap(JSContext* aCx, mozilla::dom::FetchObserver* 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;
  }

  // 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[];

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

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

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

  JSObject*
  GetConstructorObject(JSContext* aCx);

} // namespace FetchObserverBinding



class ObserverCallback : public CallbackInterface
{
public:
  explicit inline ObserverCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : CallbackInterface(aCx, aCallback, aIncumbentGlobal)
  {
  }

  explicit inline ObserverCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal, const FastCallbackConstructor& )
    : CallbackInterface(aCx, aCallback, aIncumbentGlobal, FastCallbackConstructor())
  {
  }

  explicit inline ObserverCallback(JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
    : CallbackInterface(aCallback, aAsyncStack, aIncumbentGlobal)
  {
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisVal, FetchObserver& observer, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "ObserverCallback.handleEvent";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      MOZ_ASSERT(aRv.Failed());
      return;
    }
    JS::Rooted<JS::Value> thisValJS(s.GetContext());
    if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }
    return HandleEvent(s.GetContext(), thisValJS, observer, aRv);
  }

  inline void
  HandleEvent(FetchObserver& observer, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "ObserverCallback.handleEvent";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      MOZ_ASSERT(aRv.Failed());
      return;
    }
    return HandleEvent(s.GetContext(), JS::UndefinedHandleValue, observer, aRv);
  }

  template <typename T>
  inline void
  HandleEvent(const T& thisVal, FetchObserver& observer, const char* aExecutionReason = nullptr)
  {
    IgnoredErrorResult rv;
    return HandleEvent(thisVal, observer, rv, aExecutionReason);
  }

  inline void
  HandleEvent(FetchObserver& observer, const char* aExecutionReason = nullptr)
  {
    IgnoredErrorResult rv;
    return HandleEvent(observer, rv, aExecutionReason, eReportExceptions, nullptr);
  }

  inline bool
  operator==(const ObserverCallback& aOther) const
  {
    return CallbackInterface::operator==(aOther);
  }

private:
  void HandleEvent(JSContext* cx, JS::Handle<JS::Value> aThisVal, FetchObserver& observer, ErrorResult& aRv);

  static bool
  InitIds(JSContext* cx, ObserverCallbackAtoms* atomsCache);
};


namespace binding_detail {
class FastObserverCallback : public ObserverCallback
{
public:
  explicit inline FastObserverCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : ObserverCallback(aCx, aCallback, aIncumbentGlobal, FastCallbackConstructor())
  {
  }

  inline void
  Trace(JSTracer* aTracer)
  {
    ObserverCallback::Trace(aTracer);
  }

  inline void
  HoldJSObjectsIfMoreThanOneOwner()
  {
    ObserverCallback::HoldJSObjectsIfMoreThanOneOwner();
  }
};
} // namespace binding_detail


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_FetchObserverBinding_h
