Coverage Report

Created: 2018-09-25 14:53

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