Coverage Report

Created: 2018-09-25 14:53

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