Coverage Report

Created: 2018-09-25 14:53

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