Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/RTCDTMFSenderBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM RTCDTMFSender.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventHandlerBinding.h"
5
#include "EventTargetBinding.h"
6
#include "RTCDTMFSenderBinding.h"
7
#include "WrapperFactory.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/Nullable.h"
13
#include "mozilla/dom/PrimitiveConversions.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
#include "nsContentUtils.h"
16
#include "nsIGlobalObject.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
namespace RTCDTMFSender_Binding {
26
27
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
28
              "Can't inherit from an interface with a different ownership model.");
29
30
MOZ_CAN_RUN_SCRIPT static bool
31
insertDTMF(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCDTMFSender* self, const JSJitMethodCallArgs& args)
32
0
{
33
0
  AUTO_PROFILER_LABEL_FAST("RTCDTMFSender.insertDTMF", DOM, cx);
34
0
35
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
36
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCDTMFSender.insertDTMF");
37
0
  }
38
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
39
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
40
0
  if (objIsXray) {
41
0
    unwrappedObj.emplace(cx, obj);
42
0
  }
43
0
  binding_detail::FakeString arg0;
44
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
45
0
    return false;
46
0
  }
47
0
  uint32_t arg1;
48
0
  if (args.hasDefined(1)) {
49
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
50
0
      return false;
51
0
    }
52
0
  } else {
53
0
    arg1 = 100U;
54
0
  }
55
0
  uint32_t arg2;
56
0
  if (args.hasDefined(2)) {
57
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2)) {
58
0
      return false;
59
0
    }
60
0
  } else {
61
0
    arg2 = 70U;
62
0
  }
63
0
  if (objIsXray) {
64
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
65
0
    if (!unwrappedObj.ref()) {
66
0
      return false;
67
0
    }
68
0
  }
69
0
  FastErrorResult rv;
70
0
  self->InsertDTMF(NonNullHelper(Constify(arg0)), arg1, arg2, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
71
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
72
0
    return false;
73
0
  }
74
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
75
0
  args.rval().setUndefined();
76
0
  return true;
77
0
}
78
79
static const JSJitInfo insertDTMF_methodinfo = {
80
  { (JSJitGetterOp)insertDTMF },
81
  { prototypes::id::RTCDTMFSender },
82
  { PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth },
83
  JSJitInfo::Method,
84
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
85
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
86
  false,  /* isInfallible. False in setters. */
87
  false,  /* isMovable.  Not relevant for setters. */
88
  false, /* isEliminatable.  Not relevant for setters. */
89
  false, /* isAlwaysInSlot.  Only relevant for getters. */
90
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
91
  false,  /* isTypedMethod.  Only relevant for methods. */
92
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
93
};
94
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
95
static_assert(0 < 1, "There is no slot for us");
96
97
MOZ_CAN_RUN_SCRIPT static bool
98
get_ontonechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCDTMFSender* self, JSJitGetterCallArgs args)
99
0
{
100
0
  AUTO_PROFILER_LABEL_FAST("get RTCDTMFSender.ontonechange", DOM, cx);
101
0
102
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
103
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
104
0
  if (objIsXray) {
105
0
    unwrappedObj.emplace(cx, obj);
106
0
  }
107
0
  if (objIsXray) {
108
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
109
0
    if (!unwrappedObj.ref()) {
110
0
      return false;
111
0
    }
112
0
  }
113
0
  FastErrorResult rv;
114
0
  RefPtr<EventHandlerNonNull> result(self->GetOntonechange(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
115
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
116
0
    return false;
117
0
  }
118
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
119
0
  if (result) {
120
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
121
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
122
0
      return false;
123
0
    }
124
0
    return true;
125
0
  } else {
126
0
    args.rval().setNull();
127
0
    return true;
128
0
  }
129
0
}
130
131
MOZ_CAN_RUN_SCRIPT static bool
132
set_ontonechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCDTMFSender* self, JSJitSetterCallArgs args)
133
0
{
134
0
  AUTO_PROFILER_LABEL_FAST("set RTCDTMFSender.ontonechange", DOM, cx);
135
0
136
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
137
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
138
0
  if (objIsXray) {
139
0
    unwrappedObj.emplace(cx, obj);
140
0
  }
141
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
142
0
  if (args[0].isObject()) {
143
0
    { // scope for tempRoot and tempGlobalRoot if needed
144
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
145
0
    }
146
0
  } else {
147
0
    arg0 = nullptr;
148
0
  }
149
0
  if (objIsXray) {
150
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
151
0
    if (!unwrappedObj.ref()) {
152
0
      return false;
153
0
    }
154
0
  }
155
0
  FastErrorResult rv;
156
0
  self->SetOntonechange(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
157
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
158
0
    return false;
159
0
  }
160
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
161
0
162
0
  return true;
163
0
}
164
165
static const JSJitInfo ontonechange_getterinfo = {
166
  { (JSJitGetterOp)get_ontonechange },
167
  { prototypes::id::RTCDTMFSender },
168
  { PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth },
169
  JSJitInfo::Getter,
170
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
171
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
172
  false,  /* isInfallible. False in setters. */
173
  false,  /* isMovable.  Not relevant for setters. */
174
  false, /* isEliminatable.  Not relevant for setters. */
175
  false, /* isAlwaysInSlot.  Only relevant for getters. */
176
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
177
  false,  /* isTypedMethod.  Only relevant for methods. */
178
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
179
};
180
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
181
static_assert(0 < 1, "There is no slot for us");
182
static const JSJitInfo ontonechange_setterinfo = {
183
  { (JSJitGetterOp)set_ontonechange },
184
  { prototypes::id::RTCDTMFSender },
185
  { PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth },
186
  JSJitInfo::Setter,
187
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
188
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
189
  false,  /* isInfallible. False in setters. */
190
  false,  /* isMovable.  Not relevant for setters. */
191
  false, /* isEliminatable.  Not relevant for setters. */
192
  false, /* isAlwaysInSlot.  Only relevant for getters. */
193
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
194
  false,  /* isTypedMethod.  Only relevant for methods. */
195
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
196
};
197
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
198
static_assert(0 < 1, "There is no slot for us");
199
200
MOZ_CAN_RUN_SCRIPT static bool
201
get_toneBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCDTMFSender* self, JSJitGetterCallArgs args)
202
0
{
203
0
  AUTO_PROFILER_LABEL_FAST("get RTCDTMFSender.toneBuffer", DOM, cx);
204
0
205
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
206
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
207
0
  if (objIsXray) {
208
0
    unwrappedObj.emplace(cx, obj);
209
0
  }
210
0
  if (objIsXray) {
211
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
212
0
    if (!unwrappedObj.ref()) {
213
0
      return false;
214
0
    }
215
0
  }
216
0
  FastErrorResult rv;
217
0
  DOMString result;
218
0
  self->GetToneBuffer(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
219
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
220
0
    return false;
221
0
  }
222
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
223
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
224
0
    return false;
225
0
  }
226
0
  return true;
227
0
}
228
229
static const JSJitInfo toneBuffer_getterinfo = {
230
  { (JSJitGetterOp)get_toneBuffer },
231
  { prototypes::id::RTCDTMFSender },
232
  { PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth },
233
  JSJitInfo::Getter,
234
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
235
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
236
  false,  /* isInfallible. False in setters. */
237
  false,  /* isMovable.  Not relevant for setters. */
238
  false, /* isEliminatable.  Not relevant for setters. */
239
  false, /* isAlwaysInSlot.  Only relevant for getters. */
240
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
241
  false,  /* isTypedMethod.  Only relevant for methods. */
242
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
243
};
244
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
245
static_assert(0 < 1, "There is no slot for us");
246
247
static bool
248
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
249
0
{
250
0
  mozilla::dom::RTCDTMFSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCDTMFSender>(obj);
251
0
  // We don't want to preserve if we don't have a wrapper, and we
252
0
  // obviously can't preserve if we're not initialized.
253
0
  if (self && self->GetWrapperPreserveColor()) {
254
0
    PreserveWrapper(self);
255
0
  }
256
0
  return true;
257
0
}
258
259
static void
260
_finalize(js::FreeOp* fop, JSObject* obj)
261
0
{
262
0
  mozilla::dom::RTCDTMFSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCDTMFSender>(obj);
263
0
  if (self) {
264
0
    ClearWrapper(self, self, obj);
265
0
    AddForDeferredFinalization<mozilla::dom::RTCDTMFSender>(self);
266
0
  }
267
0
}
268
269
static size_t
270
_objectMoved(JSObject* obj, JSObject* old)
271
0
{
272
0
  mozilla::dom::RTCDTMFSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCDTMFSender>(obj);
273
0
  if (self) {
274
0
    UpdateWrapper(self, self, obj, old);
275
0
  }
276
0
277
0
  return 0;
278
0
}
279
280
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
281
#if defined(__clang__)
282
#pragma clang diagnostic push
283
#pragma clang diagnostic ignored "-Wmissing-braces"
284
#endif
285
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
286
  JS_FNSPEC("_create", RTCDTMFSender::_Create, nullptr, 2, 0, nullptr),
287
  JS_FS_END
288
};
289
#if defined(__clang__)
290
#pragma clang diagnostic pop
291
#endif
292
293
294
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
295
  { nullptr, &sChromeStaticMethods_specs[0] },
296
  { nullptr, nullptr }
297
};
298
299
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
300
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
301
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
302
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
303
304
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
305
#if defined(__clang__)
306
#pragma clang diagnostic push
307
#pragma clang diagnostic ignored "-Wmissing-braces"
308
#endif
309
static const JSFunctionSpec sMethods_specs[] = {
310
  JS_FNSPEC("insertDTMF", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&insertDTMF_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
311
  JS_FS_END
312
};
313
#if defined(__clang__)
314
#pragma clang diagnostic pop
315
#endif
316
317
318
static const Prefable<const JSFunctionSpec> sMethods[] = {
319
  { nullptr, &sMethods_specs[0] },
320
  { nullptr, nullptr }
321
};
322
323
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
324
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
325
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
326
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
327
328
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
329
#if defined(__clang__)
330
#pragma clang diagnostic push
331
#pragma clang diagnostic ignored "-Wmissing-braces"
332
#endif
333
static const JSPropertySpec sAttributes_specs[] = {
334
  { "ontonechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ontonechange_getterinfo, GenericSetter<NormalThisPolicy>, &ontonechange_setterinfo },
335
  { "toneBuffer", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &toneBuffer_getterinfo, nullptr, nullptr },
336
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
337
};
338
#if defined(__clang__)
339
#pragma clang diagnostic pop
340
#endif
341
342
343
static const Prefable<const JSPropertySpec> sAttributes[] = {
344
  { nullptr, &sAttributes_specs[0] },
345
  { nullptr, nullptr }
346
};
347
348
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
349
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
350
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
351
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
352
353
354
static uint16_t sNativeProperties_sortedPropertyIndices[3];
355
static PropertyInfo sNativeProperties_propertyInfos[3];
356
357
static const NativePropertiesN<2> sNativeProperties = {
358
  false, 0,
359
  false, 0,
360
  true,  0 /* sMethods */,
361
  true,  1 /* sAttributes */,
362
  false, 0,
363
  false, 0,
364
  false, 0,
365
  -1,
366
  3,
367
  sNativeProperties_sortedPropertyIndices,
368
  {
369
    { sMethods, &sNativeProperties_propertyInfos[0] },
370
    { sAttributes, &sNativeProperties_propertyInfos[1] }
371
  }
372
};
373
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
374
    "We have a property info count that is oversized");
375
376
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
377
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
378
379
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
380
  true,  0 /* sChromeStaticMethods */,
381
  false, 0,
382
  false, 0,
383
  false, 0,
384
  false, 0,
385
  false, 0,
386
  false, 0,
387
  -1,
388
  1,
389
  sChromeOnlyNativeProperties_sortedPropertyIndices,
390
  {
391
    { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
392
  }
393
};
394
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
395
    "We have a property info count that is oversized");
396
397
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
398
  {
399
    "Function",
400
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
401
    &sBoringInterfaceObjectClassClassOps,
402
    JS_NULL_CLASS_SPEC,
403
    JS_NULL_CLASS_EXT,
404
    &sInterfaceObjectClassObjectOps
405
  },
406
  eInterface,
407
  true,
408
  prototypes::id::RTCDTMFSender,
409
  PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth,
410
  sNativePropertyHooks,
411
  "function RTCDTMFSender() {\n    [native code]\n}",
412
  EventTarget_Binding::GetConstructorObject
413
};
414
415
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
416
  {
417
    "RTCDTMFSenderPrototype",
418
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
419
    JS_NULL_CLASS_OPS,
420
    JS_NULL_CLASS_SPEC,
421
    JS_NULL_CLASS_EXT,
422
    JS_NULL_OBJECT_OPS
423
  },
424
  eInterfacePrototype,
425
  false,
426
  prototypes::id::RTCDTMFSender,
427
  PrototypeTraits<prototypes::id::RTCDTMFSender>::Depth,
428
  sNativePropertyHooks,
429
  "[object RTCDTMFSenderPrototype]",
430
  EventTarget_Binding::GetProtoObject
431
};
432
433
static const js::ClassOps sClassOps = {
434
  _addProperty, /* addProperty */
435
  nullptr,               /* delProperty */
436
  nullptr,               /* enumerate */
437
  nullptr, /* newEnumerate */
438
  nullptr, /* resolve */
439
  nullptr, /* mayResolve */
440
  _finalize, /* finalize */
441
  nullptr, /* call */
442
  nullptr,               /* hasInstance */
443
  nullptr,               /* construct */
444
  nullptr, /* trace */
445
};
446
447
static const js::ClassExtension sClassExtension = {
448
  nullptr, /* weakmapKeyDelegateOp */
449
  _objectMoved /* objectMovedOp */
450
};
451
452
static const DOMJSClass sClass = {
453
  { "RTCDTMFSender",
454
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
455
    &sClassOps,
456
    JS_NULL_CLASS_SPEC,
457
    &sClassExtension,
458
    JS_NULL_OBJECT_OPS
459
  },
460
  { prototypes::id::EventTarget, prototypes::id::RTCDTMFSender, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
461
  IsBaseOf<nsISupports, mozilla::dom::RTCDTMFSender >::value,
462
  sNativePropertyHooks,
463
  FindAssociatedGlobalForNative<mozilla::dom::RTCDTMFSender>::Get,
464
  GetProtoObjectHandle,
465
  GetCCParticipant<mozilla::dom::RTCDTMFSender>::Get()
466
};
467
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
468
              "Must have the right minimal number of reserved slots.");
469
static_assert(1 >= 1,
470
              "Must have enough reserved slots.");
471
472
const JSClass*
473
GetJSClass()
474
0
{
475
0
  return sClass.ToJSClass();
476
0
}
477
478
bool
479
Wrap(JSContext* aCx, mozilla::dom::RTCDTMFSender* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
480
0
{
481
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::RTCDTMFSender>::value,
482
0
                "Shouldn't have wrappercached things that are not refcounted.");
483
0
  MOZ_ASSERT(static_cast<mozilla::dom::RTCDTMFSender*>(aObject) ==
484
0
             reinterpret_cast<mozilla::dom::RTCDTMFSender*>(aObject),
485
0
             "Multiple inheritance for mozilla::dom::RTCDTMFSender is broken.");
486
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
487
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
488
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
489
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
490
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
491
0
  MOZ_ASSERT(!aCache->GetWrapper(),
492
0
             "You should probably not be using Wrap() directly; use "
493
0
             "GetOrCreateDOMReflector instead");
494
0
495
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
496
0
             "nsISupports must be on our primary inheritance chain");
497
0
498
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
499
0
  if (!global) {
500
0
    return false;
501
0
  }
502
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
503
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
504
0
505
0
  // That might have ended up wrapping us already, due to the wonders
506
0
  // of XBL.  Check for that, and bail out as needed.
507
0
  aReflector.set(aCache->GetWrapper());
508
0
  if (aReflector) {
509
#ifdef DEBUG
510
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
511
#endif // DEBUG
512
    return true;
513
0
  }
514
0
515
0
  JSAutoRealm ar(aCx, global);
516
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
517
0
  if (!canonicalProto) {
518
0
    return false;
519
0
  }
520
0
  JS::Rooted<JSObject*> proto(aCx);
521
0
  if (aGivenProto) {
522
0
    proto = aGivenProto;
523
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
524
0
    // coming in, we changed compartments to that of "parent" so may need
525
0
    // to wrap the proto here.
526
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
527
0
      if (!JS_WrapObject(aCx, &proto)) {
528
0
        return false;
529
0
      }
530
0
    }
531
0
  } else {
532
0
    proto = canonicalProto;
533
0
  }
534
0
535
0
  BindingJSObjectCreator<mozilla::dom::RTCDTMFSender> creator(aCx);
536
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
537
0
  if (!aReflector) {
538
0
    return false;
539
0
  }
540
0
541
0
  aCache->SetWrapper(aReflector);
542
0
  creator.InitializationSucceeded();
543
0
544
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
545
0
             aCache->GetWrapperPreserveColor() == aReflector);
546
0
  // If proto != canonicalProto, we have to preserve our wrapper;
547
0
  // otherwise we won't be able to properly recreate it later, since
548
0
  // we won't know what proto to use.  Note that we don't check
549
0
  // aGivenProto here, since it's entirely possible (and even
550
0
  // somewhat common) to have a non-null aGivenProto which is the
551
0
  // same as canonicalProto.
552
0
  if (proto != canonicalProto) {
553
0
    PreserveWrapper(aObject);
554
0
  }
555
0
556
0
  return true;
557
0
}
558
559
const NativePropertyHooks sNativePropertyHooks[] = { {
560
  nullptr,
561
  nullptr,
562
  nullptr,
563
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
564
  prototypes::id::RTCDTMFSender,
565
  constructors::id::RTCDTMFSender,
566
  EventTarget_Binding::sNativePropertyHooks,
567
  &DefaultXrayExpandoObjectClass
568
} };
569
570
void
571
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
572
0
{
573
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
574
0
  if (!parentProto) {
575
0
    return;
576
0
  }
577
0
578
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
579
0
  if (!constructorProto) {
580
0
    return;
581
0
  }
582
0
583
0
  static bool sIdsInited = false;
584
0
  if (!sIdsInited && NS_IsMainThread()) {
585
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
586
0
      return;
587
0
    }
588
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
589
0
      return;
590
0
    }
591
0
    sIdsInited = true;
592
0
  }
593
0
594
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCDTMFSender);
595
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::RTCDTMFSender);
596
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
597
0
                              &sPrototypeClass.mBase, protoCache,
598
0
                              nullptr,
599
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
600
0
                              interfaceCache,
601
0
                              sNativeProperties.Upcast(),
602
0
                              sChromeOnlyNativeProperties.Upcast(),
603
0
                              "RTCDTMFSender", 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 RTCDTMFSender_Binding
615
616
617
618
void
619
RTCDTMFSenderJSImpl::InsertDTMF(const nsAString& tones, uint32_t duration, uint32_t interToneGap, ErrorResult& aRv, JS::Realm* aRealm)
620
0
{
621
0
  CallSetup s(this, aRv, "RTCDTMFSender.insertDTMF", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
622
0
  JSContext* cx = s.GetContext();
623
0
  if (!cx) {
624
0
    MOZ_ASSERT(aRv.Failed());
625
0
    return;
626
0
  }
627
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
628
0
  JS::AutoValueVector argv(cx);
629
0
  if (!argv.resize(3)) {
630
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
631
0
    return;
632
0
  }
633
0
  unsigned argc = 3;
634
0
635
0
  do {
636
0
    argv[2].setNumber(interToneGap);
637
0
    break;
638
0
  } while (false);
639
0
640
0
  do {
641
0
    argv[1].setNumber(duration);
642
0
    break;
643
0
  } while (false);
644
0
645
0
  do {
646
0
    nsString mutableStr(tones);
647
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
648
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
649
0
      return;
650
0
    }
651
0
    break;
652
0
  } while (false);
653
0
654
0
  JS::Rooted<JS::Value> callable(cx);
655
0
  RTCDTMFSenderAtoms* atomsCache = GetAtomCache<RTCDTMFSenderAtoms>(cx);
656
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
657
0
      !GetCallableProperty(cx, atomsCache->insertDTMF_id, &callable)) {
658
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
659
0
    return;
660
0
  }
661
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
662
0
  if (!JS::Call(cx, thisValue, callable,
663
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
664
0
    aRv.NoteJSContextException(cx);
665
0
    return;
666
0
  }
667
0
}
668
669
bool
670
RTCDTMFSenderJSImpl::InitIds(JSContext* cx, RTCDTMFSenderAtoms* atomsCache)
671
0
{
672
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
673
0
674
0
  // Initialize these in reverse order so that any failure leaves the first one
675
0
  // uninitialized.
676
0
  if (!atomsCache->toneBuffer_id.init(cx, "toneBuffer") ||
677
0
      !atomsCache->ontonechange_id.init(cx, "ontonechange") ||
678
0
      !atomsCache->insertDTMF_id.init(cx, "insertDTMF")) {
679
0
    return false;
680
0
  }
681
0
  return true;
682
0
}
683
684
685
already_AddRefed<EventHandlerNonNull>
686
RTCDTMFSenderJSImpl::GetOntonechange(ErrorResult& aRv, JS::Realm* aRealm)
687
0
{
688
0
  CallSetup s(this, aRv, "RTCDTMFSender.ontonechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
689
0
  JSContext* cx = s.GetContext();
690
0
  if (!cx) {
691
0
    MOZ_ASSERT(aRv.Failed());
692
0
    return nullptr;
693
0
  }
694
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
695
0
696
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
697
0
  RTCDTMFSenderAtoms* atomsCache = GetAtomCache<RTCDTMFSenderAtoms>(cx);
698
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
699
0
      !JS_GetPropertyById(cx, callback, atomsCache->ontonechange_id, &rval)) {
700
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
701
0
    return nullptr;
702
0
  }
703
0
  RefPtr<EventHandlerNonNull> rvalDecl;
704
0
  if (rval.isObject()) {
705
0
    { // scope for tempRoot and tempGlobalRoot if needed
706
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
707
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
708
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
709
0
    }
710
0
  } else {
711
0
    rvalDecl = nullptr;
712
0
  }
713
0
  return rvalDecl.forget();
714
0
}
715
716
void
717
RTCDTMFSenderJSImpl::GetToneBuffer(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
718
0
{
719
0
  CallSetup s(this, aRv, "RTCDTMFSender.toneBuffer", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
720
0
  JSContext* cx = s.GetContext();
721
0
  if (!cx) {
722
0
    MOZ_ASSERT(aRv.Failed());
723
0
    return;
724
0
  }
725
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
726
0
727
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
728
0
  RTCDTMFSenderAtoms* atomsCache = GetAtomCache<RTCDTMFSenderAtoms>(cx);
729
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
730
0
      !JS_GetPropertyById(cx, callback, atomsCache->toneBuffer_id, &rval)) {
731
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
732
0
    return;
733
0
  }
734
0
  binding_detail::FakeString rvalDecl;
735
0
  if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
736
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
737
0
    return;
738
0
  }
739
0
  aRetVal = rvalDecl;
740
0
}
741
742
void
743
RTCDTMFSenderJSImpl::SetOntonechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
744
0
{
745
0
  CallSetup s(this, aRv, "RTCDTMFSender.ontonechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
746
0
  JSContext* cx = s.GetContext();
747
0
  if (!cx) {
748
0
    MOZ_ASSERT(aRv.Failed());
749
0
    return;
750
0
  }
751
0
  JS::AutoValueVector argv(cx);
752
0
  if (!argv.resize(1)) {
753
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
754
0
    return;
755
0
  }
756
0
  do {
757
0
    if (arg) {
758
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
759
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
760
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
761
0
        return;
762
0
      }
763
0
      break;
764
0
    } else {
765
0
      argv[0].setNull();
766
0
      break;
767
0
    }
768
0
  } while (false);
769
0
770
0
  MOZ_ASSERT(argv.length() == 1);
771
0
  RTCDTMFSenderAtoms* atomsCache = GetAtomCache<RTCDTMFSenderAtoms>(cx);
772
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
773
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->ontonechange_id, argv[0])) {
774
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
775
0
    return;
776
0
  }
777
0
}
778
779
780
NS_IMPL_CYCLE_COLLECTION_INHERITED(RTCDTMFSender, mozilla::DOMEventTargetHelper, mImpl, mParent)
781
NS_IMPL_ADDREF_INHERITED(RTCDTMFSender, mozilla::DOMEventTargetHelper)
782
NS_IMPL_RELEASE_INHERITED(RTCDTMFSender, mozilla::DOMEventTargetHelper)
783
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RTCDTMFSender)
784
0
NS_INTERFACE_MAP_END_INHERITING(mozilla::DOMEventTargetHelper)
785
786
RTCDTMFSender::RTCDTMFSender(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
787
  : mozilla::DOMEventTargetHelper(aParent),
788
    mImpl(new RTCDTMFSenderJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
789
    mParent(aParent)
790
0
{
791
0
}
792
793
794
RTCDTMFSender::~RTCDTMFSender()
795
0
{
796
0
}
797
798
nsISupports*
799
RTCDTMFSender::GetParentObject() const
800
0
{
801
0
  return mParent;
802
0
}
803
804
JSObject*
805
RTCDTMFSender::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
806
0
{
807
0
  JS::Rooted<JSObject*> obj(aCx, RTCDTMFSender_Binding::Wrap(aCx, this, aGivenProto));
808
0
  if (!obj) {
809
0
    return nullptr;
810
0
  }
811
0
812
0
  // Now define it on our chrome object
813
0
  JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
814
0
  if (!JS_WrapObject(aCx, &obj)) {
815
0
    return nullptr;
816
0
  }
817
0
  if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
818
0
    return nullptr;
819
0
  }
820
0
  return obj;
821
0
}
822
823
void
824
RTCDTMFSender::InsertDTMF(const nsAString& tones, uint32_t duration, uint32_t interToneGap, ErrorResult& aRv, JS::Realm* aRealm)
825
0
{
826
0
  return mImpl->InsertDTMF(tones, duration, interToneGap, aRv, aRealm);
827
0
}
828
829
already_AddRefed<EventHandlerNonNull>
830
RTCDTMFSender::GetOntonechange(ErrorResult& aRv, JS::Realm* aRealm) const
831
0
{
832
0
  return mImpl->GetOntonechange(aRv, aRealm);
833
0
}
834
835
void
836
RTCDTMFSender::SetOntonechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
837
0
{
838
0
  mImpl->SetOntonechange(arg, aRv, aRealm);
839
0
}
840
841
void
842
RTCDTMFSender::GetToneBuffer(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
843
0
{
844
0
  return mImpl->GetToneBuffer(aRetVal, aRv, aRealm);
845
0
}
846
847
bool
848
RTCDTMFSender::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
849
0
{
850
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
851
0
  if (args.length() < 2) {
852
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCDTMFSender._create");
853
0
  }
854
0
  if (!args[0].isObject()) {
855
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCDTMFSender._create");
856
0
  }
857
0
  if (!args[1].isObject()) {
858
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCDTMFSender._create");
859
0
  }
860
0
861
0
  // GlobalObject will go through wrappers as needed for us, and
862
0
  // is simpler than the right UnwrapArg incantation.
863
0
  GlobalObject global(cx, &args[0].toObject());
864
0
  if (global.Failed()) {
865
0
    return false;
866
0
  }
867
0
  nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
868
0
  MOZ_ASSERT(globalHolder);
869
0
  JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
870
0
  JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
871
0
  RefPtr<RTCDTMFSender> impl = new RTCDTMFSender(arg, argGlobal, globalHolder);
872
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
873
0
  return GetOrCreateDOMReflector(cx, impl, args.rval());
874
0
}
875
876
877
} // namespace dom
878
} // namespace mozilla