Coverage Report

Created: 2018-09-25 14:53

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