/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */

#ifndef mozilla_dom_FunctionBinding_h__
#define mozilla_dom_FunctionBinding_h__

#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/CallbackFunction.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/DOMJSProxyHandler.h"

class XPCWrappedNativeScope;

namespace mozilla {
namespace dom {

class Function : public CallbackFunction
{
public:
  inline Function(JSContext* cx, JSObject* aOwner, JSObject* aCallable, bool* aInited)
    : CallbackFunction(cx, aOwner, aCallable, aInited)
  {
  }

  explicit inline Function(CallbackFunction* aOther)
    : CallbackFunction(aOther)
  {
  }

  template <typename T>
  inline JS::Value
  Call(const T& thisObj, const nsTArray< JS::Value >& arguments, ErrorResult& aRv)
  {
    CallSetup s(mCallable);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return JS::UndefinedValue();
    }
    JSObject* thisObjJS = WrapCallThisObject(s.GetContext(), mCallable, thisObj);
    if (!thisObjJS) {
      aRv.Throw(NS_ERROR_FAILURE);
      return JS::UndefinedValue();
    }
    return Call(s.GetContext(), thisObjJS, arguments, aRv);
  }

  inline JS::Value
  Call(const nsTArray< JS::Value >& arguments, ErrorResult& aRv)
  {
    CallSetup s(mCallable);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return JS::UndefinedValue();
    }
    return Call(s.GetContext(), nullptr, arguments, aRv);
  }

private:
  JS::Value Call(JSContext* cx, JSObject* aThisObj, const nsTArray< JS::Value >& arguments, ErrorResult& aRv);
};


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_FunctionBinding_h__
