Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/CredentialManagementBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM CredentialManagement.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "CredentialManagementBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/Preferences.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/Credential.h"
10
#include "mozilla/dom/CredentialsContainer.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Promise.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/ToJSValue.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
26
CredentialCreationOptions::CredentialCreationOptions()
27
  : mPublicKey(FastDictionaryInitializer())
28
0
{
29
0
  // Safe to pass a null context if we pass a null value
30
0
  Init(nullptr, JS::NullHandleValue);
31
0
}
32
33
34
bool
35
CredentialCreationOptions::InitIds(JSContext* cx, CredentialCreationOptionsAtoms* atomsCache)
36
0
{
37
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
38
0
39
0
  // Initialize these in reverse order so that any failure leaves the first one
40
0
  // uninitialized.
41
0
  if (!atomsCache->signal_id.init(cx, "signal") ||
42
0
      !atomsCache->publicKey_id.init(cx, "publicKey")) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
bool
49
CredentialCreationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50
0
{
51
0
  // Passing a null JSContext is OK only if we're initing from null,
52
0
  // Since in that case we will not have to do any property gets
53
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
54
0
  // checkers by static analysis tools
55
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56
0
  CredentialCreationOptionsAtoms* atomsCache = nullptr;
57
0
  if (cx) {
58
0
    atomsCache = GetAtomCache<CredentialCreationOptionsAtoms>(cx);
59
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60
0
      return false;
61
0
    }
62
0
  }
63
0
64
0
  if (!IsConvertibleToDictionary(val)) {
65
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
66
0
  }
67
0
68
0
  bool isNull = val.isNullOrUndefined();
69
0
  // We only need these if !isNull, in which case we have |cx|.
70
0
  Maybe<JS::Rooted<JSObject *> > object;
71
0
  Maybe<JS::Rooted<JS::Value> > temp;
72
0
  if (!isNull) {
73
0
    MOZ_ASSERT(cx);
74
0
    object.emplace(cx, &val.toObject());
75
0
    temp.emplace(cx);
76
0
  }
77
0
  if (!isNull) {
78
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->publicKey_id, temp.ptr())) {
79
0
      return false;
80
0
    }
81
0
  }
82
0
  if (!mPublicKey.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'publicKey' member of CredentialCreationOptions", passedToJSImpl)) {
83
0
    return false;
84
0
  }
85
0
  mIsAnyMemberPresent = true;
86
0
87
0
  if (!isNull) {
88
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->signal_id, temp.ptr())) {
89
0
      return false;
90
0
    }
91
0
  }
92
0
  if (!isNull && !temp->isUndefined()) {
93
0
    mSignal.Construct();
94
0
    if (temp.ref().isObject()) {
95
0
      static_assert(IsRefcounted<mozilla::dom::AbortSignal>::value, "We can only store refcounted classes.");{
96
0
        nsresult rv = UnwrapObject<prototypes::id::AbortSignal, mozilla::dom::AbortSignal>(temp.ptr(), (mSignal.Value()));
97
0
        if (NS_FAILED(rv)) {
98
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'signal' member of CredentialCreationOptions", "AbortSignal");
99
0
          return false;
100
0
        }
101
0
      }
102
0
    } else {
103
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'signal' member of CredentialCreationOptions");
104
0
      return false;
105
0
    }
106
0
    mIsAnyMemberPresent = true;
107
0
  }
108
0
  return true;
109
0
}
110
111
bool
112
CredentialCreationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
113
0
{
114
0
  CredentialCreationOptionsAtoms* atomsCache = GetAtomCache<CredentialCreationOptionsAtoms>(cx);
115
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
116
0
    return false;
117
0
  }
118
0
119
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
120
0
  if (!obj) {
121
0
    return false;
122
0
  }
123
0
  rval.set(JS::ObjectValue(*obj));
124
0
125
0
  do {
126
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
127
0
    JS::Rooted<JS::Value> temp(cx);
128
0
    PublicKeyCredentialCreationOptions const & currentValue = mPublicKey;
129
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
130
0
      return false;
131
0
    }
132
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKey_id, temp, JSPROP_ENUMERATE)) {
133
0
      return false;
134
0
    }
135
0
    break;
136
0
  } while(false);
137
0
138
0
  if (mSignal.WasPassed()) {
139
0
    do {
140
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
141
0
      JS::Rooted<JS::Value> temp(cx);
142
0
      OwningNonNull<mozilla::dom::AbortSignal> const & currentValue = mSignal.InternalValue();
143
0
      if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
144
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
145
0
        return false;
146
0
      }
147
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->signal_id, temp, JSPROP_ENUMERATE)) {
148
0
        return false;
149
0
      }
150
0
      break;
151
0
    } while(false);
152
0
  }
153
0
154
0
  return true;
155
0
}
156
157
void
158
CredentialCreationOptions::TraceDictionary(JSTracer* trc)
159
0
{
160
0
  mPublicKey.TraceDictionary(trc);
161
0
}
162
163
164
165
namespace binding_detail {
166
} // namespace binding_detail
167
168
169
170
CredentialRequestOptions::CredentialRequestOptions()
171
  : mPublicKey(FastDictionaryInitializer())
172
0
{
173
0
  // Safe to pass a null context if we pass a null value
174
0
  Init(nullptr, JS::NullHandleValue);
175
0
}
176
177
178
bool
179
CredentialRequestOptions::InitIds(JSContext* cx, CredentialRequestOptionsAtoms* atomsCache)
180
0
{
181
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
182
0
183
0
  // Initialize these in reverse order so that any failure leaves the first one
184
0
  // uninitialized.
185
0
  if (!atomsCache->signal_id.init(cx, "signal") ||
186
0
      !atomsCache->publicKey_id.init(cx, "publicKey")) {
187
0
    return false;
188
0
  }
189
0
  return true;
190
0
}
191
192
bool
193
CredentialRequestOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
194
0
{
195
0
  // Passing a null JSContext is OK only if we're initing from null,
196
0
  // Since in that case we will not have to do any property gets
197
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
198
0
  // checkers by static analysis tools
199
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
200
0
  CredentialRequestOptionsAtoms* atomsCache = nullptr;
201
0
  if (cx) {
202
0
    atomsCache = GetAtomCache<CredentialRequestOptionsAtoms>(cx);
203
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
204
0
      return false;
205
0
    }
206
0
  }
207
0
208
0
  if (!IsConvertibleToDictionary(val)) {
209
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
210
0
  }
211
0
212
0
  bool isNull = val.isNullOrUndefined();
213
0
  // We only need these if !isNull, in which case we have |cx|.
214
0
  Maybe<JS::Rooted<JSObject *> > object;
215
0
  Maybe<JS::Rooted<JS::Value> > temp;
216
0
  if (!isNull) {
217
0
    MOZ_ASSERT(cx);
218
0
    object.emplace(cx, &val.toObject());
219
0
    temp.emplace(cx);
220
0
  }
221
0
  if (!isNull) {
222
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->publicKey_id, temp.ptr())) {
223
0
      return false;
224
0
    }
225
0
  }
226
0
  if (!mPublicKey.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'publicKey' member of CredentialRequestOptions", passedToJSImpl)) {
227
0
    return false;
228
0
  }
229
0
  mIsAnyMemberPresent = true;
230
0
231
0
  if (!isNull) {
232
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->signal_id, temp.ptr())) {
233
0
      return false;
234
0
    }
235
0
  }
236
0
  if (!isNull && !temp->isUndefined()) {
237
0
    mSignal.Construct();
238
0
    if (temp.ref().isObject()) {
239
0
      static_assert(IsRefcounted<mozilla::dom::AbortSignal>::value, "We can only store refcounted classes.");{
240
0
        nsresult rv = UnwrapObject<prototypes::id::AbortSignal, mozilla::dom::AbortSignal>(temp.ptr(), (mSignal.Value()));
241
0
        if (NS_FAILED(rv)) {
242
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'signal' member of CredentialRequestOptions", "AbortSignal");
243
0
          return false;
244
0
        }
245
0
      }
246
0
    } else {
247
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'signal' member of CredentialRequestOptions");
248
0
      return false;
249
0
    }
250
0
    mIsAnyMemberPresent = true;
251
0
  }
252
0
  return true;
253
0
}
254
255
bool
256
CredentialRequestOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
257
0
{
258
0
  CredentialRequestOptionsAtoms* atomsCache = GetAtomCache<CredentialRequestOptionsAtoms>(cx);
259
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
260
0
    return false;
261
0
  }
262
0
263
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
264
0
  if (!obj) {
265
0
    return false;
266
0
  }
267
0
  rval.set(JS::ObjectValue(*obj));
268
0
269
0
  do {
270
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
271
0
    JS::Rooted<JS::Value> temp(cx);
272
0
    PublicKeyCredentialRequestOptions const & currentValue = mPublicKey;
273
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
274
0
      return false;
275
0
    }
276
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKey_id, temp, JSPROP_ENUMERATE)) {
277
0
      return false;
278
0
    }
279
0
    break;
280
0
  } while(false);
281
0
282
0
  if (mSignal.WasPassed()) {
283
0
    do {
284
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
285
0
      JS::Rooted<JS::Value> temp(cx);
286
0
      OwningNonNull<mozilla::dom::AbortSignal> const & currentValue = mSignal.InternalValue();
287
0
      if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
288
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
289
0
        return false;
290
0
      }
291
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->signal_id, temp, JSPROP_ENUMERATE)) {
292
0
        return false;
293
0
      }
294
0
      break;
295
0
    } while(false);
296
0
  }
297
0
298
0
  return true;
299
0
}
300
301
void
302
CredentialRequestOptions::TraceDictionary(JSTracer* trc)
303
0
{
304
0
  mPublicKey.TraceDictionary(trc);
305
0
}
306
307
308
309
namespace binding_detail {
310
} // namespace binding_detail
311
312
313
namespace Credential_Binding {
314
315
MOZ_CAN_RUN_SCRIPT static bool
316
get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Credential* self, JSJitGetterCallArgs args)
317
0
{
318
0
  AUTO_PROFILER_LABEL_FAST("get Credential.id", DOM, cx);
319
0
320
0
  DOMString result;
321
0
  self->GetId(result);
322
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
323
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
324
0
    return false;
325
0
  }
326
0
  return true;
327
0
}
328
329
static const JSJitInfo id_getterinfo = {
330
  { (JSJitGetterOp)get_id },
331
  { prototypes::id::Credential },
332
  { PrototypeTraits<prototypes::id::Credential>::Depth },
333
  JSJitInfo::Getter,
334
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
335
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
336
  false,  /* isInfallible. False in setters. */
337
  false,  /* isMovable.  Not relevant for setters. */
338
  false, /* isEliminatable.  Not relevant for setters. */
339
  false, /* isAlwaysInSlot.  Only relevant for getters. */
340
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
341
  false,  /* isTypedMethod.  Only relevant for methods. */
342
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
343
};
344
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
345
static_assert(0 < 1, "There is no slot for us");
346
347
MOZ_CAN_RUN_SCRIPT static bool
348
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Credential* self, JSJitGetterCallArgs args)
349
0
{
350
0
  AUTO_PROFILER_LABEL_FAST("get Credential.type", DOM, cx);
351
0
352
0
  DOMString result;
353
0
  self->GetType(result);
354
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
355
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
356
0
    return false;
357
0
  }
358
0
  return true;
359
0
}
360
361
static const JSJitInfo type_getterinfo = {
362
  { (JSJitGetterOp)get_type },
363
  { prototypes::id::Credential },
364
  { PrototypeTraits<prototypes::id::Credential>::Depth },
365
  JSJitInfo::Getter,
366
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
367
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
368
  false,  /* isInfallible. False in setters. */
369
  false,  /* isMovable.  Not relevant for setters. */
370
  false, /* isEliminatable.  Not relevant for setters. */
371
  false, /* isAlwaysInSlot.  Only relevant for getters. */
372
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
373
  false,  /* isTypedMethod.  Only relevant for methods. */
374
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
375
};
376
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
377
static_assert(0 < 1, "There is no slot for us");
378
379
static bool
380
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
381
0
{
382
0
  mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
383
0
  // We don't want to preserve if we don't have a wrapper, and we
384
0
  // obviously can't preserve if we're not initialized.
385
0
  if (self && self->GetWrapperPreserveColor()) {
386
0
    PreserveWrapper(self);
387
0
  }
388
0
  return true;
389
0
}
390
391
static void
392
_finalize(js::FreeOp* fop, JSObject* obj)
393
0
{
394
0
  mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
395
0
  if (self) {
396
0
    ClearWrapper(self, self, obj);
397
0
    AddForDeferredFinalization<mozilla::dom::Credential>(self);
398
0
  }
399
0
}
400
401
static size_t
402
_objectMoved(JSObject* obj, JSObject* old)
403
0
{
404
0
  mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
405
0
  if (self) {
406
0
    UpdateWrapper(self, self, obj, old);
407
0
  }
408
0
409
0
  return 0;
410
0
}
411
412
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
413
#if defined(__clang__)
414
#pragma clang diagnostic push
415
#pragma clang diagnostic ignored "-Wmissing-braces"
416
#endif
417
static const JSPropertySpec sAttributes_specs[] = {
418
  { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, nullptr, nullptr },
419
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
420
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
421
};
422
#if defined(__clang__)
423
#pragma clang diagnostic pop
424
#endif
425
426
// Can't be const because the pref-enabled boolean needs to be writable
427
static PrefableDisablers sAttributes_disablers0 = {
428
  true, true, 0, nullptr
429
};
430
431
static const Prefable<const JSPropertySpec> sAttributes[] = {
432
  { &sAttributes_disablers0, &sAttributes_specs[0] },
433
  { nullptr, nullptr }
434
};
435
436
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
437
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
438
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
439
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
440
441
442
static uint16_t sNativeProperties_sortedPropertyIndices[2];
443
static PropertyInfo sNativeProperties_propertyInfos[2];
444
445
static const NativePropertiesN<1> sNativeProperties = {
446
  false, 0,
447
  false, 0,
448
  false, 0,
449
  true,  0 /* sAttributes */,
450
  false, 0,
451
  false, 0,
452
  false, 0,
453
  -1,
454
  2,
455
  sNativeProperties_sortedPropertyIndices,
456
  {
457
    { sAttributes, &sNativeProperties_propertyInfos[0] }
458
  }
459
};
460
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
461
    "We have a property info count that is oversized");
462
463
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
464
  {
465
    "Function",
466
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
467
    &sBoringInterfaceObjectClassClassOps,
468
    JS_NULL_CLASS_SPEC,
469
    JS_NULL_CLASS_EXT,
470
    &sInterfaceObjectClassObjectOps
471
  },
472
  eInterface,
473
  true,
474
  prototypes::id::Credential,
475
  PrototypeTraits<prototypes::id::Credential>::Depth,
476
  sNativePropertyHooks,
477
  "function Credential() {\n    [native code]\n}",
478
  JS::GetRealmFunctionPrototype
479
};
480
481
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
482
  {
483
    "CredentialPrototype",
484
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
485
    JS_NULL_CLASS_OPS,
486
    JS_NULL_CLASS_SPEC,
487
    JS_NULL_CLASS_EXT,
488
    JS_NULL_OBJECT_OPS
489
  },
490
  eInterfacePrototype,
491
  false,
492
  prototypes::id::Credential,
493
  PrototypeTraits<prototypes::id::Credential>::Depth,
494
  sNativePropertyHooks,
495
  "[object CredentialPrototype]",
496
  JS::GetRealmObjectPrototype
497
};
498
499
bool
500
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
501
0
{
502
0
  static bool sPrefValue;
503
0
  static bool sPrefCacheSetUp = false;
504
0
  if (!sPrefCacheSetUp) {
505
0
    sPrefCacheSetUp = true;
506
0
    Preferences::AddBoolVarCache(&sPrefValue, "security.webauth.webauthn");
507
0
  }
508
0
509
0
  return sPrefValue &&
510
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
511
0
}
512
513
static const js::ClassOps sClassOps = {
514
  _addProperty, /* addProperty */
515
  nullptr,               /* delProperty */
516
  nullptr,               /* enumerate */
517
  nullptr, /* newEnumerate */
518
  nullptr, /* resolve */
519
  nullptr, /* mayResolve */
520
  _finalize, /* finalize */
521
  nullptr, /* call */
522
  nullptr,               /* hasInstance */
523
  nullptr,               /* construct */
524
  nullptr, /* trace */
525
};
526
527
static const js::ClassExtension sClassExtension = {
528
  nullptr, /* weakmapKeyDelegateOp */
529
  _objectMoved /* objectMovedOp */
530
};
531
532
static const DOMJSClass sClass = {
533
  { "Credential",
534
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
535
    &sClassOps,
536
    JS_NULL_CLASS_SPEC,
537
    &sClassExtension,
538
    JS_NULL_OBJECT_OPS
539
  },
540
  { prototypes::id::Credential, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
541
  IsBaseOf<nsISupports, mozilla::dom::Credential >::value,
542
  sNativePropertyHooks,
543
  FindAssociatedGlobalForNative<mozilla::dom::Credential>::Get,
544
  GetProtoObjectHandle,
545
  GetCCParticipant<mozilla::dom::Credential>::Get()
546
};
547
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
548
              "Must have the right minimal number of reserved slots.");
549
static_assert(1 >= 1,
550
              "Must have enough reserved slots.");
551
552
const JSClass*
553
GetJSClass()
554
0
{
555
0
  return sClass.ToJSClass();
556
0
}
557
558
bool
559
Wrap(JSContext* aCx, mozilla::dom::Credential* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
560
0
{
561
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Credential>::value,
562
0
                "Shouldn't have wrappercached things that are not refcounted.");
563
0
  MOZ_ASSERT(static_cast<mozilla::dom::Credential*>(aObject) ==
564
0
             reinterpret_cast<mozilla::dom::Credential*>(aObject),
565
0
             "Multiple inheritance for mozilla::dom::Credential is broken.");
566
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
567
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
568
0
  MOZ_ASSERT(!aCache->GetWrapper(),
569
0
             "You should probably not be using Wrap() directly; use "
570
0
             "GetOrCreateDOMReflector instead");
571
0
572
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
573
0
             "nsISupports must be on our primary inheritance chain");
574
0
575
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
576
0
  if (!global) {
577
0
    return false;
578
0
  }
579
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
580
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
581
0
582
0
  // That might have ended up wrapping us already, due to the wonders
583
0
  // of XBL.  Check for that, and bail out as needed.
584
0
  aReflector.set(aCache->GetWrapper());
585
0
  if (aReflector) {
586
#ifdef DEBUG
587
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
588
#endif // DEBUG
589
    return true;
590
0
  }
591
0
592
0
  JSAutoRealm ar(aCx, global);
593
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
594
0
  if (!canonicalProto) {
595
0
    return false;
596
0
  }
597
0
  JS::Rooted<JSObject*> proto(aCx);
598
0
  if (aGivenProto) {
599
0
    proto = aGivenProto;
600
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
601
0
    // coming in, we changed compartments to that of "parent" so may need
602
0
    // to wrap the proto here.
603
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
604
0
      if (!JS_WrapObject(aCx, &proto)) {
605
0
        return false;
606
0
      }
607
0
    }
608
0
  } else {
609
0
    proto = canonicalProto;
610
0
  }
611
0
612
0
  BindingJSObjectCreator<mozilla::dom::Credential> creator(aCx);
613
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
614
0
  if (!aReflector) {
615
0
    return false;
616
0
  }
617
0
618
0
  aCache->SetWrapper(aReflector);
619
0
  creator.InitializationSucceeded();
620
0
621
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
622
0
             aCache->GetWrapperPreserveColor() == aReflector);
623
0
  // If proto != canonicalProto, we have to preserve our wrapper;
624
0
  // otherwise we won't be able to properly recreate it later, since
625
0
  // we won't know what proto to use.  Note that we don't check
626
0
  // aGivenProto here, since it's entirely possible (and even
627
0
  // somewhat common) to have a non-null aGivenProto which is the
628
0
  // same as canonicalProto.
629
0
  if (proto != canonicalProto) {
630
0
    PreserveWrapper(aObject);
631
0
  }
632
0
633
0
  return true;
634
0
}
635
636
const NativePropertyHooks sNativePropertyHooks[] = { {
637
  nullptr,
638
  nullptr,
639
  nullptr,
640
  { sNativeProperties.Upcast(), nullptr },
641
  prototypes::id::Credential,
642
  constructors::id::Credential,
643
  nullptr,
644
  &DefaultXrayExpandoObjectClass
645
} };
646
647
void
648
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
649
0
{
650
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
651
0
  if (!parentProto) {
652
0
    return;
653
0
  }
654
0
655
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
656
0
  if (!constructorProto) {
657
0
    return;
658
0
  }
659
0
660
0
  static bool sIdsInited = false;
661
0
  if (!sIdsInited && NS_IsMainThread()) {
662
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
663
0
      return;
664
0
    }
665
0
    sIdsInited = true;
666
0
  }
667
0
668
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Credential);
669
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Credential);
670
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
671
0
                              &sPrototypeClass.mBase, protoCache,
672
0
                              nullptr,
673
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
674
0
                              interfaceCache,
675
0
                              sNativeProperties.Upcast(),
676
0
                              nullptr,
677
0
                              "Credential", aDefineOnGlobal,
678
0
                              nullptr,
679
0
                              false);
680
0
}
681
682
JSObject*
683
GetProtoObject(JSContext* aCx)
684
0
{
685
0
  return GetProtoObjectHandle(aCx);
686
0
}
687
688
JSObject*
689
GetConstructorObject(JSContext* aCx)
690
0
{
691
0
  return GetConstructorObjectHandle(aCx);
692
0
}
693
694
} // namespace Credential_Binding
695
696
697
698
namespace CredentialsContainer_Binding {
699
700
MOZ_CAN_RUN_SCRIPT static bool
701
get(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
702
0
{
703
0
  AUTO_PROFILER_LABEL_FAST("CredentialsContainer.get", DOM, cx);
704
0
705
0
  RootedDictionary<binding_detail::FastCredentialRequestOptions> arg0(cx);
706
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of CredentialsContainer.get", false)) {
707
0
    return false;
708
0
  }
709
0
  FastErrorResult rv;
710
0
  auto result(StrongOrRawPtr<Promise>(self->Get(Constify(arg0), rv)));
711
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
712
0
    return false;
713
0
  }
714
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
715
0
  if (!ToJSValue(cx, result, args.rval())) {
716
0
    return false;
717
0
  }
718
0
  return true;
719
0
}
720
721
MOZ_CAN_RUN_SCRIPT static bool
722
get_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
723
0
{
724
0
  bool ok = get(cx, obj, self, args);
725
0
  if (ok) {
726
0
    return true;
727
0
  }
728
0
  return ConvertExceptionToPromise(cx, args.rval());
729
0
}
730
731
static const JSJitInfo get_methodinfo = {
732
  { (JSJitGetterOp)get_promiseWrapper },
733
  { prototypes::id::CredentialsContainer },
734
  { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
735
  JSJitInfo::Method,
736
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
737
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
738
  false,  /* isInfallible. False in setters. */
739
  false,  /* isMovable.  Not relevant for setters. */
740
  false, /* isEliminatable.  Not relevant for setters. */
741
  false, /* isAlwaysInSlot.  Only relevant for getters. */
742
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
743
  false,  /* isTypedMethod.  Only relevant for methods. */
744
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
745
};
746
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
747
static_assert(0 < 1, "There is no slot for us");
748
749
MOZ_CAN_RUN_SCRIPT static bool
750
create(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
751
0
{
752
0
  AUTO_PROFILER_LABEL_FAST("CredentialsContainer.create", DOM, cx);
753
0
754
0
  RootedDictionary<binding_detail::FastCredentialCreationOptions> arg0(cx);
755
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of CredentialsContainer.create", false)) {
756
0
    return false;
757
0
  }
758
0
  FastErrorResult rv;
759
0
  auto result(StrongOrRawPtr<Promise>(self->Create(Constify(arg0), rv)));
760
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
761
0
    return false;
762
0
  }
763
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
764
0
  if (!ToJSValue(cx, result, args.rval())) {
765
0
    return false;
766
0
  }
767
0
  return true;
768
0
}
769
770
MOZ_CAN_RUN_SCRIPT static bool
771
create_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
772
0
{
773
0
  bool ok = create(cx, obj, self, args);
774
0
  if (ok) {
775
0
    return true;
776
0
  }
777
0
  return ConvertExceptionToPromise(cx, args.rval());
778
0
}
779
780
static const JSJitInfo create_methodinfo = {
781
  { (JSJitGetterOp)create_promiseWrapper },
782
  { prototypes::id::CredentialsContainer },
783
  { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
784
  JSJitInfo::Method,
785
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
786
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
787
  false,  /* isInfallible. False in setters. */
788
  false,  /* isMovable.  Not relevant for setters. */
789
  false, /* isEliminatable.  Not relevant for setters. */
790
  false, /* isAlwaysInSlot.  Only relevant for getters. */
791
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
792
  false,  /* isTypedMethod.  Only relevant for methods. */
793
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
794
};
795
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
796
static_assert(0 < 1, "There is no slot for us");
797
798
MOZ_CAN_RUN_SCRIPT static bool
799
store(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
800
0
{
801
0
  AUTO_PROFILER_LABEL_FAST("CredentialsContainer.store", DOM, cx);
802
0
803
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
804
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CredentialsContainer.store");
805
0
  }
806
0
  NonNull<mozilla::dom::Credential> arg0;
807
0
  if (args[0].isObject()) {
808
0
    {
809
0
      nsresult rv = UnwrapObject<prototypes::id::Credential, mozilla::dom::Credential>(args[0], arg0);
810
0
      if (NS_FAILED(rv)) {
811
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of CredentialsContainer.store", "Credential");
812
0
        return false;
813
0
      }
814
0
    }
815
0
  } else {
816
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of CredentialsContainer.store");
817
0
    return false;
818
0
  }
819
0
  FastErrorResult rv;
820
0
  auto result(StrongOrRawPtr<Promise>(self->Store(MOZ_KnownLive(NonNullHelper(arg0)), rv)));
821
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
822
0
    return false;
823
0
  }
824
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
825
0
  if (!ToJSValue(cx, result, args.rval())) {
826
0
    return false;
827
0
  }
828
0
  return true;
829
0
}
830
831
MOZ_CAN_RUN_SCRIPT static bool
832
store_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
833
0
{
834
0
  bool ok = store(cx, obj, self, args);
835
0
  if (ok) {
836
0
    return true;
837
0
  }
838
0
  return ConvertExceptionToPromise(cx, args.rval());
839
0
}
840
841
static const JSJitInfo store_methodinfo = {
842
  { (JSJitGetterOp)store_promiseWrapper },
843
  { prototypes::id::CredentialsContainer },
844
  { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
845
  JSJitInfo::Method,
846
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
847
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
848
  false,  /* isInfallible. False in setters. */
849
  false,  /* isMovable.  Not relevant for setters. */
850
  false, /* isEliminatable.  Not relevant for setters. */
851
  false, /* isAlwaysInSlot.  Only relevant for getters. */
852
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
853
  false,  /* isTypedMethod.  Only relevant for methods. */
854
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
855
};
856
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
857
static_assert(0 < 1, "There is no slot for us");
858
859
MOZ_CAN_RUN_SCRIPT static bool
860
preventSilentAccess(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
861
0
{
862
0
  AUTO_PROFILER_LABEL_FAST("CredentialsContainer.preventSilentAccess", DOM, cx);
863
0
864
0
  FastErrorResult rv;
865
0
  auto result(StrongOrRawPtr<Promise>(self->PreventSilentAccess(rv)));
866
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
867
0
    return false;
868
0
  }
869
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
870
0
  if (!ToJSValue(cx, result, args.rval())) {
871
0
    return false;
872
0
  }
873
0
  return true;
874
0
}
875
876
MOZ_CAN_RUN_SCRIPT static bool
877
preventSilentAccess_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
878
0
{
879
0
  bool ok = preventSilentAccess(cx, obj, self, args);
880
0
  if (ok) {
881
0
    return true;
882
0
  }
883
0
  return ConvertExceptionToPromise(cx, args.rval());
884
0
}
885
886
static const JSJitInfo preventSilentAccess_methodinfo = {
887
  { (JSJitGetterOp)preventSilentAccess_promiseWrapper },
888
  { prototypes::id::CredentialsContainer },
889
  { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
890
  JSJitInfo::Method,
891
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
892
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
893
  false,  /* isInfallible. False in setters. */
894
  false,  /* isMovable.  Not relevant for setters. */
895
  false, /* isEliminatable.  Not relevant for setters. */
896
  false, /* isAlwaysInSlot.  Only relevant for getters. */
897
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
898
  false,  /* isTypedMethod.  Only relevant for methods. */
899
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
900
};
901
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
902
static_assert(0 < 1, "There is no slot for us");
903
904
static bool
905
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
906
0
{
907
0
  mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
908
0
  // We don't want to preserve if we don't have a wrapper, and we
909
0
  // obviously can't preserve if we're not initialized.
910
0
  if (self && self->GetWrapperPreserveColor()) {
911
0
    PreserveWrapper(self);
912
0
  }
913
0
  return true;
914
0
}
915
916
static void
917
_finalize(js::FreeOp* fop, JSObject* obj)
918
0
{
919
0
  mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
920
0
  if (self) {
921
0
    ClearWrapper(self, self, obj);
922
0
    AddForDeferredFinalization<mozilla::dom::CredentialsContainer>(self);
923
0
  }
924
0
}
925
926
static size_t
927
_objectMoved(JSObject* obj, JSObject* old)
928
0
{
929
0
  mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
930
0
  if (self) {
931
0
    UpdateWrapper(self, self, obj, old);
932
0
  }
933
0
934
0
  return 0;
935
0
}
936
937
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
938
#if defined(__clang__)
939
#pragma clang diagnostic push
940
#pragma clang diagnostic ignored "-Wmissing-braces"
941
#endif
942
static const JSFunctionSpec sMethods_specs[] = {
943
  JS_FNSPEC("get", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&get_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
944
  JS_FNSPEC("create", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&create_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
945
  JS_FNSPEC("store", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&store_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
946
  JS_FNSPEC("preventSilentAccess", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&preventSilentAccess_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
947
  JS_FS_END
948
};
949
#if defined(__clang__)
950
#pragma clang diagnostic pop
951
#endif
952
953
// Can't be const because the pref-enabled boolean needs to be writable
954
static PrefableDisablers sMethods_disablers0 = {
955
  true, true, 0, nullptr
956
};
957
958
static const Prefable<const JSFunctionSpec> sMethods[] = {
959
  { &sMethods_disablers0, &sMethods_specs[0] },
960
  { nullptr, nullptr }
961
};
962
963
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
964
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
965
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
966
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
967
968
969
static uint16_t sNativeProperties_sortedPropertyIndices[4];
970
static PropertyInfo sNativeProperties_propertyInfos[4];
971
972
static const NativePropertiesN<1> sNativeProperties = {
973
  false, 0,
974
  false, 0,
975
  true,  0 /* sMethods */,
976
  false, 0,
977
  false, 0,
978
  false, 0,
979
  false, 0,
980
  -1,
981
  4,
982
  sNativeProperties_sortedPropertyIndices,
983
  {
984
    { sMethods, &sNativeProperties_propertyInfos[0] }
985
  }
986
};
987
static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
988
    "We have a property info count that is oversized");
989
990
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
991
  {
992
    "Function",
993
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
994
    &sBoringInterfaceObjectClassClassOps,
995
    JS_NULL_CLASS_SPEC,
996
    JS_NULL_CLASS_EXT,
997
    &sInterfaceObjectClassObjectOps
998
  },
999
  eInterface,
1000
  true,
1001
  prototypes::id::CredentialsContainer,
1002
  PrototypeTraits<prototypes::id::CredentialsContainer>::Depth,
1003
  sNativePropertyHooks,
1004
  "function CredentialsContainer() {\n    [native code]\n}",
1005
  JS::GetRealmFunctionPrototype
1006
};
1007
1008
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1009
  {
1010
    "CredentialsContainerPrototype",
1011
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1012
    JS_NULL_CLASS_OPS,
1013
    JS_NULL_CLASS_SPEC,
1014
    JS_NULL_CLASS_EXT,
1015
    JS_NULL_OBJECT_OPS
1016
  },
1017
  eInterfacePrototype,
1018
  false,
1019
  prototypes::id::CredentialsContainer,
1020
  PrototypeTraits<prototypes::id::CredentialsContainer>::Depth,
1021
  sNativePropertyHooks,
1022
  "[object CredentialsContainerPrototype]",
1023
  JS::GetRealmObjectPrototype
1024
};
1025
1026
bool
1027
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1028
0
{
1029
0
  static bool sPrefValue;
1030
0
  static bool sPrefCacheSetUp = false;
1031
0
  if (!sPrefCacheSetUp) {
1032
0
    sPrefCacheSetUp = true;
1033
0
    Preferences::AddBoolVarCache(&sPrefValue, "security.webauth.webauthn");
1034
0
  }
1035
0
1036
0
  return sPrefValue &&
1037
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
1038
0
}
1039
1040
static const js::ClassOps sClassOps = {
1041
  _addProperty, /* addProperty */
1042
  nullptr,               /* delProperty */
1043
  nullptr,               /* enumerate */
1044
  nullptr, /* newEnumerate */
1045
  nullptr, /* resolve */
1046
  nullptr, /* mayResolve */
1047
  _finalize, /* finalize */
1048
  nullptr, /* call */
1049
  nullptr,               /* hasInstance */
1050
  nullptr,               /* construct */
1051
  nullptr, /* trace */
1052
};
1053
1054
static const js::ClassExtension sClassExtension = {
1055
  nullptr, /* weakmapKeyDelegateOp */
1056
  _objectMoved /* objectMovedOp */
1057
};
1058
1059
static const DOMJSClass sClass = {
1060
  { "CredentialsContainer",
1061
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1062
    &sClassOps,
1063
    JS_NULL_CLASS_SPEC,
1064
    &sClassExtension,
1065
    JS_NULL_OBJECT_OPS
1066
  },
1067
  { prototypes::id::CredentialsContainer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1068
  IsBaseOf<nsISupports, mozilla::dom::CredentialsContainer >::value,
1069
  sNativePropertyHooks,
1070
  FindAssociatedGlobalForNative<mozilla::dom::CredentialsContainer>::Get,
1071
  GetProtoObjectHandle,
1072
  GetCCParticipant<mozilla::dom::CredentialsContainer>::Get()
1073
};
1074
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1075
              "Must have the right minimal number of reserved slots.");
1076
static_assert(1 >= 1,
1077
              "Must have enough reserved slots.");
1078
1079
const JSClass*
1080
GetJSClass()
1081
0
{
1082
0
  return sClass.ToJSClass();
1083
0
}
1084
1085
bool
1086
Wrap(JSContext* aCx, mozilla::dom::CredentialsContainer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1087
0
{
1088
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::CredentialsContainer>::value,
1089
0
                "Shouldn't have wrappercached things that are not refcounted.");
1090
0
  MOZ_ASSERT(static_cast<mozilla::dom::CredentialsContainer*>(aObject) ==
1091
0
             reinterpret_cast<mozilla::dom::CredentialsContainer*>(aObject),
1092
0
             "Multiple inheritance for mozilla::dom::CredentialsContainer is broken.");
1093
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1094
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1095
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1096
0
             "You should probably not be using Wrap() directly; use "
1097
0
             "GetOrCreateDOMReflector instead");
1098
0
1099
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1100
0
             "nsISupports must be on our primary inheritance chain");
1101
0
1102
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1103
0
  if (!global) {
1104
0
    return false;
1105
0
  }
1106
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1107
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1108
0
1109
0
  // That might have ended up wrapping us already, due to the wonders
1110
0
  // of XBL.  Check for that, and bail out as needed.
1111
0
  aReflector.set(aCache->GetWrapper());
1112
0
  if (aReflector) {
1113
#ifdef DEBUG
1114
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1115
#endif // DEBUG
1116
    return true;
1117
0
  }
1118
0
1119
0
  JSAutoRealm ar(aCx, global);
1120
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1121
0
  if (!canonicalProto) {
1122
0
    return false;
1123
0
  }
1124
0
  JS::Rooted<JSObject*> proto(aCx);
1125
0
  if (aGivenProto) {
1126
0
    proto = aGivenProto;
1127
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1128
0
    // coming in, we changed compartments to that of "parent" so may need
1129
0
    // to wrap the proto here.
1130
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1131
0
      if (!JS_WrapObject(aCx, &proto)) {
1132
0
        return false;
1133
0
      }
1134
0
    }
1135
0
  } else {
1136
0
    proto = canonicalProto;
1137
0
  }
1138
0
1139
0
  BindingJSObjectCreator<mozilla::dom::CredentialsContainer> creator(aCx);
1140
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1141
0
  if (!aReflector) {
1142
0
    return false;
1143
0
  }
1144
0
1145
0
  aCache->SetWrapper(aReflector);
1146
0
  creator.InitializationSucceeded();
1147
0
1148
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1149
0
             aCache->GetWrapperPreserveColor() == aReflector);
1150
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1151
0
  // otherwise we won't be able to properly recreate it later, since
1152
0
  // we won't know what proto to use.  Note that we don't check
1153
0
  // aGivenProto here, since it's entirely possible (and even
1154
0
  // somewhat common) to have a non-null aGivenProto which is the
1155
0
  // same as canonicalProto.
1156
0
  if (proto != canonicalProto) {
1157
0
    PreserveWrapper(aObject);
1158
0
  }
1159
0
1160
0
  return true;
1161
0
}
1162
1163
const NativePropertyHooks sNativePropertyHooks[] = { {
1164
  nullptr,
1165
  nullptr,
1166
  nullptr,
1167
  { sNativeProperties.Upcast(), nullptr },
1168
  prototypes::id::CredentialsContainer,
1169
  constructors::id::CredentialsContainer,
1170
  nullptr,
1171
  &DefaultXrayExpandoObjectClass
1172
} };
1173
1174
void
1175
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1176
0
{
1177
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1178
0
  if (!parentProto) {
1179
0
    return;
1180
0
  }
1181
0
1182
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1183
0
  if (!constructorProto) {
1184
0
    return;
1185
0
  }
1186
0
1187
0
  static bool sIdsInited = false;
1188
0
  if (!sIdsInited && NS_IsMainThread()) {
1189
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1190
0
      return;
1191
0
    }
1192
0
    sIdsInited = true;
1193
0
  }
1194
0
1195
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CredentialsContainer);
1196
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CredentialsContainer);
1197
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1198
0
                              &sPrototypeClass.mBase, protoCache,
1199
0
                              nullptr,
1200
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1201
0
                              interfaceCache,
1202
0
                              sNativeProperties.Upcast(),
1203
0
                              nullptr,
1204
0
                              "CredentialsContainer", aDefineOnGlobal,
1205
0
                              nullptr,
1206
0
                              false);
1207
0
}
1208
1209
JSObject*
1210
GetConstructorObject(JSContext* aCx)
1211
0
{
1212
0
  return GetConstructorObjectHandle(aCx);
1213
0
}
1214
1215
} // namespace CredentialsContainer_Binding
1216
1217
1218
1219
} // namespace dom
1220
} // namespace mozilla