Coverage Report

Created: 2018-09-25 14:53

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