Coverage Report

Created: 2018-09-25 14:53

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