Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM UniFFI.webidl BY Codegen.py - DO NOT EDIT */
#ifndef DOM_UNIFFIBINDING_H_
#define DOM_UNIFFIBINDING_H_
#include "js/CallAndConstruct.h"
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
#include "js/Value.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/Span.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackFunction.h"
#include "mozilla/dom/FakeString.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrototypeList.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/UnionMember.h"
namespace mozilla {
namespace dom {
class DoubleOrArrayBufferOrUniFFIPointer;
struct NativePropertyHooks;
class OwningDoubleOrArrayBufferOrUniFFIPointer;
class ProtoAndIfaceCache;
class UniFFICallbackHandler;
class UniFFIPointer;
class UniFFIScaffolding;
struct UniFFIScaffoldingCallResultAtoms;
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
enum class UniFFIScaffoldingCallCode : uint8_t {
Success,
Error,
Internal_error,
};
namespace binding_detail {
template <> struct EnumStrings<UniFFIScaffoldingCallCode> {
static const nsLiteralCString Values[3];
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, UniFFIScaffoldingCallCode aArgument, JS::MutableHandle<JS::Value> aValue);
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningDoubleOrArrayBufferOrUniFFIPointer& aUnion, const char* aName, uint32_t aFlags = 0);
void
ImplCycleCollectionUnlink(OwningDoubleOrArrayBufferOrUniFFIPointer& aUnion);
class DoubleOrArrayBufferOrUniFFIPointer : public AllUnionBase,
public UnionWithTypedArraysBase
{
public:
using ApplyToTypedArrays = binding_detail::ApplyToTypedArraysHelper<DoubleOrArrayBufferOrUniFFIPointer, true, ArrayBuffer>;
private:
enum TypeOrUninit
{
eUninitialized,
eDouble,
eArrayBuffer,
eUniFFIPointer
};
public:
enum class Type
{
eDouble = TypeOrUninit::eDouble,
eArrayBuffer = TypeOrUninit::eArrayBuffer,
eUniFFIPointer = TypeOrUninit::eUniFFIPointer
};
private:
union Value
{
UnionMember<double > mDouble;
UnionMember<RootedSpiderMonkeyInterface<ArrayBuffer> > mArrayBuffer;
UnionMember<NonNull<mozilla::dom::UniFFIPointer> > mUniFFIPointer;
};
TypeOrUninit mType;
Value mValue;
DoubleOrArrayBufferOrUniFFIPointer(const DoubleOrArrayBufferOrUniFFIPointer&) = delete;
DoubleOrArrayBufferOrUniFFIPointer& operator=(const DoubleOrArrayBufferOrUniFFIPointer&) = delete;
public:
explicit inline DoubleOrArrayBufferOrUniFFIPointer()
: mType(eUninitialized)
{
}
inline ~DoubleOrArrayBufferOrUniFFIPointer()
{
Uninit();
}
[[nodiscard]] inline double&
RawSetAsDouble()
{
if (mType == eDouble) {
return mValue.mDouble.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eDouble;
return mValue.mDouble.SetValue();
}
[[nodiscard]] inline double&
SetAsDouble()
{
if (mType == eDouble) {
return mValue.mDouble.Value();
}
Uninit();
mType = eDouble;
return mValue.mDouble.SetValue();
}
inline bool
IsDouble() const
{
return mType == eDouble;
}
inline double&
GetAsDouble()
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
return mValue.mDouble.Value();
}
inline double
GetAsDouble() const
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
return mValue.mDouble.Value();
}
[[nodiscard]] inline RootedSpiderMonkeyInterface<ArrayBuffer>&
RawSetAsArrayBuffer(JSContext* cx)
{
if (mType == eArrayBuffer) {
return mValue.mArrayBuffer.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eArrayBuffer;
return mValue.mArrayBuffer.SetValue(cx);
}
[[nodiscard]] inline RootedSpiderMonkeyInterface<ArrayBuffer>&
SetAsArrayBuffer(JSContext* cx)
{
if (mType == eArrayBuffer) {
return mValue.mArrayBuffer.Value();
}
Uninit();
mType = eArrayBuffer;
return mValue.mArrayBuffer.SetValue(cx);
}
inline bool
IsArrayBuffer() const
{
return mType == eArrayBuffer;
}
inline RootedSpiderMonkeyInterface<ArrayBuffer>&
GetAsArrayBuffer()
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
return mValue.mArrayBuffer.Value();
}
inline ArrayBuffer const &
GetAsArrayBuffer() const
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
return mValue.mArrayBuffer.Value();
}
[[nodiscard]] inline NonNull<mozilla::dom::UniFFIPointer>&
RawSetAsUniFFIPointer()
{
if (mType == eUniFFIPointer) {
return mValue.mUniFFIPointer.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eUniFFIPointer;
return mValue.mUniFFIPointer.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::dom::UniFFIPointer>&
SetAsUniFFIPointer()
{
if (mType == eUniFFIPointer) {
return mValue.mUniFFIPointer.Value();
}
Uninit();
mType = eUniFFIPointer;
return mValue.mUniFFIPointer.SetValue();
}
inline bool
IsUniFFIPointer() const
{
return mType == eUniFFIPointer;
}
inline NonNull<mozilla::dom::UniFFIPointer>&
GetAsUniFFIPointer()
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
return mValue.mUniFFIPointer.Value();
}
inline mozilla::dom::UniFFIPointer&
GetAsUniFFIPointer() const
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
return mValue.mUniFFIPointer.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
inline void
Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eDouble: {
DestroyDouble();
break;
}
case eArrayBuffer: {
DestroyArrayBuffer();
break;
}
case eUniFFIPointer: {
DestroyUniFFIPointer();
break;
}
}
}
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
private:
bool
TrySetToDouble(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToDouble(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyDouble()
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
mValue.mDouble.Destroy();
mType = eUninitialized;
}
bool
TrySetToArrayBuffer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToArrayBuffer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyArrayBuffer()
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
mValue.mArrayBuffer.Destroy();
mType = eUninitialized;
}
bool
TrySetToUniFFIPointer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToUniFFIPointer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyUniFFIPointer()
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
mValue.mUniFFIPointer.Destroy();
mType = eUninitialized;
}
};
class OwningDoubleOrArrayBufferOrUniFFIPointer : public AllOwningUnionBase,
public UnionWithTypedArraysBase
{
friend void ImplCycleCollectionUnlink(OwningDoubleOrArrayBufferOrUniFFIPointer& aUnion);
public:
using ApplyToTypedArrays = binding_detail::ApplyToTypedArraysHelper<OwningDoubleOrArrayBufferOrUniFFIPointer, true, ArrayBuffer>;
private:
enum TypeOrUninit
{
eUninitialized,
eDouble,
eArrayBuffer,
eUniFFIPointer
};
public:
enum class Type
{
eDouble = TypeOrUninit::eDouble,
eArrayBuffer = TypeOrUninit::eArrayBuffer,
eUniFFIPointer = TypeOrUninit::eUniFFIPointer
};
private:
union Value
{
UnionMember<double > mDouble;
UnionMember<ArrayBuffer > mArrayBuffer;
UnionMember<OwningNonNull<mozilla::dom::UniFFIPointer> > mUniFFIPointer;
};
TypeOrUninit mType;
Value mValue;
OwningDoubleOrArrayBufferOrUniFFIPointer(const OwningDoubleOrArrayBufferOrUniFFIPointer&) = delete;
OwningDoubleOrArrayBufferOrUniFFIPointer& operator=(const OwningDoubleOrArrayBufferOrUniFFIPointer&) = delete;
public:
explicit inline OwningDoubleOrArrayBufferOrUniFFIPointer()
: mType(eUninitialized)
{
}
OwningDoubleOrArrayBufferOrUniFFIPointer(OwningDoubleOrArrayBufferOrUniFFIPointer&& aOther);
inline ~OwningDoubleOrArrayBufferOrUniFFIPointer()
{
Uninit();
}
[[nodiscard]] double&
RawSetAsDouble();
[[nodiscard]] double&
SetAsDouble();
inline bool
IsDouble() const
{
return mType == eDouble;
}
inline double&
GetAsDouble()
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
return mValue.mDouble.Value();
}
inline double const &
GetAsDouble() const
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
return mValue.mDouble.Value();
}
[[nodiscard]] ArrayBuffer&
RawSetAsArrayBuffer();
[[nodiscard]] ArrayBuffer&
SetAsArrayBuffer();
inline bool
IsArrayBuffer() const
{
return mType == eArrayBuffer;
}
inline ArrayBuffer&
GetAsArrayBuffer()
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
return mValue.mArrayBuffer.Value();
}
inline ArrayBuffer const &
GetAsArrayBuffer() const
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
return mValue.mArrayBuffer.Value();
}
[[nodiscard]] OwningNonNull<mozilla::dom::UniFFIPointer>&
RawSetAsUniFFIPointer();
[[nodiscard]] OwningNonNull<mozilla::dom::UniFFIPointer>&
SetAsUniFFIPointer();
inline bool
IsUniFFIPointer() const
{
return mType == eUniFFIPointer;
}
inline OwningNonNull<mozilla::dom::UniFFIPointer>&
GetAsUniFFIPointer()
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
return mValue.mUniFFIPointer.Value();
}
inline OwningNonNull<mozilla::dom::UniFFIPointer> const &
GetAsUniFFIPointer() const
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
return mValue.mUniFFIPointer.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
Uninit();
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
void
TraceUnion(JSTracer* trc);
OwningDoubleOrArrayBufferOrUniFFIPointer&
operator=(OwningDoubleOrArrayBufferOrUniFFIPointer&& aOther);
inline Type
GetType() const
{
MOZ_RELEASE_ASSERT(mType != eUninitialized);
return static_cast<Type>(mType);
}
private:
bool
TrySetToDouble(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToDouble(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyDouble();
bool
TrySetToArrayBuffer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToArrayBuffer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyArrayBuffer();
bool
TrySetToUniFFIPointer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToUniFFIPointer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyUniFFIPointer();
};
class UniFFICallbackHandler : public CallbackFunction
{
public:
explicit inline UniFFICallbackHandler(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UniFFICallbackHandler(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackFunction(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UniFFICallbackHandler(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UniFFICallbackHandler(CallbackFunction* aOther)
: CallbackFunction(aOther)
{
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UniFFICallbackHandler";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
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 Call(s.GetCallContext(), thisValJS, objectId, methodId, aArgs, aRv);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UniFFICallbackHandler";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return;
}
return Call(s.GetCallContext(), JS::UndefinedHandleValue, objectId, methodId, aArgs, aRv);
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, const char* aExecutionReason = nullptr)
{
return Call(thisVal, objectId, methodId, aArgs, IgnoreErrors(), aExecutionReason);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, const char* aExecutionReason = nullptr)
{
return Call(objectId, methodId, aArgs, IgnoreErrors(), aExecutionReason, eReportExceptions, nullptr);
}
inline bool
operator==(const UniFFICallbackHandler& aOther) const
{
return CallbackFunction::operator==(aOther);
}
private:
MOZ_CAN_RUN_SCRIPT void Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, ErrorResult& aRv);
};
namespace binding_detail {
class FastUniFFICallbackHandler : public UniFFICallbackHandler
{
public:
explicit inline FastUniFFICallbackHandler(JSObject* aCallback, JSObject* aCallbackGlobal)
: UniFFICallbackHandler(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
inline void
Trace(JSTracer* aTracer)
{
UniFFICallbackHandler::Trace(aTracer);
}
inline void
FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
{
UniFFICallbackHandler::FinishSlowJSInitIfMoreThanOneOwner(aCx);
}
};
} // namespace binding_detail
struct UniFFIScaffoldingCallResult : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR UniFFIScaffoldingCallCode mCode;
MOZ_INIT_OUTSIDE_CTOR Optional<OwningDoubleOrArrayBufferOrUniFFIPointer> mData;
MOZ_INIT_OUTSIDE_CTOR Optional<nsCString> mInternalErrorMessage;
UniFFIScaffoldingCallResult();
explicit inline UniFFIScaffoldingCallResult(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
UniFFIScaffoldingCallResult(UniFFIScaffoldingCallResult&& aOther) = default;
private:
UniFFIScaffoldingCallResult(const UniFFIScaffoldingCallResult&) = delete;
UniFFIScaffoldingCallResult& operator=(const UniFFIScaffoldingCallResult&) = delete;
static bool
InitIds(JSContext* cx, UniFFIScaffoldingCallResultAtoms* atomsCache);
public:
bool
Init(const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
void
TraceDictionary(JSTracer* trc);
inline void
TraverseForCC(nsCycleCollectionTraversalCallback& aCallback, uint32_t aFlags)
{
ImplCycleCollectionTraverse(aCallback, mData, "mData", aFlags);
}
inline void
UnlinkForCC()
{
ImplCycleCollectionUnlink(mData);
}
};
namespace binding_detail {
struct FastUniFFIScaffoldingCallResult : public UniFFIScaffoldingCallResult
{
inline FastUniFFIScaffoldingCallResult()
: UniFFIScaffoldingCallResult(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
namespace UniFFIPointer_Binding {
typedef mozilla::dom::UniFFIPointer NativeType;
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
bool
Wrap(JSContext* aCx, mozilla::dom::UniFFIPointer* 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);
inline JS::Handle<JSObject*> GetProtoObjectHandle(JSContext* aCx)
{
/* Get the interface prototype object for this class. This will create the
object as needed. */
return GetPerInterfaceObjectHandle(aCx, prototypes::id::UniFFIPointer,
&CreateInterfaceObjects,
/* aDefineOnGlobal = */ true);
}
inline JS::Handle<JSObject*> GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true)
{
/* Get the interface object for this class. This will create the object as
needed. */
return GetPerInterfaceObjectHandle(aCx, constructors::id::UniFFIPointer,
&CreateInterfaceObjects,
aDefineOnGlobal);
}
JSObject*
GetConstructorObject(JSContext* aCx);
} // namespace UniFFIPointer_Binding
namespace UniFFIScaffolding_Binding {
typedef mozilla::dom::UniFFIScaffolding NativeType;
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
inline JS::Handle<JSObject*> GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true)
{
/* Get the interface object for this class. This will create the object as
needed. */
return GetPerInterfaceObjectHandle(aCx, constructors::id::UniFFIScaffolding,
&CreateInterfaceObjects,
aDefineOnGlobal);
}
JSObject*
GetConstructorObject(JSContext* aCx);
} // namespace UniFFIScaffolding_Binding
} // namespace dom
template <>
struct MaxContiguousEnumValue<dom::UniFFIScaffoldingCallCode>
{
static constexpr dom::UniFFIScaffoldingCallCode value = dom::UniFFIScaffoldingCallCode::Internal_error;
static_assert(static_cast<uint8_t>(dom::UniFFIScaffoldingCallCode::Success) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(mozilla::ArrayLength(dom::binding_detail::EnumStrings<dom::UniFFIScaffoldingCallCode>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
} // namespace mozilla
#endif // DOM_UNIFFIBINDING_H_