Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MediaStreamAudioSourceNodeBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MediaStreamAudioSourceNode.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "AudioNodeBinding.h"
5
#include "MediaStreamAudioSourceNodeBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/Preferences.h"
9
#include "mozilla/dom/AudioContext.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/MediaStreamAudioSourceNode.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
#include "nsContentUtils.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
27
MediaStreamAudioSourceOptions::MediaStreamAudioSourceOptions()
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
MediaStreamAudioSourceOptions::InitIds(JSContext* cx, MediaStreamAudioSourceOptionsAtoms* 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->mediaStream_id.init(cx, "mediaStream")) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
bool
49
MediaStreamAudioSourceOptions::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
  MediaStreamAudioSourceOptionsAtoms* atomsCache = nullptr;
57
0
  if (cx) {
58
0
    atomsCache = GetAtomCache<MediaStreamAudioSourceOptionsAtoms>(cx);
59
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60
0
      return false;
61
0
    }
62
0
  }
63
0
64
0
  if (!IsConvertibleToDictionary(val)) {
65
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
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->mediaStream_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::DOMMediaStream>::value, "We can only store refcounted classes.");{
85
0
        nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(temp.ptr(), mMediaStream);
86
0
        if (NS_FAILED(rv)) {
87
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'mediaStream' member of MediaStreamAudioSourceOptions", "MediaStream");
88
0
          return false;
89
0
        }
90
0
      }
91
0
    } else {
92
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'mediaStream' member of MediaStreamAudioSourceOptions");
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
                             "'mediaStream' member of MediaStreamAudioSourceOptions");
102
0
  }
103
0
  return true;
104
0
}
105
106
bool
107
MediaStreamAudioSourceOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
108
0
{
109
0
  MediaStreamAudioSourceOptionsAtoms* atomsCache = GetAtomCache<MediaStreamAudioSourceOptionsAtoms>(cx);
110
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
111
0
    return false;
112
0
  }
113
0
114
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
115
0
  if (!obj) {
116
0
    return false;
117
0
  }
118
0
  rval.set(JS::ObjectValue(*obj));
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::DOMMediaStream> const & currentValue = mMediaStream;
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->mediaStream_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
MediaStreamAudioSourceOptions::TraceDictionary(JSTracer* trc)
139
0
{
140
0
}
141
142
143
144
MediaStreamAudioSourceOptions&
145
MediaStreamAudioSourceOptions::operator=(const MediaStreamAudioSourceOptions& aOther)
146
0
{
147
0
  DictionaryBase::operator=(aOther);
148
0
  mMediaStream = aOther.mMediaStream;
149
0
  return *this;
150
0
}
151
152
namespace binding_detail {
153
} // namespace binding_detail
154
155
156
namespace MediaStreamAudioSourceNode_Binding {
157
158
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AudioNode_Binding::NativeType>::value,
159
              "Can't inherit from an interface with a different ownership model.");
160
161
MOZ_CAN_RUN_SCRIPT static bool
162
get_passThrough(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaStreamAudioSourceNode* self, JSJitGetterCallArgs args)
163
0
{
164
0
  AUTO_PROFILER_LABEL_FAST("get MediaStreamAudioSourceNode.passThrough", DOM, cx);
165
0
166
0
  bool result(self->PassThrough());
167
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
168
0
  args.rval().setBoolean(result);
169
0
  return true;
170
0
}
171
172
MOZ_CAN_RUN_SCRIPT static bool
173
set_passThrough(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaStreamAudioSourceNode* self, JSJitSetterCallArgs args)
174
0
{
175
0
  AUTO_PROFILER_LABEL_FAST("set MediaStreamAudioSourceNode.passThrough", DOM, cx);
176
0
177
0
  bool arg0;
178
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
179
0
    return false;
180
0
  }
181
0
  self->SetPassThrough(arg0);
182
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
183
0
184
0
  return true;
185
0
}
186
187
static const JSJitInfo passThrough_getterinfo = {
188
  { (JSJitGetterOp)get_passThrough },
189
  { prototypes::id::MediaStreamAudioSourceNode },
190
  { PrototypeTraits<prototypes::id::MediaStreamAudioSourceNode>::Depth },
191
  JSJitInfo::Getter,
192
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
193
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
194
  true,  /* 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
static const JSJitInfo passThrough_setterinfo = {
205
  { (JSJitGetterOp)set_passThrough },
206
  { prototypes::id::MediaStreamAudioSourceNode },
207
  { PrototypeTraits<prototypes::id::MediaStreamAudioSourceNode>::Depth },
208
  JSJitInfo::Setter,
209
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
210
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
211
  false,  /* isInfallible. False in setters. */
212
  false,  /* isMovable.  Not relevant for setters. */
213
  false, /* isEliminatable.  Not relevant for setters. */
214
  false, /* isAlwaysInSlot.  Only relevant for getters. */
215
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
216
  false,  /* isTypedMethod.  Only relevant for methods. */
217
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
218
};
219
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
220
static_assert(0 < 1, "There is no slot for us");
221
222
static bool
223
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
224
0
{
225
0
  mozilla::dom::MediaStreamAudioSourceNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioSourceNode>(obj);
226
0
  // We don't want to preserve if we don't have a wrapper, and we
227
0
  // obviously can't preserve if we're not initialized.
228
0
  if (self && self->GetWrapperPreserveColor()) {
229
0
    PreserveWrapper(self);
230
0
  }
231
0
  return true;
232
0
}
233
234
static void
235
_finalize(js::FreeOp* fop, JSObject* obj)
236
0
{
237
0
  mozilla::dom::MediaStreamAudioSourceNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioSourceNode>(obj);
238
0
  if (self) {
239
0
    ClearWrapper(self, self, obj);
240
0
    AddForDeferredFinalization<mozilla::dom::MediaStreamAudioSourceNode>(self);
241
0
  }
242
0
}
243
244
static size_t
245
_objectMoved(JSObject* obj, JSObject* old)
246
0
{
247
0
  mozilla::dom::MediaStreamAudioSourceNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioSourceNode>(obj);
248
0
  if (self) {
249
0
    UpdateWrapper(self, self, obj, old);
250
0
  }
251
0
252
0
  return 0;
253
0
}
254
255
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
256
#if defined(__clang__)
257
#pragma clang diagnostic push
258
#pragma clang diagnostic ignored "-Wmissing-braces"
259
#endif
260
static const JSPropertySpec sChromeAttributes_specs[] = {
261
  { "passThrough", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &passThrough_getterinfo, GenericSetter<NormalThisPolicy>, &passThrough_setterinfo },
262
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
263
};
264
#if defined(__clang__)
265
#pragma clang diagnostic pop
266
#endif
267
268
269
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
270
  { nullptr, &sChromeAttributes_specs[0] },
271
  { nullptr, nullptr }
272
};
273
274
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
275
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
276
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
277
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
278
279
280
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
281
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
282
283
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
284
  false, 0,
285
  false, 0,
286
  false, 0,
287
  true,  0 /* sChromeAttributes */,
288
  false, 0,
289
  false, 0,
290
  false, 0,
291
  -1,
292
  1,
293
  sChromeOnlyNativeProperties_sortedPropertyIndices,
294
  {
295
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
296
  }
297
};
298
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
299
    "We have a property info count that is oversized");
300
301
static bool
302
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
303
0
{
304
0
  AUTO_PROFILER_LABEL_FAST("MediaStreamAudioSourceNode constructor", DOM, cx);
305
0
306
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
307
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
308
0
  if (!args.isConstructing()) {
309
0
    // XXXbz wish I could get the name from the callee instead of
310
0
    // Adding more relocations
311
0
    return ThrowConstructorWithoutNew(cx, "MediaStreamAudioSourceNode");
312
0
  }
313
0
314
0
  JS::Rooted<JSObject*> desiredProto(cx);
315
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
316
0
    return false;
317
0
  }
318
0
319
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
320
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaStreamAudioSourceNode");
321
0
  }
322
0
  GlobalObject global(cx, obj);
323
0
  if (global.Failed()) {
324
0
    return false;
325
0
  }
326
0
327
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
328
0
  NonNull<mozilla::dom::AudioContext> arg0;
329
0
  if (args[0].isObject()) {
330
0
    {
331
0
      nsresult rv = UnwrapObject<prototypes::id::AudioContext, mozilla::dom::AudioContext>(args[0], arg0);
332
0
      if (NS_FAILED(rv)) {
333
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of MediaStreamAudioSourceNode.constructor", "AudioContext");
334
0
        return false;
335
0
      }
336
0
    }
337
0
  } else {
338
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MediaStreamAudioSourceNode.constructor");
339
0
    return false;
340
0
  }
341
0
  binding_detail::FastMediaStreamAudioSourceOptions arg1;
342
0
  if (!arg1.Init(cx, args[1],  "Argument 2 of MediaStreamAudioSourceNode.constructor", false)) {
343
0
    return false;
344
0
  }
345
0
  Maybe<JSAutoRealm> ar;
346
0
  if (objIsXray) {
347
0
    obj = js::CheckedUnwrap(obj);
348
0
    if (!obj) {
349
0
      return false;
350
0
    }
351
0
    ar.emplace(cx, obj);
352
0
    if (!JS_WrapObject(cx, &desiredProto)) {
353
0
      return false;
354
0
    }
355
0
  }
356
0
  FastErrorResult rv;
357
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioSourceNode>(mozilla::dom::MediaStreamAudioSourceNode::Constructor(global, MOZ_KnownLive(NonNullHelper(arg0)), Constify(arg1), rv)));
358
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
359
0
    return false;
360
0
  }
361
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
362
0
  static_assert(!IsPointer<decltype(result)>::value,
363
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
364
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
365
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
366
0
    return false;
367
0
  }
368
0
  return true;
369
0
}
370
371
static const js::ClassOps sInterfaceObjectClassOps = {
372
    nullptr,               /* addProperty */
373
    nullptr,               /* delProperty */
374
    nullptr,               /* enumerate */
375
    nullptr,               /* newEnumerate */
376
    nullptr,               /* resolve */
377
    nullptr,               /* mayResolve */
378
    nullptr,               /* finalize */
379
    _constructor, /* call */
380
    nullptr,               /* hasInstance */
381
    _constructor, /* construct */
382
    nullptr,               /* trace */
383
};
384
385
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
386
  {
387
    "Function",
388
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
389
    &sInterfaceObjectClassOps,
390
    JS_NULL_CLASS_SPEC,
391
    JS_NULL_CLASS_EXT,
392
    &sInterfaceObjectClassObjectOps
393
  },
394
  eInterface,
395
  true,
396
  prototypes::id::MediaStreamAudioSourceNode,
397
  PrototypeTraits<prototypes::id::MediaStreamAudioSourceNode>::Depth,
398
  sNativePropertyHooks,
399
  "function MediaStreamAudioSourceNode() {\n    [native code]\n}",
400
  AudioNode_Binding::GetConstructorObject
401
};
402
403
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
404
  {
405
    "MediaStreamAudioSourceNodePrototype",
406
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
407
    JS_NULL_CLASS_OPS,
408
    JS_NULL_CLASS_SPEC,
409
    JS_NULL_CLASS_EXT,
410
    JS_NULL_OBJECT_OPS
411
  },
412
  eInterfacePrototype,
413
  false,
414
  prototypes::id::MediaStreamAudioSourceNode,
415
  PrototypeTraits<prototypes::id::MediaStreamAudioSourceNode>::Depth,
416
  sNativePropertyHooks,
417
  "[object MediaStreamAudioSourceNodePrototype]",
418
  AudioNode_Binding::GetProtoObject
419
};
420
421
bool
422
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
423
0
{
424
0
  static bool sPrefValue;
425
0
  static bool sPrefCacheSetUp = false;
426
0
  if (!sPrefCacheSetUp) {
427
0
    sPrefCacheSetUp = true;
428
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
429
0
  }
430
0
431
0
  return sPrefValue;
432
0
}
433
434
static const js::ClassOps sClassOps = {
435
  _addProperty, /* addProperty */
436
  nullptr,               /* delProperty */
437
  nullptr,               /* enumerate */
438
  nullptr, /* newEnumerate */
439
  nullptr, /* resolve */
440
  nullptr, /* mayResolve */
441
  _finalize, /* finalize */
442
  nullptr, /* call */
443
  nullptr,               /* hasInstance */
444
  nullptr,               /* construct */
445
  nullptr, /* trace */
446
};
447
448
static const js::ClassExtension sClassExtension = {
449
  nullptr, /* weakmapKeyDelegateOp */
450
  _objectMoved /* objectMovedOp */
451
};
452
453
static const DOMJSClass sClass = {
454
  { "MediaStreamAudioSourceNode",
455
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
456
    &sClassOps,
457
    JS_NULL_CLASS_SPEC,
458
    &sClassExtension,
459
    JS_NULL_OBJECT_OPS
460
  },
461
  { prototypes::id::EventTarget, prototypes::id::AudioNode, prototypes::id::MediaStreamAudioSourceNode, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
462
  IsBaseOf<nsISupports, mozilla::dom::MediaStreamAudioSourceNode >::value,
463
  sNativePropertyHooks,
464
  FindAssociatedGlobalForNative<mozilla::dom::MediaStreamAudioSourceNode>::Get,
465
  GetProtoObjectHandle,
466
  GetCCParticipant<mozilla::dom::MediaStreamAudioSourceNode>::Get()
467
};
468
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
469
              "Must have the right minimal number of reserved slots.");
470
static_assert(1 >= 1,
471
              "Must have enough reserved slots.");
472
473
const JSClass*
474
GetJSClass()
475
0
{
476
0
  return sClass.ToJSClass();
477
0
}
478
479
bool
480
Wrap(JSContext* aCx, mozilla::dom::MediaStreamAudioSourceNode* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
481
0
{
482
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaStreamAudioSourceNode>::value,
483
0
                "Shouldn't have wrappercached things that are not refcounted.");
484
0
  MOZ_ASSERT(static_cast<mozilla::dom::MediaStreamAudioSourceNode*>(aObject) ==
485
0
             reinterpret_cast<mozilla::dom::MediaStreamAudioSourceNode*>(aObject),
486
0
             "Multiple inheritance for mozilla::dom::MediaStreamAudioSourceNode is broken.");
487
0
  MOZ_ASSERT(static_cast<mozilla::dom::AudioNode*>(aObject) ==
488
0
             reinterpret_cast<mozilla::dom::AudioNode*>(aObject),
489
0
             "Multiple inheritance for mozilla::dom::AudioNode is broken.");
490
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
491
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
492
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
493
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
494
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
495
0
  MOZ_ASSERT(!aCache->GetWrapper(),
496
0
             "You should probably not be using Wrap() directly; use "
497
0
             "GetOrCreateDOMReflector instead");
498
0
499
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
500
0
             "nsISupports must be on our primary inheritance chain");
501
0
502
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
503
0
  if (!global) {
504
0
    return false;
505
0
  }
506
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
507
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
508
0
509
0
  // That might have ended up wrapping us already, due to the wonders
510
0
  // of XBL.  Check for that, and bail out as needed.
511
0
  aReflector.set(aCache->GetWrapper());
512
0
  if (aReflector) {
513
#ifdef DEBUG
514
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
515
#endif // DEBUG
516
    return true;
517
0
  }
518
0
519
0
  JSAutoRealm ar(aCx, global);
520
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
521
0
  if (!canonicalProto) {
522
0
    return false;
523
0
  }
524
0
  JS::Rooted<JSObject*> proto(aCx);
525
0
  if (aGivenProto) {
526
0
    proto = aGivenProto;
527
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
528
0
    // coming in, we changed compartments to that of "parent" so may need
529
0
    // to wrap the proto here.
530
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
531
0
      if (!JS_WrapObject(aCx, &proto)) {
532
0
        return false;
533
0
      }
534
0
    }
535
0
  } else {
536
0
    proto = canonicalProto;
537
0
  }
538
0
539
0
  BindingJSObjectCreator<mozilla::dom::MediaStreamAudioSourceNode> creator(aCx);
540
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
541
0
  if (!aReflector) {
542
0
    return false;
543
0
  }
544
0
545
0
  aCache->SetWrapper(aReflector);
546
0
  creator.InitializationSucceeded();
547
0
548
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
549
0
             aCache->GetWrapperPreserveColor() == aReflector);
550
0
  // If proto != canonicalProto, we have to preserve our wrapper;
551
0
  // otherwise we won't be able to properly recreate it later, since
552
0
  // we won't know what proto to use.  Note that we don't check
553
0
  // aGivenProto here, since it's entirely possible (and even
554
0
  // somewhat common) to have a non-null aGivenProto which is the
555
0
  // same as canonicalProto.
556
0
  if (proto != canonicalProto) {
557
0
    PreserveWrapper(aObject);
558
0
  }
559
0
560
0
  return true;
561
0
}
562
563
const NativePropertyHooks sNativePropertyHooks[] = { {
564
  nullptr,
565
  nullptr,
566
  nullptr,
567
  { nullptr, sChromeOnlyNativeProperties.Upcast() },
568
  prototypes::id::MediaStreamAudioSourceNode,
569
  constructors::id::MediaStreamAudioSourceNode,
570
  AudioNode_Binding::sNativePropertyHooks,
571
  &DefaultXrayExpandoObjectClass
572
} };
573
574
void
575
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
576
0
{
577
0
  JS::Handle<JSObject*> parentProto(AudioNode_Binding::GetProtoObjectHandle(aCx));
578
0
  if (!parentProto) {
579
0
    return;
580
0
  }
581
0
582
0
  JS::Handle<JSObject*> constructorProto(AudioNode_Binding::GetConstructorObjectHandle(aCx));
583
0
  if (!constructorProto) {
584
0
    return;
585
0
  }
586
0
587
0
  static bool sIdsInited = false;
588
0
  if (!sIdsInited && NS_IsMainThread()) {
589
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
590
0
      return;
591
0
    }
592
0
    sIdsInited = true;
593
0
  }
594
0
595
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaStreamAudioSourceNode);
596
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaStreamAudioSourceNode);
597
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
598
0
                              &sPrototypeClass.mBase, protoCache,
599
0
                              nullptr,
600
0
                              constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
601
0
                              interfaceCache,
602
0
                              nullptr,
603
0
                              sChromeOnlyNativeProperties.Upcast(),
604
0
                              "MediaStreamAudioSourceNode", aDefineOnGlobal,
605
0
                              nullptr,
606
0
                              false);
607
0
}
608
609
JSObject*
610
GetConstructorObject(JSContext* aCx)
611
0
{
612
0
  return GetConstructorObjectHandle(aCx);
613
0
}
614
615
} // namespace MediaStreamAudioSourceNode_Binding
616
617
618
619
} // namespace dom
620
} // namespace mozilla