Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ServiceWorkerBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ServiceWorker.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventHandlerBinding.h"
4
#include "EventTargetBinding.h"
5
#include "ServiceWorkerBinding.h"
6
#include "WrapperFactory.h"
7
#include "jsapi.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/Nullable.h"
13
#include "mozilla/dom/ServiceWorker.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
namespace ServiceWorkerStateValues {
24
extern const EnumEntry strings[7] = {
25
  {"parsed", 6},
26
  {"installing", 10},
27
  {"installed", 9},
28
  {"activating", 10},
29
  {"activated", 9},
30
  {"redundant", 9},
31
  { nullptr, 0 }
32
};
33
} // namespace ServiceWorkerStateValues
34
35
bool
36
ToJSValue(JSContext* aCx, ServiceWorkerState aArgument, JS::MutableHandle<JS::Value> aValue)
37
0
{
38
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ServiceWorkerStateValues::strings));
39
0
  JSString* resultStr =
40
0
    JS_NewStringCopyN(aCx, ServiceWorkerStateValues::strings[uint32_t(aArgument)].value,
41
0
                      ServiceWorkerStateValues::strings[uint32_t(aArgument)].length);
42
0
  if (!resultStr) {
43
0
    return false;
44
0
  }
45
0
  aValue.setString(resultStr);
46
0
  return true;
47
0
}
48
49
50
namespace ServiceWorker_Binding {
51
52
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
53
              "Can't inherit from an interface with a different ownership model.");
54
55
MOZ_CAN_RUN_SCRIPT static bool
56
get_scriptURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitGetterCallArgs args)
57
0
{
58
0
  AUTO_PROFILER_LABEL_FAST("get ServiceWorker.scriptURL", DOM, cx);
59
0
60
0
  DOMString result;
61
0
  self->GetScriptURL(result);
62
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
63
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
64
0
    return false;
65
0
  }
66
0
  return true;
67
0
}
68
69
static const JSJitInfo scriptURL_getterinfo = {
70
  { (JSJitGetterOp)get_scriptURL },
71
  { prototypes::id::ServiceWorker },
72
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
73
  JSJitInfo::Getter,
74
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
75
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
76
  false,  /* isInfallible. False in setters. */
77
  false,  /* isMovable.  Not relevant for setters. */
78
  false, /* isEliminatable.  Not relevant for setters. */
79
  false, /* isAlwaysInSlot.  Only relevant for getters. */
80
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
81
  false,  /* isTypedMethod.  Only relevant for methods. */
82
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
83
};
84
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
85
static_assert(0 < 1, "There is no slot for us");
86
87
MOZ_CAN_RUN_SCRIPT static bool
88
get_state(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitGetterCallArgs args)
89
0
{
90
0
  AUTO_PROFILER_LABEL_FAST("get ServiceWorker.state", DOM, cx);
91
0
92
0
  ServiceWorkerState result(self->State());
93
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
94
0
  if (!ToJSValue(cx, result, args.rval())) {
95
0
    return false;
96
0
  }
97
0
  return true;
98
0
}
99
100
static const JSJitInfo state_getterinfo = {
101
  { (JSJitGetterOp)get_state },
102
  { prototypes::id::ServiceWorker },
103
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
104
  JSJitInfo::Getter,
105
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
106
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
107
  false,  /* isInfallible. False in setters. */
108
  false,  /* isMovable.  Not relevant for setters. */
109
  false, /* isEliminatable.  Not relevant for setters. */
110
  false, /* isAlwaysInSlot.  Only relevant for getters. */
111
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
112
  false,  /* isTypedMethod.  Only relevant for methods. */
113
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
114
};
115
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
116
static_assert(0 < 1, "There is no slot for us");
117
118
MOZ_CAN_RUN_SCRIPT static bool
119
get_onstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitGetterCallArgs args)
120
0
{
121
0
  AUTO_PROFILER_LABEL_FAST("get ServiceWorker.onstatechange", DOM, cx);
122
0
123
0
  RefPtr<EventHandlerNonNull> result(self->GetOnstatechange());
124
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
125
0
  if (result) {
126
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
127
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
128
0
      return false;
129
0
    }
130
0
    return true;
131
0
  } else {
132
0
    args.rval().setNull();
133
0
    return true;
134
0
  }
135
0
}
136
137
MOZ_CAN_RUN_SCRIPT static bool
138
set_onstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitSetterCallArgs args)
139
0
{
140
0
  AUTO_PROFILER_LABEL_FAST("set ServiceWorker.onstatechange", DOM, cx);
141
0
142
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
143
0
  if (args[0].isObject()) {
144
0
    { // scope for tempRoot and tempGlobalRoot if needed
145
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
146
0
    }
147
0
  } else {
148
0
    arg0 = nullptr;
149
0
  }
150
0
  self->SetOnstatechange(Constify(arg0));
151
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
152
0
153
0
  return true;
154
0
}
155
156
static const JSJitInfo onstatechange_getterinfo = {
157
  { (JSJitGetterOp)get_onstatechange },
158
  { prototypes::id::ServiceWorker },
159
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
160
  JSJitInfo::Getter,
161
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
162
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
163
  false,  /* isInfallible. False in setters. */
164
  false,  /* isMovable.  Not relevant for setters. */
165
  false, /* isEliminatable.  Not relevant for setters. */
166
  false, /* isAlwaysInSlot.  Only relevant for getters. */
167
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
168
  false,  /* isTypedMethod.  Only relevant for methods. */
169
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
170
};
171
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
172
static_assert(0 < 1, "There is no slot for us");
173
static const JSJitInfo onstatechange_setterinfo = {
174
  { (JSJitGetterOp)set_onstatechange },
175
  { prototypes::id::ServiceWorker },
176
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
177
  JSJitInfo::Setter,
178
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
179
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
180
  false,  /* isInfallible. False in setters. */
181
  false,  /* isMovable.  Not relevant for setters. */
182
  false, /* isEliminatable.  Not relevant for setters. */
183
  false, /* isAlwaysInSlot.  Only relevant for getters. */
184
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
185
  false,  /* isTypedMethod.  Only relevant for methods. */
186
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
187
};
188
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
189
static_assert(0 < 1, "There is no slot for us");
190
191
MOZ_CAN_RUN_SCRIPT static bool
192
postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, const JSJitMethodCallArgs& args)
193
0
{
194
0
  AUTO_PROFILER_LABEL_FAST("ServiceWorker.postMessage", DOM, cx);
195
0
196
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
197
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ServiceWorker.postMessage");
198
0
  }
199
0
  JS::Rooted<JS::Value> arg0(cx);
200
0
  arg0 = args[0];
201
0
  binding_detail::AutoSequence<JSObject*> arg1;
202
0
  SequenceRooter<JSObject*> arg1_holder(cx, &arg1);
203
0
  if (args.hasDefined(1)) {
204
0
    if (args[1].isObject()) {
205
0
      JS::ForOfIterator iter(cx);
206
0
      if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
207
0
        return false;
208
0
      }
209
0
      if (!iter.valueIsIterable()) {
210
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of ServiceWorker.postMessage");
211
0
        return false;
212
0
      }
213
0
      binding_detail::AutoSequence<JSObject*> &arr = arg1;
214
0
      JS::Rooted<JS::Value> temp(cx);
215
0
      while (true) {
216
0
        bool done;
217
0
        if (!iter.next(&temp, &done)) {
218
0
          return false;
219
0
        }
220
0
        if (done) {
221
0
          break;
222
0
        }
223
0
        JSObject** slotPtr = arr.AppendElement(mozilla::fallible);
224
0
        if (!slotPtr) {
225
0
          JS_ReportOutOfMemory(cx);
226
0
          return false;
227
0
        }
228
0
        JSObject*& slot = *slotPtr;
229
0
        if (temp.isObject()) {
230
0
          slot = &temp.toObject();
231
0
        } else {
232
0
          ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of ServiceWorker.postMessage");
233
0
          return false;
234
0
        }
235
0
      }
236
0
    } else {
237
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of ServiceWorker.postMessage");
238
0
      return false;
239
0
    }
240
0
  } else {
241
0
    /* Array is already empty; nothing to do */
242
0
  }
243
0
  FastErrorResult rv;
244
0
  self->PostMessage(cx, arg0, Constify(arg1), rv);
245
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
246
0
    return false;
247
0
  }
248
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
249
0
  args.rval().setUndefined();
250
0
  return true;
251
0
}
252
253
static const JSJitInfo postMessage_methodinfo = {
254
  { (JSJitGetterOp)postMessage },
255
  { prototypes::id::ServiceWorker },
256
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
257
  JSJitInfo::Method,
258
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
259
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
260
  false,  /* isInfallible. False in setters. */
261
  false,  /* isMovable.  Not relevant for setters. */
262
  false, /* isEliminatable.  Not relevant for setters. */
263
  false, /* isAlwaysInSlot.  Only relevant for getters. */
264
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
265
  false,  /* isTypedMethod.  Only relevant for methods. */
266
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
267
};
268
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
269
static_assert(0 < 1, "There is no slot for us");
270
271
MOZ_CAN_RUN_SCRIPT static bool
272
get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitGetterCallArgs args)
273
0
{
274
0
  AUTO_PROFILER_LABEL_FAST("get ServiceWorker.onerror", DOM, cx);
275
0
276
0
  RefPtr<EventHandlerNonNull> result(self->GetOnerror());
277
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
278
0
  if (result) {
279
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
280
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
281
0
      return false;
282
0
    }
283
0
    return true;
284
0
  } else {
285
0
    args.rval().setNull();
286
0
    return true;
287
0
  }
288
0
}
289
290
MOZ_CAN_RUN_SCRIPT static bool
291
set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorker* self, JSJitSetterCallArgs args)
292
0
{
293
0
  AUTO_PROFILER_LABEL_FAST("set ServiceWorker.onerror", DOM, cx);
294
0
295
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
296
0
  if (args[0].isObject()) {
297
0
    { // scope for tempRoot and tempGlobalRoot if needed
298
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
299
0
    }
300
0
  } else {
301
0
    arg0 = nullptr;
302
0
  }
303
0
  self->SetOnerror(Constify(arg0));
304
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
305
0
306
0
  return true;
307
0
}
308
309
static const JSJitInfo onerror_getterinfo = {
310
  { (JSJitGetterOp)get_onerror },
311
  { prototypes::id::ServiceWorker },
312
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
313
  JSJitInfo::Getter,
314
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
315
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
316
  false,  /* isInfallible. False in setters. */
317
  false,  /* isMovable.  Not relevant for setters. */
318
  false, /* isEliminatable.  Not relevant for setters. */
319
  false, /* isAlwaysInSlot.  Only relevant for getters. */
320
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
321
  false,  /* isTypedMethod.  Only relevant for methods. */
322
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
323
};
324
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
325
static_assert(0 < 1, "There is no slot for us");
326
static const JSJitInfo onerror_setterinfo = {
327
  { (JSJitGetterOp)set_onerror },
328
  { prototypes::id::ServiceWorker },
329
  { PrototypeTraits<prototypes::id::ServiceWorker>::Depth },
330
  JSJitInfo::Setter,
331
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
332
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
333
  false,  /* isInfallible. False in setters. */
334
  false,  /* isMovable.  Not relevant for setters. */
335
  false, /* isEliminatable.  Not relevant for setters. */
336
  false, /* isAlwaysInSlot.  Only relevant for getters. */
337
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
338
  false,  /* isTypedMethod.  Only relevant for methods. */
339
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
340
};
341
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
342
static_assert(0 < 1, "There is no slot for us");
343
344
static bool
345
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
346
0
{
347
0
  mozilla::dom::ServiceWorker* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorker>(obj);
348
0
  // We don't want to preserve if we don't have a wrapper, and we
349
0
  // obviously can't preserve if we're not initialized.
350
0
  if (self && self->GetWrapperPreserveColor()) {
351
0
    PreserveWrapper(self);
352
0
  }
353
0
  return true;
354
0
}
355
356
static void
357
_finalize(js::FreeOp* fop, JSObject* obj)
358
0
{
359
0
  mozilla::dom::ServiceWorker* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorker>(obj);
360
0
  if (self) {
361
0
    ClearWrapper(self, self, obj);
362
0
    AddForDeferredFinalization<mozilla::dom::ServiceWorker>(self);
363
0
  }
364
0
}
365
366
static size_t
367
_objectMoved(JSObject* obj, JSObject* old)
368
0
{
369
0
  mozilla::dom::ServiceWorker* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorker>(obj);
370
0
  if (self) {
371
0
    UpdateWrapper(self, self, obj, old);
372
0
  }
373
0
374
0
  return 0;
375
0
}
376
377
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
378
#if defined(__clang__)
379
#pragma clang diagnostic push
380
#pragma clang diagnostic ignored "-Wmissing-braces"
381
#endif
382
static const JSFunctionSpec sMethods_specs[] = {
383
  JS_FNSPEC("postMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
384
  JS_FS_END
385
};
386
#if defined(__clang__)
387
#pragma clang diagnostic pop
388
#endif
389
390
391
static const Prefable<const JSFunctionSpec> sMethods[] = {
392
  { nullptr, &sMethods_specs[0] },
393
  { nullptr, nullptr }
394
};
395
396
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
397
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
398
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
399
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
400
401
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
402
#if defined(__clang__)
403
#pragma clang diagnostic push
404
#pragma clang diagnostic ignored "-Wmissing-braces"
405
#endif
406
static const JSPropertySpec sAttributes_specs[] = {
407
  { "scriptURL", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &scriptURL_getterinfo, nullptr, nullptr },
408
  { "state", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &state_getterinfo, nullptr, nullptr },
409
  { "onstatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onstatechange_getterinfo, GenericSetter<NormalThisPolicy>, &onstatechange_setterinfo },
410
  { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo },
411
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
412
};
413
#if defined(__clang__)
414
#pragma clang diagnostic pop
415
#endif
416
417
418
static const Prefable<const JSPropertySpec> sAttributes[] = {
419
  { nullptr, &sAttributes_specs[0] },
420
  { nullptr, nullptr }
421
};
422
423
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
424
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
425
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
426
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
427
428
429
static uint16_t sNativeProperties_sortedPropertyIndices[5];
430
static PropertyInfo sNativeProperties_propertyInfos[5];
431
432
static const NativePropertiesN<2> sNativeProperties = {
433
  false, 0,
434
  false, 0,
435
  true,  0 /* sMethods */,
436
  true,  1 /* sAttributes */,
437
  false, 0,
438
  false, 0,
439
  false, 0,
440
  -1,
441
  5,
442
  sNativeProperties_sortedPropertyIndices,
443
  {
444
    { sMethods, &sNativeProperties_propertyInfos[0] },
445
    { sAttributes, &sNativeProperties_propertyInfos[1] }
446
  }
447
};
448
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
449
    "We have a property info count that is oversized");
450
451
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
452
  {
453
    "Function",
454
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
455
    &sBoringInterfaceObjectClassClassOps,
456
    JS_NULL_CLASS_SPEC,
457
    JS_NULL_CLASS_EXT,
458
    &sInterfaceObjectClassObjectOps
459
  },
460
  eInterface,
461
  true,
462
  prototypes::id::ServiceWorker,
463
  PrototypeTraits<prototypes::id::ServiceWorker>::Depth,
464
  sNativePropertyHooks,
465
  "function ServiceWorker() {\n    [native code]\n}",
466
  EventTarget_Binding::GetConstructorObject
467
};
468
469
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
470
  {
471
    "ServiceWorkerPrototype",
472
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
473
    JS_NULL_CLASS_OPS,
474
    JS_NULL_CLASS_SPEC,
475
    JS_NULL_CLASS_EXT,
476
    JS_NULL_OBJECT_OPS
477
  },
478
  eInterfacePrototype,
479
  false,
480
  prototypes::id::ServiceWorker,
481
  PrototypeTraits<prototypes::id::ServiceWorker>::Depth,
482
  sNativePropertyHooks,
483
  "[object ServiceWorkerPrototype]",
484
  EventTarget_Binding::GetProtoObject
485
};
486
487
bool
488
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
489
0
{
490
0
  return ServiceWorkerVisible(aCx, aObj);
491
0
}
492
493
static const js::ClassOps sClassOps = {
494
  _addProperty, /* addProperty */
495
  nullptr,               /* delProperty */
496
  nullptr,               /* enumerate */
497
  nullptr, /* newEnumerate */
498
  nullptr, /* resolve */
499
  nullptr, /* mayResolve */
500
  _finalize, /* finalize */
501
  nullptr, /* call */
502
  nullptr,               /* hasInstance */
503
  nullptr,               /* construct */
504
  nullptr, /* trace */
505
};
506
507
static const js::ClassExtension sClassExtension = {
508
  nullptr, /* weakmapKeyDelegateOp */
509
  _objectMoved /* objectMovedOp */
510
};
511
512
static const DOMJSClass sClass = {
513
  { "ServiceWorker",
514
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
515
    &sClassOps,
516
    JS_NULL_CLASS_SPEC,
517
    &sClassExtension,
518
    JS_NULL_OBJECT_OPS
519
  },
520
  { prototypes::id::EventTarget, prototypes::id::ServiceWorker, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
521
  IsBaseOf<nsISupports, mozilla::dom::ServiceWorker >::value,
522
  sNativePropertyHooks,
523
  FindAssociatedGlobalForNative<mozilla::dom::ServiceWorker>::Get,
524
  GetProtoObjectHandle,
525
  GetCCParticipant<mozilla::dom::ServiceWorker>::Get()
526
};
527
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
528
              "Must have the right minimal number of reserved slots.");
529
static_assert(1 >= 1,
530
              "Must have enough reserved slots.");
531
532
const JSClass*
533
GetJSClass()
534
0
{
535
0
  return sClass.ToJSClass();
536
0
}
537
538
bool
539
Wrap(JSContext* aCx, mozilla::dom::ServiceWorker* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
540
0
{
541
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ServiceWorker>::value,
542
0
                "Shouldn't have wrappercached things that are not refcounted.");
543
0
  MOZ_ASSERT(static_cast<mozilla::dom::ServiceWorker*>(aObject) ==
544
0
             reinterpret_cast<mozilla::dom::ServiceWorker*>(aObject),
545
0
             "Multiple inheritance for mozilla::dom::ServiceWorker is broken.");
546
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
547
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
548
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
549
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
550
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
551
0
  MOZ_ASSERT(!aCache->GetWrapper(),
552
0
             "You should probably not be using Wrap() directly; use "
553
0
             "GetOrCreateDOMReflector instead");
554
0
555
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
556
0
             "nsISupports must be on our primary inheritance chain");
557
0
558
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
559
0
  if (!global) {
560
0
    return false;
561
0
  }
562
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
563
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
564
0
565
0
  // That might have ended up wrapping us already, due to the wonders
566
0
  // of XBL.  Check for that, and bail out as needed.
567
0
  aReflector.set(aCache->GetWrapper());
568
0
  if (aReflector) {
569
#ifdef DEBUG
570
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
571
#endif // DEBUG
572
    return true;
573
0
  }
574
0
575
0
  JSAutoRealm ar(aCx, global);
576
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
577
0
  if (!canonicalProto) {
578
0
    return false;
579
0
  }
580
0
  JS::Rooted<JSObject*> proto(aCx);
581
0
  if (aGivenProto) {
582
0
    proto = aGivenProto;
583
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
584
0
    // coming in, we changed compartments to that of "parent" so may need
585
0
    // to wrap the proto here.
586
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
587
0
      if (!JS_WrapObject(aCx, &proto)) {
588
0
        return false;
589
0
      }
590
0
    }
591
0
  } else {
592
0
    proto = canonicalProto;
593
0
  }
594
0
595
0
  BindingJSObjectCreator<mozilla::dom::ServiceWorker> creator(aCx);
596
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
597
0
  if (!aReflector) {
598
0
    return false;
599
0
  }
600
0
601
0
  aCache->SetWrapper(aReflector);
602
0
  creator.InitializationSucceeded();
603
0
604
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
605
0
             aCache->GetWrapperPreserveColor() == aReflector);
606
0
  // If proto != canonicalProto, we have to preserve our wrapper;
607
0
  // otherwise we won't be able to properly recreate it later, since
608
0
  // we won't know what proto to use.  Note that we don't check
609
0
  // aGivenProto here, since it's entirely possible (and even
610
0
  // somewhat common) to have a non-null aGivenProto which is the
611
0
  // same as canonicalProto.
612
0
  if (proto != canonicalProto) {
613
0
    PreserveWrapper(aObject);
614
0
  }
615
0
616
0
  return true;
617
0
}
618
619
const NativePropertyHooks sNativePropertyHooks[] = { {
620
  nullptr,
621
  nullptr,
622
  nullptr,
623
  { sNativeProperties.Upcast(), nullptr },
624
  prototypes::id::ServiceWorker,
625
  constructors::id::ServiceWorker,
626
  EventTarget_Binding::sNativePropertyHooks,
627
  &DefaultXrayExpandoObjectClass
628
} };
629
630
void
631
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
632
0
{
633
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
634
0
  if (!parentProto) {
635
0
    return;
636
0
  }
637
0
638
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
639
0
  if (!constructorProto) {
640
0
    return;
641
0
  }
642
0
643
0
  static bool sIdsInited = false;
644
0
  if (!sIdsInited && NS_IsMainThread()) {
645
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
646
0
      return;
647
0
    }
648
0
    sIdsInited = true;
649
0
  }
650
0
651
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ServiceWorker);
652
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ServiceWorker);
653
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
654
0
                              &sPrototypeClass.mBase, protoCache,
655
0
                              nullptr,
656
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
657
0
                              interfaceCache,
658
0
                              sNativeProperties.Upcast(),
659
0
                              nullptr,
660
0
                              "ServiceWorker", aDefineOnGlobal,
661
0
                              nullptr,
662
0
                              false);
663
0
}
664
665
JSObject*
666
GetConstructorObject(JSContext* aCx)
667
0
{
668
0
  return GetConstructorObjectHandle(aCx);
669
0
}
670
671
} // namespace ServiceWorker_Binding
672
673
674
675
} // namespace dom
676
} // namespace mozilla