Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM UniFFI.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "MainThreadUtils.h"
#include "UniFFIBinding.h"
#include "WrapperFactory.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 "jsapi.h"
#include "jsfriendapi.h"
#include "mozilla/Atomics.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/UniFFIPointer.h"
#include "mozilla/dom/UniFFIScaffolding.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "nsContentUtils.h"
namespace mozilla {
namespace dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
namespace binding_detail {
const nsLiteralCString EnumStrings<UniFFIScaffoldingCallCode>::Values[3] = {
"success"_ns,
"error"_ns,
"internal-error"_ns,
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, UniFFIScaffoldingCallCode aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(binding_detail::EnumStrings<UniFFIScaffoldingCallCode>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<UniFFIScaffoldingCallCode>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<UniFFIScaffoldingCallCode>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningDoubleOrArrayBufferOrUniFFIPointer& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsUniFFIPointer()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsUniFFIPointer(), "mUniFFIPointer", aFlags);
}
}
void
ImplCycleCollectionUnlink(OwningDoubleOrArrayBufferOrUniFFIPointer& aUnion)
{
aUnion.Uninit();
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToDouble(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
double& memberSlot = RawSetAsDouble();
if (!ValueToPrimitive<double, eDefault>(cx, value, "Double branch of (double or ArrayBuffer or UniFFIPointer)", &memberSlot)) {
return false;
} else if (!std::isfinite(memberSlot)) {
cx.ThrowErrorMessage<MSG_NOT_FINITE>("Double branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
}
return true;
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToDouble(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDouble(cx, value, tryNext, passedToJSImpl);
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToArrayBuffer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
RootedSpiderMonkeyInterface<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
if (!memberSlot.Init(&value.toObject())) {
DestroyArrayBuffer();
tryNext = true;
return true;
}
if (JS::IsSharedArrayBufferObject(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_SHARED>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
if (JS::IsLargeArrayBufferMaybeShared(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_LARGE>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
if (JS::IsResizableArrayBufferMaybeShared(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_RESIZABLE>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
}
return true;
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToArrayBuffer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToArrayBuffer(cx, value, tryNext, passedToJSImpl);
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToUniFFIPointer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::UniFFIPointer>& memberSlot = RawSetAsUniFFIPointer();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::UniFFIPointer, mozilla::dom::UniFFIPointer>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyUniFFIPointer();
tryNext = true;
return true;
}
}
}
return true;
}
bool
DoubleOrArrayBufferOrUniFFIPointer::TrySetToUniFFIPointer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToUniFFIPointer(cx, value, tryNext, passedToJSImpl);
}
bool
DoubleOrArrayBufferOrUniFFIPointer::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToArrayBuffer(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToUniFFIPointer(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToDouble(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "ArrayBuffer, UniFFIPointer");
return false;
}
return true;
}
bool
DoubleOrArrayBufferOrUniFFIPointer::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
DoubleOrArrayBufferOrUniFFIPointer::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eDouble: {
rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
return true;
}
case eArrayBuffer: {
rval.setObject(*mValue.mArrayBuffer.Value().Obj());
if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
return false;
}
return true;
}
case eUniFFIPointer: {
if (!GetOrCreateDOMReflector(cx, mValue.mUniFFIPointer.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningDoubleOrArrayBufferOrUniFFIPointer::OwningDoubleOrArrayBufferOrUniFFIPointer(OwningDoubleOrArrayBufferOrUniFFIPointer&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eDouble: {
mType = eDouble;
mValue.mDouble.SetValue(std::move(aOther.mValue.mDouble.Value()));
break;
}
case eArrayBuffer: {
mType = eArrayBuffer;
mValue.mArrayBuffer.SetValue(std::move(aOther.mValue.mArrayBuffer.Value()));
break;
}
case eUniFFIPointer: {
mType = eUniFFIPointer;
mValue.mUniFFIPointer.SetValue(std::move(aOther.mValue.mUniFFIPointer.Value()));
break;
}
}
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToDouble(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
double& memberSlot = RawSetAsDouble();
if (!ValueToPrimitive<double, eDefault>(cx, value, "Double branch of (double or ArrayBuffer or UniFFIPointer)", &memberSlot)) {
return false;
} else if (!std::isfinite(memberSlot)) {
cx.ThrowErrorMessage<MSG_NOT_FINITE>("Double branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
}
return true;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToDouble(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDouble(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] double&
OwningDoubleOrArrayBufferOrUniFFIPointer::RawSetAsDouble()
{
if (mType == eDouble) {
return mValue.mDouble.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eDouble;
return mValue.mDouble.SetValue();
}
[[nodiscard]] double&
OwningDoubleOrArrayBufferOrUniFFIPointer::SetAsDouble()
{
if (mType == eDouble) {
return mValue.mDouble.Value();
}
Uninit();
mType = eDouble;
return mValue.mDouble.SetValue();
}
void
OwningDoubleOrArrayBufferOrUniFFIPointer::DestroyDouble()
{
MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!");
mValue.mDouble.Destroy();
mType = eUninitialized;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToArrayBuffer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
if (!memberSlot.Init(&value.toObject())) {
DestroyArrayBuffer();
tryNext = true;
return true;
}
if (JS::IsSharedArrayBufferObject(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_SHARED>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
if (JS::IsLargeArrayBufferMaybeShared(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_LARGE>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
if (JS::IsResizableArrayBufferMaybeShared(memberSlot.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_RESIZABLE>("ArrayBuffer branch of (double or ArrayBuffer or UniFFIPointer)");
return false;
}
}
return true;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToArrayBuffer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToArrayBuffer(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] ArrayBuffer&
OwningDoubleOrArrayBufferOrUniFFIPointer::RawSetAsArrayBuffer()
{
if (mType == eArrayBuffer) {
return mValue.mArrayBuffer.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eArrayBuffer;
return mValue.mArrayBuffer.SetValue();
}
[[nodiscard]] ArrayBuffer&
OwningDoubleOrArrayBufferOrUniFFIPointer::SetAsArrayBuffer()
{
if (mType == eArrayBuffer) {
return mValue.mArrayBuffer.Value();
}
Uninit();
mType = eArrayBuffer;
return mValue.mArrayBuffer.SetValue();
}
void
OwningDoubleOrArrayBufferOrUniFFIPointer::DestroyArrayBuffer()
{
MOZ_RELEASE_ASSERT(IsArrayBuffer(), "Wrong type!");
mValue.mArrayBuffer.Destroy();
mType = eUninitialized;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToUniFFIPointer(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::UniFFIPointer>& memberSlot = RawSetAsUniFFIPointer();
static_assert(IsRefcounted<mozilla::dom::UniFFIPointer>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::UniFFIPointer, mozilla::dom::UniFFIPointer>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyUniFFIPointer();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::TrySetToUniFFIPointer(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToUniFFIPointer(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::UniFFIPointer>&
OwningDoubleOrArrayBufferOrUniFFIPointer::RawSetAsUniFFIPointer()
{
if (mType == eUniFFIPointer) {
return mValue.mUniFFIPointer.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eUniFFIPointer;
return mValue.mUniFFIPointer.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::UniFFIPointer>&
OwningDoubleOrArrayBufferOrUniFFIPointer::SetAsUniFFIPointer()
{
if (mType == eUniFFIPointer) {
return mValue.mUniFFIPointer.Value();
}
Uninit();
mType = eUniFFIPointer;
return mValue.mUniFFIPointer.SetValue();
}
void
OwningDoubleOrArrayBufferOrUniFFIPointer::DestroyUniFFIPointer()
{
MOZ_RELEASE_ASSERT(IsUniFFIPointer(), "Wrong type!");
mValue.mUniFFIPointer.Destroy();
mType = eUninitialized;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToArrayBuffer(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToUniFFIPointer(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToDouble(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "ArrayBuffer, UniFFIPointer");
return false;
}
return true;
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningDoubleOrArrayBufferOrUniFFIPointer::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eDouble: {
DestroyDouble();
break;
}
case eArrayBuffer: {
DestroyArrayBuffer();
break;
}
case eUniFFIPointer: {
DestroyUniFFIPointer();
break;
}
}
}
bool
OwningDoubleOrArrayBufferOrUniFFIPointer::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eDouble: {
rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
return true;
}
case eArrayBuffer: {
rval.setObject(*mValue.mArrayBuffer.Value().Obj());
if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
return false;
}
return true;
}
case eUniFFIPointer: {
if (!GetOrCreateDOMReflector(cx, mValue.mUniFFIPointer.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
void
OwningDoubleOrArrayBufferOrUniFFIPointer::TraceUnion(JSTracer* trc)
{
switch (mType) {
case eArrayBuffer: {
mValue.mArrayBuffer.Value().TraceSelf(trc);
break;
}
default: {
}
}
}
OwningDoubleOrArrayBufferOrUniFFIPointer&
OwningDoubleOrArrayBufferOrUniFFIPointer::operator=(OwningDoubleOrArrayBufferOrUniFFIPointer&& aOther)
{
this->~OwningDoubleOrArrayBufferOrUniFFIPointer();
new (this) OwningDoubleOrArrayBufferOrUniFFIPointer (std::move(aOther));
return *this;
}
MOZ_CAN_RUN_SCRIPT void
UniFFICallbackHandler::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, uint64_t objectId, uint32_t methodId, JS::Handle<JSObject*> aArgs, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(3)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 3;
do {
JS::ExposeObjectToActiveJS(aArgs);
argv[2].setObject(*aArgs);
if (!MaybeWrapNonDOMObjectValue(cx, argv[2])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
argv[1].setNumber(methodId);
break;
} while (false);
do {
argv[0].set(JS_NumberValue(double(objectId)));
break;
} while (false);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
UniFFIScaffoldingCallResult::UniFFIScaffoldingCallResult()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
UniFFIScaffoldingCallResult::InitIds(JSContext* cx, UniFFIScaffoldingCallResultAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->internalErrorMessage_id.init(cx, "internalErrorMessage") ||
!atomsCache->data_id.init(cx, "data") ||
!atomsCache->code_id.init(cx, "code")) {
return false;
}
return true;
}
bool
UniFFIScaffoldingCallResult::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
UniFFIScaffoldingCallResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
UniFFIScaffoldingCallResultAtoms* atomsCache = GetAtomCache<UniFFIScaffoldingCallResultAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
if (!obj) {
return false;
}
rval.set(JS::ObjectValue(*obj));
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
UniFFIScaffoldingCallCode const & currentValue = mCode;
if (!ToJSValue(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->code_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mData.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
OwningDoubleOrArrayBufferOrUniFFIPointer const & currentValue = mData.InternalValue();
if (!currentValue.ToJSVal(cx, obj, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mInternalErrorMessage.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsCString const & currentValue = mInternalErrorMessage.InternalValue();
if (!NonVoidByteStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->internalErrorMessage_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
UniFFIScaffoldingCallResult::TraceDictionary(JSTracer* trc)
{
if (mData.WasPassed()) {
mData.Value().TraceUnion(trc);
}
}
namespace UniFFIPointer_Binding {
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::UniFFIPointer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::UniFFIPointer>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::UniFFIPointer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::UniFFIPointer>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::UniFFIPointer>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::UniFFIPointer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::UniFFIPointer>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::UniFFIPointer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::UniFFIPointer>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, nullptr, &sNativePropertiesInited },
prototypes::id::UniFFIPointer,
constructors::id::UniFFIPointer,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
JS::GetRealmFunctionPrototype,
prototypes::id::UniFFIPointer,
PrototypeTraits<prototypes::id::UniFFIPointer>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"UniFFIPointerPrototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::UniFFIPointer,
PrototypeTraits<prototypes::id::UniFFIPointer>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
}
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "UniFFIPointer",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::UniFFIPointer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::UniFFIPointer>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::UniFFIPointer>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::UniFFIPointer>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::UniFFIPointer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::UniFFIPointer>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::UniFFIPointer*>);
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::UniFFIPointer> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::UniFFIPointer);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::UniFFIPointer);
JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
if (!parentProto) {
return;
}
JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
nullptr,
"UniFFIPointer", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace UniFFIPointer_Binding
namespace UniFFIScaffolding_Binding {
MOZ_CAN_RUN_SCRIPT static bool
callAsync(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "UniFFIScaffolding.callAsync");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "callAsync", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.callAsync", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint64_t arg0;
if (!ValueToPrimitive<uint64_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
AutoSequence<OwningDoubleOrArrayBufferOrUniFFIPointer> arg1;
SequenceRooter<OwningDoubleOrArrayBufferOrUniFFIPointer> arg1_holder(cx, &arg1);
if (args.length() > 1) {
if (!arg1.SetCapacity(args.length() - 1, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
for (uint32_t variadicArg = 1; variadicArg < args.length(); ++variadicArg) {
// OK to do infallible append here, since we ensured capacity already.
OwningDoubleOrArrayBufferOrUniFFIPointer& slot = *arg1.AppendElement();
if (!slot.Init(cx, args[variadicArg], "Argument 2", false)) {
return false;
}
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(mozilla::dom::UniFFIScaffolding::CallAsync(global, arg0, Constify(arg1), rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.callAsync"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo callAsync_methodinfo = {
{ (JSJitGetterOp)callAsync },
{ prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
JSJitInfo::AliasEverything, JSVAL_TYPE_OBJECT, false, false,
false, false, 0
};
MOZ_CAN_RUN_SCRIPT static bool
callSync(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "UniFFIScaffolding.callSync");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "callSync", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.callSync", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint64_t arg0;
if (!ValueToPrimitive<uint64_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
AutoSequence<OwningDoubleOrArrayBufferOrUniFFIPointer> arg1;
SequenceRooter<OwningDoubleOrArrayBufferOrUniFFIPointer> arg1_holder(cx, &arg1);
if (args.length() > 1) {
if (!arg1.SetCapacity(args.length() - 1, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
for (uint32_t variadicArg = 1; variadicArg < args.length(); ++variadicArg) {
// OK to do infallible append here, since we ensured capacity already.
OwningDoubleOrArrayBufferOrUniFFIPointer& slot = *arg1.AppendElement();
if (!slot.Init(cx, args[variadicArg], "Argument 2", false)) {
return false;
}
}
}
FastErrorResult rv;
RootedDictionary<UniFFIScaffoldingCallResult> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::UniFFIScaffolding::CallSync(global, arg0, Constify(arg1), result, rv))>, "Should be returning void here");
mozilla::dom::UniFFIScaffolding::CallSync(global, arg0, Constify(arg1), result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.callSync"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
readPointer(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "UniFFIScaffolding.readPointer");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "readPointer", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.readPointer", 3)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint64_t arg0;
if (!ValueToPrimitive<uint64_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
RootedSpiderMonkeyInterface<ArrayBuffer> arg1(cx);
if (args[1].isObject()) {
if (!arg1.Init(&args[1].toObject())) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 2", "ArrayBuffer");
return false;
}
if (JS::IsSharedArrayBufferObject(arg1.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_SHARED>("Argument 2");
return false;
}
if (JS::IsLargeArrayBufferMaybeShared(arg1.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_LARGE>("Argument 2");
return false;
}
if (JS::IsResizableArrayBufferMaybeShared(arg1.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_RESIZABLE>("Argument 2");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
int32_t arg2;
if (!ValueToPrimitive<int32_t, eDefault>(cx, args[2], "Argument 3", &arg2)) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::UniFFIPointer>(mozilla::dom::UniFFIScaffolding::ReadPointer(global, arg0, Constify(arg1), arg2, rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.readPointer"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
writePointer(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "UniFFIScaffolding.writePointer");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "writePointer", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.writePointer", 4)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint64_t arg0;
if (!ValueToPrimitive<uint64_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
NonNull<mozilla::dom::UniFFIPointer> arg1;
if (args[1].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::UniFFIPointer, mozilla::dom::UniFFIPointer>(args[1], arg1, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 2", "UniFFIPointer");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
RootedSpiderMonkeyInterface<ArrayBuffer> arg2(cx);
if (args[2].isObject()) {
if (!arg2.Init(&args[2].toObject())) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 3", "ArrayBuffer");
return false;
}
if (JS::IsSharedArrayBufferObject(arg2.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_SHARED>("Argument 3");
return false;
}
if (JS::IsLargeArrayBufferMaybeShared(arg2.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_LARGE>("Argument 3");
return false;
}
if (JS::IsResizableArrayBufferMaybeShared(arg2.Obj())) {
cx.ThrowErrorMessage<MSG_TYPEDARRAY_IS_RESIZABLE>("Argument 3");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 3");
return false;
}
int32_t arg3;
if (!ValueToPrimitive<int32_t, eDefault>(cx, args[3], "Argument 4", &arg3)) {
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::UniFFIScaffolding::WritePointer(global, arg0, MOZ_KnownLive(NonNullHelper(arg1)), Constify(arg2), arg3, rv))>, "Should be returning void here");
mozilla::dom::UniFFIScaffolding::WritePointer(global, arg0, MOZ_KnownLive(NonNullHelper(arg1)), Constify(arg2), arg3, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.writePointer"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
registerCallbackHandler(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "UniFFIScaffolding.registerCallbackHandler");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "registerCallbackHandler", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.registerCallbackHandler", 2)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
RootedCallback<OwningNonNull<binding_detail::FastUniFFICallbackHandler>> arg1(cx);
if (args[1].isObject()) {
if (JS::IsCallable(&args[1].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg1 = new binding_detail::FastUniFFICallbackHandler(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 2");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::UniFFIScaffolding::RegisterCallbackHandler(global, arg0, MOZ_KnownLive(NonNullHelper(arg1)), rv))>, "Should be returning void here");
mozilla::dom::UniFFIScaffolding::RegisterCallbackHandler(global, arg0, MOZ_KnownLive(NonNullHelper(arg1)), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.registerCallbackHandler"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
deregisterCallbackHandler(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"UniFFIScaffolding", "deregisterCallbackHandler", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.requireAtLeast(cx, "UniFFIScaffolding.deregisterCallbackHandler", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::UniFFIScaffolding::DeregisterCallbackHandler(global, arg0, rv))>, "Should be returning void here");
mozilla::dom::UniFFIScaffolding::DeregisterCallbackHandler(global, arg0, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "UniFFIScaffolding.deregisterCallbackHandler"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSFunctionSpec sStaticMethods_specs[] = {
JS_FNSPEC("callAsync", StaticMethodPromiseWrapper, &callAsync_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("callSync", callSync, nullptr, 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("readPointer", readPointer, nullptr, 3, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("writePointer", writePointer, nullptr, 4, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("registerCallbackHandler", registerCallbackHandler, nullptr, 2, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("deregisterCallbackHandler", deregisterCallbackHandler, nullptr, 1, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
{ nullptr, &sStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sNativeProperties_sortedPropertyIndices[6];
static PropertyInfo sNativeProperties_propertyInfos[6];
static const NativePropertiesN<1> sNativeProperties = {
true, 0 /* sStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
6,
sNativeProperties_sortedPropertyIndices,
{
{ sStaticMethods, &sNativeProperties_propertyInfos[0] }
}
};
static_assert(6 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited },
prototypes::id::_ID_Count,
constructors::id::UniFFIScaffolding,
&DefaultXrayExpandoObjectClass
};
static const DOMIfaceAndProtoJSClass sNamespaceObjectClass = {
{
"UniFFIScaffolding",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS,
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eNamespace,
prototypes::id::_ID_Count,
0,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmObjectPrototype(aCx));
if (!constructorProto) {
return;
}
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::UniFFIScaffolding);
dom::CreateNamespaceObject(aCx, aGlobal, constructorProto,
sNamespaceObjectClass,
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"UniFFIScaffolding", aDefineOnGlobal);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace UniFFIScaffolding_Binding
} // namespace dom
} // namespace mozilla