Coverage Report

Created: 2018-09-25 14:53

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