Coverage Report

Created: 2018-09-25 14:53

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