Coverage Report

Created: 2018-09-25 14:53

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