/* THIS FILE IS AUTOGENERATED FROM TextGenerator.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "MainThreadUtils.h"
#include "TextGeneratorBinding.h"
#include "WrapperFactory.h"
#include "js/Array.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/ForOfIterator.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 "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/Blob.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SimpleGlobalObject.h"
#include "mozilla/dom/TextGenerator.h"
#include "mozilla/dom/ToJSValue.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 {
constexpr nsLiteralCString EnumStrings<TextGenerationRole>::Values[3];
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, TextGenerationRole aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < std::size(binding_detail::EnumStrings<TextGenerationRole>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<TextGenerationRole>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<TextGenerationRole>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
namespace binding_detail {
constexpr nsLiteralCString EnumStrings<TextGenerationSamplerType>::Values[5];
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, TextGenerationSamplerType aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < std::size(binding_detail::EnumStrings<TextGenerationSamplerType>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<TextGenerationSamplerType>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<TextGenerationSamplerType>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
namespace binding_detail {
constexpr nsLiteralCString EnumStrings<TextGenerationFinishReason>::Values[4];
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, TextGenerationFinishReason aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < std::size(binding_detail::EnumStrings<TextGenerationFinishReason>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<TextGenerationFinishReason>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<TextGenerationFinishReason>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
namespace binding_detail {
constexpr nsLiteralCString EnumStrings<TextGenerationKVCacheDtype>::Values[7];
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, TextGenerationKVCacheDtype aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < std::size(binding_detail::EnumStrings<TextGenerationKVCacheDtype>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<TextGenerationKVCacheDtype>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<TextGenerationKVCacheDtype>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
MOZ_CAN_RUN_SCRIPT void
TextGenerationDeltaCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const nsACString& text, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!NonVoidUTF8StringToJsval(cx, text, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
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;
}
}
TextGenerationLogitBias::TextGenerationLogitBias()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TextGenerationLogitBias::InitIds(JSContext* cx, TextGenerationLogitBiasAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->token_id.init(cx, "token") ||
!atomsCache->bias_id.init(cx, "bias")) {
return false;
}
return true;
}
bool
TextGenerationLogitBias::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TextGenerationLogitBiasAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TextGenerationLogitBiasAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->bias_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), "'bias' member of TextGenerationLogitBias", &mBias)) {
return false;
} else if (!std::isfinite(mBias)) {
cx.ThrowErrorMessage<MSG_NOT_FINITE>("'bias' member of TextGenerationLogitBias");
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'bias' member of TextGenerationLogitBias");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->token_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), "'token' member of TextGenerationLogitBias", &mToken)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'token' member of TextGenerationLogitBias");
}
return true;
}
bool
TextGenerationLogitBias::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
TextGenerationLogitBias::TraceDictionary(JSTracer* trc)
{
}
TextGenerationLogitBias&
TextGenerationLogitBias::operator=(const TextGenerationLogitBias& aOther)
{
MaybeEmptyDictionaryBase::operator=(aOther);
mBias = aOther.mBias;
mToken = aOther.mToken;
return *this;
}
TextGenerationMessage::TextGenerationMessage()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TextGenerationMessage::InitIds(JSContext* cx, TextGenerationMessageAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->role_id.init(cx, "role") ||
!atomsCache->content_id.init(cx, "content")) {
return false;
}
return true;
}
bool
TextGenerationMessage::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TextGenerationMessageAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TextGenerationMessageAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->content_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mContent)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'content' member of TextGenerationMessage");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->role_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
{
int index;
if (!binding_detail::FindEnumStringIndex<true>(cx, temp.ref(),
binding_detail::EnumStrings<TextGenerationRole>::Values,
"TextGenerationRole", "'role' member of TextGenerationMessage",
&index)) {
return false;
}
MOZ_ASSERT(index >= 0);
mRole = static_cast<TextGenerationRole>(index);
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'role' member of TextGenerationMessage");
}
return true;
}
bool
TextGenerationMessage::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
TextGenerationMessage::TraceDictionary(JSTracer* trc)
{
}
TextGenerationMessage&
TextGenerationMessage::operator=(const TextGenerationMessage& aOther)
{
MaybeEmptyDictionaryBase::operator=(aOther);
mContent = aOther.mContent;
mRole = aOther.mRole;
return *this;
}
TextGenerationResourceSnapshot::TextGenerationResourceSnapshot()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TextGenerationResourceSnapshot::InitIds(JSContext* cx, TextGenerationResourceSnapshotAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->memoryBytes_id.init(cx, "memoryBytes") ||
!atomsCache->cpuTimeMs_id.init(cx, "cpuTimeMs")) {
return false;
}
return true;
}
bool
TextGenerationResourceSnapshot::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TextGenerationResourceSnapshot::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TextGenerationResourceSnapshotAtoms* atomsCache = GetAtomCache<TextGenerationResourceSnapshotAtoms>(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.setObject(*obj);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint64_t const & currentValue = mCpuTimeMs;
temp.set(JS::NumberValue(double(currentValue)));
if (!JS_DefinePropertyById(cx, obj, atomsCache->cpuTimeMs_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint64_t const & currentValue = mMemoryBytes;
temp.set(JS::NumberValue(double(currentValue)));
if (!JS_DefinePropertyById(cx, obj, atomsCache->memoryBytes_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TextGenerationResourceSnapshot::TraceDictionary(JSTracer* trc)
{
}
TextGenerationResourceSnapshot&
TextGenerationResourceSnapshot::operator=(const TextGenerationResourceSnapshot& aOther)
{
DictionaryBase::operator=(aOther);
mCpuTimeMs = aOther.mCpuTimeMs;
mMemoryBytes = aOther.mMemoryBytes;
return *this;
}
TextGenerationTimings::TextGenerationTimings()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TextGenerationTimings::InitIds(JSContext* cx, TextGenerationTimingsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->prefillMs_id.init(cx, "prefillMs") ||
!atomsCache->decodeMs_id.init(cx, "decodeMs")) {
return false;
}
return true;
}
bool
TextGenerationTimings::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TextGenerationTimings::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TextGenerationTimingsAtoms* atomsCache = GetAtomCache<TextGenerationTimingsAtoms>(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.setObject(*obj);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
double const & currentValue = mDecodeMs;
temp.set(JS::NumberValue(double(currentValue)));
if (!JS_DefinePropertyById(cx, obj, atomsCache->decodeMs_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
double const & currentValue = mPrefillMs;
temp.set(JS::NumberValue(double(currentValue)));
if (!JS_DefinePropertyById(cx, obj, atomsCache->prefillMs_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TextGenerationTimings::TraceDictionary(JSTracer* trc)
{
}
TextGenerationTimings&
TextGenerationTimings::operator=(const TextGenerationTimings& aOther)
{
DictionaryBase::operator=(aOther);
mDecodeMs = aOther.mDecodeMs;
mPrefillMs = aOther.mPrefillMs;
return *this;
}
TextGeneratorCreateOptions::TextGeneratorCreateOptions()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TextGeneratorCreateOptions::InitIds(JSContext* cx, TextGeneratorCreateOptionsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->ubatchSize_id.init(cx, "ubatchSize") ||
!atomsCache->numThreadsDecoding_id.init(cx, "numThreadsDecoding") ||
!atomsCache->numThreads_id.init(cx, "numThreads") ||
!atomsCache->kvCacheDtype_id.init(cx, "kvCacheDtype") ||
!atomsCache->flashAttn_id.init(cx, "flashAttn") ||
!atomsCache->featureId_id.init(cx, "featureId") ||
!atomsCache->contextSize_id.init(cx, "contextSize") ||
!atomsCache->batchSize_id.init(cx, "batchSize")) {
return false;
}
return true;
}
bool
TextGeneratorCreateOptions::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TextGeneratorCreateOptionsAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TextGeneratorCreateOptionsAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->batchSize_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'batchSize' member of TextGeneratorCreateOptions", &mBatchSize)) {
return false;
}
} else {
mBatchSize = 2048U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->contextSize_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'contextSize' member of TextGeneratorCreateOptions", &mContextSize)) {
return false;
}
} else {
mContextSize = 1024U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->featureId_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFeatureId)) {
return false;
}
} else {
mFeatureId.AssignLiteral("");
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->flashAttn_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'flashAttn' member of TextGeneratorCreateOptions", &mFlashAttn)) {
return false;
}
} else {
mFlashAttn = false;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->kvCacheDtype_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
{
int index;
if (!binding_detail::FindEnumStringIndex<true>(cx, temp.ref(),
binding_detail::EnumStrings<TextGenerationKVCacheDtype>::Values,
"TextGenerationKVCacheDtype", "'kvCacheDtype' member of TextGeneratorCreateOptions",
&index)) {
return false;
}
MOZ_ASSERT(index >= 0);
mKvCacheDtype = static_cast<TextGenerationKVCacheDtype>(index);
}
} else {
mKvCacheDtype = TextGenerationKVCacheDtype::F16;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->numThreads_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'numThreads' member of TextGeneratorCreateOptions", &mNumThreads)) {
return false;
}
} else {
mNumThreads = 0U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->numThreadsDecoding_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'numThreadsDecoding' member of TextGeneratorCreateOptions", &mNumThreadsDecoding)) {
return false;
}
} else {
mNumThreadsDecoding = 0U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->ubatchSize_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'ubatchSize' member of TextGeneratorCreateOptions", &mUbatchSize)) {
return false;
}
} else {
mUbatchSize = 512U;
}
mIsAnyMemberPresent = true;
return true;
}
bool
TextGeneratorCreateOptions::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
TextGeneratorCreateOptions::TraceDictionary(JSTracer* trc)
{
}
TextGeneratorCreateOptions&
TextGeneratorCreateOptions::operator=(const TextGeneratorCreateOptions& aOther)
{
MaybeEmptyDictionaryBase::operator=(aOther);
mBatchSize = aOther.mBatchSize;
mContextSize = aOther.mContextSize;
mFeatureId = aOther.mFeatureId;
mFlashAttn = aOther.mFlashAttn;
mKvCacheDtype = aOther.mKvCacheDtype;
mNumThreads = aOther.mNumThreads;
mNumThreadsDecoding = aOther.mNumThreadsDecoding;
mUbatchSize = aOther.mUbatchSize;
return *this;
}
TextGenerationResources::TextGenerationResources()
: mAfter(FastDictionaryInitializer()),
mBefore(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TextGenerationResources::InitIds(JSContext* cx, TextGenerationResourcesAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->before_id.init(cx, "before") ||
!atomsCache->after_id.init(cx, "after")) {
return false;
}
return true;
}
bool
TextGenerationResources::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TextGenerationResources::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TextGenerationResourcesAtoms* atomsCache = GetAtomCache<TextGenerationResourcesAtoms>(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.setObject(*obj);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationResourceSnapshot const & currentValue = mAfter;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->after_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationResourceSnapshot const & currentValue = mBefore;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->before_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TextGenerationResources::TraceDictionary(JSTracer* trc)
{
}
TextGenerationResources&
TextGenerationResources::operator=(const TextGenerationResources& aOther)
{
DictionaryBase::operator=(aOther);
mAfter = aOther.mAfter;
mBefore = aOther.mBefore;
return *this;
}
TextGenerationSampler::TextGenerationSampler()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TextGenerationSampler::InitIds(JSContext* cx, TextGenerationSamplerAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->type_id.init(cx, "type") ||
!atomsCache->topP_id.init(cx, "topP") ||
!atomsCache->topK_id.init(cx, "topK") ||
!atomsCache->temp_id.init(cx, "temp") ||
!atomsCache->seed_id.init(cx, "seed") ||
!atomsCache->logitBias_id.init(cx, "logitBias")) {
return false;
}
return true;
}
bool
TextGenerationSampler::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TextGenerationSamplerAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TextGenerationSamplerAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->logitBias_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'logitBias' member of TextGenerationSampler", "sequence");
return false;
}
Sequence<TextGenerationLogitBias> &arr = mLogitBias;
if (mozilla::Maybe<uint32_t> sizeHint = iter.sizeHint()) {
if (!arr.SetCapacity(*sizeHint, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
}
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
TextGenerationLogitBias* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
TextGenerationLogitBias& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'logitBias' member of TextGenerationSampler", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'logitBias' member of TextGenerationSampler", "sequence");
return false;
}
} else {
/* mLogitBias array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->seed_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mSeed.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'seed' member of TextGenerationSampler", &(mSeed.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->temp_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), "'temp' member of TextGenerationSampler", &mTemp)) {
return false;
} else if (!std::isfinite(mTemp)) {
cx.ThrowErrorMessage<MSG_NOT_FINITE>("'temp' member of TextGenerationSampler");
return false;
}
} else {
mTemp = 0.8F;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->topK_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), "'topK' member of TextGenerationSampler", &mTopK)) {
return false;
}
} else {
mTopK = 40;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->topP_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), "'topP' member of TextGenerationSampler", &mTopP)) {
return false;
} else if (!std::isfinite(mTopP)) {
cx.ThrowErrorMessage<MSG_NOT_FINITE>("'topP' member of TextGenerationSampler");
return false;
}
} else {
mTopP = 0.95F;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
{
int index;
if (!binding_detail::FindEnumStringIndex<true>(cx, temp.ref(),
binding_detail::EnumStrings<TextGenerationSamplerType>::Values,
"TextGenerationSamplerType", "'type' member of TextGenerationSampler",
&index)) {
return false;
}
MOZ_ASSERT(index >= 0);
mType = static_cast<TextGenerationSamplerType>(index);
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'type' member of TextGenerationSampler");
}
return true;
}
bool
TextGenerationSampler::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
TextGenerationSampler::TraceDictionary(JSTracer* trc)
{
}
TextGenerationSampler&
TextGenerationSampler::operator=(const TextGenerationSampler& aOther)
{
MaybeEmptyDictionaryBase::operator=(aOther);
mLogitBias = aOther.mLogitBias;
mSeed.Reset();
if (aOther.mSeed.WasPassed()) {
mSeed.Construct(aOther.mSeed.Value());
}
mTemp = aOther.mTemp;
mTopK = aOther.mTopK;
mTopP = aOther.mTopP;
mType = aOther.mType;
return *this;
}
TextGenerationUsage::TextGenerationUsage()
: mTimings(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TextGenerationUsage::InitIds(JSContext* cx, TextGenerationUsageAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->timings_id.init(cx, "timings") ||
!atomsCache->promptTokens_id.init(cx, "promptTokens") ||
!atomsCache->promptCharacters_id.init(cx, "promptCharacters") ||
!atomsCache->generatedTokens_id.init(cx, "generatedTokens")) {
return false;
}
return true;
}
bool
TextGenerationUsage::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TextGenerationUsage::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TextGenerationUsageAtoms* atomsCache = GetAtomCache<TextGenerationUsageAtoms>(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.setObject(*obj);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint32_t const & currentValue = mGeneratedTokens;
temp.setNumber(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->generatedTokens_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint32_t const & currentValue = mPromptCharacters;
temp.setNumber(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->promptCharacters_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint32_t const & currentValue = mPromptTokens;
temp.setNumber(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->promptTokens_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationTimings const & currentValue = mTimings;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->timings_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TextGenerationUsage::TraceDictionary(JSTracer* trc)
{
}
TextGenerationUsage&
TextGenerationUsage::operator=(const TextGenerationUsage& aOther)
{
DictionaryBase::operator=(aOther);
mGeneratedTokens = aOther.mGeneratedTokens;
mPromptCharacters = aOther.mPromptCharacters;
mPromptTokens = aOther.mPromptTokens;
mTimings = aOther.mTimings;
return *this;
}
TextGenerationRequest::TextGenerationRequest()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TextGenerationRequest::InitIds(JSContext* cx, TextGenerationRequestAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->stopTokens_id.init(cx, "stopTokens") ||
!atomsCache->stopOnEndOfGenerationTokens_id.init(cx, "stopOnEndOfGenerationTokens") ||
!atomsCache->samplers_id.init(cx, "samplers") ||
!atomsCache->messages_id.init(cx, "messages") ||
!atomsCache->maxTokens_id.init(cx, "maxTokens") ||
!atomsCache->bufferLength_id.init(cx, "bufferLength")) {
return false;
}
return true;
}
bool
TextGenerationRequest::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TextGenerationRequestAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TextGenerationRequestAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->bufferLength_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'bufferLength' member of TextGenerationRequest", &mBufferLength)) {
return false;
}
} else {
mBufferLength = 20U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->maxTokens_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'maxTokens' member of TextGenerationRequest", &mMaxTokens)) {
return false;
}
} else {
mMaxTokens = 512U;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->messages_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'messages' member of TextGenerationRequest", "sequence");
return false;
}
Sequence<TextGenerationMessage> &arr = mMessages;
if (mozilla::Maybe<uint32_t> sizeHint = iter.sizeHint()) {
if (!arr.SetCapacity(*sizeHint, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
}
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
TextGenerationMessage* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
TextGenerationMessage& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'messages' member of TextGenerationRequest", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'messages' member of TextGenerationRequest", "sequence");
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'messages' member of TextGenerationRequest");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->samplers_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'samplers' member of TextGenerationRequest", "sequence");
return false;
}
Sequence<TextGenerationSampler> &arr = mSamplers;
if (mozilla::Maybe<uint32_t> sizeHint = iter.sizeHint()) {
if (!arr.SetCapacity(*sizeHint, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
}
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
TextGenerationSampler* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
TextGenerationSampler& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'samplers' member of TextGenerationRequest", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'samplers' member of TextGenerationRequest", "sequence");
return false;
}
} else {
/* mSamplers array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->stopOnEndOfGenerationTokens_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'stopOnEndOfGenerationTokens' member of TextGenerationRequest", &mStopOnEndOfGenerationTokens)) {
return false;
}
} else {
mStopOnEndOfGenerationTokens = true;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->stopTokens_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'stopTokens' member of TextGenerationRequest", "sequence");
return false;
}
Sequence<int32_t> &arr = mStopTokens;
if (mozilla::Maybe<uint32_t> sizeHint = iter.sizeHint()) {
if (!arr.SetCapacity(*sizeHint, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
}
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
int32_t& slot = *slotPtr;
if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, "Element of 'stopTokens' member of TextGenerationRequest", &slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'stopTokens' member of TextGenerationRequest", "sequence");
return false;
}
} else {
/* mStopTokens array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
return true;
}
bool
TextGenerationRequest::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
TextGenerationRequest::TraceDictionary(JSTracer* trc)
{
}
TextGenerationRequest&
TextGenerationRequest::operator=(const TextGenerationRequest& aOther)
{
MaybeEmptyDictionaryBase::operator=(aOther);
mBufferLength = aOther.mBufferLength;
mMaxTokens = aOther.mMaxTokens;
mMessages = aOther.mMessages;
mSamplers = aOther.mSamplers;
mStopOnEndOfGenerationTokens = aOther.mStopOnEndOfGenerationTokens;
mStopTokens = aOther.mStopTokens;
return *this;
}
TextGenerationResult::TextGenerationResult()
: mResources(FastDictionaryInitializer()),
mUsage(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TextGenerationResult::InitIds(JSContext* cx, TextGenerationResultAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->usage_id.init(cx, "usage") ||
!atomsCache->resources_id.init(cx, "resources") ||
!atomsCache->reason_id.init(cx, "reason") ||
!atomsCache->content_id.init(cx, "content")) {
return false;
}
return true;
}
bool
TextGenerationResult::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TextGenerationResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TextGenerationResultAtoms* atomsCache = GetAtomCache<TextGenerationResultAtoms>(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.setObject(*obj);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsCString const & currentValue = mContent;
if (!NonVoidUTF8StringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->content_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationFinishReason const & currentValue = mReason;
if (!ToJSValue(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->reason_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationResources const & currentValue = mResources;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->resources_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TextGenerationUsage const & currentValue = mUsage;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->usage_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TextGenerationResult::TraceDictionary(JSTracer* trc)
{
}
TextGenerationResult&
TextGenerationResult::operator=(const TextGenerationResult& aOther)
{
DictionaryBase::operator=(aOther);
mContent = aOther.mContent;
mReason = aOther.mReason;
mResources = aOther.mResources;
mUsage = aOther.mUsage;
return *this;
}
namespace TextGenerator_Binding {
MOZ_CAN_RUN_SCRIPT static bool
create(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "TextGenerator.create");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TextGenerator", "create", 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, "TextGenerator.create", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
NonNull<mozilla::dom::Blob> arg0;
if (args[0].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(args[0], arg0, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 1", "Blob");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
binding_detail::FastTextGeneratorCreateOptions arg1;
if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2", false)) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(mozilla::dom::TextGenerator::Create(global, MOZ_KnownLive(NonNullHelper(arg0)), Constify(arg1), rv)));
if (rv.MaybeSetPendingException(cx, "TextGenerator.create")) [[unlikely]] {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo create_methodinfo = {
{ (JSJitGetterOp)create },
{ prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
JSJitInfo::AliasEverything, JSVAL_TYPE_OBJECT, false, false,
false, false, 0
};
MOZ_CAN_RUN_SCRIPT static bool
generate(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TextGenerator.generate");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TextGenerator", "generate", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TextGenerator*>(void_self);
if (!args.requireAtLeast(cx, "TextGenerator.generate", 1)) {
return false;
}
binding_detail::FastTextGenerationRequest arg0;
if (!arg0.Init(cx, args[0], "Argument 1", false)) {
return false;
}
Optional<OwningNonNull<TextGenerationDeltaCallback>> arg1;
if (args.hasDefined(1)) {
arg1.Construct();
if (args[1].isObject()) {
if (JS::IsCallable(&args[1].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
arg1.Value() = new TextGenerationDeltaCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 2");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->Generate(Constify(arg0), MOZ_KnownLive(NonNullHelper(Constify(arg1))), rv)));
if (rv.MaybeSetPendingException(cx, "TextGenerator.generate")) [[unlikely]] {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
generate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = generate(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo generate_methodinfo = {
{ (JSJitGetterOp)generate_promiseWrapper },
{ prototypes::id::TextGenerator },
{ PrototypeTraits<prototypes::id::TextGenerator>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
clear(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TextGenerator", "clear", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TextGenerator*>(void_self);
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Clear(rv))>, "Should be returning void here");
MOZ_KnownLive(self)->Clear(rv);
if (rv.MaybeSetPendingException(cx, "TextGenerator.clear")) [[unlikely]] {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo clear_methodinfo = {
{ (JSJitGetterOp)clear },
{ prototypes::id::TextGenerator },
{ PrototypeTraits<prototypes::id::TextGenerator>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
cancel(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TextGenerator", "cancel", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TextGenerator*>(void_self);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Cancel())>, "Should be returning void here");
MOZ_KnownLive(self)->Cancel();
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo cancel_methodinfo = {
{ (JSJitGetterOp)cancel },
{ prototypes::id::TextGenerator },
{ PrototypeTraits<prototypes::id::TextGenerator>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
terminate(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TextGenerator", "terminate", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TextGenerator*>(void_self);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Terminate())>, "Should be returning void here");
MOZ_KnownLive(self)->Terminate();
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo terminate_methodinfo = {
{ (JSJitGetterOp)terminate },
{ prototypes::id::TextGenerator },
{ PrototypeTraits<prototypes::id::TextGenerator>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TextGenerator* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TextGenerator>(obj);
if (self) {
JS::SetNativeObjectReservedSlot(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::TextGenerator>(self);
}
}
MOZ_GLOBINIT static const JSFunctionSpec sStaticMethods_specs[] = {
JS_FNSPEC("create", StaticMethodPromiseWrapper, &create_methodinfo, 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(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
MOZ_GLOBINIT static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("generate", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&generate_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("clear", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&clear_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("cancel", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&cancel_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("terminate", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&terminate_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ nullptr, &sMethods_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(4 <= 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[5];
static PropertyInfo sNativeProperties_propertyInfos[5];
static const NativePropertiesN<2> sNativeProperties = {
true, 0 /* sStaticMethods */,
false, 0,
true, 1 /* sMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
5,
sNativeProperties_sortedPropertyIndices,
{
{ sStaticMethods, &sNativeProperties_propertyInfos[0] },
{ sMethods, &sNativeProperties_propertyInfos[1] }
}
};
static_assert(5 < 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::TextGenerator,
constructors::id::TextGenerator,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
JS::GetRealmFunctionPrototypeHandle,
PrototypeTraits<prototypes::id::TextGenerator>::Depth,
prototypes::id::TextGenerator,
true,
0,
"TextGenerator",
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TextGeneratorPrototype",
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::TextGenerator,
PrototypeTraits<prototypes::id::TextGenerator>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
}
static JS::Handle<JSObject*>
GetProtoObjectHandle(JSContext* aCx);
static const JSClassOps sClassOps = {
nullptr, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const DOMJSClass sClass = {
{ "TextGenerator",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_PRESERVES_WRAPPER,
&sClassOps,
JS_NULL_CLASS_SPEC,
&NativeTypeHelpers<mozilla::dom::TextGenerator>::sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TextGenerator, 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::TextGenerator>,
&sNativePropertyHooks,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TextGenerator>::Get(),
nullptr,
NativeTypeHelpers<mozilla::dom::TextGenerator>::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::TextGenerator* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TextGenerator>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TextGenerator*>);
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::TextGenerator> 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, DefineInterfaceProperty aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TextGenerator);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TextGenerator);
JS::Handle<JSObject*> parentProto(JS::GetRealmObjectPrototypeHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(JS::GetRealmFunctionPrototypeHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"TextGenerator",
ShouldExpose<TextGenerator_Binding::ConstructorEnabled>(aCx, aGlobal, aDefineOnGlobal),
nullptr,
false,
nullptr);
}
static 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::TextGenerator,
&CreateInterfaceObjects,
DefineInterfaceProperty::CheckExposure);
}
JS::Handle<JSObject*>
GetConstructorObjectHandle(JSContext* aCx)
{
/* Get the interface object for this class. This will create the object as
needed. */
return GetPerInterfaceObjectHandle(aCx, constructors::id::TextGenerator,
&CreateInterfaceObjects,
DefineInterfaceProperty::CheckExposure);
}
} // namespace TextGenerator_Binding
} // namespace dom
} // namespace mozilla