Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM WebAuthentication.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "CredentialManagementBinding.h"
#include "MainThreadUtils.h"
#include "WebAuthenticationBinding.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 "jsfriendapi.h"
#include "mozilla/Atomics.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/StaticPrefs_security.h"
#include "mozilla/dom/AuthenticatorAssertionResponse.h"
#include "mozilla/dom/AuthenticatorAttestationResponse.h"
#include "mozilla/dom/AuthenticatorResponse.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PublicKeyCredential.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SimpleGlobalObject.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/WebIDLPrefs.h"
#include "mozilla/dom/XrayExpandoClass.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
AuthenticationExtensionsClientInputs::AuthenticationExtensionsClientInputs()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
AuthenticationExtensionsClientInputs::InitIds(JSContext* cx, AuthenticationExtensionsClientInputsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->minPinLength_id.init(cx, "minPinLength") ||
!atomsCache->hmacCreateSecret_id.init(cx, "hmacCreateSecret") ||
!atomsCache->credProps_id.init(cx, "credProps") ||
!atomsCache->appid_id.init(cx, "appid")) {
return false;
}
return true;
}
bool
AuthenticationExtensionsClientInputs::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());
AuthenticationExtensionsClientInputsAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<AuthenticationExtensionsClientInputsAtoms>(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->appid_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAppid.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mAppid.Value()))) {
return false;
}
if (!NormalizeUSVString((mAppid.Value()))) {
JS_ReportOutOfMemory(cx);
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->credProps_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mCredProps.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'credProps' member of AuthenticationExtensionsClientInputs", &(mCredProps.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->hmacCreateSecret_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mHmacCreateSecret.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'hmacCreateSecret' member of AuthenticationExtensionsClientInputs", &(mHmacCreateSecret.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->minPinLength_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mMinPinLength.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'minPinLength' member of AuthenticationExtensionsClientInputs", &(mMinPinLength.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
AuthenticationExtensionsClientInputs::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);
}
bool
AuthenticationExtensionsClientInputs::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticationExtensionsClientInputsAtoms* atomsCache = GetAtomCache<AuthenticationExtensionsClientInputsAtoms>(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));
if (mAppid.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mAppid.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->appid_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mCredProps.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mCredProps.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->credProps_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mHmacCreateSecret.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mHmacCreateSecret.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->hmacCreateSecret_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mMinPinLength.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mMinPinLength.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->minPinLength_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
AuthenticationExtensionsClientInputs::TraceDictionary(JSTracer* trc)
{
}
AuthenticationExtensionsClientInputs&
AuthenticationExtensionsClientInputs::operator=(const AuthenticationExtensionsClientInputs& aOther)
{
DictionaryBase::operator=(aOther);
mAppid.Reset();
if (aOther.mAppid.WasPassed()) {
mAppid.Construct(aOther.mAppid.Value());
}
mCredProps.Reset();
if (aOther.mCredProps.WasPassed()) {
mCredProps.Construct(aOther.mCredProps.Value());
}
mHmacCreateSecret.Reset();
if (aOther.mHmacCreateSecret.WasPassed()) {
mHmacCreateSecret.Construct(aOther.mHmacCreateSecret.Value());
}
mMinPinLength.Reset();
if (aOther.mMinPinLength.WasPassed()) {
mMinPinLength.Construct(aOther.mMinPinLength.Value());
}
return *this;
}
bool
AuthenticationExtensionsClientInputs::operator==(const AuthenticationExtensionsClientInputs& aOther) const
{
if (mAppid != aOther.mAppid) {
return false;
}
if (mCredProps != aOther.mCredProps) {
return false;
}
if (mHmacCreateSecret != aOther.mHmacCreateSecret) {
return false;
}
if (mMinPinLength != aOther.mMinPinLength) {
return false;
}
return true;
}
AuthenticationExtensionsClientInputsJSON::AuthenticationExtensionsClientInputsJSON()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
AuthenticationExtensionsClientInputsJSON::InitIds(JSContext* cx, AuthenticationExtensionsClientInputsJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->minPinLength_id.init(cx, "minPinLength") ||
!atomsCache->hmacCreateSecret_id.init(cx, "hmacCreateSecret") ||
!atomsCache->credProps_id.init(cx, "credProps") ||
!atomsCache->appid_id.init(cx, "appid")) {
return false;
}
return true;
}
bool
AuthenticationExtensionsClientInputsJSON::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());
AuthenticationExtensionsClientInputsJSONAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<AuthenticationExtensionsClientInputsJSONAtoms>(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->appid_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAppid.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mAppid.Value()))) {
return false;
}
if (!NormalizeUSVString((mAppid.Value()))) {
JS_ReportOutOfMemory(cx);
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->credProps_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mCredProps.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'credProps' member of AuthenticationExtensionsClientInputsJSON", &(mCredProps.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->hmacCreateSecret_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mHmacCreateSecret.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'hmacCreateSecret' member of AuthenticationExtensionsClientInputsJSON", &(mHmacCreateSecret.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->minPinLength_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mMinPinLength.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'minPinLength' member of AuthenticationExtensionsClientInputsJSON", &(mMinPinLength.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
AuthenticationExtensionsClientInputsJSON::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
AuthenticationExtensionsClientInputsJSON::TraceDictionary(JSTracer* trc)
{
}
AuthenticationExtensionsClientInputsJSON&
AuthenticationExtensionsClientInputsJSON::operator=(const AuthenticationExtensionsClientInputsJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAppid.Reset();
if (aOther.mAppid.WasPassed()) {
mAppid.Construct(aOther.mAppid.Value());
}
mCredProps.Reset();
if (aOther.mCredProps.WasPassed()) {
mCredProps.Construct(aOther.mCredProps.Value());
}
mHmacCreateSecret.Reset();
if (aOther.mHmacCreateSecret.WasPassed()) {
mHmacCreateSecret.Construct(aOther.mHmacCreateSecret.Value());
}
mMinPinLength.Reset();
if (aOther.mMinPinLength.WasPassed()) {
mMinPinLength.Construct(aOther.mMinPinLength.Value());
}
return *this;
}
bool
AuthenticationExtensionsClientInputsJSON::operator==(const AuthenticationExtensionsClientInputsJSON& aOther) const
{
if (mAppid != aOther.mAppid) {
return false;
}
if (mCredProps != aOther.mCredProps) {
return false;
}
if (mHmacCreateSecret != aOther.mHmacCreateSecret) {
return false;
}
if (mMinPinLength != aOther.mMinPinLength) {
return false;
}
return true;
}
AuthenticatorAssertionResponseJSON::AuthenticatorAssertionResponseJSON()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
AuthenticatorAssertionResponseJSON::InitIds(JSContext* cx, AuthenticatorAssertionResponseJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->userHandle_id.init(cx, "userHandle") ||
!atomsCache->signature_id.init(cx, "signature") ||
!atomsCache->clientDataJSON_id.init(cx, "clientDataJSON") ||
!atomsCache->authenticatorData_id.init(cx, "authenticatorData") ||
!atomsCache->attestationObject_id.init(cx, "attestationObject")) {
return false;
}
return true;
}
bool
AuthenticatorAssertionResponseJSON::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
AuthenticatorAssertionResponseJSON::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticatorAssertionResponseJSONAtoms* atomsCache = GetAtomCache<AuthenticatorAssertionResponseJSONAtoms>(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));
if (mAttestationObject.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mAttestationObject.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->attestationObject_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);
nsString const & currentValue = mAuthenticatorData;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorData_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);
nsString const & currentValue = mClientDataJSON;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->clientDataJSON_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);
nsString const & currentValue = mSignature;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->signature_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mUserHandle.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mUserHandle.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->userHandle_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
AuthenticatorAssertionResponseJSON::TraceDictionary(JSTracer* trc)
{
}
AuthenticatorAssertionResponseJSON&
AuthenticatorAssertionResponseJSON::operator=(const AuthenticatorAssertionResponseJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAttestationObject.Reset();
if (aOther.mAttestationObject.WasPassed()) {
mAttestationObject.Construct(aOther.mAttestationObject.Value());
}
mAuthenticatorData = aOther.mAuthenticatorData;
mClientDataJSON = aOther.mClientDataJSON;
mSignature = aOther.mSignature;
mUserHandle.Reset();
if (aOther.mUserHandle.WasPassed()) {
mUserHandle.Construct(aOther.mUserHandle.Value());
}
return *this;
}
bool
AuthenticatorAssertionResponseJSON::operator==(const AuthenticatorAssertionResponseJSON& aOther) const
{
if (mAttestationObject != aOther.mAttestationObject) {
return false;
}
if (mAuthenticatorData != aOther.mAuthenticatorData) {
return false;
}
if (mClientDataJSON != aOther.mClientDataJSON) {
return false;
}
if (mSignature != aOther.mSignature) {
return false;
}
if (mUserHandle != aOther.mUserHandle) {
return false;
}
return true;
}
AuthenticatorAttestationResponseJSON::AuthenticatorAttestationResponseJSON()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
AuthenticatorAttestationResponseJSON::InitIds(JSContext* cx, AuthenticatorAttestationResponseJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->transports_id.init(cx, "transports") ||
!atomsCache->publicKeyAlgorithm_id.init(cx, "publicKeyAlgorithm") ||
!atomsCache->publicKey_id.init(cx, "publicKey") ||
!atomsCache->clientDataJSON_id.init(cx, "clientDataJSON") ||
!atomsCache->authenticatorData_id.init(cx, "authenticatorData") ||
!atomsCache->attestationObject_id.init(cx, "attestationObject")) {
return false;
}
return true;
}
bool
AuthenticatorAttestationResponseJSON::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
AuthenticatorAttestationResponseJSON::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticatorAttestationResponseJSONAtoms* atomsCache = GetAtomCache<AuthenticatorAttestationResponseJSONAtoms>(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);
nsString const & currentValue = mAttestationObject;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->attestationObject_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);
nsString const & currentValue = mAuthenticatorData;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorData_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);
nsString const & currentValue = mClientDataJSON;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->clientDataJSON_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mPublicKey.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mPublicKey.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKey_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);
int64_t const & currentValue = mPublicKeyAlgorithm;
temp.set(JS_NumberValue(double(currentValue)));
if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKeyAlgorithm_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);
Sequence<nsString> const & currentValue = mTransports;
uint32_t length = currentValue.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
temp.setObject(*returnArray);
if (!JS_DefinePropertyById(cx, obj, atomsCache->transports_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
AuthenticatorAttestationResponseJSON::TraceDictionary(JSTracer* trc)
{
}
AuthenticatorAttestationResponseJSON&
AuthenticatorAttestationResponseJSON::operator=(const AuthenticatorAttestationResponseJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAttestationObject = aOther.mAttestationObject;
mAuthenticatorData = aOther.mAuthenticatorData;
mClientDataJSON = aOther.mClientDataJSON;
mPublicKey.Reset();
if (aOther.mPublicKey.WasPassed()) {
mPublicKey.Construct(aOther.mPublicKey.Value());
}
mPublicKeyAlgorithm = aOther.mPublicKeyAlgorithm;
mTransports = aOther.mTransports;
return *this;
}
AuthenticatorSelectionCriteria::AuthenticatorSelectionCriteria()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
AuthenticatorSelectionCriteria::InitIds(JSContext* cx, AuthenticatorSelectionCriteriaAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->userVerification_id.init(cx, "userVerification") ||
!atomsCache->residentKey_id.init(cx, "residentKey") ||
!atomsCache->requireResidentKey_id.init(cx, "requireResidentKey") ||
!atomsCache->authenticatorAttachment_id.init(cx, "authenticatorAttachment")) {
return false;
}
return true;
}
bool
AuthenticatorSelectionCriteria::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());
AuthenticatorSelectionCriteriaAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<AuthenticatorSelectionCriteriaAtoms>(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->authenticatorAttachment_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAuthenticatorAttachment.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mAuthenticatorAttachment.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->requireResidentKey_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'requireResidentKey' member of AuthenticatorSelectionCriteria", &mRequireResidentKey)) {
return false;
}
} else {
mRequireResidentKey = false;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->residentKey_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mResidentKey.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mResidentKey.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->userVerification_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mUserVerification)) {
return false;
}
} else {
mUserVerification.AssignLiteral(u"preferred");
}
mIsAnyMemberPresent = true;
return true;
}
bool
AuthenticatorSelectionCriteria::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);
}
bool
AuthenticatorSelectionCriteria::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticatorSelectionCriteriaAtoms* atomsCache = GetAtomCache<AuthenticatorSelectionCriteriaAtoms>(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));
if (mAuthenticatorAttachment.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mAuthenticatorAttachment.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorAttachment_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);
bool const & currentValue = mRequireResidentKey;
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->requireResidentKey_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mResidentKey.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mResidentKey.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->residentKey_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);
nsString const & currentValue = mUserVerification;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->userVerification_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
AuthenticatorSelectionCriteria::TraceDictionary(JSTracer* trc)
{
}
AuthenticatorSelectionCriteria&
AuthenticatorSelectionCriteria::operator=(const AuthenticatorSelectionCriteria& aOther)
{
DictionaryBase::operator=(aOther);
mAuthenticatorAttachment.Reset();
if (aOther.mAuthenticatorAttachment.WasPassed()) {
mAuthenticatorAttachment.Construct(aOther.mAuthenticatorAttachment.Value());
}
mRequireResidentKey = aOther.mRequireResidentKey;
mResidentKey.Reset();
if (aOther.mResidentKey.WasPassed()) {
mResidentKey.Construct(aOther.mResidentKey.Value());
}
mUserVerification = aOther.mUserVerification;
return *this;
}
bool
AuthenticatorSelectionCriteria::operator==(const AuthenticatorSelectionCriteria& aOther) const
{
if (mAuthenticatorAttachment != aOther.mAuthenticatorAttachment) {
return false;
}
if (mRequireResidentKey != aOther.mRequireResidentKey) {
return false;
}
if (mResidentKey != aOther.mResidentKey) {
return false;
}
if (mUserVerification != aOther.mUserVerification) {
return false;
}
return true;
}
CredentialPropertiesOutput::CredentialPropertiesOutput()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
CredentialPropertiesOutput::InitIds(JSContext* cx, CredentialPropertiesOutputAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->rk_id.init(cx, "rk")) {
return false;
}
return true;
}
bool
CredentialPropertiesOutput::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
CredentialPropertiesOutput::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
CredentialPropertiesOutputAtoms* atomsCache = GetAtomCache<CredentialPropertiesOutputAtoms>(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));
if (mRk.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mRk.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->rk_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
CredentialPropertiesOutput::TraceDictionary(JSTracer* trc)
{
}
CredentialPropertiesOutput&
CredentialPropertiesOutput::operator=(const CredentialPropertiesOutput& aOther)
{
DictionaryBase::operator=(aOther);
mRk.Reset();
if (aOther.mRk.WasPassed()) {
mRk.Construct(aOther.mRk.Value());
}
return *this;
}
bool
CredentialPropertiesOutput::operator==(const CredentialPropertiesOutput& aOther) const
{
if (mRk != aOther.mRk) {
return false;
}
return true;
}
PublicKeyCredentialDescriptor::PublicKeyCredentialDescriptor()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialDescriptor::InitIds(JSContext* cx, PublicKeyCredentialDescriptorAtoms* 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->transports_id.init(cx, "transports") ||
!atomsCache->id_id.init(cx, "id")) {
return false;
}
return true;
}
bool
PublicKeyCredentialDescriptor::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());
PublicKeyCredentialDescriptorAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialDescriptorAtoms>(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->id_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mId.Init(cx, temp.ref(), "'id' member of PublicKeyCredentialDescriptor", passedToJSImpl)) {
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>("'id' member of PublicKeyCredentialDescriptor");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->transports_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTransports.Construct();
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>("'transports' member of PublicKeyCredentialDescriptor", "sequence");
return false;
}
Sequence<nsString> &arr = (mTransports.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'transports' member of PublicKeyCredentialDescriptor", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mType)) {
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>("'type' member of PublicKeyCredentialDescriptor");
}
return true;
}
bool
PublicKeyCredentialDescriptor::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);
}
bool
PublicKeyCredentialDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialDescriptorAtoms* atomsCache = GetAtomCache<PublicKeyCredentialDescriptorAtoms>(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);
OwningArrayBufferViewOrArrayBuffer const & currentValue = mId;
if (!currentValue.ToJSVal(cx, obj, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mTransports.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
Sequence<nsString> const & currentValue = mTransports.InternalValue();
uint32_t length = currentValue.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
temp.setObject(*returnArray);
if (!JS_DefinePropertyById(cx, obj, atomsCache->transports_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);
nsString const & currentValue = mType;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialDescriptor::TraceDictionary(JSTracer* trc)
{
mId.TraceUnion(trc);
}
PublicKeyCredentialDescriptorJSON::PublicKeyCredentialDescriptorJSON()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialDescriptorJSON::InitIds(JSContext* cx, PublicKeyCredentialDescriptorJSONAtoms* 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->transports_id.init(cx, "transports") ||
!atomsCache->id_id.init(cx, "id")) {
return false;
}
return true;
}
bool
PublicKeyCredentialDescriptorJSON::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());
PublicKeyCredentialDescriptorJSONAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialDescriptorJSONAtoms>(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->id_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) {
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>("'id' member of PublicKeyCredentialDescriptorJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->transports_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTransports.Construct();
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>("'transports' member of PublicKeyCredentialDescriptorJSON", "sequence");
return false;
}
Sequence<nsString> &arr = (mTransports.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'transports' member of PublicKeyCredentialDescriptorJSON", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mType)) {
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>("'type' member of PublicKeyCredentialDescriptorJSON");
}
return true;
}
bool
PublicKeyCredentialDescriptorJSON::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
PublicKeyCredentialDescriptorJSON::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialDescriptorJSON&
PublicKeyCredentialDescriptorJSON::operator=(const PublicKeyCredentialDescriptorJSON& aOther)
{
DictionaryBase::operator=(aOther);
mId = aOther.mId;
mTransports.Reset();
if (aOther.mTransports.WasPassed()) {
mTransports.Construct(aOther.mTransports.Value());
}
mType = aOther.mType;
return *this;
}
PublicKeyCredentialEntity::PublicKeyCredentialEntity()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialEntity::InitIds(JSContext* cx, PublicKeyCredentialEntityAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->name_id.init(cx, "name")) {
return false;
}
return true;
}
bool
PublicKeyCredentialEntity::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());
PublicKeyCredentialEntityAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialEntityAtoms>(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->name_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
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>("'name' member of PublicKeyCredentialEntity");
}
return true;
}
bool
PublicKeyCredentialEntity::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);
}
bool
PublicKeyCredentialEntity::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialEntityAtoms* atomsCache = GetAtomCache<PublicKeyCredentialEntityAtoms>(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);
nsString const & currentValue = mName;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialEntity::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialEntity&
PublicKeyCredentialEntity::operator=(const PublicKeyCredentialEntity& aOther)
{
DictionaryBase::operator=(aOther);
mName = aOther.mName;
return *this;
}
bool
PublicKeyCredentialEntity::operator==(const PublicKeyCredentialEntity& aOther) const
{
if (mName != aOther.mName) {
return false;
}
return true;
}
PublicKeyCredentialParameters::PublicKeyCredentialParameters()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialParameters::InitIds(JSContext* cx, PublicKeyCredentialParametersAtoms* 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->alg_id.init(cx, "alg")) {
return false;
}
return true;
}
bool
PublicKeyCredentialParameters::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());
PublicKeyCredentialParametersAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialParametersAtoms>(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->alg_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), "'alg' member of PublicKeyCredentialParameters", &mAlg)) {
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>("'alg' member of PublicKeyCredentialParameters");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mType)) {
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>("'type' member of PublicKeyCredentialParameters");
}
return true;
}
bool
PublicKeyCredentialParameters::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);
}
bool
PublicKeyCredentialParameters::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialParametersAtoms* atomsCache = GetAtomCache<PublicKeyCredentialParametersAtoms>(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);
int32_t const & currentValue = mAlg;
temp.setInt32(int32_t(currentValue));
if (!JS_DefinePropertyById(cx, obj, atomsCache->alg_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);
nsString const & currentValue = mType;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialParameters::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialParameters&
PublicKeyCredentialParameters::operator=(const PublicKeyCredentialParameters& aOther)
{
DictionaryBase::operator=(aOther);
mAlg = aOther.mAlg;
mType = aOther.mType;
return *this;
}
bool
PublicKeyCredentialParameters::operator==(const PublicKeyCredentialParameters& aOther) const
{
if (mAlg != aOther.mAlg) {
return false;
}
if (mType != aOther.mType) {
return false;
}
return true;
}
PublicKeyCredentialUserEntityJSON::PublicKeyCredentialUserEntityJSON()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialUserEntityJSON::InitIds(JSContext* cx, PublicKeyCredentialUserEntityJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->name_id.init(cx, "name") ||
!atomsCache->id_id.init(cx, "id") ||
!atomsCache->displayName_id.init(cx, "displayName")) {
return false;
}
return true;
}
bool
PublicKeyCredentialUserEntityJSON::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());
PublicKeyCredentialUserEntityJSONAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialUserEntityJSONAtoms>(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->displayName_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDisplayName)) {
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>("'displayName' member of PublicKeyCredentialUserEntityJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) {
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>("'id' member of PublicKeyCredentialUserEntityJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
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>("'name' member of PublicKeyCredentialUserEntityJSON");
}
return true;
}
bool
PublicKeyCredentialUserEntityJSON::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
PublicKeyCredentialUserEntityJSON::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialUserEntityJSON&
PublicKeyCredentialUserEntityJSON::operator=(const PublicKeyCredentialUserEntityJSON& aOther)
{
DictionaryBase::operator=(aOther);
mDisplayName = aOther.mDisplayName;
mId = aOther.mId;
mName = aOther.mName;
return *this;
}
bool
PublicKeyCredentialUserEntityJSON::operator==(const PublicKeyCredentialUserEntityJSON& aOther) const
{
if (mDisplayName != aOther.mDisplayName) {
return false;
}
if (mId != aOther.mId) {
return false;
}
if (mName != aOther.mName) {
return false;
}
return true;
}
TokenBinding::TokenBinding()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
TokenBinding::InitIds(JSContext* cx, TokenBindingAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->status_id.init(cx, "status") ||
!atomsCache->id_id.init(cx, "id")) {
return false;
}
return true;
}
bool
TokenBinding::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
TokenBinding::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TokenBindingAtoms* atomsCache = GetAtomCache<TokenBindingAtoms>(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));
if (mId.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mId.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_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);
nsString const & currentValue = mStatus;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->status_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
TokenBinding::TraceDictionary(JSTracer* trc)
{
}
TokenBinding&
TokenBinding::operator=(const TokenBinding& aOther)
{
DictionaryBase::operator=(aOther);
mId.Reset();
if (aOther.mId.WasPassed()) {
mId.Construct(aOther.mId.Value());
}
mStatus = aOther.mStatus;
return *this;
}
bool
TokenBinding::operator==(const TokenBinding& aOther) const
{
if (mId != aOther.mId) {
return false;
}
if (mStatus != aOther.mStatus) {
return false;
}
return true;
}
AuthenticationExtensionsClientOutputs::AuthenticationExtensionsClientOutputs()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
AuthenticationExtensionsClientOutputs::InitIds(JSContext* cx, AuthenticationExtensionsClientOutputsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->hmacCreateSecret_id.init(cx, "hmacCreateSecret") ||
!atomsCache->credProps_id.init(cx, "credProps") ||
!atomsCache->appid_id.init(cx, "appid")) {
return false;
}
return true;
}
bool
AuthenticationExtensionsClientOutputs::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
AuthenticationExtensionsClientOutputs::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticationExtensionsClientOutputsAtoms* atomsCache = GetAtomCache<AuthenticationExtensionsClientOutputsAtoms>(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));
if (mAppid.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mAppid.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->appid_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mCredProps.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
CredentialPropertiesOutput const & currentValue = mCredProps.InternalValue();
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->credProps_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mHmacCreateSecret.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mHmacCreateSecret.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->hmacCreateSecret_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
AuthenticationExtensionsClientOutputs::TraceDictionary(JSTracer* trc)
{
}
AuthenticationExtensionsClientOutputs&
AuthenticationExtensionsClientOutputs::operator=(const AuthenticationExtensionsClientOutputs& aOther)
{
DictionaryBase::operator=(aOther);
mAppid.Reset();
if (aOther.mAppid.WasPassed()) {
mAppid.Construct(aOther.mAppid.Value());
}
mCredProps.Reset();
if (aOther.mCredProps.WasPassed()) {
mCredProps.Construct(aOther.mCredProps.Value());
}
mHmacCreateSecret.Reset();
if (aOther.mHmacCreateSecret.WasPassed()) {
mHmacCreateSecret.Construct(aOther.mHmacCreateSecret.Value());
}
return *this;
}
AuthenticationExtensionsClientOutputsJSON::AuthenticationExtensionsClientOutputsJSON()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
AuthenticationExtensionsClientOutputsJSON::InitIds(JSContext* cx, AuthenticationExtensionsClientOutputsJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->hmacCreateSecret_id.init(cx, "hmacCreateSecret") ||
!atomsCache->credProps_id.init(cx, "credProps") ||
!atomsCache->appid_id.init(cx, "appid")) {
return false;
}
return true;
}
bool
AuthenticationExtensionsClientOutputsJSON::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
AuthenticationExtensionsClientOutputsJSON::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticationExtensionsClientOutputsJSONAtoms* atomsCache = GetAtomCache<AuthenticationExtensionsClientOutputsJSONAtoms>(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));
if (mAppid.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mAppid.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->appid_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mCredProps.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
CredentialPropertiesOutput const & currentValue = mCredProps.InternalValue();
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->credProps_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mHmacCreateSecret.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
bool const & currentValue = mHmacCreateSecret.InternalValue();
temp.setBoolean(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->hmacCreateSecret_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
AuthenticationExtensionsClientOutputsJSON::TraceDictionary(JSTracer* trc)
{
}
AuthenticationExtensionsClientOutputsJSON&
AuthenticationExtensionsClientOutputsJSON::operator=(const AuthenticationExtensionsClientOutputsJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAppid.Reset();
if (aOther.mAppid.WasPassed()) {
mAppid.Construct(aOther.mAppid.Value());
}
mCredProps.Reset();
if (aOther.mCredProps.WasPassed()) {
mCredProps.Construct(aOther.mCredProps.Value());
}
mHmacCreateSecret.Reset();
if (aOther.mHmacCreateSecret.WasPassed()) {
mHmacCreateSecret.Construct(aOther.mHmacCreateSecret.Value());
}
return *this;
}
CollectedClientData::CollectedClientData()
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
CollectedClientData::InitIds(JSContext* cx, CollectedClientDataAtoms* 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->tokenBinding_id.init(cx, "tokenBinding") ||
!atomsCache->origin_id.init(cx, "origin") ||
!atomsCache->challenge_id.init(cx, "challenge")) {
return false;
}
return true;
}
bool
CollectedClientData::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
CollectedClientData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
CollectedClientDataAtoms* atomsCache = GetAtomCache<CollectedClientDataAtoms>(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);
nsString const & currentValue = mChallenge;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->challenge_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);
nsString const & currentValue = mOrigin;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->origin_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mTokenBinding.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
TokenBinding const & currentValue = mTokenBinding.InternalValue();
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->tokenBinding_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);
nsString const & currentValue = mType;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
bool
CollectedClientData::ToJSON(nsAString& aJSON) const
{
AutoJSAPI jsapi;
jsapi.Init();
JSContext *cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
// because we'll only be creating objects, in ways that have no
// side-effects, followed by a call to JS::ToJSONMaybeSafely,
// which likewise guarantees no side-effects for the sorts of
// things we will pass it.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
JS_ReportOutOfMemory(cx);
return false;
}
JSAutoRealm ar(cx, scope);
JS::Rooted<JS::Value> val(cx);
if (!ToObjectInternal(cx, &val)) {
return false;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
return StringifyToJSON(cx, obj, aJSON);
}
void
CollectedClientData::TraceDictionary(JSTracer* trc)
{
}
CollectedClientData&
CollectedClientData::operator=(const CollectedClientData& aOther)
{
DictionaryBase::operator=(aOther);
mChallenge = aOther.mChallenge;
mOrigin = aOther.mOrigin;
mTokenBinding.Reset();
if (aOther.mTokenBinding.WasPassed()) {
mTokenBinding.Construct(aOther.mTokenBinding.Value());
}
mType = aOther.mType;
return *this;
}
PublicKeyCredentialRequestOptions::PublicKeyCredentialRequestOptions()
: mExtensions(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialRequestOptions::InitIds(JSContext* cx, PublicKeyCredentialRequestOptionsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->userVerification_id.init(cx, "userVerification") ||
!atomsCache->timeout_id.init(cx, "timeout") ||
!atomsCache->rpId_id.init(cx, "rpId") ||
!atomsCache->extensions_id.init(cx, "extensions") ||
!atomsCache->challenge_id.init(cx, "challenge") ||
!atomsCache->allowCredentials_id.init(cx, "allowCredentials")) {
return false;
}
return true;
}
bool
PublicKeyCredentialRequestOptions::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());
PublicKeyCredentialRequestOptionsAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialRequestOptionsAtoms>(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->allowCredentials_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>("'allowCredentials' member of PublicKeyCredentialRequestOptions", "sequence");
return false;
}
Sequence<PublicKeyCredentialDescriptor> &arr = mAllowCredentials;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialDescriptor* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialDescriptor& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'allowCredentials' member of PublicKeyCredentialRequestOptions", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'allowCredentials' member of PublicKeyCredentialRequestOptions", "sequence");
return false;
}
} else {
/* mAllowCredentials array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->challenge_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mChallenge.Init(cx, temp.ref(), "'challenge' member of PublicKeyCredentialRequestOptions", passedToJSImpl)) {
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>("'challenge' member of PublicKeyCredentialRequestOptions");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->extensions_id, temp.ptr())) {
return false;
}
}
if (!mExtensions.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'extensions' member of PublicKeyCredentialRequestOptions", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->rpId_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mRpId.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mRpId.Value()))) {
return false;
}
if (!NormalizeUSVString((mRpId.Value()))) {
JS_ReportOutOfMemory(cx);
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->timeout_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTimeout.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'timeout' member of PublicKeyCredentialRequestOptions", &(mTimeout.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->userVerification_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mUserVerification)) {
return false;
}
} else {
mUserVerification.AssignLiteral(u"preferred");
}
mIsAnyMemberPresent = true;
return true;
}
bool
PublicKeyCredentialRequestOptions::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);
}
bool
PublicKeyCredentialRequestOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialRequestOptionsAtoms* atomsCache = GetAtomCache<PublicKeyCredentialRequestOptionsAtoms>(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);
Sequence<PublicKeyCredentialDescriptor> const & currentValue = mAllowCredentials;
uint32_t length = currentValue.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
temp.setObject(*returnArray);
if (!JS_DefinePropertyById(cx, obj, atomsCache->allowCredentials_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);
OwningArrayBufferViewOrArrayBuffer const & currentValue = mChallenge;
if (!currentValue.ToJSVal(cx, obj, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->challenge_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);
AuthenticationExtensionsClientInputs const & currentValue = mExtensions;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->extensions_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mRpId.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mRpId.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->rpId_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
if (mTimeout.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint32_t const & currentValue = mTimeout.InternalValue();
temp.setNumber(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->timeout_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);
nsString const & currentValue = mUserVerification;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->userVerification_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialRequestOptions::TraceDictionary(JSTracer* trc)
{
DoTraceSequence(trc, mAllowCredentials);
mChallenge.TraceUnion(trc);
}
PublicKeyCredentialRequestOptionsJSON::PublicKeyCredentialRequestOptionsJSON()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialRequestOptionsJSON::InitIds(JSContext* cx, PublicKeyCredentialRequestOptionsJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->userVerification_id.init(cx, "userVerification") ||
!atomsCache->timeout_id.init(cx, "timeout") ||
!atomsCache->rpId_id.init(cx, "rpId") ||
!atomsCache->hints_id.init(cx, "hints") ||
!atomsCache->extensions_id.init(cx, "extensions") ||
!atomsCache->challenge_id.init(cx, "challenge") ||
!atomsCache->attestationFormats_id.init(cx, "attestationFormats") ||
!atomsCache->attestation_id.init(cx, "attestation") ||
!atomsCache->allowCredentials_id.init(cx, "allowCredentials")) {
return false;
}
return true;
}
bool
PublicKeyCredentialRequestOptionsJSON::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());
PublicKeyCredentialRequestOptionsJSONAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialRequestOptionsJSONAtoms>(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->allowCredentials_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>("'allowCredentials' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
Sequence<PublicKeyCredentialDescriptorJSON> &arr = mAllowCredentials;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialDescriptorJSON* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialDescriptorJSON& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'allowCredentials' member of PublicKeyCredentialRequestOptionsJSON", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'allowCredentials' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
} else {
/* mAllowCredentials array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attestation_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAttestation)) {
return false;
}
} else {
mAttestation.AssignLiteral(u"none");
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attestationFormats_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>("'attestationFormats' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
Sequence<nsString> &arr = mAttestationFormats;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attestationFormats' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
} else {
/* mAttestationFormats array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->challenge_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mChallenge)) {
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>("'challenge' member of PublicKeyCredentialRequestOptionsJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->extensions_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mExtensions.Construct();
if (!(mExtensions.Value()).Init(cx, temp.ref(), "'extensions' member of PublicKeyCredentialRequestOptionsJSON", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->hints_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>("'hints' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
Sequence<nsString> &arr = mHints;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'hints' member of PublicKeyCredentialRequestOptionsJSON", "sequence");
return false;
}
} else {
/* mHints array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->rpId_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mRpId.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mRpId.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->timeout_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTimeout.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'timeout' member of PublicKeyCredentialRequestOptionsJSON", &(mTimeout.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->userVerification_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mUserVerification)) {
return false;
}
} else {
mUserVerification.AssignLiteral(u"preferred");
}
mIsAnyMemberPresent = true;
return true;
}
bool
PublicKeyCredentialRequestOptionsJSON::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
PublicKeyCredentialRequestOptionsJSON::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialRequestOptionsJSON&
PublicKeyCredentialRequestOptionsJSON::operator=(const PublicKeyCredentialRequestOptionsJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAllowCredentials = aOther.mAllowCredentials;
mAttestation = aOther.mAttestation;
mAttestationFormats = aOther.mAttestationFormats;
mChallenge = aOther.mChallenge;
mExtensions.Reset();
if (aOther.mExtensions.WasPassed()) {
mExtensions.Construct(aOther.mExtensions.Value());
}
mHints = aOther.mHints;
mRpId.Reset();
if (aOther.mRpId.WasPassed()) {
mRpId.Construct(aOther.mRpId.Value());
}
mTimeout.Reset();
if (aOther.mTimeout.WasPassed()) {
mTimeout.Construct(aOther.mTimeout.Value());
}
mUserVerification = aOther.mUserVerification;
return *this;
}
PublicKeyCredentialRpEntity::PublicKeyCredentialRpEntity()
: PublicKeyCredentialEntity(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialRpEntity::InitIds(JSContext* cx, PublicKeyCredentialRpEntityAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->id_id.init(cx, "id")) {
return false;
}
return true;
}
bool
PublicKeyCredentialRpEntity::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());
PublicKeyCredentialRpEntityAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialRpEntityAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
// Per spec, we init the parent's members first
if (!PublicKeyCredentialEntity::Init(cx, val)) {
return false;
}
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->id_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mId.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mId.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
PublicKeyCredentialRpEntity::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);
}
bool
PublicKeyCredentialRpEntity::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialRpEntityAtoms* atomsCache = GetAtomCache<PublicKeyCredentialRpEntityAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
// Per spec, we define the parent's members first
if (!PublicKeyCredentialEntity::ToObjectInternal(cx, rval)) {
return false;
}
JS::Rooted<JSObject*> obj(cx, &rval.toObject());
if (mId.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mId.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
PublicKeyCredentialRpEntity::TraceDictionary(JSTracer* trc)
{
PublicKeyCredentialEntity::TraceDictionary(trc);
}
PublicKeyCredentialRpEntity&
PublicKeyCredentialRpEntity::operator=(const PublicKeyCredentialRpEntity& aOther)
{
PublicKeyCredentialEntity::operator=(aOther);
mId.Reset();
if (aOther.mId.WasPassed()) {
mId.Construct(aOther.mId.Value());
}
return *this;
}
bool
PublicKeyCredentialRpEntity::operator==(const PublicKeyCredentialRpEntity& aOther) const
{
if (mId != aOther.mId) {
return false;
}
return true;
}
PublicKeyCredentialUserEntity::PublicKeyCredentialUserEntity()
: PublicKeyCredentialEntity(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialUserEntity::InitIds(JSContext* cx, PublicKeyCredentialUserEntityAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->id_id.init(cx, "id") ||
!atomsCache->displayName_id.init(cx, "displayName")) {
return false;
}
return true;
}
bool
PublicKeyCredentialUserEntity::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());
PublicKeyCredentialUserEntityAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialUserEntityAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
// Per spec, we init the parent's members first
if (!PublicKeyCredentialEntity::Init(cx, val)) {
return false;
}
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->displayName_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDisplayName)) {
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>("'displayName' member of PublicKeyCredentialUserEntity");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mId.Init(cx, temp.ref(), "'id' member of PublicKeyCredentialUserEntity", passedToJSImpl)) {
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>("'id' member of PublicKeyCredentialUserEntity");
}
return true;
}
bool
PublicKeyCredentialUserEntity::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);
}
bool
PublicKeyCredentialUserEntity::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialUserEntityAtoms* atomsCache = GetAtomCache<PublicKeyCredentialUserEntityAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
// Per spec, we define the parent's members first
if (!PublicKeyCredentialEntity::ToObjectInternal(cx, rval)) {
return false;
}
JS::Rooted<JSObject*> obj(cx, &rval.toObject());
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mDisplayName;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->displayName_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);
OwningArrayBufferViewOrArrayBuffer const & currentValue = mId;
if (!currentValue.ToJSVal(cx, obj, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialUserEntity::TraceDictionary(JSTracer* trc)
{
PublicKeyCredentialEntity::TraceDictionary(trc);
mId.TraceUnion(trc);
}
AuthenticationResponseJSON::AuthenticationResponseJSON()
: mClientExtensionResults(FastDictionaryInitializer()),
mResponse(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
AuthenticationResponseJSON::InitIds(JSContext* cx, AuthenticationResponseJSONAtoms* 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->response_id.init(cx, "response") ||
!atomsCache->rawId_id.init(cx, "rawId") ||
!atomsCache->id_id.init(cx, "id") ||
!atomsCache->clientExtensionResults_id.init(cx, "clientExtensionResults") ||
!atomsCache->authenticatorAttachment_id.init(cx, "authenticatorAttachment")) {
return false;
}
return true;
}
bool
AuthenticationResponseJSON::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
AuthenticationResponseJSON::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
AuthenticationResponseJSONAtoms* atomsCache = GetAtomCache<AuthenticationResponseJSONAtoms>(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));
if (mAuthenticatorAttachment.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mAuthenticatorAttachment.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorAttachment_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);
AuthenticationExtensionsClientOutputsJSON const & currentValue = mClientExtensionResults;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->clientExtensionResults_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);
nsString const & currentValue = mId;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_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);
nsString const & currentValue = mRawId;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->rawId_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);
AuthenticatorAssertionResponseJSON const & currentValue = mResponse;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->response_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);
nsString const & currentValue = mType;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
AuthenticationResponseJSON::TraceDictionary(JSTracer* trc)
{
}
AuthenticationResponseJSON&
AuthenticationResponseJSON::operator=(const AuthenticationResponseJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAuthenticatorAttachment.Reset();
if (aOther.mAuthenticatorAttachment.WasPassed()) {
mAuthenticatorAttachment.Construct(aOther.mAuthenticatorAttachment.Value());
}
mClientExtensionResults = aOther.mClientExtensionResults;
mId = aOther.mId;
mRawId = aOther.mRawId;
mResponse = aOther.mResponse;
mType = aOther.mType;
return *this;
}
PublicKeyCredentialCreationOptions::PublicKeyCredentialCreationOptions()
: mAuthenticatorSelection(FastDictionaryInitializer()),
mExtensions(FastDictionaryInitializer()),
mRp(FastDictionaryInitializer()),
mUser(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialCreationOptions::InitIds(JSContext* cx, PublicKeyCredentialCreationOptionsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->user_id.init(cx, "user") ||
!atomsCache->timeout_id.init(cx, "timeout") ||
!atomsCache->rp_id.init(cx, "rp") ||
!atomsCache->pubKeyCredParams_id.init(cx, "pubKeyCredParams") ||
!atomsCache->extensions_id.init(cx, "extensions") ||
!atomsCache->excludeCredentials_id.init(cx, "excludeCredentials") ||
!atomsCache->challenge_id.init(cx, "challenge") ||
!atomsCache->authenticatorSelection_id.init(cx, "authenticatorSelection") ||
!atomsCache->attestation_id.init(cx, "attestation")) {
return false;
}
return true;
}
bool
PublicKeyCredentialCreationOptions::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());
PublicKeyCredentialCreationOptionsAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialCreationOptionsAtoms>(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->attestation_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAttestation)) {
return false;
}
} else {
mAttestation.AssignLiteral(u"none");
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->authenticatorSelection_id, temp.ptr())) {
return false;
}
}
if (!mAuthenticatorSelection.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'authenticatorSelection' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->challenge_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mChallenge.Init(cx, temp.ref(), "'challenge' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
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>("'challenge' member of PublicKeyCredentialCreationOptions");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->excludeCredentials_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>("'excludeCredentials' member of PublicKeyCredentialCreationOptions", "sequence");
return false;
}
Sequence<PublicKeyCredentialDescriptor> &arr = mExcludeCredentials;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialDescriptor* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialDescriptor& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'excludeCredentials' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'excludeCredentials' member of PublicKeyCredentialCreationOptions", "sequence");
return false;
}
} else {
/* mExcludeCredentials array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->extensions_id, temp.ptr())) {
return false;
}
}
if (!mExtensions.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'extensions' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->pubKeyCredParams_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>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptions", "sequence");
return false;
}
Sequence<PublicKeyCredentialParameters> &arr = mPubKeyCredParams;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialParameters* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialParameters& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'pubKeyCredParams' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptions", "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>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptions");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->rp_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mRp.Init(cx, temp.ref(), "'rp' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
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>("'rp' member of PublicKeyCredentialCreationOptions");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->timeout_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTimeout.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'timeout' member of PublicKeyCredentialCreationOptions", &(mTimeout.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->user_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mUser.Init(cx, temp.ref(), "'user' member of PublicKeyCredentialCreationOptions", passedToJSImpl)) {
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>("'user' member of PublicKeyCredentialCreationOptions");
}
return true;
}
bool
PublicKeyCredentialCreationOptions::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);
}
bool
PublicKeyCredentialCreationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
PublicKeyCredentialCreationOptionsAtoms* atomsCache = GetAtomCache<PublicKeyCredentialCreationOptionsAtoms>(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);
nsString const & currentValue = mAttestation;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->attestation_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);
AuthenticatorSelectionCriteria const & currentValue = mAuthenticatorSelection;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorSelection_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);
OwningArrayBufferViewOrArrayBuffer const & currentValue = mChallenge;
if (!currentValue.ToJSVal(cx, obj, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->challenge_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);
Sequence<PublicKeyCredentialDescriptor> const & currentValue = mExcludeCredentials;
uint32_t length = currentValue.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
temp.setObject(*returnArray);
if (!JS_DefinePropertyById(cx, obj, atomsCache->excludeCredentials_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);
AuthenticationExtensionsClientInputs const & currentValue = mExtensions;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->extensions_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);
Sequence<PublicKeyCredentialParameters> const & currentValue = mPubKeyCredParams;
uint32_t length = currentValue.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
temp.setObject(*returnArray);
if (!JS_DefinePropertyById(cx, obj, atomsCache->pubKeyCredParams_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);
PublicKeyCredentialRpEntity const & currentValue = mRp;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->rp_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mTimeout.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
uint32_t const & currentValue = mTimeout.InternalValue();
temp.setNumber(currentValue);
if (!JS_DefinePropertyById(cx, obj, atomsCache->timeout_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);
PublicKeyCredentialUserEntity const & currentValue = mUser;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->user_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
PublicKeyCredentialCreationOptions::TraceDictionary(JSTracer* trc)
{
mChallenge.TraceUnion(trc);
DoTraceSequence(trc, mExcludeCredentials);
mUser.TraceDictionary(trc);
}
PublicKeyCredentialCreationOptionsJSON::PublicKeyCredentialCreationOptionsJSON()
: mRp(FastDictionaryInitializer()),
mUser(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
PublicKeyCredentialCreationOptionsJSON::InitIds(JSContext* cx, PublicKeyCredentialCreationOptionsJSONAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->user_id.init(cx, "user") ||
!atomsCache->timeout_id.init(cx, "timeout") ||
!atomsCache->rp_id.init(cx, "rp") ||
!atomsCache->pubKeyCredParams_id.init(cx, "pubKeyCredParams") ||
!atomsCache->hints_id.init(cx, "hints") ||
!atomsCache->extensions_id.init(cx, "extensions") ||
!atomsCache->excludeCredentials_id.init(cx, "excludeCredentials") ||
!atomsCache->challenge_id.init(cx, "challenge") ||
!atomsCache->authenticatorSelection_id.init(cx, "authenticatorSelection") ||
!atomsCache->attestationFormats_id.init(cx, "attestationFormats") ||
!atomsCache->attestation_id.init(cx, "attestation")) {
return false;
}
return true;
}
bool
PublicKeyCredentialCreationOptionsJSON::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());
PublicKeyCredentialCreationOptionsJSONAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<PublicKeyCredentialCreationOptionsJSONAtoms>(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->attestation_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAttestation)) {
return false;
}
} else {
mAttestation.AssignLiteral(u"none");
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attestationFormats_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>("'attestationFormats' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
Sequence<nsString> &arr = mAttestationFormats;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attestationFormats' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
} else {
/* mAttestationFormats array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->authenticatorSelection_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAuthenticatorSelection.Construct();
if (!(mAuthenticatorSelection.Value()).Init(cx, temp.ref(), "'authenticatorSelection' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->challenge_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mChallenge)) {
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>("'challenge' member of PublicKeyCredentialCreationOptionsJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->excludeCredentials_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>("'excludeCredentials' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
Sequence<PublicKeyCredentialDescriptorJSON> &arr = mExcludeCredentials;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialDescriptorJSON* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialDescriptorJSON& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'excludeCredentials' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'excludeCredentials' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
} else {
/* mExcludeCredentials array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->extensions_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mExtensions.Construct();
if (!(mExtensions.Value()).Init(cx, temp.ref(), "'extensions' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->hints_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>("'hints' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
Sequence<nsString> &arr = mHints;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'hints' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
} else {
/* mHints array is already empty; nothing to do */
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->pubKeyCredParams_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>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptionsJSON", "sequence");
return false;
}
Sequence<PublicKeyCredentialParameters> &arr = mPubKeyCredParams;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
PublicKeyCredentialParameters* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
PublicKeyCredentialParameters& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'pubKeyCredParams' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptionsJSON", "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>("'pubKeyCredParams' member of PublicKeyCredentialCreationOptionsJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->rp_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mRp.Init(cx, temp.ref(), "'rp' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
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>("'rp' member of PublicKeyCredentialCreationOptionsJSON");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->timeout_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mTimeout.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'timeout' member of PublicKeyCredentialCreationOptionsJSON", &(mTimeout.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->user_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!mUser.Init(cx, temp.ref(), "'user' member of PublicKeyCredentialCreationOptionsJSON", passedToJSImpl)) {
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>("'user' member of PublicKeyCredentialCreationOptionsJSON");
}
return true;
}
bool
PublicKeyCredentialCreationOptionsJSON::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
PublicKeyCredentialCreationOptionsJSON::TraceDictionary(JSTracer* trc)
{
}
PublicKeyCredentialCreationOptionsJSON&
PublicKeyCredentialCreationOptionsJSON::operator=(const PublicKeyCredentialCreationOptionsJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAttestation = aOther.mAttestation;
mAttestationFormats = aOther.mAttestationFormats;
mAuthenticatorSelection.Reset();
if (aOther.mAuthenticatorSelection.WasPassed()) {
mAuthenticatorSelection.Construct(aOther.mAuthenticatorSelection.Value());
}
mChallenge = aOther.mChallenge;
mExcludeCredentials = aOther.mExcludeCredentials;
mExtensions.Reset();
if (aOther.mExtensions.WasPassed()) {
mExtensions.Construct(aOther.mExtensions.Value());
}
mHints = aOther.mHints;
mPubKeyCredParams = aOther.mPubKeyCredParams;
mRp = aOther.mRp;
mTimeout.Reset();
if (aOther.mTimeout.WasPassed()) {
mTimeout.Construct(aOther.mTimeout.Value());
}
mUser = aOther.mUser;
return *this;
}
RegistrationResponseJSON::RegistrationResponseJSON()
: mClientExtensionResults(FastDictionaryInitializer()),
mResponse(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init();
}
bool
RegistrationResponseJSON::InitIds(JSContext* cx, RegistrationResponseJSONAtoms* 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->response_id.init(cx, "response") ||
!atomsCache->rawId_id.init(cx, "rawId") ||
!atomsCache->id_id.init(cx, "id") ||
!atomsCache->clientExtensionResults_id.init(cx, "clientExtensionResults") ||
!atomsCache->authenticatorAttachment_id.init(cx, "authenticatorAttachment")) {
return false;
}
return true;
}
bool
RegistrationResponseJSON::Init(const char* sourceDescription, bool passedToJSImpl)
{
return true;
}
bool
RegistrationResponseJSON::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
RegistrationResponseJSONAtoms* atomsCache = GetAtomCache<RegistrationResponseJSONAtoms>(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));
if (mAuthenticatorAttachment.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
nsString const & currentValue = mAuthenticatorAttachment.InternalValue();
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->authenticatorAttachment_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);
AuthenticationExtensionsClientOutputsJSON const & currentValue = mClientExtensionResults;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->clientExtensionResults_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);
nsString const & currentValue = mId;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->id_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);
nsString const & currentValue = mRawId;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->rawId_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);
AuthenticatorAttestationResponseJSON const & currentValue = mResponse;
if (!currentValue.ToObjectInternal(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->response_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);
nsString const & currentValue = mType;
if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
return true;
}
void
RegistrationResponseJSON::TraceDictionary(JSTracer* trc)
{
}
RegistrationResponseJSON&
RegistrationResponseJSON::operator=(const RegistrationResponseJSON& aOther)
{
DictionaryBase::operator=(aOther);
mAuthenticatorAttachment.Reset();
if (aOther.mAuthenticatorAttachment.WasPassed()) {
mAuthenticatorAttachment.Construct(aOther.mAuthenticatorAttachment.Value());
}
mClientExtensionResults = aOther.mClientExtensionResults;
mId = aOther.mId;
mRawId = aOther.mRawId;
mResponse = aOther.mResponse;
mType = aOther.mType;
return *this;
}
namespace AuthenticatorAssertionResponse_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AuthenticatorResponse_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
MOZ_CAN_RUN_SCRIPT static bool
get_authenticatorData(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAssertionResponse", "authenticatorData", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAssertionResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAuthenticatorData(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAuthenticatorData(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAssertionResponse.authenticatorData getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo authenticatorData_getterinfo = {
{ get_authenticatorData },
{ prototypes::id::AuthenticatorAssertionResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAssertionResponse>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* 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
get_signature(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAssertionResponse", "signature", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAssertionResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetSignature(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetSignature(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAssertionResponse.signature getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo signature_getterinfo = {
{ get_signature },
{ prototypes::id::AuthenticatorAssertionResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAssertionResponse>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* 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
get_userHandle(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAssertionResponse", "userHandle", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAssertionResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetUserHandle(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetUserHandle(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAssertionResponse.userHandle getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (result) {
JS::ExposeObjectToActiveJS(result);
}
args.rval().setObjectOrNull(result);
if (!MaybeWrapNonDOMObjectOrNullValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo userHandle_getterinfo = {
{ get_userHandle },
{ prototypes::id::AuthenticatorAssertionResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAssertionResponse>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* 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. */
};
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::AuthenticatorAssertionResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAssertionResponse>(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::AuthenticatorAssertionResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAssertionResponse>(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::AuthenticatorAssertionResponse>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::AuthenticatorAssertionResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAssertionResponse>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::AuthenticatorAssertionResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAssertionResponse>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("authenticatorData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &authenticatorData_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("signature", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &signature_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("userHandle", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &userHandle_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const PrefableDisablers sAttributes_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ &sAttributes_disablers0, &sAttributes_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(3 <= 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[3];
static PropertyInfo sNativeProperties_propertyInfos[3];
static const NativePropertiesN<1> sNativeProperties = {
false, 0,
false, 0,
false, 0,
true, 0 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
3,
sNativeProperties_sortedPropertyIndices,
{
{ sAttributes, &sNativeProperties_propertyInfos[0] }
}
};
static_assert(3 < 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::AuthenticatorAssertionResponse,
constructors::id::AuthenticatorAssertionResponse,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
AuthenticatorResponse_Binding::GetConstructorObject,
prototypes::id::AuthenticatorAssertionResponse,
PrototypeTraits<prototypes::id::AuthenticatorAssertionResponse>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"AuthenticatorAssertionResponsePrototype",
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::AuthenticatorAssertionResponse,
PrototypeTraits<prototypes::id::AuthenticatorAssertionResponse>::Depth,
&sNativePropertyHooks,
AuthenticatorResponse_Binding::GetProtoObject
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::security_webauth_webauthn() &&
mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
}
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 = {
{ "AuthenticatorAssertionResponse",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::AuthenticatorResponse, prototypes::id::AuthenticatorAssertionResponse, 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::AuthenticatorAssertionResponse>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::AuthenticatorAssertionResponse>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::AuthenticatorAssertionResponse>::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::AuthenticatorAssertionResponse* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::AuthenticatorAssertionResponse>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::AuthenticatorAssertionResponse*>);
MOZ_ASSERT(static_cast<mozilla::dom::AuthenticatorResponse*>(aObject) ==
reinterpret_cast<mozilla::dom::AuthenticatorResponse*>(aObject),
"Multiple inheritance for mozilla::dom::AuthenticatorResponse is broken.");
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::AuthenticatorAssertionResponse> 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::AuthenticatorAssertionResponse);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AuthenticatorAssertionResponse);
JS::Handle<JSObject*> parentProto(AuthenticatorResponse_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(AuthenticatorResponse_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"AuthenticatorAssertionResponse", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace AuthenticatorAssertionResponse_Binding
namespace AuthenticatorAttestationResponse_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AuthenticatorResponse_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
MOZ_CAN_RUN_SCRIPT static bool
get_attestationObject(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAttestationResponse", "attestationObject", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAttestationResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAttestationObject(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAttestationObject(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAttestationResponse.attestationObject getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo attestationObject_getterinfo = {
{ get_attestationObject },
{ prototypes::id::AuthenticatorAttestationResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* 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
getTransports(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAttestationResponse", "getTransports", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAttestationResponse*>(void_self);
nsTArray<nsString> result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetTransports(result))>, "Should be returning void here");
MOZ_KnownLive(self)->GetTransports(result);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
uint32_t length = result.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, result[sequenceIdx0], &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
args.rval().setObject(*returnArray);
return true;
}
static const JSJitInfo getTransports_methodinfo = {
{ (JSJitGetterOp)getTransports },
{ prototypes::id::AuthenticatorAttestationResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::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
getAuthenticatorData(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAttestationResponse", "getAuthenticatorData", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAttestationResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAuthenticatorData(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAuthenticatorData(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAttestationResponse.getAuthenticatorData"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getAuthenticatorData_methodinfo = {
{ (JSJitGetterOp)getAuthenticatorData },
{ prototypes::id::AuthenticatorAttestationResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::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
getPublicKey(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAttestationResponse", "getPublicKey", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAttestationResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetPublicKey(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetPublicKey(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAttestationResponse.getPublicKey"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (result) {
JS::ExposeObjectToActiveJS(result);
}
args.rval().setObjectOrNull(result);
if (!MaybeWrapNonDOMObjectOrNullValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getPublicKey_methodinfo = {
{ (JSJitGetterOp)getPublicKey },
{ prototypes::id::AuthenticatorAttestationResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* 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
getPublicKeyAlgorithm(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorAttestationResponse", "getPublicKeyAlgorithm", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorAttestationResponse*>(void_self);
FastErrorResult rv;
int32_t result(MOZ_KnownLive(self)->GetPublicKeyAlgorithm(rv));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorAttestationResponse.getPublicKeyAlgorithm"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setInt32(int32_t(result));
return true;
}
static const JSJitInfo getPublicKeyAlgorithm_methodinfo = {
{ (JSJitGetterOp)getPublicKeyAlgorithm },
{ prototypes::id::AuthenticatorAttestationResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_INT32, /* 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. */
};
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::AuthenticatorAttestationResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAttestationResponse>(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::AuthenticatorAttestationResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAttestationResponse>(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::AuthenticatorAttestationResponse>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::AuthenticatorAttestationResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAttestationResponse>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::AuthenticatorAttestationResponse* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AuthenticatorAttestationResponse>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("getTransports", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getTransports_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getAuthenticatorData", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAuthenticatorData_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getPublicKey", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getPublicKey_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getPublicKeyAlgorithm", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getPublicKeyAlgorithm_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const PrefableDisablers sMethods_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ &sMethods_disablers0, &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 const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("attestationObject", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &attestationObject_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const PrefableDisablers sAttributes_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ &sAttributes_disablers0, &sAttributes_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)");
static uint16_t sNativeProperties_sortedPropertyIndices[5];
static PropertyInfo sNativeProperties_propertyInfos[5];
static const NativePropertiesN<2> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
true, 1 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
5,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] },
{ sAttributes, &sNativeProperties_propertyInfos[4] }
}
};
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::AuthenticatorAttestationResponse,
constructors::id::AuthenticatorAttestationResponse,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
AuthenticatorResponse_Binding::GetConstructorObject,
prototypes::id::AuthenticatorAttestationResponse,
PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"AuthenticatorAttestationResponsePrototype",
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::AuthenticatorAttestationResponse,
PrototypeTraits<prototypes::id::AuthenticatorAttestationResponse>::Depth,
&sNativePropertyHooks,
AuthenticatorResponse_Binding::GetProtoObject
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::security_webauth_webauthn() &&
mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
}
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 = {
{ "AuthenticatorAttestationResponse",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::AuthenticatorResponse, prototypes::id::AuthenticatorAttestationResponse, 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::AuthenticatorAttestationResponse>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::AuthenticatorAttestationResponse>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::AuthenticatorAttestationResponse>::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::AuthenticatorAttestationResponse* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::AuthenticatorAttestationResponse>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::AuthenticatorAttestationResponse*>);
MOZ_ASSERT(static_cast<mozilla::dom::AuthenticatorResponse*>(aObject) ==
reinterpret_cast<mozilla::dom::AuthenticatorResponse*>(aObject),
"Multiple inheritance for mozilla::dom::AuthenticatorResponse is broken.");
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::AuthenticatorAttestationResponse> 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::AuthenticatorAttestationResponse);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AuthenticatorAttestationResponse);
JS::Handle<JSObject*> parentProto(AuthenticatorResponse_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(AuthenticatorResponse_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"AuthenticatorAttestationResponse", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace AuthenticatorAttestationResponse_Binding
namespace AuthenticatorResponse_Binding {
MOZ_CAN_RUN_SCRIPT static bool
get_clientDataJSON(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AuthenticatorResponse", "clientDataJSON", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AuthenticatorResponse*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetClientDataJSON(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetClientDataJSON(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AuthenticatorResponse.clientDataJSON getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo clientDataJSON_getterinfo = {
{ get_clientDataJSON },
{ prototypes::id::AuthenticatorResponse },
{ PrototypeTraits<prototypes::id::AuthenticatorResponse>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* 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. */
};
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("clientDataJSON", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &clientDataJSON_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const PrefableDisablers sAttributes_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ &sAttributes_disablers0, &sAttributes_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)");
static uint16_t sNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sNativeProperties = {
false, 0,
false, 0,
false, 0,
true, 0 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
1,
sNativeProperties_sortedPropertyIndices,
{
{ sAttributes, &sNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 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::AuthenticatorResponse,
constructors::id::AuthenticatorResponse,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
JS::GetRealmFunctionPrototype,
prototypes::id::AuthenticatorResponse,
PrototypeTraits<prototypes::id::AuthenticatorResponse>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"AuthenticatorResponsePrototype",
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::AuthenticatorResponse,
PrototypeTraits<prototypes::id::AuthenticatorResponse>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::security_webauth_webauthn() &&
mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::AuthenticatorResponse);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AuthenticatorResponse);
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,
sNativeProperties.Upcast(),
nullptr,
"AuthenticatorResponse", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetProtoObject(JSContext* aCx)
{
return GetProtoObjectHandle(aCx);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace AuthenticatorResponse_Binding
namespace PublicKeyCredential_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Credential_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
MOZ_CAN_RUN_SCRIPT static bool
get_rawId(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "rawId", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::PublicKeyCredential*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetRawId(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->GetRawId(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.rawId getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo rawId_getterinfo = {
{ get_rawId },
{ prototypes::id::PublicKeyCredential },
{ PrototypeTraits<prototypes::id::PublicKeyCredential>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* 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
get_response(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "response", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::PublicKeyCredential*>(void_self);
auto result(StrongOrRawPtr<mozilla::dom::AuthenticatorResponse>(MOZ_KnownLive(self)->Response()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo response_getterinfo = {
{ get_response },
{ prototypes::id::PublicKeyCredential },
{ PrototypeTraits<prototypes::id::PublicKeyCredential>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
true, /* isMovable. Not relevant for setters. */
true, /* 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
get_authenticatorAttachment(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "authenticatorAttachment", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::PublicKeyCredential*>(void_self);
DOMString result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAuthenticatorAttachment(result))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAuthenticatorAttachment(result);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!xpc::StringToJsval(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo authenticatorAttachment_getterinfo = {
{ get_authenticatorAttachment },
{ prototypes::id::PublicKeyCredential },
{ PrototypeTraits<prototypes::id::PublicKeyCredential>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* 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
getClientExtensionResults(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "getClientExtensionResults", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::PublicKeyCredential*>(void_self);
AuthenticationExtensionsClientOutputs result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetClientExtensionResults(result))>, "Should be returning void here");
MOZ_KnownLive(self)->GetClientExtensionResults(result);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getClientExtensionResults_methodinfo = {
{ (JSJitGetterOp)getClientExtensionResults },
{ prototypes::id::PublicKeyCredential },
{ PrototypeTraits<prototypes::id::PublicKeyCredential>::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
isConditionalMediationAvailable(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "isConditionalMediationAvailable", 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());
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(mozilla::dom::PublicKeyCredential::IsConditionalMediationAvailable(global, rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.isConditionalMediationAvailable"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo isConditionalMediationAvailable_methodinfo = {
{ (JSJitGetterOp)isConditionalMediationAvailable },
{ prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
JSJitInfo::AliasEverything, JSVAL_TYPE_OBJECT, false, false,
false, false, 0
};
MOZ_CAN_RUN_SCRIPT static bool
toJSON(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "toJSON", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::PublicKeyCredential*>(void_self);
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ToJSON(cx, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->ToJSON(cx, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.toJSON"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo toJSON_methodinfo = {
{ (JSJitGetterOp)toJSON },
{ prototypes::id::PublicKeyCredential },
{ PrototypeTraits<prototypes::id::PublicKeyCredential>::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
isUserVerifyingPlatformAuthenticatorAvailable(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "isUserVerifyingPlatformAuthenticatorAvailable", 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());
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(mozilla::dom::PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(global, rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo isUserVerifyingPlatformAuthenticatorAvailable_methodinfo = {
{ (JSJitGetterOp)isUserVerifyingPlatformAuthenticatorAvailable },
{ prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
JSJitInfo::AliasEverything, JSVAL_TYPE_OBJECT, false, false,
false, false, 0
};
MOZ_CAN_RUN_SCRIPT static bool
parseCreationOptionsFromJSON(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "PublicKeyCredential.parseCreationOptionsFromJSON");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "parseCreationOptionsFromJSON", 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, "PublicKeyCredential.parseCreationOptionsFromJSON", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
binding_detail::FastPublicKeyCredentialCreationOptionsJSON arg0;
if (!arg0.Init(cx, args[0], "Argument 1", false)) {
return false;
}
FastErrorResult rv;
RootedDictionary<PublicKeyCredentialCreationOptions> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::PublicKeyCredential::ParseCreationOptionsFromJSON(global, Constify(arg0), result, rv))>, "Should be returning void here");
mozilla::dom::PublicKeyCredential::ParseCreationOptionsFromJSON(global, Constify(arg0), result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.parseCreationOptionsFromJSON"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
parseRequestOptionsFromJSON(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "PublicKeyCredential.parseRequestOptionsFromJSON");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"PublicKeyCredential", "parseRequestOptionsFromJSON", 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, "PublicKeyCredential.parseRequestOptionsFromJSON", 1)) {
return false;
}
GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
if (global.Failed()) {
return false;
}
binding_detail::FastPublicKeyCredentialRequestOptionsJSON arg0;
if (!arg0.Init(cx, args[0], "Argument 1", false)) {
return false;
}
FastErrorResult rv;
RootedDictionary<PublicKeyCredentialRequestOptions> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(mozilla::dom::PublicKeyCredential::ParseRequestOptionsFromJSON(global, Constify(arg0), result, rv))>, "Should be returning void here");
mozilla::dom::PublicKeyCredential::ParseRequestOptionsFromJSON(global, Constify(arg0), result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "PublicKeyCredential.parseRequestOptionsFromJSON"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::PublicKeyCredential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PublicKeyCredential>(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::PublicKeyCredential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PublicKeyCredential>(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::PublicKeyCredential>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::PublicKeyCredential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PublicKeyCredential>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::PublicKeyCredential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PublicKeyCredential>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sStaticMethods_specs[] = {
JS_FNSPEC("isConditionalMediationAvailable", StaticMethodPromiseWrapper, &isConditionalMediationAvailable_methodinfo, 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("isUserVerifyingPlatformAuthenticatorAvailable", StaticMethodPromiseWrapper, &isUserVerifyingPlatformAuthenticatorAvailable_methodinfo, 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END,
JS_FNSPEC("parseCreationOptionsFromJSON", parseCreationOptionsFromJSON, nullptr, 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("parseRequestOptionsFromJSON", parseRequestOptionsFromJSON, nullptr, 1, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const PrefableDisablers sStaticMethods_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const PrefableDisablers sStaticMethods_disablers3 = {
WebIDLPrefIndex::security_webauthn_enable_json_serialization_methods, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
{ &sStaticMethods_disablers0, &sStaticMethods_specs[0] },
{ &sStaticMethods_disablers3, &sStaticMethods_specs[3] },
{ nullptr, nullptr }
};
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("getClientExtensionResults", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getClientExtensionResults_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END,
JS_FNSPEC("toJSON", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&toJSON_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const PrefableDisablers sMethods_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const PrefableDisablers sMethods_disablers2 = {
WebIDLPrefIndex::security_webauthn_enable_json_serialization_methods, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ &sMethods_disablers0, &sMethods_specs[0] },
{ &sMethods_disablers2, &sMethods_specs[2] },
{ nullptr, nullptr }
};
static_assert(2 <= 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)");
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("rawId", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &rawId_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("response", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &response_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("authenticatorAttachment", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &authenticatorAttachment_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const PrefableDisablers sAttributes_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ &sAttributes_disablers0, &sAttributes_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(3 <= 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[9];
static PropertyInfo sNativeProperties_propertyInfos[9];
static const NativePropertiesN<3> sNativeProperties = {
true, 0 /* sStaticMethods */,
false, 0,
true, 1 /* sMethods */,
true, 2 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
9,
sNativeProperties_sortedPropertyIndices,
{
{ sStaticMethods, &sNativeProperties_propertyInfos[0] },
{ sMethods, &sNativeProperties_propertyInfos[4] },
{ sAttributes, &sNativeProperties_propertyInfos[6] }
}
};
static_assert(9 < 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::PublicKeyCredential,
constructors::id::PublicKeyCredential,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
Credential_Binding::GetConstructorObject,
prototypes::id::PublicKeyCredential,
PrototypeTraits<prototypes::id::PublicKeyCredential>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"PublicKeyCredentialPrototype",
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::PublicKeyCredential,
PrototypeTraits<prototypes::id::PublicKeyCredential>::Depth,
&sNativePropertyHooks,
Credential_Binding::GetProtoObject
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::security_webauth_webauthn() &&
mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
}
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 = {
{ "PublicKeyCredential",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::Credential, prototypes::id::PublicKeyCredential, 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::PublicKeyCredential>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::PublicKeyCredential>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::PublicKeyCredential>::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::PublicKeyCredential* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::PublicKeyCredential>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::PublicKeyCredential*>);
MOZ_ASSERT(static_cast<mozilla::dom::Credential*>(aObject) ==
reinterpret_cast<mozilla::dom::Credential*>(aObject),
"Multiple inheritance for mozilla::dom::Credential is broken.");
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::PublicKeyCredential> 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::PublicKeyCredential);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PublicKeyCredential);
JS::Handle<JSObject*> parentProto(Credential_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(Credential_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"PublicKeyCredential", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace PublicKeyCredential_Binding
} // namespace mozilla::dom