Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MediaStreamAudioDestinationNodeBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MediaStreamAudioDestinationNode.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AudioNodeBinding.h"
4
#include "DOMMediaStream.h"
5
#include "MediaStreamAudioDestinationNodeBinding.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/MediaStreamAudioDestinationNode.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
namespace MediaStreamAudioDestinationNode_Binding {
24
25
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AudioNode_Binding::NativeType>::value,
26
              "Can't inherit from an interface with a different ownership model.");
27
28
MOZ_CAN_RUN_SCRIPT static bool
29
get_stream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaStreamAudioDestinationNode* self, JSJitGetterCallArgs args)
30
0
{
31
0
  AUTO_PROFILER_LABEL_FAST("get MediaStreamAudioDestinationNode.stream", DOM, cx);
32
0
33
0
  auto result(StrongOrRawPtr<mozilla::DOMMediaStream>(self->DOMStream()));
34
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
35
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
36
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
37
0
    return false;
38
0
  }
39
0
  return true;
40
0
}
41
42
static const JSJitInfo stream_getterinfo = {
43
  { (JSJitGetterOp)get_stream },
44
  { prototypes::id::MediaStreamAudioDestinationNode },
45
  { PrototypeTraits<prototypes::id::MediaStreamAudioDestinationNode>::Depth },
46
  JSJitInfo::Getter,
47
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
48
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
49
  false,  /* isInfallible. False in setters. */
50
  false,  /* isMovable.  Not relevant for setters. */
51
  false, /* isEliminatable.  Not relevant for setters. */
52
  false, /* isAlwaysInSlot.  Only relevant for getters. */
53
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
54
  false,  /* isTypedMethod.  Only relevant for methods. */
55
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
56
};
57
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
58
static_assert(0 < 1, "There is no slot for us");
59
60
static bool
61
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
62
0
{
63
0
  mozilla::dom::MediaStreamAudioDestinationNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioDestinationNode>(obj);
64
0
  // We don't want to preserve if we don't have a wrapper, and we
65
0
  // obviously can't preserve if we're not initialized.
66
0
  if (self && self->GetWrapperPreserveColor()) {
67
0
    PreserveWrapper(self);
68
0
  }
69
0
  return true;
70
0
}
71
72
static void
73
_finalize(js::FreeOp* fop, JSObject* obj)
74
0
{
75
0
  mozilla::dom::MediaStreamAudioDestinationNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioDestinationNode>(obj);
76
0
  if (self) {
77
0
    ClearWrapper(self, self, obj);
78
0
    AddForDeferredFinalization<mozilla::dom::MediaStreamAudioDestinationNode>(self);
79
0
  }
80
0
}
81
82
static size_t
83
_objectMoved(JSObject* obj, JSObject* old)
84
0
{
85
0
  mozilla::dom::MediaStreamAudioDestinationNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamAudioDestinationNode>(obj);
86
0
  if (self) {
87
0
    UpdateWrapper(self, self, obj, old);
88
0
  }
89
0
90
0
  return 0;
91
0
}
92
93
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
94
#if defined(__clang__)
95
#pragma clang diagnostic push
96
#pragma clang diagnostic ignored "-Wmissing-braces"
97
#endif
98
static const JSPropertySpec sAttributes_specs[] = {
99
  { "stream", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &stream_getterinfo, nullptr, nullptr },
100
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
101
};
102
#if defined(__clang__)
103
#pragma clang diagnostic pop
104
#endif
105
106
107
static const Prefable<const JSPropertySpec> sAttributes[] = {
108
  { nullptr, &sAttributes_specs[0] },
109
  { nullptr, nullptr }
110
};
111
112
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
113
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
114
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
115
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
116
117
118
static uint16_t sNativeProperties_sortedPropertyIndices[1];
119
static PropertyInfo sNativeProperties_propertyInfos[1];
120
121
static const NativePropertiesN<1> sNativeProperties = {
122
  false, 0,
123
  false, 0,
124
  false, 0,
125
  true,  0 /* sAttributes */,
126
  false, 0,
127
  false, 0,
128
  false, 0,
129
  -1,
130
  1,
131
  sNativeProperties_sortedPropertyIndices,
132
  {
133
    { sAttributes, &sNativeProperties_propertyInfos[0] }
134
  }
135
};
136
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
137
    "We have a property info count that is oversized");
138
139
static bool
140
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
141
0
{
142
0
  AUTO_PROFILER_LABEL_FAST("MediaStreamAudioDestinationNode constructor", DOM, cx);
143
0
144
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
145
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
146
0
  if (!args.isConstructing()) {
147
0
    // XXXbz wish I could get the name from the callee instead of
148
0
    // Adding more relocations
149
0
    return ThrowConstructorWithoutNew(cx, "MediaStreamAudioDestinationNode");
150
0
  }
151
0
152
0
  JS::Rooted<JSObject*> desiredProto(cx);
153
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
154
0
    return false;
155
0
  }
156
0
157
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
158
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaStreamAudioDestinationNode");
159
0
  }
160
0
  GlobalObject global(cx, obj);
161
0
  if (global.Failed()) {
162
0
    return false;
163
0
  }
164
0
165
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
166
0
  NonNull<mozilla::dom::AudioContext> arg0;
167
0
  if (args[0].isObject()) {
168
0
    {
169
0
      nsresult rv = UnwrapObject<prototypes::id::AudioContext, mozilla::dom::AudioContext>(args[0], arg0);
170
0
      if (NS_FAILED(rv)) {
171
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of MediaStreamAudioDestinationNode.constructor", "AudioContext");
172
0
        return false;
173
0
      }
174
0
    }
175
0
  } else {
176
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MediaStreamAudioDestinationNode.constructor");
177
0
    return false;
178
0
  }
179
0
  binding_detail::FastAudioNodeOptions arg1;
180
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of MediaStreamAudioDestinationNode.constructor", false)) {
181
0
    return false;
182
0
  }
183
0
  Maybe<JSAutoRealm> ar;
184
0
  if (objIsXray) {
185
0
    obj = js::CheckedUnwrap(obj);
186
0
    if (!obj) {
187
0
      return false;
188
0
    }
189
0
    ar.emplace(cx, obj);
190
0
    if (!JS_WrapObject(cx, &desiredProto)) {
191
0
      return false;
192
0
    }
193
0
  }
194
0
  FastErrorResult rv;
195
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioDestinationNode>(mozilla::dom::MediaStreamAudioDestinationNode::Constructor(global, MOZ_KnownLive(NonNullHelper(arg0)), Constify(arg1), rv)));
196
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
197
0
    return false;
198
0
  }
199
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
200
0
  static_assert(!IsPointer<decltype(result)>::value,
201
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
202
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
203
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
204
0
    return false;
205
0
  }
206
0
  return true;
207
0
}
208
209
static const js::ClassOps sInterfaceObjectClassOps = {
210
    nullptr,               /* addProperty */
211
    nullptr,               /* delProperty */
212
    nullptr,               /* enumerate */
213
    nullptr,               /* newEnumerate */
214
    nullptr,               /* resolve */
215
    nullptr,               /* mayResolve */
216
    nullptr,               /* finalize */
217
    _constructor, /* call */
218
    nullptr,               /* hasInstance */
219
    _constructor, /* construct */
220
    nullptr,               /* trace */
221
};
222
223
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
224
  {
225
    "Function",
226
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
227
    &sInterfaceObjectClassOps,
228
    JS_NULL_CLASS_SPEC,
229
    JS_NULL_CLASS_EXT,
230
    &sInterfaceObjectClassObjectOps
231
  },
232
  eInterface,
233
  true,
234
  prototypes::id::MediaStreamAudioDestinationNode,
235
  PrototypeTraits<prototypes::id::MediaStreamAudioDestinationNode>::Depth,
236
  sNativePropertyHooks,
237
  "function MediaStreamAudioDestinationNode() {\n    [native code]\n}",
238
  AudioNode_Binding::GetConstructorObject
239
};
240
241
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
242
  {
243
    "MediaStreamAudioDestinationNodePrototype",
244
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
245
    JS_NULL_CLASS_OPS,
246
    JS_NULL_CLASS_SPEC,
247
    JS_NULL_CLASS_EXT,
248
    JS_NULL_OBJECT_OPS
249
  },
250
  eInterfacePrototype,
251
  false,
252
  prototypes::id::MediaStreamAudioDestinationNode,
253
  PrototypeTraits<prototypes::id::MediaStreamAudioDestinationNode>::Depth,
254
  sNativePropertyHooks,
255
  "[object MediaStreamAudioDestinationNodePrototype]",
256
  AudioNode_Binding::GetProtoObject
257
};
258
259
bool
260
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
261
0
{
262
0
  static bool sPrefValue;
263
0
  static bool sPrefCacheSetUp = false;
264
0
  if (!sPrefCacheSetUp) {
265
0
    sPrefCacheSetUp = true;
266
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
267
0
  }
268
0
269
0
  return sPrefValue;
270
0
}
271
272
static const js::ClassOps sClassOps = {
273
  _addProperty, /* addProperty */
274
  nullptr,               /* delProperty */
275
  nullptr,               /* enumerate */
276
  nullptr, /* newEnumerate */
277
  nullptr, /* resolve */
278
  nullptr, /* mayResolve */
279
  _finalize, /* finalize */
280
  nullptr, /* call */
281
  nullptr,               /* hasInstance */
282
  nullptr,               /* construct */
283
  nullptr, /* trace */
284
};
285
286
static const js::ClassExtension sClassExtension = {
287
  nullptr, /* weakmapKeyDelegateOp */
288
  _objectMoved /* objectMovedOp */
289
};
290
291
static const DOMJSClass sClass = {
292
  { "MediaStreamAudioDestinationNode",
293
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
294
    &sClassOps,
295
    JS_NULL_CLASS_SPEC,
296
    &sClassExtension,
297
    JS_NULL_OBJECT_OPS
298
  },
299
  { prototypes::id::EventTarget, prototypes::id::AudioNode, prototypes::id::MediaStreamAudioDestinationNode, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
300
  IsBaseOf<nsISupports, mozilla::dom::MediaStreamAudioDestinationNode >::value,
301
  sNativePropertyHooks,
302
  FindAssociatedGlobalForNative<mozilla::dom::MediaStreamAudioDestinationNode>::Get,
303
  GetProtoObjectHandle,
304
  GetCCParticipant<mozilla::dom::MediaStreamAudioDestinationNode>::Get()
305
};
306
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
307
              "Must have the right minimal number of reserved slots.");
308
static_assert(1 >= 1,
309
              "Must have enough reserved slots.");
310
311
const JSClass*
312
GetJSClass()
313
0
{
314
0
  return sClass.ToJSClass();
315
0
}
316
317
bool
318
Wrap(JSContext* aCx, mozilla::dom::MediaStreamAudioDestinationNode* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
319
0
{
320
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaStreamAudioDestinationNode>::value,
321
0
                "Shouldn't have wrappercached things that are not refcounted.");
322
0
  MOZ_ASSERT(static_cast<mozilla::dom::MediaStreamAudioDestinationNode*>(aObject) ==
323
0
             reinterpret_cast<mozilla::dom::MediaStreamAudioDestinationNode*>(aObject),
324
0
             "Multiple inheritance for mozilla::dom::MediaStreamAudioDestinationNode is broken.");
325
0
  MOZ_ASSERT(static_cast<mozilla::dom::AudioNode*>(aObject) ==
326
0
             reinterpret_cast<mozilla::dom::AudioNode*>(aObject),
327
0
             "Multiple inheritance for mozilla::dom::AudioNode is broken.");
328
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
329
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
330
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
331
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
332
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
333
0
  MOZ_ASSERT(!aCache->GetWrapper(),
334
0
             "You should probably not be using Wrap() directly; use "
335
0
             "GetOrCreateDOMReflector instead");
336
0
337
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
338
0
             "nsISupports must be on our primary inheritance chain");
339
0
340
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
341
0
  if (!global) {
342
0
    return false;
343
0
  }
344
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
345
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
346
0
347
0
  // That might have ended up wrapping us already, due to the wonders
348
0
  // of XBL.  Check for that, and bail out as needed.
349
0
  aReflector.set(aCache->GetWrapper());
350
0
  if (aReflector) {
351
#ifdef DEBUG
352
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
353
#endif // DEBUG
354
    return true;
355
0
  }
356
0
357
0
  JSAutoRealm ar(aCx, global);
358
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
359
0
  if (!canonicalProto) {
360
0
    return false;
361
0
  }
362
0
  JS::Rooted<JSObject*> proto(aCx);
363
0
  if (aGivenProto) {
364
0
    proto = aGivenProto;
365
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
366
0
    // coming in, we changed compartments to that of "parent" so may need
367
0
    // to wrap the proto here.
368
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
369
0
      if (!JS_WrapObject(aCx, &proto)) {
370
0
        return false;
371
0
      }
372
0
    }
373
0
  } else {
374
0
    proto = canonicalProto;
375
0
  }
376
0
377
0
  BindingJSObjectCreator<mozilla::dom::MediaStreamAudioDestinationNode> creator(aCx);
378
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
379
0
  if (!aReflector) {
380
0
    return false;
381
0
  }
382
0
383
0
  aCache->SetWrapper(aReflector);
384
0
  creator.InitializationSucceeded();
385
0
386
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
387
0
             aCache->GetWrapperPreserveColor() == aReflector);
388
0
  // If proto != canonicalProto, we have to preserve our wrapper;
389
0
  // otherwise we won't be able to properly recreate it later, since
390
0
  // we won't know what proto to use.  Note that we don't check
391
0
  // aGivenProto here, since it's entirely possible (and even
392
0
  // somewhat common) to have a non-null aGivenProto which is the
393
0
  // same as canonicalProto.
394
0
  if (proto != canonicalProto) {
395
0
    PreserveWrapper(aObject);
396
0
  }
397
0
398
0
  return true;
399
0
}
400
401
const NativePropertyHooks sNativePropertyHooks[] = { {
402
  nullptr,
403
  nullptr,
404
  nullptr,
405
  { sNativeProperties.Upcast(), nullptr },
406
  prototypes::id::MediaStreamAudioDestinationNode,
407
  constructors::id::MediaStreamAudioDestinationNode,
408
  AudioNode_Binding::sNativePropertyHooks,
409
  &DefaultXrayExpandoObjectClass
410
} };
411
412
void
413
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
414
0
{
415
0
  JS::Handle<JSObject*> parentProto(AudioNode_Binding::GetProtoObjectHandle(aCx));
416
0
  if (!parentProto) {
417
0
    return;
418
0
  }
419
0
420
0
  JS::Handle<JSObject*> constructorProto(AudioNode_Binding::GetConstructorObjectHandle(aCx));
421
0
  if (!constructorProto) {
422
0
    return;
423
0
  }
424
0
425
0
  static bool sIdsInited = false;
426
0
  if (!sIdsInited && NS_IsMainThread()) {
427
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
428
0
      return;
429
0
    }
430
0
    sIdsInited = true;
431
0
  }
432
0
433
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaStreamAudioDestinationNode);
434
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaStreamAudioDestinationNode);
435
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
436
0
                              &sPrototypeClass.mBase, protoCache,
437
0
                              nullptr,
438
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
439
0
                              interfaceCache,
440
0
                              sNativeProperties.Upcast(),
441
0
                              nullptr,
442
0
                              "MediaStreamAudioDestinationNode", aDefineOnGlobal,
443
0
                              nullptr,
444
0
                              false);
445
0
}
446
447
JSObject*
448
GetConstructorObject(JSContext* aCx)
449
0
{
450
0
  return GetConstructorObjectHandle(aCx);
451
0
}
452
453
} // namespace MediaStreamAudioDestinationNode_Binding
454
455
456
457
} // namespace dom
458
} // namespace mozilla