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/ErrorResult.h"
#include "mozilla/Span.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackInterface.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;
struct UniFFICallbackHandlerAtoms;
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 constexpr nsLiteralCString Values[3] {
"success"_ns,
"error"_ns,
"internal-error"_ns,
};
};
} // 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();
};
struct UniFFIScaffoldingCallResult : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR UniFFIScaffoldingCallCode mCode;
MOZ_INIT_OUTSIDE_CTOR Optional<OwningDoubleOrArrayBufferOrUniFFIPointer> mData;
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, DefineInterfaceProperty aDefineOnGlobal);
JS::Handle<JSObject*>
GetConstructorObjectHandle(JSContext* aCx);
inline bool CreateAndDefineOnGlobal(JSContext* aCx)
{
// Get the interface or namespace object for this class. This will
// create the object as needed and always define the properties for
// it on the global. The caller should make sure the interface or
// namespace is exposed on the global before calling this.
return GetPerInterfaceObjectHandle(aCx, constructors::id::UniFFIPointer,
&CreateInterfaceObjects,
DefineInterfaceProperty::Always);
}
} // 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, DefineInterfaceProperty aDefineOnGlobal);
JS::Handle<JSObject*>
GetConstructorObjectHandle(JSContext* aCx);
inline bool CreateAndDefineOnGlobal(JSContext* aCx)
{
// Get the interface or namespace object for this class. This will
// create the object as needed and always define the properties for
// it on the global. The caller should make sure the interface or
// namespace is exposed on the global before calling this.
return GetPerInterfaceObjectHandle(aCx, constructors::id::UniFFIScaffolding,
&CreateInterfaceObjects,
DefineInterfaceProperty::Always);
}
} // namespace UniFFIScaffolding_Binding
class UniFFICallbackHandler : public CallbackInterface
{
public:
explicit inline UniFFICallbackHandler(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackInterface(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
}
explicit inline UniFFICallbackHandler(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackInterface(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
explicit inline UniFFICallbackHandler(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackInterface(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
}
void Call(uint64_t objectHandle, uint32_t methodIndex, const nsTArray<OwningDoubleOrArrayBufferOrUniFFIPointer>& args, Nullable<OwningDoubleOrArrayBufferOrUniFFIPointer>& aRetVal, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr);
void Destroy(uint64_t objectHandle, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr);
inline bool
operator==(const UniFFICallbackHandler& aOther) const
{
return CallbackInterface::operator==(aOther);
}
private:
static bool
InitIds(JSContext* cx, UniFFICallbackHandlerAtoms* atomsCache);
};
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
} // 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(std::size(dom::binding_detail::EnumStrings<dom::UniFFIScaffoldingCallCode>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
} // namespace mozilla
#endif // DOM_UNIFFIBINDING_H_