Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/AudioContextBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM AudioContext.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "AudioContextBinding.h"
5
#include "BaseAudioContextBinding.h"
6
#include "DOMMediaStream.h"
7
#include "WrapperFactory.h"
8
#include "mozilla/FloatingPoint.h"
9
#include "mozilla/OwningNonNull.h"
10
#include "mozilla/Preferences.h"
11
#include "mozilla/dom/AudioContext.h"
12
#include "mozilla/dom/BindingUtils.h"
13
#include "mozilla/dom/DOMJSClass.h"
14
#include "mozilla/dom/HTMLMediaElement.h"
15
#include "mozilla/dom/MediaElementAudioSourceNode.h"
16
#include "mozilla/dom/MediaStreamAudioDestinationNode.h"
17
#include "mozilla/dom/MediaStreamAudioSourceNode.h"
18
#include "mozilla/dom/NonRefcountedDOMObject.h"
19
#include "mozilla/dom/PrimitiveConversions.h"
20
#include "mozilla/dom/Promise.h"
21
#include "mozilla/dom/ScriptSettings.h"
22
#include "mozilla/dom/SimpleGlobalObject.h"
23
#include "mozilla/dom/ToJSValue.h"
24
#include "mozilla/dom/XrayExpandoClass.h"
25
26
namespace mozilla {
27
namespace dom {
28
29
namespace binding_detail {}; // Just to make sure it's known as a namespace
30
using namespace mozilla::dom::binding_detail;
31
32
33
34
AudioContextOptions::AudioContextOptions()
35
0
{
36
0
  // Safe to pass a null context if we pass a null value
37
0
  Init(nullptr, JS::NullHandleValue);
38
0
}
39
40
41
42
bool
43
AudioContextOptions::InitIds(JSContext* cx, AudioContextOptionsAtoms* atomsCache)
44
0
{
45
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
46
0
47
0
  // Initialize these in reverse order so that any failure leaves the first one
48
0
  // uninitialized.
49
0
  if (!atomsCache->sampleRate_id.init(cx, "sampleRate")) {
50
0
    return false;
51
0
  }
52
0
  return true;
53
0
}
54
55
bool
56
AudioContextOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
57
0
{
58
0
  // Passing a null JSContext is OK only if we're initing from null,
59
0
  // Since in that case we will not have to do any property gets
60
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
61
0
  // checkers by static analysis tools
62
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
63
0
  AudioContextOptionsAtoms* atomsCache = nullptr;
64
0
  if (cx) {
65
0
    atomsCache = GetAtomCache<AudioContextOptionsAtoms>(cx);
66
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
67
0
      return false;
68
0
    }
69
0
  }
70
0
71
0
  if (!IsConvertibleToDictionary(val)) {
72
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
73
0
  }
74
0
75
0
  bool isNull = val.isNullOrUndefined();
76
0
  // We only need these if !isNull, in which case we have |cx|.
77
0
  Maybe<JS::Rooted<JSObject *> > object;
78
0
  Maybe<JS::Rooted<JS::Value> > temp;
79
0
  if (!isNull) {
80
0
    MOZ_ASSERT(cx);
81
0
    object.emplace(cx, &val.toObject());
82
0
    temp.emplace(cx);
83
0
  }
84
0
  if (!isNull) {
85
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->sampleRate_id, temp.ptr())) {
86
0
      return false;
87
0
    }
88
0
  }
89
0
  if (!isNull && !temp->isUndefined()) {
90
0
    if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mSampleRate)) {
91
0
      return false;
92
0
    } else if (!mozilla::IsFinite(mSampleRate)) {
93
0
      ThrowErrorMessage(cx, MSG_NOT_FINITE, "'sampleRate' member of AudioContextOptions");
94
0
      return false;
95
0
    }
96
0
  } else {
97
0
    mSampleRate = 0.0F;
98
0
  }
99
0
  mIsAnyMemberPresent = true;
100
0
  return true;
101
0
}
102
103
bool
104
AudioContextOptions::Init(const nsAString& aJSON)
105
0
{
106
0
  AutoJSAPI jsapi;
107
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
108
0
  if (!cleanGlobal) {
109
0
    return false;
110
0
  }
111
0
  if (!jsapi.Init(cleanGlobal)) {
112
0
    return false;
113
0
  }
114
0
  JSContext* cx = jsapi.cx();
115
0
  JS::Rooted<JS::Value> json(cx);
116
0
  bool ok = ParseJSON(cx, aJSON, &json);
117
0
  NS_ENSURE_TRUE(ok, false);
118
0
  return Init(cx, json);
119
0
}
120
121
bool
122
AudioContextOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
123
0
{
124
0
  AudioContextOptionsAtoms* atomsCache = GetAtomCache<AudioContextOptionsAtoms>(cx);
125
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
126
0
    return false;
127
0
  }
128
0
129
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
130
0
  if (!obj) {
131
0
    return false;
132
0
  }
133
0
  rval.set(JS::ObjectValue(*obj));
134
0
135
0
  do {
136
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
137
0
    JS::Rooted<JS::Value> temp(cx);
138
0
    float const & currentValue = mSampleRate;
139
0
    temp.set(JS_NumberValue(double(currentValue)));
140
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->sampleRate_id, temp, JSPROP_ENUMERATE)) {
141
0
      return false;
142
0
    }
143
0
    break;
144
0
  } while(false);
145
0
146
0
  return true;
147
0
}
148
149
bool
150
AudioContextOptions::ToJSON(nsAString& aJSON) const
151
0
{
152
0
  AutoJSAPI jsapi;
153
0
  jsapi.Init();
154
0
  JSContext *cx = jsapi.cx();
155
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
156
0
  // because we'll only be creating objects, in ways that have no
157
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
158
0
  // which likewise guarantees no side-effects for the sorts of
159
0
  // things we will pass it.
160
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
161
0
  JS::Rooted<JS::Value> val(cx);
162
0
  if (!ToObjectInternal(cx, &val)) {
163
0
    return false;
164
0
  }
165
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
166
0
  return StringifyToJSON(cx, obj, aJSON);
167
0
}
168
169
void
170
AudioContextOptions::TraceDictionary(JSTracer* trc)
171
0
{
172
0
}
173
174
AudioContextOptions&
175
AudioContextOptions::operator=(const AudioContextOptions& aOther)
176
0
{
177
0
  DictionaryBase::operator=(aOther);
178
0
  mSampleRate = aOther.mSampleRate;
179
0
  return *this;
180
0
}
181
182
namespace binding_detail {
183
} // namespace binding_detail
184
185
186
namespace AudioContext_Binding {
187
188
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<BaseAudioContext_Binding::NativeType>::value,
189
              "Can't inherit from an interface with a different ownership model.");
190
191
MOZ_CAN_RUN_SCRIPT static bool
192
suspend(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
193
0
{
194
0
  AUTO_PROFILER_LABEL_FAST("AudioContext.suspend", DOM, cx);
195
0
196
0
  FastErrorResult rv;
197
0
  auto result(StrongOrRawPtr<Promise>(self->Suspend(rv)));
198
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
199
0
    return false;
200
0
  }
201
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
202
0
  if (!ToJSValue(cx, result, args.rval())) {
203
0
    return false;
204
0
  }
205
0
  return true;
206
0
}
207
208
MOZ_CAN_RUN_SCRIPT static bool
209
suspend_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
210
0
{
211
0
  bool ok = suspend(cx, obj, self, args);
212
0
  if (ok) {
213
0
    return true;
214
0
  }
215
0
  return ConvertExceptionToPromise(cx, args.rval());
216
0
}
217
218
static const JSJitInfo suspend_methodinfo = {
219
  { (JSJitGetterOp)suspend_promiseWrapper },
220
  { prototypes::id::AudioContext },
221
  { PrototypeTraits<prototypes::id::AudioContext>::Depth },
222
  JSJitInfo::Method,
223
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
224
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
225
  false,  /* isInfallible. False in setters. */
226
  false,  /* isMovable.  Not relevant for setters. */
227
  false, /* isEliminatable.  Not relevant for setters. */
228
  false, /* isAlwaysInSlot.  Only relevant for getters. */
229
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
230
  false,  /* isTypedMethod.  Only relevant for methods. */
231
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
232
};
233
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
234
static_assert(0 < 1, "There is no slot for us");
235
236
MOZ_CAN_RUN_SCRIPT static bool
237
close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
238
0
{
239
0
  AUTO_PROFILER_LABEL_FAST("AudioContext.close", DOM, cx);
240
0
241
0
  FastErrorResult rv;
242
0
  auto result(StrongOrRawPtr<Promise>(self->Close(rv)));
243
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
244
0
    return false;
245
0
  }
246
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
247
0
  if (!ToJSValue(cx, result, args.rval())) {
248
0
    return false;
249
0
  }
250
0
  return true;
251
0
}
252
253
MOZ_CAN_RUN_SCRIPT static bool
254
close_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
255
0
{
256
0
  bool ok = close(cx, obj, self, args);
257
0
  if (ok) {
258
0
    return true;
259
0
  }
260
0
  return ConvertExceptionToPromise(cx, args.rval());
261
0
}
262
263
static const JSJitInfo close_methodinfo = {
264
  { (JSJitGetterOp)close_promiseWrapper },
265
  { prototypes::id::AudioContext },
266
  { PrototypeTraits<prototypes::id::AudioContext>::Depth },
267
  JSJitInfo::Method,
268
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
269
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
270
  false,  /* isInfallible. False in setters. */
271
  false,  /* isMovable.  Not relevant for setters. */
272
  false, /* isEliminatable.  Not relevant for setters. */
273
  false, /* isAlwaysInSlot.  Only relevant for getters. */
274
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
275
  false,  /* isTypedMethod.  Only relevant for methods. */
276
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
277
};
278
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
279
static_assert(0 < 1, "There is no slot for us");
280
281
MOZ_CAN_RUN_SCRIPT static bool
282
createMediaElementSource(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
283
0
{
284
0
  AUTO_PROFILER_LABEL_FAST("AudioContext.createMediaElementSource", DOM, cx);
285
0
286
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
287
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "AudioContext.createMediaElementSource");
288
0
  }
289
0
  NonNull<mozilla::dom::HTMLMediaElement> arg0;
290
0
  if (args[0].isObject()) {
291
0
    {
292
0
      nsresult rv = UnwrapObject<prototypes::id::HTMLMediaElement, mozilla::dom::HTMLMediaElement>(args[0], arg0);
293
0
      if (NS_FAILED(rv)) {
294
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of AudioContext.createMediaElementSource", "HTMLMediaElement");
295
0
        return false;
296
0
      }
297
0
    }
298
0
  } else {
299
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of AudioContext.createMediaElementSource");
300
0
    return false;
301
0
  }
302
0
  FastErrorResult rv;
303
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaElementAudioSourceNode>(self->CreateMediaElementSource(MOZ_KnownLive(NonNullHelper(arg0)), rv)));
304
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
305
0
    return false;
306
0
  }
307
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
308
0
  static_assert(!IsPointer<decltype(result)>::value,
309
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
310
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
311
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
312
0
    return false;
313
0
  }
314
0
  return true;
315
0
}
316
317
static const JSJitInfo createMediaElementSource_methodinfo = {
318
  { (JSJitGetterOp)createMediaElementSource },
319
  { prototypes::id::AudioContext },
320
  { PrototypeTraits<prototypes::id::AudioContext>::Depth },
321
  JSJitInfo::Method,
322
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
323
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
324
  false,  /* isInfallible. False in setters. */
325
  false,  /* isMovable.  Not relevant for setters. */
326
  false, /* isEliminatable.  Not relevant for setters. */
327
  false, /* isAlwaysInSlot.  Only relevant for getters. */
328
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
329
  false,  /* isTypedMethod.  Only relevant for methods. */
330
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
331
};
332
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
333
static_assert(0 < 1, "There is no slot for us");
334
335
MOZ_CAN_RUN_SCRIPT static bool
336
createMediaStreamSource(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
337
0
{
338
0
  AUTO_PROFILER_LABEL_FAST("AudioContext.createMediaStreamSource", DOM, cx);
339
0
340
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
341
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "AudioContext.createMediaStreamSource");
342
0
  }
343
0
  NonNull<mozilla::DOMMediaStream> arg0;
344
0
  if (args[0].isObject()) {
345
0
    {
346
0
      nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[0], arg0);
347
0
      if (NS_FAILED(rv)) {
348
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of AudioContext.createMediaStreamSource", "MediaStream");
349
0
        return false;
350
0
      }
351
0
    }
352
0
  } else {
353
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of AudioContext.createMediaStreamSource");
354
0
    return false;
355
0
  }
356
0
  FastErrorResult rv;
357
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioSourceNode>(self->CreateMediaStreamSource(MOZ_KnownLive(NonNullHelper(arg0)), 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())) {
365
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
366
0
    return false;
367
0
  }
368
0
  return true;
369
0
}
370
371
static const JSJitInfo createMediaStreamSource_methodinfo = {
372
  { (JSJitGetterOp)createMediaStreamSource },
373
  { prototypes::id::AudioContext },
374
  { PrototypeTraits<prototypes::id::AudioContext>::Depth },
375
  JSJitInfo::Method,
376
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
377
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
378
  false,  /* isInfallible. False in setters. */
379
  false,  /* isMovable.  Not relevant for setters. */
380
  false, /* isEliminatable.  Not relevant for setters. */
381
  false, /* isAlwaysInSlot.  Only relevant for getters. */
382
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
383
  false,  /* isTypedMethod.  Only relevant for methods. */
384
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
385
};
386
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
387
static_assert(0 < 1, "There is no slot for us");
388
389
MOZ_CAN_RUN_SCRIPT static bool
390
createMediaStreamDestination(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
391
0
{
392
0
  AUTO_PROFILER_LABEL_FAST("AudioContext.createMediaStreamDestination", DOM, cx);
393
0
394
0
  FastErrorResult rv;
395
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioDestinationNode>(self->CreateMediaStreamDestination(rv)));
396
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
397
0
    return false;
398
0
  }
399
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
400
0
  static_assert(!IsPointer<decltype(result)>::value,
401
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
402
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
403
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
404
0
    return false;
405
0
  }
406
0
  return true;
407
0
}
408
409
static const JSJitInfo createMediaStreamDestination_methodinfo = {
410
  { (JSJitGetterOp)createMediaStreamDestination },
411
  { prototypes::id::AudioContext },
412
  { PrototypeTraits<prototypes::id::AudioContext>::Depth },
413
  JSJitInfo::Method,
414
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
415
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
416
  false,  /* isInfallible. False in setters. */
417
  false,  /* isMovable.  Not relevant for setters. */
418
  false, /* isEliminatable.  Not relevant for setters. */
419
  false, /* isAlwaysInSlot.  Only relevant for getters. */
420
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
421
  false,  /* isTypedMethod.  Only relevant for methods. */
422
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
423
};
424
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
425
static_assert(0 < 1, "There is no slot for us");
426
427
static bool
428
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
429
0
{
430
0
  mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
431
0
  // We don't want to preserve if we don't have a wrapper, and we
432
0
  // obviously can't preserve if we're not initialized.
433
0
  if (self && self->GetWrapperPreserveColor()) {
434
0
    PreserveWrapper(self);
435
0
  }
436
0
  return true;
437
0
}
438
439
static void
440
_finalize(js::FreeOp* fop, JSObject* obj)
441
0
{
442
0
  mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
443
0
  if (self) {
444
0
    ClearWrapper(self, self, obj);
445
0
    AddForDeferredFinalization<mozilla::dom::AudioContext>(self);
446
0
  }
447
0
}
448
449
static size_t
450
_objectMoved(JSObject* obj, JSObject* old)
451
0
{
452
0
  mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
453
0
  if (self) {
454
0
    UpdateWrapper(self, self, obj, old);
455
0
  }
456
0
457
0
  return 0;
458
0
}
459
460
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
461
#if defined(__clang__)
462
#pragma clang diagnostic push
463
#pragma clang diagnostic ignored "-Wmissing-braces"
464
#endif
465
static const JSFunctionSpec sMethods_specs[] = {
466
  JS_FNSPEC("suspend", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&suspend_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
467
  JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
468
  JS_FNSPEC("createMediaElementSource", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createMediaElementSource_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
469
  JS_FNSPEC("createMediaStreamSource", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createMediaStreamSource_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
470
  JS_FNSPEC("createMediaStreamDestination", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createMediaStreamDestination_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
471
  JS_FS_END
472
};
473
#if defined(__clang__)
474
#pragma clang diagnostic pop
475
#endif
476
477
478
static const Prefable<const JSFunctionSpec> sMethods[] = {
479
  { nullptr, &sMethods_specs[0] },
480
  { nullptr, nullptr }
481
};
482
483
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
484
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
485
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
486
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
487
488
489
static uint16_t sNativeProperties_sortedPropertyIndices[5];
490
static PropertyInfo sNativeProperties_propertyInfos[5];
491
492
static const NativePropertiesN<1> sNativeProperties = {
493
  false, 0,
494
  false, 0,
495
  true,  0 /* sMethods */,
496
  false, 0,
497
  false, 0,
498
  false, 0,
499
  false, 0,
500
  -1,
501
  5,
502
  sNativeProperties_sortedPropertyIndices,
503
  {
504
    { sMethods, &sNativeProperties_propertyInfos[0] }
505
  }
506
};
507
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
508
    "We have a property info count that is oversized");
509
510
static bool
511
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
512
0
{
513
0
  AUTO_PROFILER_LABEL_FAST("AudioContext constructor", DOM, cx);
514
0
515
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
516
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
517
0
  if (!args.isConstructing()) {
518
0
    // XXXbz wish I could get the name from the callee instead of
519
0
    // Adding more relocations
520
0
    return ThrowConstructorWithoutNew(cx, "AudioContext");
521
0
  }
522
0
523
0
  JS::Rooted<JSObject*> desiredProto(cx);
524
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
525
0
    return false;
526
0
  }
527
0
528
0
  GlobalObject global(cx, obj);
529
0
  if (global.Failed()) {
530
0
    return false;
531
0
  }
532
0
533
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
534
0
  binding_detail::FastAudioContextOptions arg0;
535
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of AudioContext.constructor", false)) {
536
0
    return false;
537
0
  }
538
0
  Maybe<JSAutoRealm> ar;
539
0
  if (objIsXray) {
540
0
    obj = js::CheckedUnwrap(obj);
541
0
    if (!obj) {
542
0
      return false;
543
0
    }
544
0
    ar.emplace(cx, obj);
545
0
    if (!JS_WrapObject(cx, &desiredProto)) {
546
0
      return false;
547
0
    }
548
0
  }
549
0
  FastErrorResult rv;
550
0
  auto result(StrongOrRawPtr<mozilla::dom::AudioContext>(mozilla::dom::AudioContext::Constructor(global, Constify(arg0), rv)));
551
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
552
0
    return false;
553
0
  }
554
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
555
0
  static_assert(!IsPointer<decltype(result)>::value,
556
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
557
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
558
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
559
0
    return false;
560
0
  }
561
0
  return true;
562
0
}
563
564
static const js::ClassOps sInterfaceObjectClassOps = {
565
    nullptr,               /* addProperty */
566
    nullptr,               /* delProperty */
567
    nullptr,               /* enumerate */
568
    nullptr,               /* newEnumerate */
569
    nullptr,               /* resolve */
570
    nullptr,               /* mayResolve */
571
    nullptr,               /* finalize */
572
    _constructor, /* call */
573
    nullptr,               /* hasInstance */
574
    _constructor, /* construct */
575
    nullptr,               /* trace */
576
};
577
578
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
579
  {
580
    "Function",
581
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
582
    &sInterfaceObjectClassOps,
583
    JS_NULL_CLASS_SPEC,
584
    JS_NULL_CLASS_EXT,
585
    &sInterfaceObjectClassObjectOps
586
  },
587
  eInterface,
588
  true,
589
  prototypes::id::AudioContext,
590
  PrototypeTraits<prototypes::id::AudioContext>::Depth,
591
  sNativePropertyHooks,
592
  "function AudioContext() {\n    [native code]\n}",
593
  BaseAudioContext_Binding::GetConstructorObject
594
};
595
596
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
597
  {
598
    "AudioContextPrototype",
599
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
600
    JS_NULL_CLASS_OPS,
601
    JS_NULL_CLASS_SPEC,
602
    JS_NULL_CLASS_EXT,
603
    JS_NULL_OBJECT_OPS
604
  },
605
  eInterfacePrototype,
606
  false,
607
  prototypes::id::AudioContext,
608
  PrototypeTraits<prototypes::id::AudioContext>::Depth,
609
  sNativePropertyHooks,
610
  "[object AudioContextPrototype]",
611
  BaseAudioContext_Binding::GetProtoObject
612
};
613
614
bool
615
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
616
0
{
617
0
  static bool sPrefValue;
618
0
  static bool sPrefCacheSetUp = false;
619
0
  if (!sPrefCacheSetUp) {
620
0
    sPrefCacheSetUp = true;
621
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
622
0
  }
623
0
624
0
  return sPrefValue;
625
0
}
626
627
static const js::ClassOps sClassOps = {
628
  _addProperty, /* addProperty */
629
  nullptr,               /* delProperty */
630
  nullptr,               /* enumerate */
631
  nullptr, /* newEnumerate */
632
  nullptr, /* resolve */
633
  nullptr, /* mayResolve */
634
  _finalize, /* finalize */
635
  nullptr, /* call */
636
  nullptr,               /* hasInstance */
637
  nullptr,               /* construct */
638
  nullptr, /* trace */
639
};
640
641
static const js::ClassExtension sClassExtension = {
642
  nullptr, /* weakmapKeyDelegateOp */
643
  _objectMoved /* objectMovedOp */
644
};
645
646
static const DOMJSClass sClass = {
647
  { "AudioContext",
648
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
649
    &sClassOps,
650
    JS_NULL_CLASS_SPEC,
651
    &sClassExtension,
652
    JS_NULL_OBJECT_OPS
653
  },
654
  { prototypes::id::EventTarget, prototypes::id::BaseAudioContext, prototypes::id::AudioContext, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
655
  IsBaseOf<nsISupports, mozilla::dom::AudioContext >::value,
656
  sNativePropertyHooks,
657
  FindAssociatedGlobalForNative<mozilla::dom::AudioContext>::Get,
658
  GetProtoObjectHandle,
659
  GetCCParticipant<mozilla::dom::AudioContext>::Get()
660
};
661
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
662
              "Must have the right minimal number of reserved slots.");
663
static_assert(1 >= 1,
664
              "Must have enough reserved slots.");
665
666
const JSClass*
667
GetJSClass()
668
0
{
669
0
  return sClass.ToJSClass();
670
0
}
671
672
bool
673
Wrap(JSContext* aCx, mozilla::dom::AudioContext* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
674
0
{
675
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::AudioContext>::value,
676
0
                "Shouldn't have wrappercached things that are not refcounted.");
677
0
  MOZ_ASSERT(static_cast<mozilla::dom::AudioContext*>(aObject) ==
678
0
             reinterpret_cast<mozilla::dom::AudioContext*>(aObject),
679
0
             "Multiple inheritance for mozilla::dom::AudioContext is broken.");
680
0
  MOZ_ASSERT(static_cast<mozilla::dom::AudioContext*>(aObject) ==
681
0
             reinterpret_cast<mozilla::dom::AudioContext*>(aObject),
682
0
             "Multiple inheritance for mozilla::dom::AudioContext is broken.");
683
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
684
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
685
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
686
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
687
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
688
0
  MOZ_ASSERT(!aCache->GetWrapper(),
689
0
             "You should probably not be using Wrap() directly; use "
690
0
             "GetOrCreateDOMReflector instead");
691
0
692
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
693
0
             "nsISupports must be on our primary inheritance chain");
694
0
695
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
696
0
  if (!global) {
697
0
    return false;
698
0
  }
699
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
700
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
701
0
702
0
  // That might have ended up wrapping us already, due to the wonders
703
0
  // of XBL.  Check for that, and bail out as needed.
704
0
  aReflector.set(aCache->GetWrapper());
705
0
  if (aReflector) {
706
#ifdef DEBUG
707
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
708
#endif // DEBUG
709
    return true;
710
0
  }
711
0
712
0
  JSAutoRealm ar(aCx, global);
713
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
714
0
  if (!canonicalProto) {
715
0
    return false;
716
0
  }
717
0
  JS::Rooted<JSObject*> proto(aCx);
718
0
  if (aGivenProto) {
719
0
    proto = aGivenProto;
720
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
721
0
    // coming in, we changed compartments to that of "parent" so may need
722
0
    // to wrap the proto here.
723
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
724
0
      if (!JS_WrapObject(aCx, &proto)) {
725
0
        return false;
726
0
      }
727
0
    }
728
0
  } else {
729
0
    proto = canonicalProto;
730
0
  }
731
0
732
0
  BindingJSObjectCreator<mozilla::dom::AudioContext> creator(aCx);
733
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
734
0
  if (!aReflector) {
735
0
    return false;
736
0
  }
737
0
738
0
  aCache->SetWrapper(aReflector);
739
0
  creator.InitializationSucceeded();
740
0
741
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
742
0
             aCache->GetWrapperPreserveColor() == aReflector);
743
0
  // If proto != canonicalProto, we have to preserve our wrapper;
744
0
  // otherwise we won't be able to properly recreate it later, since
745
0
  // we won't know what proto to use.  Note that we don't check
746
0
  // aGivenProto here, since it's entirely possible (and even
747
0
  // somewhat common) to have a non-null aGivenProto which is the
748
0
  // same as canonicalProto.
749
0
  if (proto != canonicalProto) {
750
0
    PreserveWrapper(aObject);
751
0
  }
752
0
753
0
  return true;
754
0
}
755
756
const NativePropertyHooks sNativePropertyHooks[] = { {
757
  nullptr,
758
  nullptr,
759
  nullptr,
760
  { sNativeProperties.Upcast(), nullptr },
761
  prototypes::id::AudioContext,
762
  constructors::id::AudioContext,
763
  BaseAudioContext_Binding::sNativePropertyHooks,
764
  &DefaultXrayExpandoObjectClass
765
} };
766
767
void
768
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
769
0
{
770
0
  JS::Handle<JSObject*> parentProto(BaseAudioContext_Binding::GetProtoObjectHandle(aCx));
771
0
  if (!parentProto) {
772
0
    return;
773
0
  }
774
0
775
0
  JS::Handle<JSObject*> constructorProto(BaseAudioContext_Binding::GetConstructorObjectHandle(aCx));
776
0
  if (!constructorProto) {
777
0
    return;
778
0
  }
779
0
780
0
  static bool sIdsInited = false;
781
0
  if (!sIdsInited && NS_IsMainThread()) {
782
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
783
0
      return;
784
0
    }
785
0
    sIdsInited = true;
786
0
  }
787
0
788
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::AudioContext);
789
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AudioContext);
790
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
791
0
                              &sPrototypeClass.mBase, protoCache,
792
0
                              nullptr,
793
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
794
0
                              interfaceCache,
795
0
                              sNativeProperties.Upcast(),
796
0
                              nullptr,
797
0
                              "AudioContext", aDefineOnGlobal,
798
0
                              nullptr,
799
0
                              false);
800
0
}
801
802
JSObject*
803
GetConstructorObject(JSContext* aCx)
804
0
{
805
0
  return GetConstructorObjectHandle(aCx);
806
0
}
807
808
} // namespace AudioContext_Binding
809
810
811
812
} // namespace dom
813
} // namespace mozilla