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