Coverage Report

Created: 2018-09-25 14:53

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