Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ClientsBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Clients.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "ClientsBinding.h"
5
#include "WrapperFactory.h"
6
#include "jsapi.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/Clients.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/Promise.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/SimpleGlobalObject.h"
16
#include "mozilla/dom/ToJSValue.h"
17
#include "nsThreadUtils.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace ClientTypeValues {
27
extern const EnumEntry strings[6] = {
28
  {"window", 6},
29
  {"worker", 6},
30
  {"sharedworker", 12},
31
  {"serviceworker", 13},
32
  {"all", 3},
33
  { nullptr, 0 }
34
};
35
} // namespace ClientTypeValues
36
37
bool
38
ToJSValue(JSContext* aCx, ClientType aArgument, JS::MutableHandle<JS::Value> aValue)
39
0
{
40
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ClientTypeValues::strings));
41
0
  JSString* resultStr =
42
0
    JS_NewStringCopyN(aCx, ClientTypeValues::strings[uint32_t(aArgument)].value,
43
0
                      ClientTypeValues::strings[uint32_t(aArgument)].length);
44
0
  if (!resultStr) {
45
0
    return false;
46
0
  }
47
0
  aValue.setString(resultStr);
48
0
  return true;
49
0
}
50
51
52
53
ClientQueryOptions::ClientQueryOptions()
54
0
{
55
0
  // Safe to pass a null context if we pass a null value
56
0
  Init(nullptr, JS::NullHandleValue);
57
0
}
58
59
60
61
bool
62
ClientQueryOptions::InitIds(JSContext* cx, ClientQueryOptionsAtoms* atomsCache)
63
0
{
64
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
65
0
66
0
  // Initialize these in reverse order so that any failure leaves the first one
67
0
  // uninitialized.
68
0
  if (!atomsCache->type_id.init(cx, "type") ||
69
0
      !atomsCache->includeUncontrolled_id.init(cx, "includeUncontrolled")) {
70
0
    return false;
71
0
  }
72
0
  return true;
73
0
}
74
75
bool
76
ClientQueryOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
77
0
{
78
0
  // Passing a null JSContext is OK only if we're initing from null,
79
0
  // Since in that case we will not have to do any property gets
80
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
81
0
  // checkers by static analysis tools
82
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
83
0
  ClientQueryOptionsAtoms* atomsCache = nullptr;
84
0
  if (cx) {
85
0
    atomsCache = GetAtomCache<ClientQueryOptionsAtoms>(cx);
86
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
87
0
      return false;
88
0
    }
89
0
  }
90
0
91
0
  if (!IsConvertibleToDictionary(val)) {
92
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
93
0
  }
94
0
95
0
  bool isNull = val.isNullOrUndefined();
96
0
  // We only need these if !isNull, in which case we have |cx|.
97
0
  Maybe<JS::Rooted<JSObject *> > object;
98
0
  Maybe<JS::Rooted<JS::Value> > temp;
99
0
  if (!isNull) {
100
0
    MOZ_ASSERT(cx);
101
0
    object.emplace(cx, &val.toObject());
102
0
    temp.emplace(cx);
103
0
  }
104
0
  if (!isNull) {
105
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->includeUncontrolled_id, temp.ptr())) {
106
0
      return false;
107
0
    }
108
0
  }
109
0
  if (!isNull && !temp->isUndefined()) {
110
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIncludeUncontrolled)) {
111
0
      return false;
112
0
    }
113
0
  } else {
114
0
    mIncludeUncontrolled = false;
115
0
  }
116
0
  mIsAnyMemberPresent = true;
117
0
118
0
  if (!isNull) {
119
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
120
0
      return false;
121
0
    }
122
0
  }
123
0
  if (!isNull && !temp->isUndefined()) {
124
0
    {
125
0
      int index;
126
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), ClientTypeValues::strings, "ClientType", "'type' member of ClientQueryOptions", &index)) {
127
0
        return false;
128
0
      }
129
0
      MOZ_ASSERT(index >= 0);
130
0
      mType = static_cast<ClientType>(index);
131
0
    }
132
0
  } else {
133
0
    mType = ClientType::Window;
134
0
  }
135
0
  mIsAnyMemberPresent = true;
136
0
  return true;
137
0
}
138
139
bool
140
ClientQueryOptions::Init(const nsAString& aJSON)
141
0
{
142
0
  AutoJSAPI jsapi;
143
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
144
0
  if (!cleanGlobal) {
145
0
    return false;
146
0
  }
147
0
  if (!jsapi.Init(cleanGlobal)) {
148
0
    return false;
149
0
  }
150
0
  JSContext* cx = jsapi.cx();
151
0
  JS::Rooted<JS::Value> json(cx);
152
0
  bool ok = ParseJSON(cx, aJSON, &json);
153
0
  NS_ENSURE_TRUE(ok, false);
154
0
  return Init(cx, json);
155
0
}
156
157
bool
158
ClientQueryOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
159
0
{
160
0
  ClientQueryOptionsAtoms* atomsCache = GetAtomCache<ClientQueryOptionsAtoms>(cx);
161
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
162
0
    return false;
163
0
  }
164
0
165
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
166
0
  if (!obj) {
167
0
    return false;
168
0
  }
169
0
  rval.set(JS::ObjectValue(*obj));
170
0
171
0
  do {
172
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
173
0
    JS::Rooted<JS::Value> temp(cx);
174
0
    bool const & currentValue = mIncludeUncontrolled;
175
0
    temp.setBoolean(currentValue);
176
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->includeUncontrolled_id, temp, JSPROP_ENUMERATE)) {
177
0
      return false;
178
0
    }
179
0
    break;
180
0
  } while(false);
181
0
182
0
  do {
183
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
184
0
    JS::Rooted<JS::Value> temp(cx);
185
0
    ClientType const & currentValue = mType;
186
0
    if (!ToJSValue(cx, currentValue, &temp)) {
187
0
      return false;
188
0
    }
189
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
190
0
      return false;
191
0
    }
192
0
    break;
193
0
  } while(false);
194
0
195
0
  return true;
196
0
}
197
198
bool
199
ClientQueryOptions::ToJSON(nsAString& aJSON) const
200
0
{
201
0
  AutoJSAPI jsapi;
202
0
  jsapi.Init();
203
0
  JSContext *cx = jsapi.cx();
204
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
205
0
  // because we'll only be creating objects, in ways that have no
206
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
207
0
  // which likewise guarantees no side-effects for the sorts of
208
0
  // things we will pass it.
209
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
210
0
  JS::Rooted<JS::Value> val(cx);
211
0
  if (!ToObjectInternal(cx, &val)) {
212
0
    return false;
213
0
  }
214
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
215
0
  return StringifyToJSON(cx, obj, aJSON);
216
0
}
217
218
void
219
ClientQueryOptions::TraceDictionary(JSTracer* trc)
220
0
{
221
0
}
222
223
ClientQueryOptions&
224
ClientQueryOptions::operator=(const ClientQueryOptions& aOther)
225
0
{
226
0
  DictionaryBase::operator=(aOther);
227
0
  mIncludeUncontrolled = aOther.mIncludeUncontrolled;
228
0
  mType = aOther.mType;
229
0
  return *this;
230
0
}
231
232
namespace binding_detail {
233
} // namespace binding_detail
234
235
236
namespace Clients_Binding {
237
238
MOZ_CAN_RUN_SCRIPT static bool
239
get(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
240
0
{
241
0
  AUTO_PROFILER_LABEL_FAST("Clients.get", DOM, cx);
242
0
243
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
244
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Clients.get");
245
0
  }
246
0
  binding_detail::FakeString arg0;
247
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
248
0
    return false;
249
0
  }
250
0
  FastErrorResult rv;
251
0
  auto result(StrongOrRawPtr<Promise>(self->Get(NonNullHelper(Constify(arg0)), rv)));
252
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
253
0
    return false;
254
0
  }
255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
256
0
  static_assert(!IsPointer<decltype(result)>::value,
257
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
258
0
  if (!ToJSValue(cx, result, args.rval())) {
259
0
    return false;
260
0
  }
261
0
  return true;
262
0
}
263
264
MOZ_CAN_RUN_SCRIPT static bool
265
get_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
266
0
{
267
0
  bool ok = get(cx, obj, self, args);
268
0
  if (ok) {
269
0
    return true;
270
0
  }
271
0
  return ConvertExceptionToPromise(cx, args.rval());
272
0
}
273
274
static const JSJitInfo get_methodinfo = {
275
  { (JSJitGetterOp)get_promiseWrapper },
276
  { prototypes::id::Clients },
277
  { PrototypeTraits<prototypes::id::Clients>::Depth },
278
  JSJitInfo::Method,
279
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
280
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
281
  false,  /* isInfallible. False in setters. */
282
  false,  /* isMovable.  Not relevant for setters. */
283
  false, /* isEliminatable.  Not relevant for setters. */
284
  false, /* isAlwaysInSlot.  Only relevant for getters. */
285
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
286
  false,  /* isTypedMethod.  Only relevant for methods. */
287
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
288
};
289
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
290
static_assert(0 < 1, "There is no slot for us");
291
292
MOZ_CAN_RUN_SCRIPT static bool
293
matchAll(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
294
0
{
295
0
  AUTO_PROFILER_LABEL_FAST("Clients.matchAll", DOM, cx);
296
0
297
0
  binding_detail::FastClientQueryOptions arg0;
298
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of Clients.matchAll", false)) {
299
0
    return false;
300
0
  }
301
0
  FastErrorResult rv;
302
0
  auto result(StrongOrRawPtr<Promise>(self->MatchAll(Constify(arg0), rv)));
303
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
304
0
    return false;
305
0
  }
306
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
307
0
  static_assert(!IsPointer<decltype(result)>::value,
308
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
309
0
  if (!ToJSValue(cx, result, args.rval())) {
310
0
    return false;
311
0
  }
312
0
  return true;
313
0
}
314
315
MOZ_CAN_RUN_SCRIPT static bool
316
matchAll_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
317
0
{
318
0
  bool ok = matchAll(cx, obj, self, args);
319
0
  if (ok) {
320
0
    return true;
321
0
  }
322
0
  return ConvertExceptionToPromise(cx, args.rval());
323
0
}
324
325
static const JSJitInfo matchAll_methodinfo = {
326
  { (JSJitGetterOp)matchAll_promiseWrapper },
327
  { prototypes::id::Clients },
328
  { PrototypeTraits<prototypes::id::Clients>::Depth },
329
  JSJitInfo::Method,
330
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
331
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
332
  false,  /* isInfallible. False in setters. */
333
  false,  /* isMovable.  Not relevant for setters. */
334
  false, /* isEliminatable.  Not relevant for setters. */
335
  false, /* isAlwaysInSlot.  Only relevant for getters. */
336
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
337
  false,  /* isTypedMethod.  Only relevant for methods. */
338
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
339
};
340
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
341
static_assert(0 < 1, "There is no slot for us");
342
343
MOZ_CAN_RUN_SCRIPT static bool
344
openWindow(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
345
0
{
346
0
  AUTO_PROFILER_LABEL_FAST("Clients.openWindow", DOM, cx);
347
0
348
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
349
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Clients.openWindow");
350
0
  }
351
0
  binding_detail::FakeString arg0;
352
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
353
0
    return false;
354
0
  }
355
0
  NormalizeUSVString(arg0);
356
0
  FastErrorResult rv;
357
0
  auto result(StrongOrRawPtr<Promise>(self->OpenWindow(Constify(arg0), rv)));
358
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
359
0
    return false;
360
0
  }
361
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
362
0
  static_assert(!IsPointer<decltype(result)>::value,
363
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
364
0
  if (!ToJSValue(cx, result, args.rval())) {
365
0
    return false;
366
0
  }
367
0
  return true;
368
0
}
369
370
MOZ_CAN_RUN_SCRIPT static bool
371
openWindow_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
372
0
{
373
0
  bool ok = openWindow(cx, obj, self, args);
374
0
  if (ok) {
375
0
    return true;
376
0
  }
377
0
  return ConvertExceptionToPromise(cx, args.rval());
378
0
}
379
380
static const JSJitInfo openWindow_methodinfo = {
381
  { (JSJitGetterOp)openWindow_promiseWrapper },
382
  { prototypes::id::Clients },
383
  { PrototypeTraits<prototypes::id::Clients>::Depth },
384
  JSJitInfo::Method,
385
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
386
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
387
  false,  /* isInfallible. False in setters. */
388
  false,  /* isMovable.  Not relevant for setters. */
389
  false, /* isEliminatable.  Not relevant for setters. */
390
  false, /* isAlwaysInSlot.  Only relevant for getters. */
391
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
392
  false,  /* isTypedMethod.  Only relevant for methods. */
393
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
394
};
395
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
396
static_assert(0 < 1, "There is no slot for us");
397
398
MOZ_CAN_RUN_SCRIPT static bool
399
claim(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
400
0
{
401
0
  AUTO_PROFILER_LABEL_FAST("Clients.claim", DOM, cx);
402
0
403
0
  FastErrorResult rv;
404
0
  auto result(StrongOrRawPtr<Promise>(self->Claim(rv)));
405
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
406
0
    return false;
407
0
  }
408
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
409
0
  static_assert(!IsPointer<decltype(result)>::value,
410
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
411
0
  if (!ToJSValue(cx, result, args.rval())) {
412
0
    return false;
413
0
  }
414
0
  return true;
415
0
}
416
417
MOZ_CAN_RUN_SCRIPT static bool
418
claim_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Clients* self, const JSJitMethodCallArgs& args)
419
0
{
420
0
  bool ok = claim(cx, obj, self, args);
421
0
  if (ok) {
422
0
    return true;
423
0
  }
424
0
  return ConvertExceptionToPromise(cx, args.rval());
425
0
}
426
427
static const JSJitInfo claim_methodinfo = {
428
  { (JSJitGetterOp)claim_promiseWrapper },
429
  { prototypes::id::Clients },
430
  { PrototypeTraits<prototypes::id::Clients>::Depth },
431
  JSJitInfo::Method,
432
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
433
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
434
  false,  /* isInfallible. False in setters. */
435
  false,  /* isMovable.  Not relevant for setters. */
436
  false, /* isEliminatable.  Not relevant for setters. */
437
  false, /* isAlwaysInSlot.  Only relevant for getters. */
438
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
439
  false,  /* isTypedMethod.  Only relevant for methods. */
440
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
441
};
442
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
443
static_assert(0 < 1, "There is no slot for us");
444
445
static bool
446
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
447
0
{
448
0
  mozilla::dom::Clients* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Clients>(obj);
449
0
  // We don't want to preserve if we don't have a wrapper, and we
450
0
  // obviously can't preserve if we're not initialized.
451
0
  if (self && self->GetWrapperPreserveColor()) {
452
0
    PreserveWrapper(self);
453
0
  }
454
0
  return true;
455
0
}
456
457
static void
458
_finalize(js::FreeOp* fop, JSObject* obj)
459
0
{
460
0
  mozilla::dom::Clients* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Clients>(obj);
461
0
  if (self) {
462
0
    ClearWrapper(self, self, obj);
463
0
    AddForDeferredFinalization<mozilla::dom::Clients>(self);
464
0
  }
465
0
}
466
467
static size_t
468
_objectMoved(JSObject* obj, JSObject* old)
469
0
{
470
0
  mozilla::dom::Clients* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Clients>(obj);
471
0
  if (self) {
472
0
    UpdateWrapper(self, self, obj, old);
473
0
  }
474
0
475
0
  return 0;
476
0
}
477
478
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
479
#if defined(__clang__)
480
#pragma clang diagnostic push
481
#pragma clang diagnostic ignored "-Wmissing-braces"
482
#endif
483
static const JSFunctionSpec sMethods_specs[] = {
484
  JS_FNSPEC("get", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&get_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
485
  JS_FNSPEC("matchAll", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&matchAll_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
486
  JS_FNSPEC("openWindow", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&openWindow_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
487
  JS_FNSPEC("claim", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&claim_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
488
  JS_FS_END
489
};
490
#if defined(__clang__)
491
#pragma clang diagnostic pop
492
#endif
493
494
495
static const Prefable<const JSFunctionSpec> sMethods[] = {
496
  { nullptr, &sMethods_specs[0] },
497
  { nullptr, nullptr }
498
};
499
500
501
static const NativePropertiesN<1> sNativeProperties = {
502
  false, 0,
503
  false, 0,
504
  true,  0 /* sMethods */,
505
  false, 0,
506
  false, 0,
507
  false, 0,
508
  false, 0,
509
  -1,
510
  0,
511
  nullptr,
512
  {
513
    { sMethods, nullptr }
514
  }
515
};
516
517
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
518
  {
519
    "Function",
520
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
521
    &sBoringInterfaceObjectClassClassOps,
522
    JS_NULL_CLASS_SPEC,
523
    JS_NULL_CLASS_EXT,
524
    &sInterfaceObjectClassObjectOps
525
  },
526
  eInterface,
527
  true,
528
  prototypes::id::Clients,
529
  PrototypeTraits<prototypes::id::Clients>::Depth,
530
  &sEmptyNativePropertyHooks,
531
  "function Clients() {\n    [native code]\n}",
532
  JS::GetRealmFunctionPrototype
533
};
534
535
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
536
  {
537
    "ClientsPrototype",
538
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
539
    JS_NULL_CLASS_OPS,
540
    JS_NULL_CLASS_SPEC,
541
    JS_NULL_CLASS_EXT,
542
    JS_NULL_OBJECT_OPS
543
  },
544
  eInterfacePrototype,
545
  false,
546
  prototypes::id::Clients,
547
  PrototypeTraits<prototypes::id::Clients>::Depth,
548
  &sEmptyNativePropertyHooks,
549
  "[object ClientsPrototype]",
550
  JS::GetRealmObjectPrototype
551
};
552
553
bool
554
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
555
0
{
556
0
  MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?");
557
0
558
0
  const char* name = js::GetObjectClass(aObj)->name;
559
0
  if (strcmp(name, "ServiceWorkerGlobalScope")) {
560
0
    return false;
561
0
  }
562
0
563
0
  return true;
564
0
}
565
566
static const js::ClassOps sClassOps = {
567
  _addProperty, /* addProperty */
568
  nullptr,               /* delProperty */
569
  nullptr,               /* enumerate */
570
  nullptr, /* newEnumerate */
571
  nullptr, /* resolve */
572
  nullptr, /* mayResolve */
573
  _finalize, /* finalize */
574
  nullptr, /* call */
575
  nullptr,               /* hasInstance */
576
  nullptr,               /* construct */
577
  nullptr, /* trace */
578
};
579
580
static const js::ClassExtension sClassExtension = {
581
  nullptr, /* weakmapKeyDelegateOp */
582
  _objectMoved /* objectMovedOp */
583
};
584
585
static const DOMJSClass sClass = {
586
  { "Clients",
587
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
588
    &sClassOps,
589
    JS_NULL_CLASS_SPEC,
590
    &sClassExtension,
591
    JS_NULL_OBJECT_OPS
592
  },
593
  { prototypes::id::Clients, 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 },
594
  IsBaseOf<nsISupports, mozilla::dom::Clients >::value,
595
  &sEmptyNativePropertyHooks,
596
  FindAssociatedGlobalForNative<mozilla::dom::Clients>::Get,
597
  GetProtoObjectHandle,
598
  GetCCParticipant<mozilla::dom::Clients>::Get()
599
};
600
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
601
              "Must have the right minimal number of reserved slots.");
602
static_assert(1 >= 1,
603
              "Must have enough reserved slots.");
604
605
const JSClass*
606
GetJSClass()
607
0
{
608
0
  return sClass.ToJSClass();
609
0
}
610
611
bool
612
Wrap(JSContext* aCx, mozilla::dom::Clients* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
613
0
{
614
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Clients>::value,
615
0
                "Shouldn't have wrappercached things that are not refcounted.");
616
0
  MOZ_ASSERT(static_cast<mozilla::dom::Clients*>(aObject) ==
617
0
             reinterpret_cast<mozilla::dom::Clients*>(aObject),
618
0
             "Multiple inheritance for mozilla::dom::Clients is broken.");
619
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
620
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
621
0
  MOZ_ASSERT(!aCache->GetWrapper(),
622
0
             "You should probably not be using Wrap() directly; use "
623
0
             "GetOrCreateDOMReflector instead");
624
0
625
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
626
0
             "nsISupports must be on our primary inheritance chain");
627
0
628
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
629
0
  if (!global) {
630
0
    return false;
631
0
  }
632
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
633
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
634
0
635
0
  // That might have ended up wrapping us already, due to the wonders
636
0
  // of XBL.  Check for that, and bail out as needed.
637
0
  aReflector.set(aCache->GetWrapper());
638
0
  if (aReflector) {
639
#ifdef DEBUG
640
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
641
#endif // DEBUG
642
    return true;
643
0
  }
644
0
645
0
  JSAutoRealm ar(aCx, global);
646
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
647
0
  if (!canonicalProto) {
648
0
    return false;
649
0
  }
650
0
  JS::Rooted<JSObject*> proto(aCx);
651
0
  if (aGivenProto) {
652
0
    proto = aGivenProto;
653
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
654
0
    // coming in, we changed compartments to that of "parent" so may need
655
0
    // to wrap the proto here.
656
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
657
0
      if (!JS_WrapObject(aCx, &proto)) {
658
0
        return false;
659
0
      }
660
0
    }
661
0
  } else {
662
0
    proto = canonicalProto;
663
0
  }
664
0
665
0
  BindingJSObjectCreator<mozilla::dom::Clients> creator(aCx);
666
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
667
0
  if (!aReflector) {
668
0
    return false;
669
0
  }
670
0
671
0
  aCache->SetWrapper(aReflector);
672
0
  creator.InitializationSucceeded();
673
0
674
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
675
0
             aCache->GetWrapperPreserveColor() == aReflector);
676
0
  // If proto != canonicalProto, we have to preserve our wrapper;
677
0
  // otherwise we won't be able to properly recreate it later, since
678
0
  // we won't know what proto to use.  Note that we don't check
679
0
  // aGivenProto here, since it's entirely possible (and even
680
0
  // somewhat common) to have a non-null aGivenProto which is the
681
0
  // same as canonicalProto.
682
0
  if (proto != canonicalProto) {
683
0
    PreserveWrapper(aObject);
684
0
  }
685
0
686
0
  return true;
687
0
}
688
689
void
690
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
691
0
{
692
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
693
0
  if (!parentProto) {
694
0
    return;
695
0
  }
696
0
697
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
698
0
  if (!constructorProto) {
699
0
    return;
700
0
  }
701
0
702
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Clients);
703
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Clients);
704
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
705
0
                              &sPrototypeClass.mBase, protoCache,
706
0
                              nullptr,
707
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
708
0
                              interfaceCache,
709
0
                              sNativeProperties.Upcast(),
710
0
                              nullptr,
711
0
                              "Clients", aDefineOnGlobal,
712
0
                              nullptr,
713
0
                              false);
714
0
}
715
716
JSObject*
717
GetConstructorObject(JSContext* aCx)
718
0
{
719
0
  return GetConstructorObjectHandle(aCx);
720
0
}
721
722
} // namespace Clients_Binding
723
724
725
726
} // namespace dom
727
} // namespace mozilla