Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM RTCPeerConnection.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "DOMMediaStream.h"
5 : #include "EventHandlerBinding.h"
6 : #include "EventTargetBinding.h"
7 : #include "FunctionBinding.h"
8 : #include "RTCConfigurationBinding.h"
9 : #include "RTCIceCandidateBinding.h"
10 : #include "RTCPeerConnectionBinding.h"
11 : #include "RTCRtpReceiverBinding.h"
12 : #include "RTCRtpSenderBinding.h"
13 : #include "RTCSessionDescriptionBinding.h"
14 : #include "RTCStatsReportBinding.h"
15 : #include "WrapperFactory.h"
16 : #include "jsapi.h"
17 : #include "mozilla/OwningNonNull.h"
18 : #include "mozilla/Preferences.h"
19 : #include "mozilla/dom/BindingUtils.h"
20 : #include "mozilla/dom/DOMError.h"
21 : #include "mozilla/dom/DOMJSClass.h"
22 : #include "mozilla/dom/MediaStreamTrack.h"
23 : #include "mozilla/dom/NonRefcountedDOMObject.h"
24 : #include "mozilla/dom/Nullable.h"
25 : #include "mozilla/dom/PrimitiveConversions.h"
26 : #include "mozilla/dom/Promise.h"
27 : #include "mozilla/dom/RTCCertificate.h"
28 : #include "mozilla/dom/ScriptSettings.h"
29 : #include "mozilla/dom/SimpleGlobalObject.h"
30 : #include "mozilla/dom/ToJSValue.h"
31 : #include "mozilla/dom/UnionConversions.h"
32 : #include "mozilla/dom/UnionTypes.h"
33 : #include "mozilla/dom/XrayExpandoClass.h"
34 : #include "nsContentUtils.h"
35 : #include "nsIDOMDataChannel.h"
36 : #include "nsIDocument.h"
37 : #include "nsIGlobalObject.h"
38 :
39 : namespace mozilla {
40 : namespace dom {
41 :
42 : namespace RTCSignalingStateValues {
43 : extern const EnumEntry strings[7] = {
44 : {"stable", 6},
45 : {"have-local-offer", 16},
46 : {"have-remote-offer", 17},
47 : {"have-local-pranswer", 19},
48 : {"have-remote-pranswer", 20},
49 : {"closed", 6},
50 : { nullptr, 0 }
51 : };
52 : } // namespace RTCSignalingStateValues
53 :
54 : bool
55 0 : ToJSValue(JSContext* aCx, RTCSignalingState aArgument, JS::MutableHandle<JS::Value> aValue)
56 : {
57 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCSignalingStateValues::strings));
58 : JSString* resultStr =
59 0 : JS_NewStringCopyN(aCx, RTCSignalingStateValues::strings[uint32_t(aArgument)].value,
60 0 : RTCSignalingStateValues::strings[uint32_t(aArgument)].length);
61 0 : if (!resultStr) {
62 0 : return false;
63 : }
64 0 : aValue.setString(resultStr);
65 0 : return true;
66 : }
67 :
68 :
69 : namespace RTCIceGatheringStateValues {
70 : extern const EnumEntry strings[4] = {
71 : {"new", 3},
72 : {"gathering", 9},
73 : {"complete", 8},
74 : { nullptr, 0 }
75 : };
76 : } // namespace RTCIceGatheringStateValues
77 :
78 : bool
79 0 : ToJSValue(JSContext* aCx, RTCIceGatheringState aArgument, JS::MutableHandle<JS::Value> aValue)
80 : {
81 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceGatheringStateValues::strings));
82 : JSString* resultStr =
83 0 : JS_NewStringCopyN(aCx, RTCIceGatheringStateValues::strings[uint32_t(aArgument)].value,
84 0 : RTCIceGatheringStateValues::strings[uint32_t(aArgument)].length);
85 0 : if (!resultStr) {
86 0 : return false;
87 : }
88 0 : aValue.setString(resultStr);
89 0 : return true;
90 : }
91 :
92 :
93 : namespace RTCIceConnectionStateValues {
94 : extern const EnumEntry strings[8] = {
95 : {"new", 3},
96 : {"checking", 8},
97 : {"connected", 9},
98 : {"completed", 9},
99 : {"failed", 6},
100 : {"disconnected", 12},
101 : {"closed", 6},
102 : { nullptr, 0 }
103 : };
104 : } // namespace RTCIceConnectionStateValues
105 :
106 : bool
107 0 : ToJSValue(JSContext* aCx, RTCIceConnectionState aArgument, JS::MutableHandle<JS::Value> aValue)
108 : {
109 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceConnectionStateValues::strings));
110 : JSString* resultStr =
111 0 : JS_NewStringCopyN(aCx, RTCIceConnectionStateValues::strings[uint32_t(aArgument)].value,
112 0 : RTCIceConnectionStateValues::strings[uint32_t(aArgument)].length);
113 0 : if (!resultStr) {
114 0 : return false;
115 : }
116 0 : aValue.setString(resultStr);
117 0 : return true;
118 : }
119 :
120 :
121 : void
122 0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningRTCIceCandidateInitOrRTCIceCandidate& aUnion, const char* aName, uint32_t aFlags)
123 : {
124 0 : if (aUnion.IsRTCIceCandidate()) {
125 0 : ImplCycleCollectionTraverse(aCallback, aUnion.GetAsRTCIceCandidate(), "mRTCIceCandidate", aFlags);
126 : }
127 0 : }
128 :
129 :
130 : void
131 0 : ImplCycleCollectionUnlink(OwningRTCIceCandidateInitOrRTCIceCandidate& aUnion)
132 : {
133 0 : aUnion.Uninit();
134 0 : }
135 :
136 :
137 :
138 0 : RTCDataChannelInit::RTCDataChannelInit()
139 : {
140 : // Safe to pass a null context if we pass a null value
141 0 : Init(nullptr, JS::NullHandleValue);
142 0 : }
143 :
144 :
145 :
146 : bool
147 0 : RTCDataChannelInit::InitIds(JSContext* cx, RTCDataChannelInitAtoms* atomsCache)
148 : {
149 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
150 :
151 : // Initialize these in reverse order so that any failure leaves the first one
152 : // uninitialized.
153 0 : if (!atomsCache->protocol_id.init(cx, "protocol") ||
154 0 : !atomsCache->ordered_id.init(cx, "ordered") ||
155 0 : !atomsCache->negotiated_id.init(cx, "negotiated") ||
156 0 : !atomsCache->maxRetransmits_id.init(cx, "maxRetransmits") ||
157 0 : !atomsCache->maxRetransmitTime_id.init(cx, "maxRetransmitTime") ||
158 0 : !atomsCache->maxPacketLifeTime_id.init(cx, "maxPacketLifeTime") ||
159 0 : !atomsCache->id_id.init(cx, "id")) {
160 0 : return false;
161 : }
162 0 : return true;
163 : }
164 :
165 : bool
166 0 : RTCDataChannelInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
167 : {
168 : // Passing a null JSContext is OK only if we're initing from null,
169 : // Since in that case we will not have to do any property gets
170 : // Also evaluate isNullOrUndefined in order to avoid false-positive
171 : // checkers by static analysis tools
172 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
173 0 : RTCDataChannelInitAtoms* atomsCache = nullptr;
174 0 : if (cx) {
175 0 : atomsCache = GetAtomCache<RTCDataChannelInitAtoms>(cx);
176 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
177 0 : return false;
178 : }
179 : }
180 :
181 0 : if (!IsConvertibleToDictionary(val)) {
182 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
183 : }
184 :
185 0 : bool isNull = val.isNullOrUndefined();
186 : // We only need these if !isNull, in which case we have |cx|.
187 0 : Maybe<JS::Rooted<JSObject *> > object;
188 0 : Maybe<JS::Rooted<JS::Value> > temp;
189 0 : if (!isNull) {
190 0 : MOZ_ASSERT(cx);
191 0 : object.emplace(cx, &val.toObject());
192 0 : temp.emplace(cx);
193 : }
194 0 : if (!isNull) {
195 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
196 0 : return false;
197 : }
198 : }
199 0 : if (!isNull && !temp->isUndefined()) {
200 0 : mId.Construct();
201 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mId.Value()))) {
202 0 : return false;
203 : }
204 0 : mIsAnyMemberPresent = true;
205 : }
206 :
207 0 : if (!isNull) {
208 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->maxPacketLifeTime_id, temp.ptr())) {
209 0 : return false;
210 : }
211 : }
212 0 : if (!isNull && !temp->isUndefined()) {
213 0 : mMaxPacketLifeTime.Construct();
214 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxPacketLifeTime.Value()))) {
215 0 : return false;
216 : }
217 0 : mIsAnyMemberPresent = true;
218 : }
219 :
220 0 : if (!isNull) {
221 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->maxRetransmitTime_id, temp.ptr())) {
222 0 : return false;
223 : }
224 : }
225 0 : if (!isNull && !temp->isUndefined()) {
226 0 : mMaxRetransmitTime.Construct();
227 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxRetransmitTime.Value()))) {
228 0 : return false;
229 : }
230 0 : mIsAnyMemberPresent = true;
231 : }
232 :
233 0 : if (!isNull) {
234 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->maxRetransmits_id, temp.ptr())) {
235 0 : return false;
236 : }
237 : }
238 0 : if (!isNull && !temp->isUndefined()) {
239 0 : mMaxRetransmits.Construct();
240 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxRetransmits.Value()))) {
241 0 : return false;
242 : }
243 0 : mIsAnyMemberPresent = true;
244 : }
245 :
246 0 : if (!isNull) {
247 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->negotiated_id, temp.ptr())) {
248 0 : return false;
249 : }
250 : }
251 0 : if (!isNull && !temp->isUndefined()) {
252 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mNegotiated)) {
253 0 : return false;
254 : }
255 : } else {
256 0 : mNegotiated = false;
257 : }
258 0 : mIsAnyMemberPresent = true;
259 :
260 0 : if (!isNull) {
261 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->ordered_id, temp.ptr())) {
262 0 : return false;
263 : }
264 : }
265 0 : if (!isNull && !temp->isUndefined()) {
266 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mOrdered)) {
267 0 : return false;
268 : }
269 : } else {
270 0 : mOrdered = true;
271 : }
272 0 : mIsAnyMemberPresent = true;
273 :
274 0 : if (!isNull) {
275 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->protocol_id, temp.ptr())) {
276 0 : return false;
277 : }
278 : }
279 0 : if (!isNull && !temp->isUndefined()) {
280 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mProtocol)) {
281 0 : return false;
282 : }
283 : } else {
284 : static const char16_t data[] = { 0 };
285 0 : mProtocol.Rebind(data, ArrayLength(data) - 1);
286 : }
287 0 : mIsAnyMemberPresent = true;
288 0 : return true;
289 : }
290 :
291 : bool
292 0 : RTCDataChannelInit::Init(const nsAString& aJSON)
293 : {
294 0 : AutoJSAPI jsapi;
295 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
296 0 : if (!cleanGlobal) {
297 0 : return false;
298 : }
299 0 : if (!jsapi.Init(cleanGlobal)) {
300 0 : return false;
301 : }
302 0 : JSContext* cx = jsapi.cx();
303 0 : JS::Rooted<JS::Value> json(cx);
304 0 : bool ok = ParseJSON(cx, aJSON, &json);
305 0 : NS_ENSURE_TRUE(ok, false);
306 0 : return Init(cx, json);
307 : }
308 :
309 : bool
310 0 : RTCDataChannelInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
311 : {
312 0 : RTCDataChannelInitAtoms* atomsCache = GetAtomCache<RTCDataChannelInitAtoms>(cx);
313 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
314 0 : return false;
315 : }
316 :
317 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
318 0 : if (!obj) {
319 0 : return false;
320 : }
321 0 : rval.set(JS::ObjectValue(*obj));
322 :
323 0 : if (mId.WasPassed()) {
324 : do {
325 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
326 0 : JS::Rooted<JS::Value> temp(cx);
327 0 : uint16_t const & currentValue = mId.InternalValue();
328 0 : temp.setInt32(int32_t(currentValue));
329 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
330 0 : return false;
331 : }
332 0 : break;
333 : } while(0);
334 : }
335 :
336 0 : if (mMaxPacketLifeTime.WasPassed()) {
337 : do {
338 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
339 0 : JS::Rooted<JS::Value> temp(cx);
340 0 : uint16_t const & currentValue = mMaxPacketLifeTime.InternalValue();
341 0 : temp.setInt32(int32_t(currentValue));
342 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->maxPacketLifeTime_id, temp, JSPROP_ENUMERATE)) {
343 0 : return false;
344 : }
345 0 : break;
346 : } while(0);
347 : }
348 :
349 0 : if (mMaxRetransmitTime.WasPassed()) {
350 : do {
351 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
352 0 : JS::Rooted<JS::Value> temp(cx);
353 0 : uint16_t const & currentValue = mMaxRetransmitTime.InternalValue();
354 0 : temp.setInt32(int32_t(currentValue));
355 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->maxRetransmitTime_id, temp, JSPROP_ENUMERATE)) {
356 0 : return false;
357 : }
358 0 : break;
359 : } while(0);
360 : }
361 :
362 0 : if (mMaxRetransmits.WasPassed()) {
363 : do {
364 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
365 0 : JS::Rooted<JS::Value> temp(cx);
366 0 : uint16_t const & currentValue = mMaxRetransmits.InternalValue();
367 0 : temp.setInt32(int32_t(currentValue));
368 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->maxRetransmits_id, temp, JSPROP_ENUMERATE)) {
369 0 : return false;
370 : }
371 0 : break;
372 : } while(0);
373 : }
374 :
375 : do {
376 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
377 0 : JS::Rooted<JS::Value> temp(cx);
378 0 : bool const & currentValue = mNegotiated;
379 0 : temp.setBoolean(currentValue);
380 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->negotiated_id, temp, JSPROP_ENUMERATE)) {
381 0 : return false;
382 : }
383 0 : break;
384 : } while(0);
385 :
386 : do {
387 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
388 0 : JS::Rooted<JS::Value> temp(cx);
389 0 : bool const & currentValue = mOrdered;
390 0 : temp.setBoolean(currentValue);
391 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->ordered_id, temp, JSPROP_ENUMERATE)) {
392 0 : return false;
393 : }
394 0 : break;
395 : } while(0);
396 :
397 : do {
398 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
399 0 : JS::Rooted<JS::Value> temp(cx);
400 0 : nsString const & currentValue = mProtocol;
401 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
402 0 : return false;
403 : }
404 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->protocol_id, temp, JSPROP_ENUMERATE)) {
405 0 : return false;
406 : }
407 0 : break;
408 : } while(0);
409 :
410 0 : return true;
411 : }
412 :
413 : bool
414 0 : RTCDataChannelInit::ToJSON(nsAString& aJSON) const
415 : {
416 0 : AutoJSAPI jsapi;
417 0 : jsapi.Init();
418 0 : JSContext *cx = jsapi.cx();
419 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
420 : // because we'll only be creating objects, in ways that have no
421 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
422 : // which likewise guarantees no side-effects for the sorts of
423 : // things we will pass it.
424 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
425 0 : JS::Rooted<JS::Value> val(cx);
426 0 : if (!ToObjectInternal(cx, &val)) {
427 0 : return false;
428 : }
429 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
430 0 : return StringifyToJSON(cx, obj, aJSON);
431 : }
432 :
433 : void
434 0 : RTCDataChannelInit::TraceDictionary(JSTracer* trc)
435 : {
436 0 : }
437 :
438 : RTCDataChannelInit&
439 0 : RTCDataChannelInit::operator=(const RTCDataChannelInit& aOther)
440 : {
441 0 : mId.Reset();
442 0 : if (aOther.mId.WasPassed()) {
443 0 : mId.Construct(aOther.mId.Value());
444 : }
445 0 : mMaxPacketLifeTime.Reset();
446 0 : if (aOther.mMaxPacketLifeTime.WasPassed()) {
447 0 : mMaxPacketLifeTime.Construct(aOther.mMaxPacketLifeTime.Value());
448 : }
449 0 : mMaxRetransmitTime.Reset();
450 0 : if (aOther.mMaxRetransmitTime.WasPassed()) {
451 0 : mMaxRetransmitTime.Construct(aOther.mMaxRetransmitTime.Value());
452 : }
453 0 : mMaxRetransmits.Reset();
454 0 : if (aOther.mMaxRetransmits.WasPassed()) {
455 0 : mMaxRetransmits.Construct(aOther.mMaxRetransmits.Value());
456 : }
457 0 : mNegotiated = aOther.mNegotiated;
458 0 : mOrdered = aOther.mOrdered;
459 0 : mProtocol = aOther.mProtocol;
460 0 : return *this;
461 : }
462 :
463 : namespace binding_detail {
464 : } // namespace binding_detail
465 :
466 :
467 : bool
468 0 : RTCIceCandidateInitOrRTCIceCandidate::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
469 : {
470 0 : switch (mType) {
471 : case eUninitialized: {
472 0 : return false;
473 : break;
474 : }
475 : case eRTCIceCandidateInit: {
476 0 : if (!mValue.mRTCIceCandidateInit.Value().ToObjectInternal(cx, rval)) {
477 0 : return false;
478 : }
479 0 : return true;
480 : break;
481 : }
482 : case eRTCIceCandidate: {
483 0 : if (!GetOrCreateDOMReflector(cx, mValue.mRTCIceCandidate.Value(), rval)) {
484 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
485 0 : return false;
486 : }
487 0 : return true;
488 : break;
489 : }
490 : default: {
491 0 : return false;
492 : break;
493 : }
494 : }
495 :
496 : return false;
497 : }
498 :
499 :
500 : RTCIceCandidateInit&
501 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::RawSetAsRTCIceCandidateInit()
502 : {
503 0 : if (mType == eRTCIceCandidateInit) {
504 0 : return mValue.mRTCIceCandidateInit.Value();
505 : }
506 0 : MOZ_ASSERT(mType == eUninitialized);
507 0 : mType = eRTCIceCandidateInit;
508 0 : return mValue.mRTCIceCandidateInit.SetValue();
509 : }
510 :
511 : RTCIceCandidateInit&
512 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::SetAsRTCIceCandidateInit()
513 : {
514 0 : if (mType == eRTCIceCandidateInit) {
515 0 : return mValue.mRTCIceCandidateInit.Value();
516 : }
517 0 : Uninit();
518 0 : mType = eRTCIceCandidateInit;
519 0 : return mValue.mRTCIceCandidateInit.SetValue();
520 : }
521 :
522 : bool
523 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::TrySetToRTCIceCandidateInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
524 : {
525 0 : tryNext = false;
526 : { // scope for memberSlot
527 0 : RTCIceCandidateInit& memberSlot = RawSetAsRTCIceCandidateInit();
528 0 : if (!IsConvertibleToDictionary(value)) {
529 0 : DestroyRTCIceCandidateInit();
530 0 : tryNext = true;
531 0 : return true;
532 : }
533 0 : if (!memberSlot.Init(cx, value, "Member of RTCIceCandidateInitOrRTCIceCandidate", passedToJSImpl)) {
534 0 : return false;
535 : }
536 : }
537 0 : return true;
538 : }
539 :
540 : void
541 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::DestroyRTCIceCandidateInit()
542 : {
543 0 : MOZ_ASSERT(IsRTCIceCandidateInit(), "Wrong type!");
544 0 : mValue.mRTCIceCandidateInit.Destroy();
545 0 : mType = eUninitialized;
546 0 : }
547 :
548 :
549 :
550 :
551 : OwningNonNull<mozilla::dom::RTCIceCandidate>&
552 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::RawSetAsRTCIceCandidate()
553 : {
554 0 : if (mType == eRTCIceCandidate) {
555 0 : return mValue.mRTCIceCandidate.Value();
556 : }
557 0 : MOZ_ASSERT(mType == eUninitialized);
558 0 : mType = eRTCIceCandidate;
559 0 : return mValue.mRTCIceCandidate.SetValue();
560 : }
561 :
562 : OwningNonNull<mozilla::dom::RTCIceCandidate>&
563 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::SetAsRTCIceCandidate()
564 : {
565 0 : if (mType == eRTCIceCandidate) {
566 0 : return mValue.mRTCIceCandidate.Value();
567 : }
568 0 : Uninit();
569 0 : mType = eRTCIceCandidate;
570 0 : return mValue.mRTCIceCandidate.SetValue();
571 : }
572 :
573 : bool
574 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::TrySetToRTCIceCandidate(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
575 : {
576 0 : tryNext = false;
577 : { // scope for memberSlot
578 0 : OwningNonNull<mozilla::dom::RTCIceCandidate>& memberSlot = RawSetAsRTCIceCandidate();
579 : static_assert(IsRefcounted<mozilla::dom::RTCIceCandidate>::value, "We can only store refcounted classes.");{
580 0 : nsresult rv = UnwrapObject<prototypes::id::RTCIceCandidate, mozilla::dom::RTCIceCandidate>(value, memberSlot);
581 0 : if (NS_FAILED(rv)) {
582 0 : DestroyRTCIceCandidate();
583 0 : tryNext = true;
584 0 : return true;
585 : }
586 : }
587 : }
588 0 : return true;
589 : }
590 :
591 : void
592 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::DestroyRTCIceCandidate()
593 : {
594 0 : MOZ_ASSERT(IsRTCIceCandidate(), "Wrong type!");
595 0 : mValue.mRTCIceCandidate.Destroy();
596 0 : mType = eUninitialized;
597 0 : }
598 :
599 :
600 :
601 :
602 : void
603 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::Uninit()
604 : {
605 0 : switch (mType) {
606 : case eUninitialized: {
607 0 : break;
608 : }
609 : case eRTCIceCandidateInit: {
610 0 : DestroyRTCIceCandidateInit();
611 0 : break;
612 : }
613 : case eRTCIceCandidate: {
614 0 : DestroyRTCIceCandidate();
615 0 : break;
616 : }
617 : }
618 0 : }
619 :
620 : bool
621 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
622 : {
623 0 : switch (mType) {
624 : case eUninitialized: {
625 0 : return false;
626 : break;
627 : }
628 : case eRTCIceCandidateInit: {
629 0 : if (!mValue.mRTCIceCandidateInit.Value().ToObjectInternal(cx, rval)) {
630 0 : return false;
631 : }
632 0 : return true;
633 : break;
634 : }
635 : case eRTCIceCandidate: {
636 0 : if (!GetOrCreateDOMReflector(cx, mValue.mRTCIceCandidate.Value(), rval)) {
637 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
638 0 : return false;
639 : }
640 0 : return true;
641 : break;
642 : }
643 : default: {
644 0 : return false;
645 : break;
646 : }
647 : }
648 :
649 : return false;
650 : }
651 :
652 : void
653 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::TraceUnion(JSTracer* trc)
654 : {
655 0 : }
656 :
657 : OwningRTCIceCandidateInitOrRTCIceCandidate&
658 0 : OwningRTCIceCandidateInitOrRTCIceCandidate::operator=(const OwningRTCIceCandidateInitOrRTCIceCandidate& aOther)
659 : {
660 0 : switch (aOther.mType) {
661 : case eUninitialized: {
662 0 : MOZ_ASSERT(mType == eUninitialized,
663 : "We need to destroy ourselves?");
664 0 : break;
665 : }
666 : case eRTCIceCandidateInit: {
667 0 : SetAsRTCIceCandidateInit() = aOther.GetAsRTCIceCandidateInit();
668 0 : break;
669 : }
670 : case eRTCIceCandidate: {
671 0 : SetAsRTCIceCandidate() = aOther.GetAsRTCIceCandidate();
672 0 : break;
673 : }
674 : }
675 0 : return *this;
676 : }
677 :
678 :
679 :
680 0 : RTCOfferAnswerOptions::RTCOfferAnswerOptions()
681 : {
682 : // Safe to pass a null context if we pass a null value
683 0 : Init(nullptr, JS::NullHandleValue);
684 0 : }
685 :
686 :
687 :
688 : bool
689 0 : RTCOfferAnswerOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
690 : {
691 : // Passing a null JSContext is OK only if we're initing from null,
692 : // Since in that case we will not have to do any property gets
693 : // Also evaluate isNullOrUndefined in order to avoid false-positive
694 : // checkers by static analysis tools
695 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
696 0 : if (!IsConvertibleToDictionary(val)) {
697 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
698 : }
699 :
700 0 : return true;
701 : }
702 :
703 : bool
704 0 : RTCOfferAnswerOptions::Init(const nsAString& aJSON)
705 : {
706 0 : AutoJSAPI jsapi;
707 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
708 0 : if (!cleanGlobal) {
709 0 : return false;
710 : }
711 0 : if (!jsapi.Init(cleanGlobal)) {
712 0 : return false;
713 : }
714 0 : JSContext* cx = jsapi.cx();
715 0 : JS::Rooted<JS::Value> json(cx);
716 0 : bool ok = ParseJSON(cx, aJSON, &json);
717 0 : NS_ENSURE_TRUE(ok, false);
718 0 : return Init(cx, json);
719 : }
720 :
721 : bool
722 0 : RTCOfferAnswerOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
723 : {
724 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
725 0 : if (!obj) {
726 0 : return false;
727 : }
728 0 : rval.set(JS::ObjectValue(*obj));
729 :
730 :
731 0 : return true;
732 : }
733 :
734 : bool
735 0 : RTCOfferAnswerOptions::ToJSON(nsAString& aJSON) const
736 : {
737 0 : AutoJSAPI jsapi;
738 0 : jsapi.Init();
739 0 : JSContext *cx = jsapi.cx();
740 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
741 : // because we'll only be creating objects, in ways that have no
742 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
743 : // which likewise guarantees no side-effects for the sorts of
744 : // things we will pass it.
745 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
746 0 : JS::Rooted<JS::Value> val(cx);
747 0 : if (!ToObjectInternal(cx, &val)) {
748 0 : return false;
749 : }
750 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
751 0 : return StringifyToJSON(cx, obj, aJSON);
752 : }
753 :
754 : void
755 0 : RTCOfferAnswerOptions::TraceDictionary(JSTracer* trc)
756 : {
757 0 : }
758 :
759 : RTCOfferAnswerOptions&
760 0 : RTCOfferAnswerOptions::operator=(const RTCOfferAnswerOptions& aOther)
761 : {
762 0 : return *this;
763 : }
764 :
765 : namespace binding_detail {
766 : } // namespace binding_detail
767 :
768 :
769 :
770 0 : RTCAnswerOptions::RTCAnswerOptions()
771 0 : : RTCOfferAnswerOptions(FastDictionaryInitializer())
772 : {
773 : // Safe to pass a null context if we pass a null value
774 0 : Init(nullptr, JS::NullHandleValue);
775 0 : }
776 :
777 :
778 :
779 : bool
780 0 : RTCAnswerOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
781 : {
782 : // Passing a null JSContext is OK only if we're initing from null,
783 : // Since in that case we will not have to do any property gets
784 : // Also evaluate isNullOrUndefined in order to avoid false-positive
785 : // checkers by static analysis tools
786 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
787 : // Per spec, we init the parent's members first
788 0 : if (!RTCOfferAnswerOptions::Init(cx, val)) {
789 0 : return false;
790 : }
791 :
792 0 : return true;
793 : }
794 :
795 : bool
796 0 : RTCAnswerOptions::Init(const nsAString& aJSON)
797 : {
798 0 : AutoJSAPI jsapi;
799 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
800 0 : if (!cleanGlobal) {
801 0 : return false;
802 : }
803 0 : if (!jsapi.Init(cleanGlobal)) {
804 0 : return false;
805 : }
806 0 : JSContext* cx = jsapi.cx();
807 0 : JS::Rooted<JS::Value> json(cx);
808 0 : bool ok = ParseJSON(cx, aJSON, &json);
809 0 : NS_ENSURE_TRUE(ok, false);
810 0 : return Init(cx, json);
811 : }
812 :
813 : bool
814 0 : RTCAnswerOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
815 : {
816 : // Per spec, we define the parent's members first
817 0 : if (!RTCOfferAnswerOptions::ToObjectInternal(cx, rval)) {
818 0 : return false;
819 : }
820 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
821 :
822 :
823 0 : return true;
824 : }
825 :
826 : bool
827 0 : RTCAnswerOptions::ToJSON(nsAString& aJSON) const
828 : {
829 0 : AutoJSAPI jsapi;
830 0 : jsapi.Init();
831 0 : JSContext *cx = jsapi.cx();
832 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
833 : // because we'll only be creating objects, in ways that have no
834 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
835 : // which likewise guarantees no side-effects for the sorts of
836 : // things we will pass it.
837 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
838 0 : JS::Rooted<JS::Value> val(cx);
839 0 : if (!ToObjectInternal(cx, &val)) {
840 0 : return false;
841 : }
842 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
843 0 : return StringifyToJSON(cx, obj, aJSON);
844 : }
845 :
846 : void
847 0 : RTCAnswerOptions::TraceDictionary(JSTracer* trc)
848 : {
849 0 : RTCOfferAnswerOptions::TraceDictionary(trc);
850 0 : }
851 :
852 : RTCAnswerOptions&
853 0 : RTCAnswerOptions::operator=(const RTCAnswerOptions& aOther)
854 : {
855 0 : RTCOfferAnswerOptions::operator=(aOther);
856 0 : return *this;
857 : }
858 :
859 : namespace binding_detail {
860 : } // namespace binding_detail
861 :
862 :
863 :
864 0 : RTCOfferOptions::RTCOfferOptions()
865 0 : : RTCOfferAnswerOptions(FastDictionaryInitializer())
866 : {
867 : // Safe to pass a null context if we pass a null value
868 0 : Init(nullptr, JS::NullHandleValue);
869 0 : }
870 :
871 :
872 :
873 : bool
874 0 : RTCOfferOptions::InitIds(JSContext* cx, RTCOfferOptionsAtoms* atomsCache)
875 : {
876 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
877 :
878 : // Initialize these in reverse order so that any failure leaves the first one
879 : // uninitialized.
880 0 : if (!atomsCache->offerToReceiveVideo_id.init(cx, "offerToReceiveVideo") ||
881 0 : !atomsCache->offerToReceiveAudio_id.init(cx, "offerToReceiveAudio") ||
882 0 : !atomsCache->mozDontOfferDataChannel_id.init(cx, "mozDontOfferDataChannel") ||
883 0 : !atomsCache->mozBundleOnly_id.init(cx, "mozBundleOnly") ||
884 0 : !atomsCache->iceRestart_id.init(cx, "iceRestart")) {
885 0 : return false;
886 : }
887 0 : return true;
888 : }
889 :
890 : bool
891 0 : RTCOfferOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
892 : {
893 : // Passing a null JSContext is OK only if we're initing from null,
894 : // Since in that case we will not have to do any property gets
895 : // Also evaluate isNullOrUndefined in order to avoid false-positive
896 : // checkers by static analysis tools
897 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
898 0 : RTCOfferOptionsAtoms* atomsCache = nullptr;
899 0 : if (cx) {
900 0 : atomsCache = GetAtomCache<RTCOfferOptionsAtoms>(cx);
901 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
902 0 : return false;
903 : }
904 : }
905 :
906 : // Per spec, we init the parent's members first
907 0 : if (!RTCOfferAnswerOptions::Init(cx, val)) {
908 0 : return false;
909 : }
910 :
911 0 : bool isNull = val.isNullOrUndefined();
912 : // We only need these if !isNull, in which case we have |cx|.
913 0 : Maybe<JS::Rooted<JSObject *> > object;
914 0 : Maybe<JS::Rooted<JS::Value> > temp;
915 0 : if (!isNull) {
916 0 : MOZ_ASSERT(cx);
917 0 : object.emplace(cx, &val.toObject());
918 0 : temp.emplace(cx);
919 : }
920 0 : if (!isNull) {
921 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->iceRestart_id, temp.ptr())) {
922 0 : return false;
923 : }
924 : }
925 0 : if (!isNull && !temp->isUndefined()) {
926 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIceRestart)) {
927 0 : return false;
928 : }
929 : } else {
930 0 : mIceRestart = false;
931 : }
932 0 : mIsAnyMemberPresent = true;
933 :
934 0 : if (!isNull) {
935 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->mozBundleOnly_id, temp.ptr())) {
936 0 : return false;
937 : }
938 : }
939 0 : if (!isNull && !temp->isUndefined()) {
940 0 : mMozBundleOnly.Construct();
941 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mMozBundleOnly.Value()))) {
942 0 : return false;
943 : }
944 0 : mIsAnyMemberPresent = true;
945 : }
946 :
947 0 : if (!isNull) {
948 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->mozDontOfferDataChannel_id, temp.ptr())) {
949 0 : return false;
950 : }
951 : }
952 0 : if (!isNull && !temp->isUndefined()) {
953 0 : mMozDontOfferDataChannel.Construct();
954 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mMozDontOfferDataChannel.Value()))) {
955 0 : return false;
956 : }
957 0 : mIsAnyMemberPresent = true;
958 : }
959 :
960 0 : if (!isNull) {
961 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->offerToReceiveAudio_id, temp.ptr())) {
962 0 : return false;
963 : }
964 : }
965 0 : if (!isNull && !temp->isUndefined()) {
966 0 : mOfferToReceiveAudio.Construct();
967 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &(mOfferToReceiveAudio.Value()))) {
968 0 : return false;
969 : }
970 0 : mIsAnyMemberPresent = true;
971 : }
972 :
973 0 : if (!isNull) {
974 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->offerToReceiveVideo_id, temp.ptr())) {
975 0 : return false;
976 : }
977 : }
978 0 : if (!isNull && !temp->isUndefined()) {
979 0 : mOfferToReceiveVideo.Construct();
980 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &(mOfferToReceiveVideo.Value()))) {
981 0 : return false;
982 : }
983 0 : mIsAnyMemberPresent = true;
984 : }
985 0 : return true;
986 : }
987 :
988 : bool
989 0 : RTCOfferOptions::Init(const nsAString& aJSON)
990 : {
991 0 : AutoJSAPI jsapi;
992 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
993 0 : if (!cleanGlobal) {
994 0 : return false;
995 : }
996 0 : if (!jsapi.Init(cleanGlobal)) {
997 0 : return false;
998 : }
999 0 : JSContext* cx = jsapi.cx();
1000 0 : JS::Rooted<JS::Value> json(cx);
1001 0 : bool ok = ParseJSON(cx, aJSON, &json);
1002 0 : NS_ENSURE_TRUE(ok, false);
1003 0 : return Init(cx, json);
1004 : }
1005 :
1006 : bool
1007 0 : RTCOfferOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1008 : {
1009 0 : RTCOfferOptionsAtoms* atomsCache = GetAtomCache<RTCOfferOptionsAtoms>(cx);
1010 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1011 0 : return false;
1012 : }
1013 :
1014 : // Per spec, we define the parent's members first
1015 0 : if (!RTCOfferAnswerOptions::ToObjectInternal(cx, rval)) {
1016 0 : return false;
1017 : }
1018 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
1019 :
1020 : do {
1021 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1022 0 : JS::Rooted<JS::Value> temp(cx);
1023 0 : bool const & currentValue = mIceRestart;
1024 0 : temp.setBoolean(currentValue);
1025 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->iceRestart_id, temp, JSPROP_ENUMERATE)) {
1026 0 : return false;
1027 : }
1028 0 : break;
1029 : } while(0);
1030 :
1031 0 : if (mMozBundleOnly.WasPassed()) {
1032 : do {
1033 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1034 0 : JS::Rooted<JS::Value> temp(cx);
1035 0 : bool const & currentValue = mMozBundleOnly.InternalValue();
1036 0 : temp.setBoolean(currentValue);
1037 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->mozBundleOnly_id, temp, JSPROP_ENUMERATE)) {
1038 0 : return false;
1039 : }
1040 0 : break;
1041 : } while(0);
1042 : }
1043 :
1044 0 : if (mMozDontOfferDataChannel.WasPassed()) {
1045 : do {
1046 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1047 0 : JS::Rooted<JS::Value> temp(cx);
1048 0 : bool const & currentValue = mMozDontOfferDataChannel.InternalValue();
1049 0 : temp.setBoolean(currentValue);
1050 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->mozDontOfferDataChannel_id, temp, JSPROP_ENUMERATE)) {
1051 0 : return false;
1052 : }
1053 0 : break;
1054 : } while(0);
1055 : }
1056 :
1057 0 : if (mOfferToReceiveAudio.WasPassed()) {
1058 : do {
1059 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1060 0 : JS::Rooted<JS::Value> temp(cx);
1061 0 : int32_t const & currentValue = mOfferToReceiveAudio.InternalValue();
1062 0 : temp.setInt32(int32_t(currentValue));
1063 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->offerToReceiveAudio_id, temp, JSPROP_ENUMERATE)) {
1064 0 : return false;
1065 : }
1066 0 : break;
1067 : } while(0);
1068 : }
1069 :
1070 0 : if (mOfferToReceiveVideo.WasPassed()) {
1071 : do {
1072 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1073 0 : JS::Rooted<JS::Value> temp(cx);
1074 0 : int32_t const & currentValue = mOfferToReceiveVideo.InternalValue();
1075 0 : temp.setInt32(int32_t(currentValue));
1076 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->offerToReceiveVideo_id, temp, JSPROP_ENUMERATE)) {
1077 0 : return false;
1078 : }
1079 0 : break;
1080 : } while(0);
1081 : }
1082 :
1083 0 : return true;
1084 : }
1085 :
1086 : bool
1087 0 : RTCOfferOptions::ToJSON(nsAString& aJSON) const
1088 : {
1089 0 : AutoJSAPI jsapi;
1090 0 : jsapi.Init();
1091 0 : JSContext *cx = jsapi.cx();
1092 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1093 : // because we'll only be creating objects, in ways that have no
1094 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1095 : // which likewise guarantees no side-effects for the sorts of
1096 : // things we will pass it.
1097 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1098 0 : JS::Rooted<JS::Value> val(cx);
1099 0 : if (!ToObjectInternal(cx, &val)) {
1100 0 : return false;
1101 : }
1102 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1103 0 : return StringifyToJSON(cx, obj, aJSON);
1104 : }
1105 :
1106 : void
1107 0 : RTCOfferOptions::TraceDictionary(JSTracer* trc)
1108 : {
1109 0 : RTCOfferAnswerOptions::TraceDictionary(trc);
1110 0 : }
1111 :
1112 : RTCOfferOptions&
1113 0 : RTCOfferOptions::operator=(const RTCOfferOptions& aOther)
1114 : {
1115 0 : RTCOfferAnswerOptions::operator=(aOther);
1116 0 : mIceRestart = aOther.mIceRestart;
1117 0 : mMozBundleOnly.Reset();
1118 0 : if (aOther.mMozBundleOnly.WasPassed()) {
1119 0 : mMozBundleOnly.Construct(aOther.mMozBundleOnly.Value());
1120 : }
1121 0 : mMozDontOfferDataChannel.Reset();
1122 0 : if (aOther.mMozDontOfferDataChannel.WasPassed()) {
1123 0 : mMozDontOfferDataChannel.Construct(aOther.mMozDontOfferDataChannel.Value());
1124 : }
1125 0 : mOfferToReceiveAudio.Reset();
1126 0 : if (aOther.mOfferToReceiveAudio.WasPassed()) {
1127 0 : mOfferToReceiveAudio.Construct(aOther.mOfferToReceiveAudio.Value());
1128 : }
1129 0 : mOfferToReceiveVideo.Reset();
1130 0 : if (aOther.mOfferToReceiveVideo.WasPassed()) {
1131 0 : mOfferToReceiveVideo.Construct(aOther.mOfferToReceiveVideo.Value());
1132 : }
1133 0 : return *this;
1134 : }
1135 :
1136 : namespace binding_detail {
1137 : } // namespace binding_detail
1138 :
1139 :
1140 : void
1141 0 : RTCSessionDescriptionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const RTCSessionDescriptionInit& description, ErrorResult& aRv)
1142 : {
1143 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1144 0 : JS::AutoValueVector argv(cx);
1145 0 : if (!argv.resize(1)) {
1146 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1147 0 : return;
1148 : }
1149 0 : unsigned argc = 1;
1150 :
1151 : do {
1152 0 : if (!description.ToObjectInternal(cx, argv[0])) {
1153 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1154 0 : return;
1155 : }
1156 0 : break;
1157 : } while (0);
1158 :
1159 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1160 0 : if (!JS::Call(cx, aThisVal, callable,
1161 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1162 0 : aRv.NoteJSContextException(cx);
1163 0 : return;
1164 : }
1165 : }
1166 :
1167 :
1168 :
1169 : void
1170 0 : RTCPeerConnectionErrorCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, DOMError& error, ErrorResult& aRv)
1171 : {
1172 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1173 0 : JS::AutoValueVector argv(cx);
1174 0 : if (!argv.resize(1)) {
1175 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1176 0 : return;
1177 : }
1178 0 : unsigned argc = 1;
1179 :
1180 : do {
1181 0 : if (!GetOrCreateDOMReflector(cx, error, argv[0])) {
1182 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1183 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1184 0 : return;
1185 : }
1186 0 : break;
1187 : } while (0);
1188 :
1189 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1190 0 : if (!JS::Call(cx, aThisVal, callable,
1191 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1192 0 : aRv.NoteJSContextException(cx);
1193 0 : return;
1194 : }
1195 : }
1196 :
1197 :
1198 :
1199 : void
1200 0 : RTCStatsCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, RTCStatsReport& report, ErrorResult& aRv)
1201 : {
1202 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1203 0 : JS::AutoValueVector argv(cx);
1204 0 : if (!argv.resize(1)) {
1205 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1206 0 : return;
1207 : }
1208 0 : unsigned argc = 1;
1209 :
1210 : do {
1211 0 : if (!GetOrCreateDOMReflector(cx, report, argv[0])) {
1212 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1213 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1214 0 : return;
1215 : }
1216 0 : break;
1217 : } while (0);
1218 :
1219 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1220 0 : if (!JS::Call(cx, aThisVal, callable,
1221 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1222 0 : aRv.NoteJSContextException(cx);
1223 0 : return;
1224 : }
1225 : }
1226 :
1227 :
1228 :
1229 : namespace binding_detail {
1230 : } // namespace binding_detail
1231 :
1232 :
1233 : namespace binding_detail {
1234 : } // namespace binding_detail
1235 :
1236 :
1237 : namespace binding_detail {
1238 : } // namespace binding_detail
1239 :
1240 :
1241 : namespace RTCPeerConnectionBinding {
1242 :
1243 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
1244 : "Can't inherit from an interface with a different ownership model.");
1245 :
1246 : static bool
1247 0 : generateCertificate(JSContext* cx, unsigned argc, JS::Value* vp)
1248 : {
1249 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1250 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
1251 :
1252 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1253 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.generateCertificate");
1254 : }
1255 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1256 0 : if (global.Failed()) {
1257 0 : return false;
1258 : }
1259 :
1260 0 : ObjectOrString arg0;
1261 0 : ObjectOrStringArgument arg0_holder(arg0);
1262 : {
1263 0 : bool done = false, failed = false, tryNext;
1264 0 : if (args[0].isObject()) {
1265 0 : if (!arg0_holder.SetToObject(cx, &args[0].toObject(), true)) {
1266 0 : return false;
1267 : }
1268 0 : done = true;
1269 : } else {
1270 : do {
1271 0 : done = (failed = !arg0_holder.TrySetToString(cx, args[0], tryNext)) || !tryNext;
1272 0 : break;
1273 : } while (0);
1274 : }
1275 0 : if (failed) {
1276 0 : return false;
1277 : }
1278 0 : if (!done) {
1279 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of RTCPeerConnection.generateCertificate", "Object");
1280 0 : return false;
1281 : }
1282 : }
1283 0 : binding_detail::FastErrorResult rv;
1284 0 : auto result(StrongOrRawPtr<Promise>(mozilla::dom::RTCCertificate::GenerateCertificate(global, Constify(arg0), rv)));
1285 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1286 0 : return false;
1287 : }
1288 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1289 0 : if (!ToJSValue(cx, result, args.rval())) {
1290 0 : return false;
1291 : }
1292 0 : return true;
1293 : }
1294 :
1295 :
1296 : static const JSJitInfo generateCertificate_methodinfo = {
1297 : { (JSJitGetterOp)generateCertificate },
1298 : { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
1299 : JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
1300 : false, false, 0
1301 : };
1302 :
1303 : static bool
1304 0 : setIdentityProvider(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1305 : {
1306 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1307 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setIdentityProvider");
1308 : }
1309 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1310 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1311 0 : if (objIsXray) {
1312 0 : unwrappedObj.emplace(cx, obj);
1313 : }
1314 0 : binding_detail::FakeString arg0;
1315 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1316 0 : return false;
1317 : }
1318 0 : Optional<nsAString> arg1;
1319 0 : binding_detail::FakeString arg1_holder;
1320 0 : if (args.hasDefined(1)) {
1321 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) {
1322 0 : return false;
1323 : }
1324 0 : arg1 = &arg1_holder;
1325 : }
1326 0 : Optional<nsAString> arg2;
1327 0 : binding_detail::FakeString arg2_holder;
1328 0 : if (args.hasDefined(2)) {
1329 0 : if (!ConvertJSValueToString(cx, args[2], eStringify, eStringify, arg2_holder)) {
1330 0 : return false;
1331 : }
1332 0 : arg2 = &arg2_holder;
1333 : }
1334 0 : if (objIsXray) {
1335 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1336 0 : if (!unwrappedObj.ref()) {
1337 0 : return false;
1338 : }
1339 : }
1340 0 : binding_detail::FastErrorResult rv;
1341 0 : self->SetIdentityProvider(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
1342 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1343 0 : return false;
1344 : }
1345 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1346 0 : args.rval().setUndefined();
1347 0 : return true;
1348 : }
1349 :
1350 : static const JSJitInfo setIdentityProvider_methodinfo = {
1351 : { (JSJitGetterOp)setIdentityProvider },
1352 : { prototypes::id::RTCPeerConnection },
1353 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1354 : JSJitInfo::Method,
1355 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1356 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
1357 : false, /* isInfallible. False in setters. */
1358 : false, /* isMovable. Not relevant for setters. */
1359 : false, /* isEliminatable. Not relevant for setters. */
1360 : false, /* isAlwaysInSlot. Only relevant for getters. */
1361 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1362 : false, /* isTypedMethod. Only relevant for methods. */
1363 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1364 : };
1365 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1366 : static_assert(0 < 1, "There is no slot for us");
1367 :
1368 : static bool
1369 0 : getIdentityAssertion(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1370 : {
1371 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1372 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1373 0 : if (objIsXray) {
1374 0 : unwrappedObj.emplace(cx, obj);
1375 : }
1376 0 : if (objIsXray) {
1377 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1378 0 : if (!unwrappedObj.ref()) {
1379 0 : return false;
1380 : }
1381 : }
1382 0 : binding_detail::FastErrorResult rv;
1383 0 : auto result(StrongOrRawPtr<Promise>(self->GetIdentityAssertion(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1384 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1385 0 : return false;
1386 : }
1387 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1388 0 : if (!ToJSValue(cx, result, args.rval())) {
1389 0 : return false;
1390 : }
1391 0 : return true;
1392 : }
1393 :
1394 : static bool
1395 0 : getIdentityAssertion_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1396 : {
1397 : // Make sure to save the callee before someone maybe messes
1398 : // with rval().
1399 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1400 0 : bool ok = getIdentityAssertion(cx, obj, self, args);
1401 0 : if (ok) {
1402 0 : return true;
1403 : }
1404 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1405 0 : args.rval());
1406 : }
1407 :
1408 : static const JSJitInfo getIdentityAssertion_methodinfo = {
1409 : { (JSJitGetterOp)getIdentityAssertion_promiseWrapper },
1410 : { prototypes::id::RTCPeerConnection },
1411 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1412 : JSJitInfo::Method,
1413 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1414 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1415 : false, /* isInfallible. False in setters. */
1416 : false, /* isMovable. Not relevant for setters. */
1417 : false, /* isEliminatable. Not relevant for setters. */
1418 : false, /* isAlwaysInSlot. Only relevant for getters. */
1419 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1420 : false, /* isTypedMethod. Only relevant for methods. */
1421 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1422 : };
1423 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1424 : static_assert(0 < 1, "There is no slot for us");
1425 :
1426 : static bool
1427 0 : createOffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1428 : {
1429 0 : unsigned argcount = std::min(args.length(), 3u);
1430 0 : switch (argcount) {
1431 : case 0: {
1432 : MOZ_FALLTHROUGH;
1433 : }
1434 : case 1: {
1435 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1436 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1437 0 : if (objIsXray) {
1438 0 : unwrappedObj.emplace(cx, obj);
1439 : }
1440 0 : binding_detail::FastRTCOfferOptions arg0;
1441 0 : if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of RTCPeerConnection.createOffer", true)) {
1442 0 : return false;
1443 : }
1444 0 : if (objIsXray) {
1445 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1446 0 : if (!unwrappedObj.ref()) {
1447 0 : return false;
1448 : }
1449 : }
1450 0 : binding_detail::FastErrorResult rv;
1451 0 : auto result(StrongOrRawPtr<Promise>(self->CreateOffer(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1452 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1453 0 : return false;
1454 : }
1455 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1456 0 : if (!ToJSValue(cx, result, args.rval())) {
1457 0 : return false;
1458 : }
1459 0 : return true;
1460 : break;
1461 : }
1462 : case 2: {
1463 : MOZ_FALLTHROUGH;
1464 : }
1465 : case 3: {
1466 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1467 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1468 0 : if (objIsXray) {
1469 0 : unwrappedObj.emplace(cx, obj);
1470 : }
1471 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCSessionDescriptionCallback>> arg0(cx);
1472 0 : if (args[0].isObject()) {
1473 0 : if (JS::IsCallable(&args[0].toObject())) {
1474 : { // scope for tempRoot
1475 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
1476 0 : arg0 = new binding_detail::FastRTCSessionDescriptionCallback(tempRoot);
1477 : }
1478 : } else {
1479 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of RTCPeerConnection.createOffer");
1480 0 : return false;
1481 : }
1482 : } else {
1483 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.createOffer");
1484 0 : return false;
1485 : }
1486 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg1(cx);
1487 0 : if (args[1].isObject()) {
1488 0 : if (JS::IsCallable(&args[1].toObject())) {
1489 : { // scope for tempRoot
1490 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
1491 0 : arg1 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
1492 : }
1493 : } else {
1494 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.createOffer");
1495 0 : return false;
1496 : }
1497 : } else {
1498 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.createOffer");
1499 0 : return false;
1500 : }
1501 0 : binding_detail::FastRTCOfferOptions arg2;
1502 0 : if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of RTCPeerConnection.createOffer", true)) {
1503 0 : return false;
1504 : }
1505 0 : if (objIsXray) {
1506 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1507 0 : if (!unwrappedObj.ref()) {
1508 0 : return false;
1509 : }
1510 : }
1511 0 : binding_detail::FastErrorResult rv;
1512 0 : auto result(StrongOrRawPtr<Promise>(self->CreateOffer(NonNullHelper(arg0), NonNullHelper(arg1), Constify(arg2), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1513 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1514 0 : return false;
1515 : }
1516 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1517 0 : if (!ToJSValue(cx, result, args.rval())) {
1518 0 : return false;
1519 : }
1520 0 : return true;
1521 : break;
1522 : }
1523 : default: {
1524 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createOffer");
1525 : break;
1526 : }
1527 : }
1528 : MOZ_CRASH("We have an always-returning default case");
1529 : return false;
1530 : }
1531 :
1532 : static bool
1533 0 : createOffer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1534 : {
1535 : // Make sure to save the callee before someone maybe messes
1536 : // with rval().
1537 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1538 0 : bool ok = createOffer(cx, obj, self, args);
1539 0 : if (ok) {
1540 0 : return true;
1541 : }
1542 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1543 0 : args.rval());
1544 : }
1545 :
1546 : static const JSJitInfo createOffer_methodinfo = {
1547 : { (JSJitGetterOp)createOffer_promiseWrapper },
1548 : { prototypes::id::RTCPeerConnection },
1549 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1550 : JSJitInfo::Method,
1551 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1552 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1553 : false, /* isInfallible. False in setters. */
1554 : false, /* isMovable. Not relevant for setters. */
1555 : false, /* isEliminatable. Not relevant for setters. */
1556 : false, /* isAlwaysInSlot. Only relevant for getters. */
1557 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1558 : false, /* isTypedMethod. Only relevant for methods. */
1559 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1560 : };
1561 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1562 : static_assert(0 < 1, "There is no slot for us");
1563 :
1564 : static bool
1565 0 : createAnswer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1566 : {
1567 0 : unsigned argcount = std::min(args.length(), 2u);
1568 0 : switch (argcount) {
1569 : case 0: {
1570 : MOZ_FALLTHROUGH;
1571 : }
1572 : case 1: {
1573 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1574 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1575 0 : if (objIsXray) {
1576 0 : unwrappedObj.emplace(cx, obj);
1577 : }
1578 0 : binding_detail::FastRTCAnswerOptions arg0;
1579 0 : if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of RTCPeerConnection.createAnswer", true)) {
1580 0 : return false;
1581 : }
1582 0 : if (objIsXray) {
1583 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1584 0 : if (!unwrappedObj.ref()) {
1585 0 : return false;
1586 : }
1587 : }
1588 0 : binding_detail::FastErrorResult rv;
1589 0 : auto result(StrongOrRawPtr<Promise>(self->CreateAnswer(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1590 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1591 0 : return false;
1592 : }
1593 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1594 0 : if (!ToJSValue(cx, result, args.rval())) {
1595 0 : return false;
1596 : }
1597 0 : return true;
1598 : break;
1599 : }
1600 : case 2: {
1601 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1602 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1603 0 : if (objIsXray) {
1604 0 : unwrappedObj.emplace(cx, obj);
1605 : }
1606 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCSessionDescriptionCallback>> arg0(cx);
1607 0 : if (args[0].isObject()) {
1608 0 : if (JS::IsCallable(&args[0].toObject())) {
1609 : { // scope for tempRoot
1610 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
1611 0 : arg0 = new binding_detail::FastRTCSessionDescriptionCallback(tempRoot);
1612 : }
1613 : } else {
1614 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of RTCPeerConnection.createAnswer");
1615 0 : return false;
1616 : }
1617 : } else {
1618 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.createAnswer");
1619 0 : return false;
1620 : }
1621 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg1(cx);
1622 0 : if (args[1].isObject()) {
1623 0 : if (JS::IsCallable(&args[1].toObject())) {
1624 : { // scope for tempRoot
1625 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
1626 0 : arg1 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
1627 : }
1628 : } else {
1629 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.createAnswer");
1630 0 : return false;
1631 : }
1632 : } else {
1633 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.createAnswer");
1634 0 : return false;
1635 : }
1636 0 : if (objIsXray) {
1637 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1638 0 : if (!unwrappedObj.ref()) {
1639 0 : return false;
1640 : }
1641 : }
1642 0 : binding_detail::FastErrorResult rv;
1643 0 : auto result(StrongOrRawPtr<Promise>(self->CreateAnswer(NonNullHelper(arg0), NonNullHelper(arg1), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1644 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1645 0 : return false;
1646 : }
1647 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1648 0 : if (!ToJSValue(cx, result, args.rval())) {
1649 0 : return false;
1650 : }
1651 0 : return true;
1652 : break;
1653 : }
1654 : default: {
1655 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createAnswer");
1656 : break;
1657 : }
1658 : }
1659 : MOZ_CRASH("We have an always-returning default case");
1660 : return false;
1661 : }
1662 :
1663 : static bool
1664 0 : createAnswer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1665 : {
1666 : // Make sure to save the callee before someone maybe messes
1667 : // with rval().
1668 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1669 0 : bool ok = createAnswer(cx, obj, self, args);
1670 0 : if (ok) {
1671 0 : return true;
1672 : }
1673 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1674 0 : args.rval());
1675 : }
1676 :
1677 : static const JSJitInfo createAnswer_methodinfo = {
1678 : { (JSJitGetterOp)createAnswer_promiseWrapper },
1679 : { prototypes::id::RTCPeerConnection },
1680 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1681 : JSJitInfo::Method,
1682 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1683 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1684 : false, /* isInfallible. False in setters. */
1685 : false, /* isMovable. Not relevant for setters. */
1686 : false, /* isEliminatable. Not relevant for setters. */
1687 : false, /* isAlwaysInSlot. Only relevant for getters. */
1688 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1689 : false, /* isTypedMethod. Only relevant for methods. */
1690 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1691 : };
1692 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1693 : static_assert(0 < 1, "There is no slot for us");
1694 :
1695 : static bool
1696 0 : setLocalDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1697 : {
1698 0 : unsigned argcount = std::min(args.length(), 3u);
1699 0 : switch (argcount) {
1700 : case 1: {
1701 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1702 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1703 0 : if (objIsXray) {
1704 0 : unwrappedObj.emplace(cx, obj);
1705 : }
1706 0 : binding_detail::FastRTCSessionDescriptionInit arg0;
1707 0 : if (!arg0.Init(cx, args[0], "Argument 1 of RTCPeerConnection.setLocalDescription", true)) {
1708 0 : return false;
1709 : }
1710 0 : if (objIsXray) {
1711 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1712 0 : if (!unwrappedObj.ref()) {
1713 0 : return false;
1714 : }
1715 : }
1716 0 : binding_detail::FastErrorResult rv;
1717 0 : auto result(StrongOrRawPtr<Promise>(self->SetLocalDescription(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1718 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1719 0 : return false;
1720 : }
1721 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1722 0 : if (!ToJSValue(cx, result, args.rval())) {
1723 0 : return false;
1724 : }
1725 0 : return true;
1726 : break;
1727 : }
1728 : case 3: {
1729 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1730 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1731 0 : if (objIsXray) {
1732 0 : unwrappedObj.emplace(cx, obj);
1733 : }
1734 0 : binding_detail::FastRTCSessionDescriptionInit arg0;
1735 0 : if (!arg0.Init(cx, args[0], "Argument 1 of RTCPeerConnection.setLocalDescription", true)) {
1736 0 : return false;
1737 : }
1738 0 : RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
1739 0 : if (args[1].isObject()) {
1740 0 : if (JS::IsCallable(&args[1].toObject())) {
1741 : { // scope for tempRoot
1742 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
1743 0 : arg1 = new binding_detail::FastVoidFunction(tempRoot);
1744 : }
1745 : } else {
1746 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.setLocalDescription");
1747 0 : return false;
1748 : }
1749 : } else {
1750 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.setLocalDescription");
1751 0 : return false;
1752 : }
1753 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
1754 0 : if (args[2].isObject()) {
1755 0 : if (JS::IsCallable(&args[2].toObject())) {
1756 : { // scope for tempRoot
1757 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[2].toObject());
1758 0 : arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
1759 : }
1760 : } else {
1761 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.setLocalDescription");
1762 0 : return false;
1763 : }
1764 : } else {
1765 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.setLocalDescription");
1766 0 : return false;
1767 : }
1768 0 : if (objIsXray) {
1769 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1770 0 : if (!unwrappedObj.ref()) {
1771 0 : return false;
1772 : }
1773 : }
1774 0 : binding_detail::FastErrorResult rv;
1775 0 : auto result(StrongOrRawPtr<Promise>(self->SetLocalDescription(Constify(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1776 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1777 0 : return false;
1778 : }
1779 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1780 0 : if (!ToJSValue(cx, result, args.rval())) {
1781 0 : return false;
1782 : }
1783 0 : return true;
1784 : break;
1785 : }
1786 : default: {
1787 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setLocalDescription");
1788 : break;
1789 : }
1790 : }
1791 : MOZ_CRASH("We have an always-returning default case");
1792 : return false;
1793 : }
1794 :
1795 : static bool
1796 0 : setLocalDescription_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1797 : {
1798 : // Make sure to save the callee before someone maybe messes
1799 : // with rval().
1800 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1801 0 : bool ok = setLocalDescription(cx, obj, self, args);
1802 0 : if (ok) {
1803 0 : return true;
1804 : }
1805 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1806 0 : args.rval());
1807 : }
1808 :
1809 : static const JSJitInfo setLocalDescription_methodinfo = {
1810 : { (JSJitGetterOp)setLocalDescription_promiseWrapper },
1811 : { prototypes::id::RTCPeerConnection },
1812 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1813 : JSJitInfo::Method,
1814 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1815 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1816 : false, /* isInfallible. False in setters. */
1817 : false, /* isMovable. Not relevant for setters. */
1818 : false, /* isEliminatable. Not relevant for setters. */
1819 : false, /* isAlwaysInSlot. Only relevant for getters. */
1820 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1821 : false, /* isTypedMethod. Only relevant for methods. */
1822 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1823 : };
1824 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1825 : static_assert(0 < 1, "There is no slot for us");
1826 :
1827 : static bool
1828 0 : setRemoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1829 : {
1830 0 : unsigned argcount = std::min(args.length(), 3u);
1831 0 : switch (argcount) {
1832 : case 1: {
1833 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1834 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1835 0 : if (objIsXray) {
1836 0 : unwrappedObj.emplace(cx, obj);
1837 : }
1838 0 : binding_detail::FastRTCSessionDescriptionInit arg0;
1839 0 : if (!arg0.Init(cx, args[0], "Argument 1 of RTCPeerConnection.setRemoteDescription", true)) {
1840 0 : return false;
1841 : }
1842 0 : if (objIsXray) {
1843 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1844 0 : if (!unwrappedObj.ref()) {
1845 0 : return false;
1846 : }
1847 : }
1848 0 : binding_detail::FastErrorResult rv;
1849 0 : auto result(StrongOrRawPtr<Promise>(self->SetRemoteDescription(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1850 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1851 0 : return false;
1852 : }
1853 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1854 0 : if (!ToJSValue(cx, result, args.rval())) {
1855 0 : return false;
1856 : }
1857 0 : return true;
1858 : break;
1859 : }
1860 : case 3: {
1861 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1862 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1863 0 : if (objIsXray) {
1864 0 : unwrappedObj.emplace(cx, obj);
1865 : }
1866 0 : binding_detail::FastRTCSessionDescriptionInit arg0;
1867 0 : if (!arg0.Init(cx, args[0], "Argument 1 of RTCPeerConnection.setRemoteDescription", true)) {
1868 0 : return false;
1869 : }
1870 0 : RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
1871 0 : if (args[1].isObject()) {
1872 0 : if (JS::IsCallable(&args[1].toObject())) {
1873 : { // scope for tempRoot
1874 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
1875 0 : arg1 = new binding_detail::FastVoidFunction(tempRoot);
1876 : }
1877 : } else {
1878 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.setRemoteDescription");
1879 0 : return false;
1880 : }
1881 : } else {
1882 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.setRemoteDescription");
1883 0 : return false;
1884 : }
1885 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
1886 0 : if (args[2].isObject()) {
1887 0 : if (JS::IsCallable(&args[2].toObject())) {
1888 : { // scope for tempRoot
1889 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[2].toObject());
1890 0 : arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
1891 : }
1892 : } else {
1893 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.setRemoteDescription");
1894 0 : return false;
1895 : }
1896 : } else {
1897 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.setRemoteDescription");
1898 0 : return false;
1899 : }
1900 0 : if (objIsXray) {
1901 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1902 0 : if (!unwrappedObj.ref()) {
1903 0 : return false;
1904 : }
1905 : }
1906 0 : binding_detail::FastErrorResult rv;
1907 0 : auto result(StrongOrRawPtr<Promise>(self->SetRemoteDescription(Constify(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1908 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1909 0 : return false;
1910 : }
1911 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1912 0 : if (!ToJSValue(cx, result, args.rval())) {
1913 0 : return false;
1914 : }
1915 0 : return true;
1916 : break;
1917 : }
1918 : default: {
1919 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setRemoteDescription");
1920 : break;
1921 : }
1922 : }
1923 : MOZ_CRASH("We have an always-returning default case");
1924 : return false;
1925 : }
1926 :
1927 : static bool
1928 0 : setRemoteDescription_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1929 : {
1930 : // Make sure to save the callee before someone maybe messes
1931 : // with rval().
1932 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1933 0 : bool ok = setRemoteDescription(cx, obj, self, args);
1934 0 : if (ok) {
1935 0 : return true;
1936 : }
1937 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1938 0 : args.rval());
1939 : }
1940 :
1941 : static const JSJitInfo setRemoteDescription_methodinfo = {
1942 : { (JSJitGetterOp)setRemoteDescription_promiseWrapper },
1943 : { prototypes::id::RTCPeerConnection },
1944 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1945 : JSJitInfo::Method,
1946 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1947 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1948 : false, /* isInfallible. False in setters. */
1949 : false, /* isMovable. Not relevant for setters. */
1950 : false, /* isEliminatable. Not relevant for setters. */
1951 : false, /* isAlwaysInSlot. Only relevant for getters. */
1952 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1953 : false, /* isTypedMethod. Only relevant for methods. */
1954 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1955 : };
1956 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1957 : static_assert(0 < 1, "There is no slot for us");
1958 :
1959 : static bool
1960 0 : get_localDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
1961 : {
1962 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1963 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1964 0 : if (objIsXray) {
1965 0 : unwrappedObj.emplace(cx, obj);
1966 : }
1967 0 : if (objIsXray) {
1968 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1969 0 : if (!unwrappedObj.ref()) {
1970 0 : return false;
1971 : }
1972 : }
1973 0 : binding_detail::FastErrorResult rv;
1974 0 : auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetLocalDescription(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
1975 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1976 0 : return false;
1977 : }
1978 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1979 0 : if (!result) {
1980 0 : args.rval().setNull();
1981 0 : return true;
1982 : }
1983 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1984 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1985 0 : return false;
1986 : }
1987 0 : return true;
1988 : }
1989 :
1990 : static const JSJitInfo localDescription_getterinfo = {
1991 : { (JSJitGetterOp)get_localDescription },
1992 : { prototypes::id::RTCPeerConnection },
1993 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1994 : JSJitInfo::Getter,
1995 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1996 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
1997 : false, /* isInfallible. False in setters. */
1998 : false, /* isMovable. Not relevant for setters. */
1999 : false, /* isEliminatable. Not relevant for setters. */
2000 : false, /* isAlwaysInSlot. Only relevant for getters. */
2001 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2002 : false, /* isTypedMethod. Only relevant for methods. */
2003 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2004 : };
2005 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2006 : static_assert(0 < 1, "There is no slot for us");
2007 :
2008 : static bool
2009 0 : get_remoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2010 : {
2011 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2012 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2013 0 : if (objIsXray) {
2014 0 : unwrappedObj.emplace(cx, obj);
2015 : }
2016 0 : if (objIsXray) {
2017 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2018 0 : if (!unwrappedObj.ref()) {
2019 0 : return false;
2020 : }
2021 : }
2022 0 : binding_detail::FastErrorResult rv;
2023 0 : auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetRemoteDescription(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
2024 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2025 0 : return false;
2026 : }
2027 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2028 0 : if (!result) {
2029 0 : args.rval().setNull();
2030 0 : return true;
2031 : }
2032 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2033 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
2034 0 : return false;
2035 : }
2036 0 : return true;
2037 : }
2038 :
2039 : static const JSJitInfo remoteDescription_getterinfo = {
2040 : { (JSJitGetterOp)get_remoteDescription },
2041 : { prototypes::id::RTCPeerConnection },
2042 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2043 : JSJitInfo::Getter,
2044 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2045 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
2046 : false, /* isInfallible. False in setters. */
2047 : false, /* isMovable. Not relevant for setters. */
2048 : false, /* isEliminatable. Not relevant for setters. */
2049 : false, /* isAlwaysInSlot. Only relevant for getters. */
2050 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2051 : false, /* isTypedMethod. Only relevant for methods. */
2052 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2053 : };
2054 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2055 : static_assert(0 < 1, "There is no slot for us");
2056 :
2057 : static bool
2058 0 : get_signalingState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2059 : {
2060 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2061 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2062 0 : if (objIsXray) {
2063 0 : unwrappedObj.emplace(cx, obj);
2064 : }
2065 0 : if (objIsXray) {
2066 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2067 0 : if (!unwrappedObj.ref()) {
2068 0 : return false;
2069 : }
2070 : }
2071 0 : binding_detail::FastErrorResult rv;
2072 0 : RTCSignalingState result(self->GetSignalingState(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
2073 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2074 0 : return false;
2075 : }
2076 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2077 0 : if (!ToJSValue(cx, result, args.rval())) {
2078 0 : return false;
2079 : }
2080 0 : return true;
2081 : }
2082 :
2083 : static const JSJitInfo signalingState_getterinfo = {
2084 : { (JSJitGetterOp)get_signalingState },
2085 : { prototypes::id::RTCPeerConnection },
2086 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2087 : JSJitInfo::Getter,
2088 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2089 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
2090 : false, /* isInfallible. False in setters. */
2091 : false, /* isMovable. Not relevant for setters. */
2092 : false, /* isEliminatable. Not relevant for setters. */
2093 : false, /* isAlwaysInSlot. Only relevant for getters. */
2094 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2095 : false, /* isTypedMethod. Only relevant for methods. */
2096 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2097 : };
2098 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2099 : static_assert(0 < 1, "There is no slot for us");
2100 :
2101 : static bool
2102 0 : addIceCandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2103 : {
2104 0 : unsigned argcount = std::min(args.length(), 3u);
2105 0 : switch (argcount) {
2106 : case 1: {
2107 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2108 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2109 0 : if (objIsXray) {
2110 0 : unwrappedObj.emplace(cx, obj);
2111 : }
2112 0 : Nullable<RTCIceCandidateInitOrRTCIceCandidate > arg0;
2113 0 : Maybe<RTCIceCandidateInitOrRTCIceCandidateArgument> arg0_holder;
2114 0 : if (args[0].isNullOrUndefined()) {
2115 0 : arg0.SetNull();
2116 : } else {
2117 0 : arg0_holder.emplace(arg0.SetValue());
2118 : {
2119 0 : bool done = false, failed = false, tryNext;
2120 0 : if (args[0].isObject()) {
2121 0 : done = (failed = !arg0_holder.ref().TrySetToRTCIceCandidate(cx, args[0], tryNext, true)) || !tryNext;
2122 :
2123 : }
2124 0 : if (!done) {
2125 0 : done = (failed = !arg0_holder.ref().TrySetToRTCIceCandidateInit(cx, args[0], tryNext, true)) || !tryNext;
2126 : }
2127 0 : if (failed) {
2128 0 : return false;
2129 : }
2130 0 : if (!done) {
2131 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of RTCPeerConnection.addIceCandidate", "RTCIceCandidate, RTCIceCandidateInit");
2132 0 : return false;
2133 : }
2134 : }
2135 : }
2136 0 : if (objIsXray) {
2137 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2138 0 : if (!unwrappedObj.ref()) {
2139 0 : return false;
2140 : }
2141 : }
2142 0 : binding_detail::FastErrorResult rv;
2143 0 : auto result(StrongOrRawPtr<Promise>(self->AddIceCandidate(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
2144 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2145 0 : return false;
2146 : }
2147 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2148 0 : if (!ToJSValue(cx, result, args.rval())) {
2149 0 : return false;
2150 : }
2151 0 : return true;
2152 : break;
2153 : }
2154 : case 3: {
2155 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2156 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2157 0 : if (objIsXray) {
2158 0 : unwrappedObj.emplace(cx, obj);
2159 : }
2160 0 : NonNull<mozilla::dom::RTCIceCandidate> arg0;
2161 0 : if (args[0].isObject()) {
2162 : {
2163 0 : nsresult rv = UnwrapObject<prototypes::id::RTCIceCandidate, mozilla::dom::RTCIceCandidate>(args[0], arg0);
2164 0 : if (NS_FAILED(rv)) {
2165 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addIceCandidate", "RTCIceCandidate");
2166 0 : return false;
2167 : }
2168 : }
2169 : } else {
2170 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addIceCandidate");
2171 0 : return false;
2172 : }
2173 0 : RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
2174 0 : if (args[1].isObject()) {
2175 0 : if (JS::IsCallable(&args[1].toObject())) {
2176 : { // scope for tempRoot
2177 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
2178 0 : arg1 = new binding_detail::FastVoidFunction(tempRoot);
2179 : }
2180 : } else {
2181 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.addIceCandidate");
2182 0 : return false;
2183 : }
2184 : } else {
2185 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.addIceCandidate");
2186 0 : return false;
2187 : }
2188 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
2189 0 : if (args[2].isObject()) {
2190 0 : if (JS::IsCallable(&args[2].toObject())) {
2191 : { // scope for tempRoot
2192 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[2].toObject());
2193 0 : arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
2194 : }
2195 : } else {
2196 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.addIceCandidate");
2197 0 : return false;
2198 : }
2199 : } else {
2200 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.addIceCandidate");
2201 0 : return false;
2202 : }
2203 0 : if (objIsXray) {
2204 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2205 0 : if (!unwrappedObj.ref()) {
2206 0 : return false;
2207 : }
2208 : }
2209 0 : binding_detail::FastErrorResult rv;
2210 0 : auto result(StrongOrRawPtr<Promise>(self->AddIceCandidate(NonNullHelper(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
2211 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2212 0 : return false;
2213 : }
2214 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2215 0 : if (!ToJSValue(cx, result, args.rval())) {
2216 0 : return false;
2217 : }
2218 0 : return true;
2219 : break;
2220 : }
2221 : default: {
2222 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addIceCandidate");
2223 : break;
2224 : }
2225 : }
2226 : MOZ_CRASH("We have an always-returning default case");
2227 : return false;
2228 : }
2229 :
2230 : static bool
2231 0 : addIceCandidate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2232 : {
2233 : // Make sure to save the callee before someone maybe messes
2234 : // with rval().
2235 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
2236 0 : bool ok = addIceCandidate(cx, obj, self, args);
2237 0 : if (ok) {
2238 0 : return true;
2239 : }
2240 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
2241 0 : args.rval());
2242 : }
2243 :
2244 : static const JSJitInfo addIceCandidate_methodinfo = {
2245 : { (JSJitGetterOp)addIceCandidate_promiseWrapper },
2246 : { prototypes::id::RTCPeerConnection },
2247 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2248 : JSJitInfo::Method,
2249 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2250 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2251 : false, /* isInfallible. False in setters. */
2252 : false, /* isMovable. Not relevant for setters. */
2253 : false, /* isEliminatable. Not relevant for setters. */
2254 : false, /* isAlwaysInSlot. Only relevant for getters. */
2255 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2256 : false, /* isTypedMethod. Only relevant for methods. */
2257 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2258 : };
2259 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2260 : static_assert(0 < 1, "There is no slot for us");
2261 :
2262 : static bool
2263 0 : get_canTrickleIceCandidates(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2264 : {
2265 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2266 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2267 0 : if (objIsXray) {
2268 0 : unwrappedObj.emplace(cx, obj);
2269 : }
2270 0 : if (objIsXray) {
2271 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2272 0 : if (!unwrappedObj.ref()) {
2273 0 : return false;
2274 : }
2275 : }
2276 0 : binding_detail::FastErrorResult rv;
2277 0 : Nullable<bool> result(self->GetCanTrickleIceCandidates(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
2278 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2279 0 : return false;
2280 : }
2281 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2282 0 : if (result.IsNull()) {
2283 0 : args.rval().setNull();
2284 0 : return true;
2285 : }
2286 0 : args.rval().setBoolean(result.Value());
2287 0 : return true;
2288 : }
2289 :
2290 : static const JSJitInfo canTrickleIceCandidates_getterinfo = {
2291 : { (JSJitGetterOp)get_canTrickleIceCandidates },
2292 : { prototypes::id::RTCPeerConnection },
2293 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2294 : JSJitInfo::Getter,
2295 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2296 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
2297 : false, /* isInfallible. False in setters. */
2298 : false, /* isMovable. Not relevant for setters. */
2299 : false, /* isEliminatable. Not relevant for setters. */
2300 : false, /* isAlwaysInSlot. Only relevant for getters. */
2301 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2302 : false, /* isTypedMethod. Only relevant for methods. */
2303 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2304 : };
2305 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2306 : static_assert(0 < 1, "There is no slot for us");
2307 :
2308 : static bool
2309 0 : get_iceGatheringState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2310 : {
2311 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2312 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2313 0 : if (objIsXray) {
2314 0 : unwrappedObj.emplace(cx, obj);
2315 : }
2316 0 : if (objIsXray) {
2317 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2318 0 : if (!unwrappedObj.ref()) {
2319 0 : return false;
2320 : }
2321 : }
2322 0 : binding_detail::FastErrorResult rv;
2323 0 : RTCIceGatheringState result(self->GetIceGatheringState(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
2324 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2325 0 : return false;
2326 : }
2327 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2328 0 : if (!ToJSValue(cx, result, args.rval())) {
2329 0 : return false;
2330 : }
2331 0 : return true;
2332 : }
2333 :
2334 : static const JSJitInfo iceGatheringState_getterinfo = {
2335 : { (JSJitGetterOp)get_iceGatheringState },
2336 : { prototypes::id::RTCPeerConnection },
2337 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2338 : JSJitInfo::Getter,
2339 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2340 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
2341 : false, /* isInfallible. False in setters. */
2342 : false, /* isMovable. Not relevant for setters. */
2343 : false, /* isEliminatable. Not relevant for setters. */
2344 : false, /* isAlwaysInSlot. Only relevant for getters. */
2345 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2346 : false, /* isTypedMethod. Only relevant for methods. */
2347 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2348 : };
2349 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2350 : static_assert(0 < 1, "There is no slot for us");
2351 :
2352 : static bool
2353 0 : get_iceConnectionState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2354 : {
2355 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2356 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2357 0 : if (objIsXray) {
2358 0 : unwrappedObj.emplace(cx, obj);
2359 : }
2360 0 : if (objIsXray) {
2361 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2362 0 : if (!unwrappedObj.ref()) {
2363 0 : return false;
2364 : }
2365 : }
2366 0 : binding_detail::FastErrorResult rv;
2367 0 : RTCIceConnectionState result(self->GetIceConnectionState(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
2368 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2369 0 : return false;
2370 : }
2371 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2372 0 : if (!ToJSValue(cx, result, args.rval())) {
2373 0 : return false;
2374 : }
2375 0 : return true;
2376 : }
2377 :
2378 : static const JSJitInfo iceConnectionState_getterinfo = {
2379 : { (JSJitGetterOp)get_iceConnectionState },
2380 : { prototypes::id::RTCPeerConnection },
2381 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2382 : JSJitInfo::Getter,
2383 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2384 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
2385 : false, /* isInfallible. False in setters. */
2386 : false, /* isMovable. Not relevant for setters. */
2387 : false, /* isEliminatable. Not relevant for setters. */
2388 : false, /* isAlwaysInSlot. Only relevant for getters. */
2389 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2390 : false, /* isTypedMethod. Only relevant for methods. */
2391 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2392 : };
2393 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2394 : static_assert(0 < 1, "There is no slot for us");
2395 :
2396 : static bool
2397 0 : get_peerIdentity(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2398 : {
2399 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2400 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2401 0 : if (objIsXray) {
2402 0 : unwrappedObj.emplace(cx, obj);
2403 : }
2404 0 : if (objIsXray) {
2405 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2406 0 : if (!unwrappedObj.ref()) {
2407 0 : return false;
2408 : }
2409 : }
2410 0 : binding_detail::FastErrorResult rv;
2411 0 : auto result(StrongOrRawPtr<Promise>(self->GetPeerIdentity(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
2412 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2413 0 : return false;
2414 : }
2415 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2416 0 : if (!ToJSValue(cx, result, args.rval())) {
2417 0 : return false;
2418 : }
2419 0 : return true;
2420 : }
2421 :
2422 : static bool
2423 0 : get_peerIdentity_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2424 : {
2425 0 : bool ok = get_peerIdentity(cx, obj, self, args);
2426 0 : if (ok) {
2427 0 : return true;
2428 : }
2429 0 : JS::Rooted<JSObject*> globalForPromise(cx);
2430 : // We can't use xpc::XrayAwareCalleeGlobal here because we have no
2431 : // callee. Use our hacky version instead.
2432 0 : if (!xpc::XrayAwareCalleeGlobalForSpecializedGetters(cx, obj,
2433 : &globalForPromise)) {
2434 0 : return false;
2435 : }
2436 0 : return ConvertExceptionToPromise(cx, globalForPromise, args.rval());
2437 : }
2438 :
2439 : static const JSJitInfo peerIdentity_getterinfo = {
2440 : { (JSJitGetterOp)get_peerIdentity_promiseWrapper },
2441 : { prototypes::id::RTCPeerConnection },
2442 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2443 : JSJitInfo::Getter,
2444 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2445 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2446 : false, /* isInfallible. False in setters. */
2447 : false, /* isMovable. Not relevant for setters. */
2448 : false, /* isEliminatable. Not relevant for setters. */
2449 : false, /* isAlwaysInSlot. Only relevant for getters. */
2450 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2451 : false, /* isTypedMethod. Only relevant for methods. */
2452 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2453 : };
2454 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2455 : static_assert(0 < 1, "There is no slot for us");
2456 :
2457 : static bool
2458 0 : get_idpLoginUrl(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2459 : {
2460 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2461 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2462 0 : if (objIsXray) {
2463 0 : unwrappedObj.emplace(cx, obj);
2464 : }
2465 0 : if (objIsXray) {
2466 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2467 0 : if (!unwrappedObj.ref()) {
2468 0 : return false;
2469 : }
2470 : }
2471 0 : binding_detail::FastErrorResult rv;
2472 0 : DOMString result;
2473 0 : self->GetIdpLoginUrl(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2474 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2475 0 : return false;
2476 : }
2477 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2478 0 : if (!xpc::StringToJsval(cx, result, args.rval())) {
2479 0 : return false;
2480 : }
2481 0 : return true;
2482 : }
2483 :
2484 : static const JSJitInfo idpLoginUrl_getterinfo = {
2485 : { (JSJitGetterOp)get_idpLoginUrl },
2486 : { prototypes::id::RTCPeerConnection },
2487 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2488 : JSJitInfo::Getter,
2489 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2490 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
2491 : false, /* isInfallible. False in setters. */
2492 : false, /* isMovable. Not relevant for setters. */
2493 : false, /* isEliminatable. Not relevant for setters. */
2494 : false, /* isAlwaysInSlot. Only relevant for getters. */
2495 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2496 : false, /* isTypedMethod. Only relevant for methods. */
2497 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2498 : };
2499 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2500 : static_assert(0 < 1, "There is no slot for us");
2501 :
2502 : static bool
2503 0 : get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2504 : {
2505 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2506 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2507 0 : if (objIsXray) {
2508 0 : unwrappedObj.emplace(cx, obj);
2509 : }
2510 0 : if (objIsXray) {
2511 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2512 0 : if (!unwrappedObj.ref()) {
2513 0 : return false;
2514 : }
2515 : }
2516 0 : binding_detail::FastErrorResult rv;
2517 0 : DOMString result;
2518 0 : self->GetId(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2519 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2520 0 : return false;
2521 : }
2522 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2523 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
2524 0 : return false;
2525 : }
2526 0 : return true;
2527 : }
2528 :
2529 : static bool
2530 0 : set_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
2531 : {
2532 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2533 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2534 0 : if (objIsXray) {
2535 0 : unwrappedObj.emplace(cx, obj);
2536 : }
2537 0 : binding_detail::FakeString arg0;
2538 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2539 0 : return false;
2540 : }
2541 0 : if (objIsXray) {
2542 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2543 0 : if (!unwrappedObj.ref()) {
2544 0 : return false;
2545 : }
2546 : }
2547 0 : binding_detail::FastErrorResult rv;
2548 0 : self->SetId(NonNullHelper(Constify(arg0)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2549 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2550 0 : return false;
2551 : }
2552 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2553 :
2554 0 : return true;
2555 : }
2556 :
2557 : static const JSJitInfo id_getterinfo = {
2558 : { (JSJitGetterOp)get_id },
2559 : { prototypes::id::RTCPeerConnection },
2560 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2561 : JSJitInfo::Getter,
2562 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2563 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
2564 : false, /* isInfallible. False in setters. */
2565 : false, /* isMovable. Not relevant for setters. */
2566 : false, /* isEliminatable. Not relevant for setters. */
2567 : false, /* isAlwaysInSlot. Only relevant for getters. */
2568 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2569 : false, /* isTypedMethod. Only relevant for methods. */
2570 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2571 : };
2572 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2573 : static_assert(0 < 1, "There is no slot for us");
2574 : static const JSJitInfo id_setterinfo = {
2575 : { (JSJitGetterOp)set_id },
2576 : { prototypes::id::RTCPeerConnection },
2577 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2578 : JSJitInfo::Setter,
2579 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2580 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
2581 : false, /* isInfallible. False in setters. */
2582 : false, /* isMovable. Not relevant for setters. */
2583 : false, /* isEliminatable. Not relevant for setters. */
2584 : false, /* isAlwaysInSlot. Only relevant for getters. */
2585 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2586 : false, /* isTypedMethod. Only relevant for methods. */
2587 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2588 : };
2589 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2590 : static_assert(0 < 1, "There is no slot for us");
2591 :
2592 : static bool
2593 0 : getConfiguration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2594 : {
2595 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2596 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2597 0 : if (objIsXray) {
2598 0 : unwrappedObj.emplace(cx, obj);
2599 : }
2600 0 : if (objIsXray) {
2601 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2602 0 : if (!unwrappedObj.ref()) {
2603 0 : return false;
2604 : }
2605 : }
2606 0 : binding_detail::FastErrorResult rv;
2607 0 : RTCConfiguration result;
2608 0 : self->GetConfiguration(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2609 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2610 0 : return false;
2611 : }
2612 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2613 0 : if (!result.ToObjectInternal(cx, args.rval())) {
2614 0 : return false;
2615 : }
2616 0 : return true;
2617 : }
2618 :
2619 : static const JSJitInfo getConfiguration_methodinfo = {
2620 : { (JSJitGetterOp)getConfiguration },
2621 : { prototypes::id::RTCPeerConnection },
2622 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2623 : JSJitInfo::Method,
2624 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2625 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2626 : false, /* isInfallible. False in setters. */
2627 : false, /* isMovable. Not relevant for setters. */
2628 : false, /* isEliminatable. Not relevant for setters. */
2629 : false, /* isAlwaysInSlot. Only relevant for getters. */
2630 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2631 : false, /* isTypedMethod. Only relevant for methods. */
2632 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2633 : };
2634 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2635 : static_assert(0 < 1, "There is no slot for us");
2636 :
2637 : static bool
2638 0 : getLocalStreams(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2639 : {
2640 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
2641 : // Return false from the JSNative in order to trigger
2642 : // an uncatchable exception.
2643 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2644 0 : return false;
2645 : }
2646 0 : DeprecationWarning(cx, obj, nsIDocument::eRTCPeerConnectionGetStreams);
2647 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2648 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2649 0 : if (objIsXray) {
2650 0 : unwrappedObj.emplace(cx, obj);
2651 : }
2652 0 : if (objIsXray) {
2653 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2654 0 : if (!unwrappedObj.ref()) {
2655 0 : return false;
2656 : }
2657 : }
2658 0 : binding_detail::FastErrorResult rv;
2659 0 : nsTArray<StrongPtrForMember<mozilla::DOMMediaStream>::Type> result;
2660 0 : self->GetLocalStreams(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2661 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2662 0 : return false;
2663 : }
2664 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2665 :
2666 0 : uint32_t length = result.Length();
2667 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
2668 0 : if (!returnArray) {
2669 0 : return false;
2670 : }
2671 : // Scope for 'tmp'
2672 : {
2673 0 : JS::Rooted<JS::Value> tmp(cx);
2674 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
2675 : // Control block to let us common up the JS_DefineElement calls when there
2676 : // are different ways to succeed at wrapping the object.
2677 : do {
2678 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
2679 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
2680 0 : return false;
2681 : }
2682 0 : break;
2683 : } while (0);
2684 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
2685 : JSPROP_ENUMERATE)) {
2686 0 : return false;
2687 : }
2688 : }
2689 : }
2690 0 : args.rval().setObject(*returnArray);
2691 0 : return true;
2692 : }
2693 :
2694 : static const JSJitInfo getLocalStreams_methodinfo = {
2695 : { (JSJitGetterOp)getLocalStreams },
2696 : { prototypes::id::RTCPeerConnection },
2697 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2698 : JSJitInfo::Method,
2699 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2700 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2701 : false, /* isInfallible. False in setters. */
2702 : false, /* isMovable. Not relevant for setters. */
2703 : false, /* isEliminatable. Not relevant for setters. */
2704 : false, /* isAlwaysInSlot. Only relevant for getters. */
2705 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2706 : false, /* isTypedMethod. Only relevant for methods. */
2707 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2708 : };
2709 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2710 : static_assert(0 < 1, "There is no slot for us");
2711 :
2712 : static bool
2713 0 : getRemoteStreams(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2714 : {
2715 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
2716 : // Return false from the JSNative in order to trigger
2717 : // an uncatchable exception.
2718 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2719 0 : return false;
2720 : }
2721 0 : DeprecationWarning(cx, obj, nsIDocument::eRTCPeerConnectionGetStreams);
2722 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2723 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2724 0 : if (objIsXray) {
2725 0 : unwrappedObj.emplace(cx, obj);
2726 : }
2727 0 : if (objIsXray) {
2728 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2729 0 : if (!unwrappedObj.ref()) {
2730 0 : return false;
2731 : }
2732 : }
2733 0 : binding_detail::FastErrorResult rv;
2734 0 : nsTArray<StrongPtrForMember<mozilla::DOMMediaStream>::Type> result;
2735 0 : self->GetRemoteStreams(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2736 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2737 0 : return false;
2738 : }
2739 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2740 :
2741 0 : uint32_t length = result.Length();
2742 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
2743 0 : if (!returnArray) {
2744 0 : return false;
2745 : }
2746 : // Scope for 'tmp'
2747 : {
2748 0 : JS::Rooted<JS::Value> tmp(cx);
2749 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
2750 : // Control block to let us common up the JS_DefineElement calls when there
2751 : // are different ways to succeed at wrapping the object.
2752 : do {
2753 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
2754 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
2755 0 : return false;
2756 : }
2757 0 : break;
2758 : } while (0);
2759 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
2760 : JSPROP_ENUMERATE)) {
2761 0 : return false;
2762 : }
2763 : }
2764 : }
2765 0 : args.rval().setObject(*returnArray);
2766 0 : return true;
2767 : }
2768 :
2769 : static const JSJitInfo getRemoteStreams_methodinfo = {
2770 : { (JSJitGetterOp)getRemoteStreams },
2771 : { prototypes::id::RTCPeerConnection },
2772 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2773 : JSJitInfo::Method,
2774 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2775 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2776 : false, /* isInfallible. False in setters. */
2777 : false, /* isMovable. Not relevant for setters. */
2778 : false, /* isEliminatable. Not relevant for setters. */
2779 : false, /* isAlwaysInSlot. Only relevant for getters. */
2780 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2781 : false, /* isTypedMethod. Only relevant for methods. */
2782 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2783 : };
2784 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2785 : static_assert(0 < 1, "There is no slot for us");
2786 :
2787 : static bool
2788 0 : addStream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2789 : {
2790 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
2791 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addStream");
2792 : }
2793 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2794 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2795 0 : if (objIsXray) {
2796 0 : unwrappedObj.emplace(cx, obj);
2797 : }
2798 0 : NonNull<mozilla::DOMMediaStream> arg0;
2799 0 : if (args[0].isObject()) {
2800 : {
2801 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[0], arg0);
2802 0 : if (NS_FAILED(rv)) {
2803 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addStream", "MediaStream");
2804 0 : return false;
2805 : }
2806 : }
2807 : } else {
2808 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addStream");
2809 0 : return false;
2810 : }
2811 0 : if (objIsXray) {
2812 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2813 0 : if (!unwrappedObj.ref()) {
2814 0 : return false;
2815 : }
2816 : }
2817 0 : binding_detail::FastErrorResult rv;
2818 0 : self->AddStream(NonNullHelper(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2819 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2820 0 : return false;
2821 : }
2822 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2823 0 : args.rval().setUndefined();
2824 0 : return true;
2825 : }
2826 :
2827 : static const JSJitInfo addStream_methodinfo = {
2828 : { (JSJitGetterOp)addStream },
2829 : { prototypes::id::RTCPeerConnection },
2830 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2831 : JSJitInfo::Method,
2832 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2833 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
2834 : false, /* isInfallible. False in setters. */
2835 : false, /* isMovable. Not relevant for setters. */
2836 : false, /* isEliminatable. Not relevant for setters. */
2837 : false, /* isAlwaysInSlot. Only relevant for getters. */
2838 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2839 : false, /* isTypedMethod. Only relevant for methods. */
2840 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2841 : };
2842 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2843 : static_assert(0 < 1, "There is no slot for us");
2844 :
2845 : static bool
2846 0 : addTrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2847 : {
2848 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
2849 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addTrack");
2850 : }
2851 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2852 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2853 0 : if (objIsXray) {
2854 0 : unwrappedObj.emplace(cx, obj);
2855 : }
2856 0 : NonNull<mozilla::dom::MediaStreamTrack> arg0;
2857 0 : if (args[0].isObject()) {
2858 : {
2859 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0);
2860 0 : if (NS_FAILED(rv)) {
2861 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addTrack", "MediaStreamTrack");
2862 0 : return false;
2863 : }
2864 : }
2865 : } else {
2866 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addTrack");
2867 0 : return false;
2868 : }
2869 0 : NonNull<mozilla::DOMMediaStream> arg1;
2870 0 : if (args[1].isObject()) {
2871 : {
2872 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[1], arg1);
2873 0 : if (NS_FAILED(rv)) {
2874 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of RTCPeerConnection.addTrack", "MediaStream");
2875 0 : return false;
2876 : }
2877 : }
2878 : } else {
2879 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.addTrack");
2880 0 : return false;
2881 : }
2882 0 : binding_detail::AutoSequence<OwningNonNull<mozilla::DOMMediaStream>> arg2;
2883 0 : if (args.length() > 2) {
2884 0 : if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
2885 0 : JS_ReportOutOfMemory(cx);
2886 0 : return false;
2887 : }
2888 0 : for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
2889 0 : OwningNonNull<mozilla::DOMMediaStream>& slot = *arg2.AppendElement(mozilla::fallible);
2890 0 : if (args[variadicArg].isObject()) {
2891 : static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
2892 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[variadicArg], slot);
2893 0 : if (NS_FAILED(rv)) {
2894 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of RTCPeerConnection.addTrack", "MediaStream");
2895 0 : return false;
2896 : }
2897 : }
2898 : } else {
2899 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.addTrack");
2900 0 : return false;
2901 : }
2902 : }
2903 : }
2904 0 : if (objIsXray) {
2905 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2906 0 : if (!unwrappedObj.ref()) {
2907 0 : return false;
2908 : }
2909 : }
2910 0 : binding_detail::FastErrorResult rv;
2911 0 : auto result(StrongOrRawPtr<mozilla::dom::RTCRtpSender>(self->AddTrack(NonNullHelper(arg0), NonNullHelper(arg1), NonNullHelper(Constify(arg2)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
2912 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2913 0 : return false;
2914 : }
2915 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2916 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2917 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
2918 0 : return false;
2919 : }
2920 0 : return true;
2921 : }
2922 :
2923 : static const JSJitInfo addTrack_methodinfo = {
2924 : { (JSJitGetterOp)addTrack },
2925 : { prototypes::id::RTCPeerConnection },
2926 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2927 : JSJitInfo::Method,
2928 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2929 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
2930 : false, /* isInfallible. False in setters. */
2931 : false, /* isMovable. Not relevant for setters. */
2932 : false, /* isEliminatable. Not relevant for setters. */
2933 : false, /* isAlwaysInSlot. Only relevant for getters. */
2934 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2935 : false, /* isTypedMethod. Only relevant for methods. */
2936 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2937 : };
2938 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2939 : static_assert(0 < 1, "There is no slot for us");
2940 :
2941 : static bool
2942 0 : removeTrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2943 : {
2944 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
2945 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.removeTrack");
2946 : }
2947 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2948 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2949 0 : if (objIsXray) {
2950 0 : unwrappedObj.emplace(cx, obj);
2951 : }
2952 0 : NonNull<mozilla::dom::RTCRtpSender> arg0;
2953 0 : if (args[0].isObject()) {
2954 : {
2955 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(args[0], arg0);
2956 0 : if (NS_FAILED(rv)) {
2957 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.removeTrack", "RTCRtpSender");
2958 0 : return false;
2959 : }
2960 : }
2961 : } else {
2962 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.removeTrack");
2963 0 : return false;
2964 : }
2965 0 : if (objIsXray) {
2966 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2967 0 : if (!unwrappedObj.ref()) {
2968 0 : return false;
2969 : }
2970 : }
2971 0 : binding_detail::FastErrorResult rv;
2972 0 : self->RemoveTrack(NonNullHelper(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
2973 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2974 0 : return false;
2975 : }
2976 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2977 0 : args.rval().setUndefined();
2978 0 : return true;
2979 : }
2980 :
2981 : static const JSJitInfo removeTrack_methodinfo = {
2982 : { (JSJitGetterOp)removeTrack },
2983 : { prototypes::id::RTCPeerConnection },
2984 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2985 : JSJitInfo::Method,
2986 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
2987 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
2988 : false, /* isInfallible. False in setters. */
2989 : false, /* isMovable. Not relevant for setters. */
2990 : false, /* isEliminatable. Not relevant for setters. */
2991 : false, /* isAlwaysInSlot. Only relevant for getters. */
2992 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
2993 : false, /* isTypedMethod. Only relevant for methods. */
2994 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
2995 : };
2996 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2997 : static_assert(0 < 1, "There is no slot for us");
2998 :
2999 : static bool
3000 0 : getSenders(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3001 : {
3002 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3003 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3004 0 : if (objIsXray) {
3005 0 : unwrappedObj.emplace(cx, obj);
3006 : }
3007 0 : if (objIsXray) {
3008 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3009 0 : if (!unwrappedObj.ref()) {
3010 0 : return false;
3011 : }
3012 : }
3013 0 : binding_detail::FastErrorResult rv;
3014 0 : nsTArray<StrongPtrForMember<mozilla::dom::RTCRtpSender>::Type> result;
3015 0 : self->GetSenders(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3016 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3017 0 : return false;
3018 : }
3019 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3020 :
3021 0 : uint32_t length = result.Length();
3022 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3023 0 : if (!returnArray) {
3024 0 : return false;
3025 : }
3026 : // Scope for 'tmp'
3027 : {
3028 0 : JS::Rooted<JS::Value> tmp(cx);
3029 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3030 : // Control block to let us common up the JS_DefineElement calls when there
3031 : // are different ways to succeed at wrapping the object.
3032 : do {
3033 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3034 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
3035 0 : return false;
3036 : }
3037 0 : break;
3038 : } while (0);
3039 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3040 : JSPROP_ENUMERATE)) {
3041 0 : return false;
3042 : }
3043 : }
3044 : }
3045 0 : args.rval().setObject(*returnArray);
3046 0 : return true;
3047 : }
3048 :
3049 : static const JSJitInfo getSenders_methodinfo = {
3050 : { (JSJitGetterOp)getSenders },
3051 : { prototypes::id::RTCPeerConnection },
3052 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3053 : JSJitInfo::Method,
3054 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3055 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
3056 : false, /* isInfallible. False in setters. */
3057 : false, /* isMovable. Not relevant for setters. */
3058 : false, /* isEliminatable. Not relevant for setters. */
3059 : false, /* isAlwaysInSlot. Only relevant for getters. */
3060 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3061 : false, /* isTypedMethod. Only relevant for methods. */
3062 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3063 : };
3064 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3065 : static_assert(0 < 1, "There is no slot for us");
3066 :
3067 : static bool
3068 0 : getReceivers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3069 : {
3070 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3071 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3072 0 : if (objIsXray) {
3073 0 : unwrappedObj.emplace(cx, obj);
3074 : }
3075 0 : if (objIsXray) {
3076 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3077 0 : if (!unwrappedObj.ref()) {
3078 0 : return false;
3079 : }
3080 : }
3081 0 : binding_detail::FastErrorResult rv;
3082 0 : nsTArray<StrongPtrForMember<mozilla::dom::RTCRtpReceiver>::Type> result;
3083 0 : self->GetReceivers(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3084 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3085 0 : return false;
3086 : }
3087 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3088 :
3089 0 : uint32_t length = result.Length();
3090 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3091 0 : if (!returnArray) {
3092 0 : return false;
3093 : }
3094 : // Scope for 'tmp'
3095 : {
3096 0 : JS::Rooted<JS::Value> tmp(cx);
3097 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3098 : // Control block to let us common up the JS_DefineElement calls when there
3099 : // are different ways to succeed at wrapping the object.
3100 : do {
3101 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3102 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
3103 0 : return false;
3104 : }
3105 0 : break;
3106 : } while (0);
3107 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3108 : JSPROP_ENUMERATE)) {
3109 0 : return false;
3110 : }
3111 : }
3112 : }
3113 0 : args.rval().setObject(*returnArray);
3114 0 : return true;
3115 : }
3116 :
3117 : static const JSJitInfo getReceivers_methodinfo = {
3118 : { (JSJitGetterOp)getReceivers },
3119 : { prototypes::id::RTCPeerConnection },
3120 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3121 : JSJitInfo::Method,
3122 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3123 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
3124 : false, /* isInfallible. False in setters. */
3125 : false, /* isMovable. Not relevant for setters. */
3126 : false, /* isEliminatable. Not relevant for setters. */
3127 : false, /* isAlwaysInSlot. Only relevant for getters. */
3128 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3129 : false, /* isTypedMethod. Only relevant for methods. */
3130 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3131 : };
3132 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3133 : static_assert(0 < 1, "There is no slot for us");
3134 :
3135 : static bool
3136 0 : mozAddRIDExtension(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3137 : {
3138 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
3139 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozAddRIDExtension");
3140 : }
3141 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3142 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3143 0 : if (objIsXray) {
3144 0 : unwrappedObj.emplace(cx, obj);
3145 : }
3146 0 : NonNull<mozilla::dom::RTCRtpReceiver> arg0;
3147 0 : if (args[0].isObject()) {
3148 : {
3149 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(args[0], arg0);
3150 0 : if (NS_FAILED(rv)) {
3151 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.mozAddRIDExtension", "RTCRtpReceiver");
3152 0 : return false;
3153 : }
3154 : }
3155 : } else {
3156 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozAddRIDExtension");
3157 0 : return false;
3158 : }
3159 : uint16_t arg1;
3160 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
3161 0 : return false;
3162 : }
3163 0 : if (objIsXray) {
3164 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3165 0 : if (!unwrappedObj.ref()) {
3166 0 : return false;
3167 : }
3168 : }
3169 0 : binding_detail::FastErrorResult rv;
3170 0 : self->MozAddRIDExtension(NonNullHelper(arg0), arg1, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3171 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3172 0 : return false;
3173 : }
3174 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3175 0 : args.rval().setUndefined();
3176 0 : return true;
3177 : }
3178 :
3179 : static const JSJitInfo mozAddRIDExtension_methodinfo = {
3180 : { (JSJitGetterOp)mozAddRIDExtension },
3181 : { prototypes::id::RTCPeerConnection },
3182 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3183 : JSJitInfo::Method,
3184 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3185 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3186 : false, /* isInfallible. False in setters. */
3187 : false, /* isMovable. Not relevant for setters. */
3188 : false, /* isEliminatable. Not relevant for setters. */
3189 : false, /* isAlwaysInSlot. Only relevant for getters. */
3190 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3191 : false, /* isTypedMethod. Only relevant for methods. */
3192 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3193 : };
3194 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3195 : static_assert(0 < 1, "There is no slot for us");
3196 :
3197 : static bool
3198 0 : mozAddRIDFilter(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3199 : {
3200 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
3201 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozAddRIDFilter");
3202 : }
3203 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3204 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3205 0 : if (objIsXray) {
3206 0 : unwrappedObj.emplace(cx, obj);
3207 : }
3208 0 : NonNull<mozilla::dom::RTCRtpReceiver> arg0;
3209 0 : if (args[0].isObject()) {
3210 : {
3211 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(args[0], arg0);
3212 0 : if (NS_FAILED(rv)) {
3213 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.mozAddRIDFilter", "RTCRtpReceiver");
3214 0 : return false;
3215 : }
3216 : }
3217 : } else {
3218 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozAddRIDFilter");
3219 0 : return false;
3220 : }
3221 0 : binding_detail::FakeString arg1;
3222 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
3223 0 : return false;
3224 : }
3225 0 : if (objIsXray) {
3226 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3227 0 : if (!unwrappedObj.ref()) {
3228 0 : return false;
3229 : }
3230 : }
3231 0 : binding_detail::FastErrorResult rv;
3232 0 : self->MozAddRIDFilter(NonNullHelper(arg0), NonNullHelper(Constify(arg1)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3233 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3234 0 : return false;
3235 : }
3236 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3237 0 : args.rval().setUndefined();
3238 0 : return true;
3239 : }
3240 :
3241 : static const JSJitInfo mozAddRIDFilter_methodinfo = {
3242 : { (JSJitGetterOp)mozAddRIDFilter },
3243 : { prototypes::id::RTCPeerConnection },
3244 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3245 : JSJitInfo::Method,
3246 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3247 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3248 : false, /* isInfallible. False in setters. */
3249 : false, /* isMovable. Not relevant for setters. */
3250 : false, /* isEliminatable. Not relevant for setters. */
3251 : false, /* isAlwaysInSlot. Only relevant for getters. */
3252 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3253 : false, /* isTypedMethod. Only relevant for methods. */
3254 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3255 : };
3256 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3257 : static_assert(0 < 1, "There is no slot for us");
3258 :
3259 : static bool
3260 0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3261 : {
3262 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3263 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3264 0 : if (objIsXray) {
3265 0 : unwrappedObj.emplace(cx, obj);
3266 : }
3267 0 : if (objIsXray) {
3268 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3269 0 : if (!unwrappedObj.ref()) {
3270 0 : return false;
3271 : }
3272 : }
3273 0 : binding_detail::FastErrorResult rv;
3274 0 : self->Close(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3275 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3276 0 : return false;
3277 : }
3278 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3279 0 : args.rval().setUndefined();
3280 0 : return true;
3281 : }
3282 :
3283 : static const JSJitInfo close_methodinfo = {
3284 : { (JSJitGetterOp)close },
3285 : { prototypes::id::RTCPeerConnection },
3286 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3287 : JSJitInfo::Method,
3288 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3289 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3290 : false, /* isInfallible. False in setters. */
3291 : false, /* isMovable. Not relevant for setters. */
3292 : false, /* isEliminatable. Not relevant for setters. */
3293 : false, /* isAlwaysInSlot. Only relevant for getters. */
3294 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3295 : false, /* isTypedMethod. Only relevant for methods. */
3296 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3297 : };
3298 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3299 : static_assert(0 < 1, "There is no slot for us");
3300 :
3301 : static bool
3302 0 : get_onnegotiationneeded(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3303 : {
3304 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3305 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3306 0 : if (objIsXray) {
3307 0 : unwrappedObj.emplace(cx, obj);
3308 : }
3309 0 : if (objIsXray) {
3310 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3311 0 : if (!unwrappedObj.ref()) {
3312 0 : return false;
3313 : }
3314 : }
3315 0 : binding_detail::FastErrorResult rv;
3316 0 : RefPtr<EventHandlerNonNull> result(self->GetOnnegotiationneeded(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3317 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3318 0 : return false;
3319 : }
3320 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3321 0 : if (result) {
3322 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3323 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3324 0 : return false;
3325 : }
3326 0 : return true;
3327 : } else {
3328 0 : args.rval().setNull();
3329 0 : return true;
3330 : }
3331 : }
3332 :
3333 : static bool
3334 0 : set_onnegotiationneeded(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3335 : {
3336 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3337 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3338 0 : if (objIsXray) {
3339 0 : unwrappedObj.emplace(cx, obj);
3340 : }
3341 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3342 0 : if (args[0].isObject()) {
3343 : { // scope for tempRoot
3344 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3345 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3346 : }
3347 : } else {
3348 0 : arg0 = nullptr;
3349 : }
3350 0 : if (objIsXray) {
3351 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3352 0 : if (!unwrappedObj.ref()) {
3353 0 : return false;
3354 : }
3355 : }
3356 0 : binding_detail::FastErrorResult rv;
3357 0 : self->SetOnnegotiationneeded(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3358 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3359 0 : return false;
3360 : }
3361 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3362 :
3363 0 : return true;
3364 : }
3365 :
3366 : static const JSJitInfo onnegotiationneeded_getterinfo = {
3367 : { (JSJitGetterOp)get_onnegotiationneeded },
3368 : { prototypes::id::RTCPeerConnection },
3369 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3370 : JSJitInfo::Getter,
3371 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3372 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3373 : false, /* isInfallible. False in setters. */
3374 : false, /* isMovable. Not relevant for setters. */
3375 : false, /* isEliminatable. Not relevant for setters. */
3376 : false, /* isAlwaysInSlot. Only relevant for getters. */
3377 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3378 : false, /* isTypedMethod. Only relevant for methods. */
3379 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3380 : };
3381 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3382 : static_assert(0 < 1, "There is no slot for us");
3383 : static const JSJitInfo onnegotiationneeded_setterinfo = {
3384 : { (JSJitGetterOp)set_onnegotiationneeded },
3385 : { prototypes::id::RTCPeerConnection },
3386 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3387 : JSJitInfo::Setter,
3388 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3389 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3390 : false, /* isInfallible. False in setters. */
3391 : false, /* isMovable. Not relevant for setters. */
3392 : false, /* isEliminatable. Not relevant for setters. */
3393 : false, /* isAlwaysInSlot. Only relevant for getters. */
3394 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3395 : false, /* isTypedMethod. Only relevant for methods. */
3396 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3397 : };
3398 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3399 : static_assert(0 < 1, "There is no slot for us");
3400 :
3401 : static bool
3402 0 : get_onicecandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3403 : {
3404 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3405 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3406 0 : if (objIsXray) {
3407 0 : unwrappedObj.emplace(cx, obj);
3408 : }
3409 0 : if (objIsXray) {
3410 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3411 0 : if (!unwrappedObj.ref()) {
3412 0 : return false;
3413 : }
3414 : }
3415 0 : binding_detail::FastErrorResult rv;
3416 0 : RefPtr<EventHandlerNonNull> result(self->GetOnicecandidate(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3417 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3418 0 : return false;
3419 : }
3420 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3421 0 : if (result) {
3422 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3423 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3424 0 : return false;
3425 : }
3426 0 : return true;
3427 : } else {
3428 0 : args.rval().setNull();
3429 0 : return true;
3430 : }
3431 : }
3432 :
3433 : static bool
3434 0 : set_onicecandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3435 : {
3436 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3437 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3438 0 : if (objIsXray) {
3439 0 : unwrappedObj.emplace(cx, obj);
3440 : }
3441 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3442 0 : if (args[0].isObject()) {
3443 : { // scope for tempRoot
3444 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3445 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3446 : }
3447 : } else {
3448 0 : arg0 = nullptr;
3449 : }
3450 0 : if (objIsXray) {
3451 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3452 0 : if (!unwrappedObj.ref()) {
3453 0 : return false;
3454 : }
3455 : }
3456 0 : binding_detail::FastErrorResult rv;
3457 0 : self->SetOnicecandidate(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3458 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3459 0 : return false;
3460 : }
3461 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3462 :
3463 0 : return true;
3464 : }
3465 :
3466 : static const JSJitInfo onicecandidate_getterinfo = {
3467 : { (JSJitGetterOp)get_onicecandidate },
3468 : { prototypes::id::RTCPeerConnection },
3469 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3470 : JSJitInfo::Getter,
3471 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3472 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3473 : false, /* isInfallible. False in setters. */
3474 : false, /* isMovable. Not relevant for setters. */
3475 : false, /* isEliminatable. Not relevant for setters. */
3476 : false, /* isAlwaysInSlot. Only relevant for getters. */
3477 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3478 : false, /* isTypedMethod. Only relevant for methods. */
3479 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3480 : };
3481 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3482 : static_assert(0 < 1, "There is no slot for us");
3483 : static const JSJitInfo onicecandidate_setterinfo = {
3484 : { (JSJitGetterOp)set_onicecandidate },
3485 : { prototypes::id::RTCPeerConnection },
3486 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3487 : JSJitInfo::Setter,
3488 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3489 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3490 : false, /* isInfallible. False in setters. */
3491 : false, /* isMovable. Not relevant for setters. */
3492 : false, /* isEliminatable. Not relevant for setters. */
3493 : false, /* isAlwaysInSlot. Only relevant for getters. */
3494 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3495 : false, /* isTypedMethod. Only relevant for methods. */
3496 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3497 : };
3498 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3499 : static_assert(0 < 1, "There is no slot for us");
3500 :
3501 : static bool
3502 0 : get_onsignalingstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3503 : {
3504 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3505 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3506 0 : if (objIsXray) {
3507 0 : unwrappedObj.emplace(cx, obj);
3508 : }
3509 0 : if (objIsXray) {
3510 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3511 0 : if (!unwrappedObj.ref()) {
3512 0 : return false;
3513 : }
3514 : }
3515 0 : binding_detail::FastErrorResult rv;
3516 0 : RefPtr<EventHandlerNonNull> result(self->GetOnsignalingstatechange(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3517 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3518 0 : return false;
3519 : }
3520 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3521 0 : if (result) {
3522 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3523 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3524 0 : return false;
3525 : }
3526 0 : return true;
3527 : } else {
3528 0 : args.rval().setNull();
3529 0 : return true;
3530 : }
3531 : }
3532 :
3533 : static bool
3534 0 : set_onsignalingstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3535 : {
3536 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3537 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3538 0 : if (objIsXray) {
3539 0 : unwrappedObj.emplace(cx, obj);
3540 : }
3541 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3542 0 : if (args[0].isObject()) {
3543 : { // scope for tempRoot
3544 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3545 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3546 : }
3547 : } else {
3548 0 : arg0 = nullptr;
3549 : }
3550 0 : if (objIsXray) {
3551 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3552 0 : if (!unwrappedObj.ref()) {
3553 0 : return false;
3554 : }
3555 : }
3556 0 : binding_detail::FastErrorResult rv;
3557 0 : self->SetOnsignalingstatechange(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3558 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3559 0 : return false;
3560 : }
3561 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3562 :
3563 0 : return true;
3564 : }
3565 :
3566 : static const JSJitInfo onsignalingstatechange_getterinfo = {
3567 : { (JSJitGetterOp)get_onsignalingstatechange },
3568 : { prototypes::id::RTCPeerConnection },
3569 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3570 : JSJitInfo::Getter,
3571 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3572 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3573 : false, /* isInfallible. False in setters. */
3574 : false, /* isMovable. Not relevant for setters. */
3575 : false, /* isEliminatable. Not relevant for setters. */
3576 : false, /* isAlwaysInSlot. Only relevant for getters. */
3577 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3578 : false, /* isTypedMethod. Only relevant for methods. */
3579 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3580 : };
3581 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3582 : static_assert(0 < 1, "There is no slot for us");
3583 : static const JSJitInfo onsignalingstatechange_setterinfo = {
3584 : { (JSJitGetterOp)set_onsignalingstatechange },
3585 : { prototypes::id::RTCPeerConnection },
3586 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3587 : JSJitInfo::Setter,
3588 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3589 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3590 : false, /* isInfallible. False in setters. */
3591 : false, /* isMovable. Not relevant for setters. */
3592 : false, /* isEliminatable. Not relevant for setters. */
3593 : false, /* isAlwaysInSlot. Only relevant for getters. */
3594 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3595 : false, /* isTypedMethod. Only relevant for methods. */
3596 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3597 : };
3598 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3599 : static_assert(0 < 1, "There is no slot for us");
3600 :
3601 : static bool
3602 0 : get_onaddstream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3603 : {
3604 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3605 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3606 0 : if (objIsXray) {
3607 0 : unwrappedObj.emplace(cx, obj);
3608 : }
3609 0 : if (objIsXray) {
3610 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3611 0 : if (!unwrappedObj.ref()) {
3612 0 : return false;
3613 : }
3614 : }
3615 0 : binding_detail::FastErrorResult rv;
3616 0 : RefPtr<EventHandlerNonNull> result(self->GetOnaddstream(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3617 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3618 0 : return false;
3619 : }
3620 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3621 0 : if (result) {
3622 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3623 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3624 0 : return false;
3625 : }
3626 0 : return true;
3627 : } else {
3628 0 : args.rval().setNull();
3629 0 : return true;
3630 : }
3631 : }
3632 :
3633 : static bool
3634 0 : set_onaddstream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3635 : {
3636 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3637 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3638 0 : if (objIsXray) {
3639 0 : unwrappedObj.emplace(cx, obj);
3640 : }
3641 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3642 0 : if (args[0].isObject()) {
3643 : { // scope for tempRoot
3644 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3645 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3646 : }
3647 : } else {
3648 0 : arg0 = nullptr;
3649 : }
3650 0 : if (objIsXray) {
3651 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3652 0 : if (!unwrappedObj.ref()) {
3653 0 : return false;
3654 : }
3655 : }
3656 0 : binding_detail::FastErrorResult rv;
3657 0 : self->SetOnaddstream(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3658 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3659 0 : return false;
3660 : }
3661 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3662 :
3663 0 : return true;
3664 : }
3665 :
3666 : static const JSJitInfo onaddstream_getterinfo = {
3667 : { (JSJitGetterOp)get_onaddstream },
3668 : { prototypes::id::RTCPeerConnection },
3669 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3670 : JSJitInfo::Getter,
3671 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3672 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3673 : false, /* isInfallible. False in setters. */
3674 : false, /* isMovable. Not relevant for setters. */
3675 : false, /* isEliminatable. Not relevant for setters. */
3676 : false, /* isAlwaysInSlot. Only relevant for getters. */
3677 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3678 : false, /* isTypedMethod. Only relevant for methods. */
3679 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3680 : };
3681 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3682 : static_assert(0 < 1, "There is no slot for us");
3683 : static const JSJitInfo onaddstream_setterinfo = {
3684 : { (JSJitGetterOp)set_onaddstream },
3685 : { prototypes::id::RTCPeerConnection },
3686 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3687 : JSJitInfo::Setter,
3688 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3689 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3690 : false, /* isInfallible. False in setters. */
3691 : false, /* isMovable. Not relevant for setters. */
3692 : false, /* isEliminatable. Not relevant for setters. */
3693 : false, /* isAlwaysInSlot. Only relevant for getters. */
3694 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3695 : false, /* isTypedMethod. Only relevant for methods. */
3696 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3697 : };
3698 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3699 : static_assert(0 < 1, "There is no slot for us");
3700 :
3701 : static bool
3702 0 : get_onaddtrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3703 : {
3704 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3705 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3706 0 : if (objIsXray) {
3707 0 : unwrappedObj.emplace(cx, obj);
3708 : }
3709 0 : if (objIsXray) {
3710 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3711 0 : if (!unwrappedObj.ref()) {
3712 0 : return false;
3713 : }
3714 : }
3715 0 : binding_detail::FastErrorResult rv;
3716 0 : RefPtr<EventHandlerNonNull> result(self->GetOnaddtrack(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3717 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3718 0 : return false;
3719 : }
3720 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3721 0 : if (result) {
3722 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3723 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3724 0 : return false;
3725 : }
3726 0 : return true;
3727 : } else {
3728 0 : args.rval().setNull();
3729 0 : return true;
3730 : }
3731 : }
3732 :
3733 : static bool
3734 0 : set_onaddtrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3735 : {
3736 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3737 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3738 0 : if (objIsXray) {
3739 0 : unwrappedObj.emplace(cx, obj);
3740 : }
3741 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3742 0 : if (args[0].isObject()) {
3743 : { // scope for tempRoot
3744 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3745 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3746 : }
3747 : } else {
3748 0 : arg0 = nullptr;
3749 : }
3750 0 : if (objIsXray) {
3751 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3752 0 : if (!unwrappedObj.ref()) {
3753 0 : return false;
3754 : }
3755 : }
3756 0 : binding_detail::FastErrorResult rv;
3757 0 : self->SetOnaddtrack(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3758 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3759 0 : return false;
3760 : }
3761 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3762 :
3763 0 : return true;
3764 : }
3765 :
3766 : static const JSJitInfo onaddtrack_getterinfo = {
3767 : { (JSJitGetterOp)get_onaddtrack },
3768 : { prototypes::id::RTCPeerConnection },
3769 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3770 : JSJitInfo::Getter,
3771 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3772 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3773 : false, /* isInfallible. False in setters. */
3774 : false, /* isMovable. Not relevant for setters. */
3775 : false, /* isEliminatable. Not relevant for setters. */
3776 : false, /* isAlwaysInSlot. Only relevant for getters. */
3777 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3778 : false, /* isTypedMethod. Only relevant for methods. */
3779 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3780 : };
3781 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3782 : static_assert(0 < 1, "There is no slot for us");
3783 : static const JSJitInfo onaddtrack_setterinfo = {
3784 : { (JSJitGetterOp)set_onaddtrack },
3785 : { prototypes::id::RTCPeerConnection },
3786 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3787 : JSJitInfo::Setter,
3788 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3789 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3790 : false, /* isInfallible. False in setters. */
3791 : false, /* isMovable. Not relevant for setters. */
3792 : false, /* isEliminatable. Not relevant for setters. */
3793 : false, /* isAlwaysInSlot. Only relevant for getters. */
3794 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3795 : false, /* isTypedMethod. Only relevant for methods. */
3796 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3797 : };
3798 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3799 : static_assert(0 < 1, "There is no slot for us");
3800 :
3801 : static bool
3802 0 : get_ontrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3803 : {
3804 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3805 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3806 0 : if (objIsXray) {
3807 0 : unwrappedObj.emplace(cx, obj);
3808 : }
3809 0 : if (objIsXray) {
3810 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3811 0 : if (!unwrappedObj.ref()) {
3812 0 : return false;
3813 : }
3814 : }
3815 0 : binding_detail::FastErrorResult rv;
3816 0 : RefPtr<EventHandlerNonNull> result(self->GetOntrack(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3817 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3818 0 : return false;
3819 : }
3820 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3821 0 : if (result) {
3822 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3823 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3824 0 : return false;
3825 : }
3826 0 : return true;
3827 : } else {
3828 0 : args.rval().setNull();
3829 0 : return true;
3830 : }
3831 : }
3832 :
3833 : static bool
3834 0 : set_ontrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3835 : {
3836 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3837 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3838 0 : if (objIsXray) {
3839 0 : unwrappedObj.emplace(cx, obj);
3840 : }
3841 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3842 0 : if (args[0].isObject()) {
3843 : { // scope for tempRoot
3844 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3845 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3846 : }
3847 : } else {
3848 0 : arg0 = nullptr;
3849 : }
3850 0 : if (objIsXray) {
3851 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3852 0 : if (!unwrappedObj.ref()) {
3853 0 : return false;
3854 : }
3855 : }
3856 0 : binding_detail::FastErrorResult rv;
3857 0 : self->SetOntrack(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3858 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3859 0 : return false;
3860 : }
3861 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3862 :
3863 0 : return true;
3864 : }
3865 :
3866 : static const JSJitInfo ontrack_getterinfo = {
3867 : { (JSJitGetterOp)get_ontrack },
3868 : { prototypes::id::RTCPeerConnection },
3869 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3870 : JSJitInfo::Getter,
3871 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3872 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3873 : false, /* isInfallible. False in setters. */
3874 : false, /* isMovable. Not relevant for setters. */
3875 : false, /* isEliminatable. Not relevant for setters. */
3876 : false, /* isAlwaysInSlot. Only relevant for getters. */
3877 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3878 : false, /* isTypedMethod. Only relevant for methods. */
3879 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3880 : };
3881 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3882 : static_assert(0 < 1, "There is no slot for us");
3883 : static const JSJitInfo ontrack_setterinfo = {
3884 : { (JSJitGetterOp)set_ontrack },
3885 : { prototypes::id::RTCPeerConnection },
3886 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3887 : JSJitInfo::Setter,
3888 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3889 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3890 : false, /* isInfallible. False in setters. */
3891 : false, /* isMovable. Not relevant for setters. */
3892 : false, /* isEliminatable. Not relevant for setters. */
3893 : false, /* isAlwaysInSlot. Only relevant for getters. */
3894 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3895 : false, /* isTypedMethod. Only relevant for methods. */
3896 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3897 : };
3898 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3899 : static_assert(0 < 1, "There is no slot for us");
3900 :
3901 : static bool
3902 0 : get_onremovestream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
3903 : {
3904 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3905 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3906 0 : if (objIsXray) {
3907 0 : unwrappedObj.emplace(cx, obj);
3908 : }
3909 0 : if (objIsXray) {
3910 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3911 0 : if (!unwrappedObj.ref()) {
3912 0 : return false;
3913 : }
3914 : }
3915 0 : binding_detail::FastErrorResult rv;
3916 0 : RefPtr<EventHandlerNonNull> result(self->GetOnremovestream(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
3917 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3918 0 : return false;
3919 : }
3920 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3921 0 : if (result) {
3922 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
3923 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
3924 0 : return false;
3925 : }
3926 0 : return true;
3927 : } else {
3928 0 : args.rval().setNull();
3929 0 : return true;
3930 : }
3931 : }
3932 :
3933 : static bool
3934 0 : set_onremovestream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
3935 : {
3936 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3937 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3938 0 : if (objIsXray) {
3939 0 : unwrappedObj.emplace(cx, obj);
3940 : }
3941 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
3942 0 : if (args[0].isObject()) {
3943 : { // scope for tempRoot
3944 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
3945 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
3946 : }
3947 : } else {
3948 0 : arg0 = nullptr;
3949 : }
3950 0 : if (objIsXray) {
3951 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3952 0 : if (!unwrappedObj.ref()) {
3953 0 : return false;
3954 : }
3955 : }
3956 0 : binding_detail::FastErrorResult rv;
3957 0 : self->SetOnremovestream(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
3958 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3959 0 : return false;
3960 : }
3961 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
3962 :
3963 0 : return true;
3964 : }
3965 :
3966 : static const JSJitInfo onremovestream_getterinfo = {
3967 : { (JSJitGetterOp)get_onremovestream },
3968 : { prototypes::id::RTCPeerConnection },
3969 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3970 : JSJitInfo::Getter,
3971 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3972 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
3973 : false, /* isInfallible. False in setters. */
3974 : false, /* isMovable. Not relevant for setters. */
3975 : false, /* isEliminatable. Not relevant for setters. */
3976 : false, /* isAlwaysInSlot. Only relevant for getters. */
3977 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3978 : false, /* isTypedMethod. Only relevant for methods. */
3979 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3980 : };
3981 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3982 : static_assert(0 < 1, "There is no slot for us");
3983 : static const JSJitInfo onremovestream_setterinfo = {
3984 : { (JSJitGetterOp)set_onremovestream },
3985 : { prototypes::id::RTCPeerConnection },
3986 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3987 : JSJitInfo::Setter,
3988 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
3989 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
3990 : false, /* isInfallible. False in setters. */
3991 : false, /* isMovable. Not relevant for setters. */
3992 : false, /* isEliminatable. Not relevant for setters. */
3993 : false, /* isAlwaysInSlot. Only relevant for getters. */
3994 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
3995 : false, /* isTypedMethod. Only relevant for methods. */
3996 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
3997 : };
3998 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3999 : static_assert(0 < 1, "There is no slot for us");
4000 :
4001 : static bool
4002 0 : get_oniceconnectionstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4003 : {
4004 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4005 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4006 0 : if (objIsXray) {
4007 0 : unwrappedObj.emplace(cx, obj);
4008 : }
4009 0 : if (objIsXray) {
4010 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4011 0 : if (!unwrappedObj.ref()) {
4012 0 : return false;
4013 : }
4014 : }
4015 0 : binding_detail::FastErrorResult rv;
4016 0 : RefPtr<EventHandlerNonNull> result(self->GetOniceconnectionstatechange(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
4017 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4018 0 : return false;
4019 : }
4020 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4021 0 : if (result) {
4022 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
4023 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4024 0 : return false;
4025 : }
4026 0 : return true;
4027 : } else {
4028 0 : args.rval().setNull();
4029 0 : return true;
4030 : }
4031 : }
4032 :
4033 : static bool
4034 0 : set_oniceconnectionstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4035 : {
4036 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4037 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4038 0 : if (objIsXray) {
4039 0 : unwrappedObj.emplace(cx, obj);
4040 : }
4041 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4042 0 : if (args[0].isObject()) {
4043 : { // scope for tempRoot
4044 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
4045 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
4046 : }
4047 : } else {
4048 0 : arg0 = nullptr;
4049 : }
4050 0 : if (objIsXray) {
4051 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4052 0 : if (!unwrappedObj.ref()) {
4053 0 : return false;
4054 : }
4055 : }
4056 0 : binding_detail::FastErrorResult rv;
4057 0 : self->SetOniceconnectionstatechange(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
4058 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4059 0 : return false;
4060 : }
4061 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4062 :
4063 0 : return true;
4064 : }
4065 :
4066 : static const JSJitInfo oniceconnectionstatechange_getterinfo = {
4067 : { (JSJitGetterOp)get_oniceconnectionstatechange },
4068 : { prototypes::id::RTCPeerConnection },
4069 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4070 : JSJitInfo::Getter,
4071 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4072 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
4073 : false, /* isInfallible. False in setters. */
4074 : false, /* isMovable. Not relevant for setters. */
4075 : false, /* isEliminatable. Not relevant for setters. */
4076 : false, /* isAlwaysInSlot. Only relevant for getters. */
4077 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4078 : false, /* isTypedMethod. Only relevant for methods. */
4079 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4080 : };
4081 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4082 : static_assert(0 < 1, "There is no slot for us");
4083 : static const JSJitInfo oniceconnectionstatechange_setterinfo = {
4084 : { (JSJitGetterOp)set_oniceconnectionstatechange },
4085 : { prototypes::id::RTCPeerConnection },
4086 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4087 : JSJitInfo::Setter,
4088 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4089 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
4090 : false, /* isInfallible. False in setters. */
4091 : false, /* isMovable. Not relevant for setters. */
4092 : false, /* isEliminatable. Not relevant for setters. */
4093 : false, /* isAlwaysInSlot. Only relevant for getters. */
4094 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4095 : false, /* isTypedMethod. Only relevant for methods. */
4096 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4097 : };
4098 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4099 : static_assert(0 < 1, "There is no slot for us");
4100 :
4101 : static bool
4102 0 : get_onicegatheringstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4103 : {
4104 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4105 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4106 0 : if (objIsXray) {
4107 0 : unwrappedObj.emplace(cx, obj);
4108 : }
4109 0 : if (objIsXray) {
4110 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4111 0 : if (!unwrappedObj.ref()) {
4112 0 : return false;
4113 : }
4114 : }
4115 0 : binding_detail::FastErrorResult rv;
4116 0 : RefPtr<EventHandlerNonNull> result(self->GetOnicegatheringstatechange(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
4117 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4118 0 : return false;
4119 : }
4120 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4121 0 : if (result) {
4122 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
4123 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4124 0 : return false;
4125 : }
4126 0 : return true;
4127 : } else {
4128 0 : args.rval().setNull();
4129 0 : return true;
4130 : }
4131 : }
4132 :
4133 : static bool
4134 0 : set_onicegatheringstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4135 : {
4136 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4137 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4138 0 : if (objIsXray) {
4139 0 : unwrappedObj.emplace(cx, obj);
4140 : }
4141 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4142 0 : if (args[0].isObject()) {
4143 : { // scope for tempRoot
4144 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
4145 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
4146 : }
4147 : } else {
4148 0 : arg0 = nullptr;
4149 : }
4150 0 : if (objIsXray) {
4151 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4152 0 : if (!unwrappedObj.ref()) {
4153 0 : return false;
4154 : }
4155 : }
4156 0 : binding_detail::FastErrorResult rv;
4157 0 : self->SetOnicegatheringstatechange(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
4158 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4159 0 : return false;
4160 : }
4161 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4162 :
4163 0 : return true;
4164 : }
4165 :
4166 : static const JSJitInfo onicegatheringstatechange_getterinfo = {
4167 : { (JSJitGetterOp)get_onicegatheringstatechange },
4168 : { prototypes::id::RTCPeerConnection },
4169 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4170 : JSJitInfo::Getter,
4171 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4172 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
4173 : false, /* isInfallible. False in setters. */
4174 : false, /* isMovable. Not relevant for setters. */
4175 : false, /* isEliminatable. Not relevant for setters. */
4176 : false, /* isAlwaysInSlot. Only relevant for getters. */
4177 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4178 : false, /* isTypedMethod. Only relevant for methods. */
4179 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4180 : };
4181 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4182 : static_assert(0 < 1, "There is no slot for us");
4183 : static const JSJitInfo onicegatheringstatechange_setterinfo = {
4184 : { (JSJitGetterOp)set_onicegatheringstatechange },
4185 : { prototypes::id::RTCPeerConnection },
4186 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4187 : JSJitInfo::Setter,
4188 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4189 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
4190 : false, /* isInfallible. False in setters. */
4191 : false, /* isMovable. Not relevant for setters. */
4192 : false, /* isEliminatable. Not relevant for setters. */
4193 : false, /* isAlwaysInSlot. Only relevant for getters. */
4194 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4195 : false, /* isTypedMethod. Only relevant for methods. */
4196 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4197 : };
4198 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4199 : static_assert(0 < 1, "There is no slot for us");
4200 :
4201 : static bool
4202 0 : getStats(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4203 : {
4204 0 : unsigned argcount = std::min(args.length(), 3u);
4205 0 : switch (argcount) {
4206 : case 0: {
4207 : MOZ_FALLTHROUGH;
4208 : }
4209 : case 1: {
4210 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4211 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4212 0 : if (objIsXray) {
4213 0 : unwrappedObj.emplace(cx, obj);
4214 : }
4215 0 : Optional<mozilla::dom::MediaStreamTrack*> arg0;
4216 0 : if (args.hasDefined(0)) {
4217 0 : arg0.Construct();
4218 0 : if (args[0].isObject()) {
4219 : {
4220 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0.Value());
4221 0 : if (NS_FAILED(rv)) {
4222 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.getStats", "MediaStreamTrack");
4223 0 : return false;
4224 : }
4225 : }
4226 0 : } else if (args[0].isNullOrUndefined()) {
4227 0 : arg0.Value() = nullptr;
4228 : } else {
4229 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.getStats");
4230 0 : return false;
4231 : }
4232 : }
4233 0 : if (objIsXray) {
4234 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4235 0 : if (!unwrappedObj.ref()) {
4236 0 : return false;
4237 : }
4238 : }
4239 0 : binding_detail::FastErrorResult rv;
4240 0 : auto result(StrongOrRawPtr<Promise>(self->GetStats(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
4241 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4242 0 : return false;
4243 : }
4244 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4245 0 : if (!ToJSValue(cx, result, args.rval())) {
4246 0 : return false;
4247 : }
4248 0 : return true;
4249 : break;
4250 : }
4251 : case 3: {
4252 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4253 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4254 0 : if (objIsXray) {
4255 0 : unwrappedObj.emplace(cx, obj);
4256 : }
4257 : mozilla::dom::MediaStreamTrack* arg0;
4258 0 : if (args[0].isObject()) {
4259 : {
4260 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0);
4261 0 : if (NS_FAILED(rv)) {
4262 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.getStats", "MediaStreamTrack");
4263 0 : return false;
4264 : }
4265 : }
4266 0 : } else if (args[0].isNullOrUndefined()) {
4267 0 : arg0 = nullptr;
4268 : } else {
4269 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.getStats");
4270 0 : return false;
4271 : }
4272 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCStatsCallback>> arg1(cx);
4273 0 : if (args[1].isObject()) {
4274 0 : if (JS::IsCallable(&args[1].toObject())) {
4275 : { // scope for tempRoot
4276 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
4277 0 : arg1 = new binding_detail::FastRTCStatsCallback(tempRoot);
4278 : }
4279 : } else {
4280 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.getStats");
4281 0 : return false;
4282 : }
4283 : } else {
4284 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.getStats");
4285 0 : return false;
4286 : }
4287 0 : RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
4288 0 : if (args[2].isObject()) {
4289 0 : if (JS::IsCallable(&args[2].toObject())) {
4290 : { // scope for tempRoot
4291 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[2].toObject());
4292 0 : arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(tempRoot);
4293 : }
4294 : } else {
4295 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.getStats");
4296 0 : return false;
4297 : }
4298 : } else {
4299 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.getStats");
4300 0 : return false;
4301 : }
4302 0 : if (objIsXray) {
4303 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4304 0 : if (!unwrappedObj.ref()) {
4305 0 : return false;
4306 : }
4307 : }
4308 0 : binding_detail::FastErrorResult rv;
4309 0 : auto result(StrongOrRawPtr<Promise>(self->GetStats(Constify(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
4310 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4311 0 : return false;
4312 : }
4313 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4314 0 : if (!ToJSValue(cx, result, args.rval())) {
4315 0 : return false;
4316 : }
4317 0 : return true;
4318 : break;
4319 : }
4320 : default: {
4321 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.getStats");
4322 : break;
4323 : }
4324 : }
4325 : MOZ_CRASH("We have an always-returning default case");
4326 : return false;
4327 : }
4328 :
4329 : static bool
4330 0 : getStats_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4331 : {
4332 : // Make sure to save the callee before someone maybe messes
4333 : // with rval().
4334 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
4335 0 : bool ok = getStats(cx, obj, self, args);
4336 0 : if (ok) {
4337 0 : return true;
4338 : }
4339 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
4340 0 : args.rval());
4341 : }
4342 :
4343 : static const JSJitInfo getStats_methodinfo = {
4344 : { (JSJitGetterOp)getStats_promiseWrapper },
4345 : { prototypes::id::RTCPeerConnection },
4346 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4347 : JSJitInfo::Method,
4348 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4349 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
4350 : false, /* isInfallible. False in setters. */
4351 : false, /* isMovable. Not relevant for setters. */
4352 : false, /* isEliminatable. Not relevant for setters. */
4353 : false, /* isAlwaysInSlot. Only relevant for getters. */
4354 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4355 : false, /* isTypedMethod. Only relevant for methods. */
4356 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4357 : };
4358 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4359 : static_assert(0 < 1, "There is no slot for us");
4360 :
4361 : static bool
4362 0 : createDataChannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4363 : {
4364 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
4365 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createDataChannel");
4366 : }
4367 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4368 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4369 0 : if (objIsXray) {
4370 0 : unwrappedObj.emplace(cx, obj);
4371 : }
4372 0 : binding_detail::FakeString arg0;
4373 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
4374 0 : return false;
4375 : }
4376 0 : binding_detail::FastRTCDataChannelInit arg1;
4377 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of RTCPeerConnection.createDataChannel", true)) {
4378 0 : return false;
4379 : }
4380 0 : if (objIsXray) {
4381 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4382 0 : if (!unwrappedObj.ref()) {
4383 0 : return false;
4384 : }
4385 : }
4386 0 : binding_detail::FastErrorResult rv;
4387 0 : auto result(StrongOrRawPtr<nsIDOMDataChannel>(self->CreateDataChannel(NonNullHelper(Constify(arg0)), Constify(arg1), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
4388 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4389 0 : return false;
4390 : }
4391 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4392 0 : if (!WrapObject(cx, result, args.rval())) {
4393 0 : return false;
4394 : }
4395 0 : return true;
4396 : }
4397 :
4398 : static const JSJitInfo createDataChannel_methodinfo = {
4399 : { (JSJitGetterOp)createDataChannel },
4400 : { prototypes::id::RTCPeerConnection },
4401 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4402 : JSJitInfo::Method,
4403 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4404 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
4405 : false, /* isInfallible. False in setters. */
4406 : false, /* isMovable. Not relevant for setters. */
4407 : false, /* isEliminatable. Not relevant for setters. */
4408 : false, /* isAlwaysInSlot. Only relevant for getters. */
4409 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4410 : false, /* isTypedMethod. Only relevant for methods. */
4411 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4412 : };
4413 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4414 : static_assert(0 < 1, "There is no slot for us");
4415 :
4416 : static bool
4417 0 : get_ondatachannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4418 : {
4419 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4420 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4421 0 : if (objIsXray) {
4422 0 : unwrappedObj.emplace(cx, obj);
4423 : }
4424 0 : if (objIsXray) {
4425 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4426 0 : if (!unwrappedObj.ref()) {
4427 0 : return false;
4428 : }
4429 : }
4430 0 : binding_detail::FastErrorResult rv;
4431 0 : RefPtr<EventHandlerNonNull> result(self->GetOndatachannel(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
4432 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4433 0 : return false;
4434 : }
4435 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4436 0 : if (result) {
4437 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
4438 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4439 0 : return false;
4440 : }
4441 0 : return true;
4442 : } else {
4443 0 : args.rval().setNull();
4444 0 : return true;
4445 : }
4446 : }
4447 :
4448 : static bool
4449 0 : set_ondatachannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4450 : {
4451 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4452 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4453 0 : if (objIsXray) {
4454 0 : unwrappedObj.emplace(cx, obj);
4455 : }
4456 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4457 0 : if (args[0].isObject()) {
4458 : { // scope for tempRoot
4459 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
4460 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
4461 : }
4462 : } else {
4463 0 : arg0 = nullptr;
4464 : }
4465 0 : if (objIsXray) {
4466 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4467 0 : if (!unwrappedObj.ref()) {
4468 0 : return false;
4469 : }
4470 : }
4471 0 : binding_detail::FastErrorResult rv;
4472 0 : self->SetOndatachannel(Constify(arg0), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
4473 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4474 0 : return false;
4475 : }
4476 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4477 :
4478 0 : return true;
4479 : }
4480 :
4481 : static const JSJitInfo ondatachannel_getterinfo = {
4482 : { (JSJitGetterOp)get_ondatachannel },
4483 : { prototypes::id::RTCPeerConnection },
4484 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4485 : JSJitInfo::Getter,
4486 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4487 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
4488 : false, /* isInfallible. False in setters. */
4489 : false, /* isMovable. Not relevant for setters. */
4490 : false, /* isEliminatable. Not relevant for setters. */
4491 : false, /* isAlwaysInSlot. Only relevant for getters. */
4492 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4493 : false, /* isTypedMethod. Only relevant for methods. */
4494 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4495 : };
4496 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4497 : static_assert(0 < 1, "There is no slot for us");
4498 : static const JSJitInfo ondatachannel_setterinfo = {
4499 : { (JSJitGetterOp)set_ondatachannel },
4500 : { prototypes::id::RTCPeerConnection },
4501 : { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4502 : JSJitInfo::Setter,
4503 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
4504 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
4505 : false, /* isInfallible. False in setters. */
4506 : false, /* isMovable. Not relevant for setters. */
4507 : false, /* isEliminatable. Not relevant for setters. */
4508 : false, /* isAlwaysInSlot. Only relevant for getters. */
4509 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
4510 : false, /* isTypedMethod. Only relevant for methods. */
4511 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
4512 : };
4513 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4514 : static_assert(0 < 1, "There is no slot for us");
4515 :
4516 : static bool
4517 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
4518 : {
4519 0 : mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
4520 : // We don't want to preserve if we don't have a wrapper, and we
4521 : // obviously can't preserve if we're not initialized.
4522 0 : if (self && self->GetWrapperPreserveColor()) {
4523 0 : PreserveWrapper(self);
4524 : }
4525 0 : return true;
4526 : }
4527 :
4528 : static void
4529 0 : _finalize(js::FreeOp* fop, JSObject* obj)
4530 : {
4531 0 : mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
4532 0 : if (self) {
4533 0 : ClearWrapper(self, self, obj);
4534 0 : AddForDeferredFinalization<mozilla::dom::RTCPeerConnection>(self);
4535 : }
4536 0 : }
4537 :
4538 : static void
4539 0 : _objectMoved(JSObject* obj, const JSObject* old)
4540 : {
4541 0 : mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
4542 0 : if (self) {
4543 0 : UpdateWrapper(self, self, obj, old);
4544 : }
4545 0 : }
4546 :
4547 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4548 : #if defined(__clang__)
4549 : #pragma clang diagnostic push
4550 : #pragma clang diagnostic ignored "-Wmissing-braces"
4551 : #endif
4552 : static const JSFunctionSpec sStaticMethods_specs[] = {
4553 : JS_FNSPEC("generateCertificate", StaticMethodPromiseWrapper, &generateCertificate_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
4554 : JS_FS_END
4555 : };
4556 : #if defined(__clang__)
4557 : #pragma clang diagnostic pop
4558 : #endif
4559 :
4560 :
4561 : // Can't be const because the pref-enabled boolean needs to be writable
4562 : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
4563 : { nullptr, &sStaticMethods_specs[0] },
4564 : { nullptr, nullptr }
4565 : };
4566 :
4567 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4568 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4569 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4570 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4571 :
4572 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4573 : #if defined(__clang__)
4574 : #pragma clang diagnostic push
4575 : #pragma clang diagnostic ignored "-Wmissing-braces"
4576 : #endif
4577 : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
4578 : JS_FNSPEC("_create", RTCPeerConnection::_Create, nullptr, 2, 0, nullptr),
4579 : JS_FS_END
4580 : };
4581 : #if defined(__clang__)
4582 : #pragma clang diagnostic pop
4583 : #endif
4584 :
4585 :
4586 : // Can't be const because the pref-enabled boolean needs to be writable
4587 : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
4588 : { nullptr, &sChromeStaticMethods_specs[0] },
4589 : { nullptr, nullptr }
4590 : };
4591 :
4592 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4593 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4594 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4595 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4596 :
4597 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4598 : #if defined(__clang__)
4599 : #pragma clang diagnostic push
4600 : #pragma clang diagnostic ignored "-Wmissing-braces"
4601 : #endif
4602 : static const JSFunctionSpec sMethods_specs[] = {
4603 : JS_FNSPEC("setIdentityProvider", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setIdentityProvider_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4604 : JS_FNSPEC("getIdentityAssertion", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&getIdentityAssertion_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4605 : JS_FS_END,
4606 : JS_FNSPEC("createOffer", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&createOffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4607 : JS_FNSPEC("createAnswer", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&createAnswer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4608 : JS_FNSPEC("setLocalDescription", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&setLocalDescription_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4609 : JS_FNSPEC("setRemoteDescription", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&setRemoteDescription_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4610 : JS_FNSPEC("addIceCandidate", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&addIceCandidate_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4611 : JS_FNSPEC("getConfiguration", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getConfiguration_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4612 : JS_FNSPEC("getLocalStreams", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getLocalStreams_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4613 : JS_FNSPEC("getRemoteStreams", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRemoteStreams_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4614 : JS_FNSPEC("addStream", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&addStream_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4615 : JS_FNSPEC("addTrack", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&addTrack_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
4616 : JS_FNSPEC("removeTrack", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&removeTrack_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4617 : JS_FNSPEC("getSenders", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getSenders_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4618 : JS_FNSPEC("getReceivers", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getReceivers_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4619 : JS_FNSPEC("close", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4620 : JS_FNSPEC("getStats", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&getStats_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
4621 : JS_FNSPEC("createDataChannel", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createDataChannel_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
4622 : JS_FS_END
4623 : };
4624 : #if defined(__clang__)
4625 : #pragma clang diagnostic pop
4626 : #endif
4627 :
4628 : static PrefableDisablers sMethods_disablers0 = {
4629 : true, false, 0, nullptr
4630 : };
4631 :
4632 : // Can't be const because the pref-enabled boolean needs to be writable
4633 : static Prefable<const JSFunctionSpec> sMethods[] = {
4634 : { &sMethods_disablers0, &sMethods_specs[0] },
4635 : { nullptr, &sMethods_specs[3] },
4636 : { nullptr, nullptr }
4637 : };
4638 :
4639 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4640 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4641 : static_assert(16 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4642 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4643 :
4644 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4645 : #if defined(__clang__)
4646 : #pragma clang diagnostic push
4647 : #pragma clang diagnostic ignored "-Wmissing-braces"
4648 : #endif
4649 : static const JSFunctionSpec sChromeMethods_specs[] = {
4650 : JS_FNSPEC("mozAddRIDExtension", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&mozAddRIDExtension_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
4651 : JS_FNSPEC("mozAddRIDFilter", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&mozAddRIDFilter_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
4652 : JS_FS_END
4653 : };
4654 : #if defined(__clang__)
4655 : #pragma clang diagnostic pop
4656 : #endif
4657 :
4658 :
4659 : // Can't be const because the pref-enabled boolean needs to be writable
4660 : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
4661 : { nullptr, &sChromeMethods_specs[0] },
4662 : { nullptr, nullptr }
4663 : };
4664 :
4665 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4666 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4667 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4668 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4669 :
4670 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4671 : #if defined(__clang__)
4672 : #pragma clang diagnostic push
4673 : #pragma clang diagnostic ignored "-Wmissing-braces"
4674 : #endif
4675 : static const JSPropertySpec sAttributes_specs[] = {
4676 : { "localDescription", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &localDescription_getterinfo, nullptr, nullptr },
4677 : { "remoteDescription", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &remoteDescription_getterinfo, nullptr, nullptr },
4678 : { "signalingState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &signalingState_getterinfo, nullptr, nullptr },
4679 : { "canTrickleIceCandidates", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &canTrickleIceCandidates_getterinfo, nullptr, nullptr },
4680 : { "iceGatheringState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &iceGatheringState_getterinfo, nullptr, nullptr },
4681 : { "iceConnectionState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &iceConnectionState_getterinfo, nullptr, nullptr },
4682 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
4683 : { "peerIdentity", JSPROP_SHARED | JSPROP_ENUMERATE, GenericPromiseReturningBindingGetter, &peerIdentity_getterinfo, nullptr, nullptr },
4684 : { "idpLoginUrl", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &idpLoginUrl_getterinfo, nullptr, nullptr },
4685 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
4686 : { "onnegotiationneeded", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onnegotiationneeded_getterinfo, GenericBindingSetter, &onnegotiationneeded_setterinfo },
4687 : { "onicecandidate", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onicecandidate_getterinfo, GenericBindingSetter, &onicecandidate_setterinfo },
4688 : { "onsignalingstatechange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onsignalingstatechange_getterinfo, GenericBindingSetter, &onsignalingstatechange_setterinfo },
4689 : { "onaddstream", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onaddstream_getterinfo, GenericBindingSetter, &onaddstream_setterinfo },
4690 : { "onaddtrack", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onaddtrack_getterinfo, GenericBindingSetter, &onaddtrack_setterinfo },
4691 : { "ontrack", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ontrack_getterinfo, GenericBindingSetter, &ontrack_setterinfo },
4692 : { "onremovestream", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onremovestream_getterinfo, GenericBindingSetter, &onremovestream_setterinfo },
4693 : { "oniceconnectionstatechange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &oniceconnectionstatechange_getterinfo, GenericBindingSetter, &oniceconnectionstatechange_setterinfo },
4694 : { "onicegatheringstatechange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onicegatheringstatechange_getterinfo, GenericBindingSetter, &onicegatheringstatechange_setterinfo },
4695 : { "ondatachannel", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ondatachannel_getterinfo, GenericBindingSetter, &ondatachannel_setterinfo },
4696 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
4697 : };
4698 : #if defined(__clang__)
4699 : #pragma clang diagnostic pop
4700 : #endif
4701 :
4702 : static PrefableDisablers sAttributes_disablers7 = {
4703 : true, false, 0, nullptr
4704 : };
4705 :
4706 : // Can't be const because the pref-enabled boolean needs to be writable
4707 : static Prefable<const JSPropertySpec> sAttributes[] = {
4708 : { nullptr, &sAttributes_specs[0] },
4709 : { &sAttributes_disablers7, &sAttributes_specs[7] },
4710 : { nullptr, &sAttributes_specs[10] },
4711 : { nullptr, nullptr }
4712 : };
4713 :
4714 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4715 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4716 : static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4717 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4718 :
4719 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
4720 : #if defined(__clang__)
4721 : #pragma clang diagnostic push
4722 : #pragma clang diagnostic ignored "-Wmissing-braces"
4723 : #endif
4724 : static const JSPropertySpec sChromeAttributes_specs[] = {
4725 : { "id", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &id_getterinfo, GenericBindingSetter, &id_setterinfo },
4726 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
4727 : };
4728 : #if defined(__clang__)
4729 : #pragma clang diagnostic pop
4730 : #endif
4731 :
4732 :
4733 : // Can't be const because the pref-enabled boolean needs to be writable
4734 : static Prefable<const JSPropertySpec> sChromeAttributes[] = {
4735 : { nullptr, &sChromeAttributes_specs[0] },
4736 : { nullptr, nullptr }
4737 : };
4738 :
4739 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
4740 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
4741 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
4742 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
4743 :
4744 :
4745 : static uint16_t sNativeProperties_sortedPropertyIndices[37];
4746 : static PropertyInfo sNativeProperties_propertyInfos[37];
4747 :
4748 : static const NativePropertiesN<3> sNativeProperties = {
4749 : true, 0 /* sStaticMethods */,
4750 : false, 0,
4751 : true, 1 /* sMethods */,
4752 : true, 2 /* sAttributes */,
4753 : false, 0,
4754 : false, 0,
4755 : false, 0,
4756 : -1,
4757 : 37,
4758 : sNativeProperties_sortedPropertyIndices,
4759 : {
4760 : { sStaticMethods, &sNativeProperties_propertyInfos[0] },
4761 : { sMethods, &sNativeProperties_propertyInfos[1] },
4762 : { sAttributes, &sNativeProperties_propertyInfos[19] }
4763 : }
4764 : };
4765 : static_assert(37 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
4766 : "We have a property info count that is oversized");
4767 :
4768 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[4];
4769 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[4];
4770 :
4771 : static const NativePropertiesN<3> sChromeOnlyNativeProperties = {
4772 : true, 0 /* sChromeStaticMethods */,
4773 : false, 0,
4774 : true, 1 /* sChromeMethods */,
4775 : true, 2 /* sChromeAttributes */,
4776 : false, 0,
4777 : false, 0,
4778 : false, 0,
4779 : -1,
4780 : 4,
4781 : sChromeOnlyNativeProperties_sortedPropertyIndices,
4782 : {
4783 : { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] },
4784 : { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[1] },
4785 : { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[3] }
4786 : }
4787 : };
4788 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
4789 : "We have a property info count that is oversized");
4790 :
4791 : static bool
4792 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
4793 : {
4794 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
4795 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
4796 0 : if (!args.isConstructing()) {
4797 : // XXXbz wish I could get the name from the callee instead of
4798 : // Adding more relocations
4799 0 : return ThrowConstructorWithoutNew(cx, "RTCPeerConnection");
4800 : }
4801 :
4802 0 : GlobalObject global(cx, obj);
4803 0 : if (global.Failed()) {
4804 0 : return false;
4805 : }
4806 :
4807 0 : JS::Rooted<JSObject*> desiredProto(cx);
4808 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
4809 0 : return false;
4810 : }
4811 :
4812 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4813 0 : binding_detail::FastRTCConfiguration arg0;
4814 0 : if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of RTCPeerConnection.constructor", true)) {
4815 0 : return false;
4816 : }
4817 0 : Optional<JS::Handle<JSObject*>> arg1;
4818 0 : if (args.hasDefined(1)) {
4819 0 : arg1.Construct(cx);
4820 0 : if (args[1].isObject()) {
4821 : #ifdef __clang__
4822 : #pragma clang diagnostic push
4823 : #pragma clang diagnostic ignored "-Wunreachable-code"
4824 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
4825 : #endif // __clang__
4826 0 : if ((true) && !CallerSubsumes(args[1])) {
4827 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "argument 2 of RTCPeerConnection.constructor");
4828 0 : return false;
4829 : }
4830 : #ifdef __clang__
4831 : #pragma clang diagnostic pop
4832 : #endif // __clang__
4833 0 : arg1.Value() = &args[1].toObject();
4834 0 : } else if (args[1].isNullOrUndefined()) {
4835 0 : arg1.Value() = nullptr;
4836 : } else {
4837 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.constructor");
4838 0 : return false;
4839 : }
4840 : }
4841 0 : Maybe<JSAutoCompartment> ac;
4842 0 : if (objIsXray) {
4843 0 : obj = js::CheckedUnwrap(obj);
4844 0 : if (!obj) {
4845 0 : return false;
4846 : }
4847 0 : ac.emplace(cx, obj);
4848 0 : if (!JS_WrapObject(cx, &desiredProto)) {
4849 0 : return false;
4850 : }
4851 0 : if (arg1.WasPassed()) {
4852 0 : if (!JS_WrapObject(cx, &arg1.Value())) {
4853 0 : return false;
4854 : }
4855 : }
4856 : }
4857 0 : binding_detail::FastErrorResult rv;
4858 0 : auto result(StrongOrRawPtr<mozilla::dom::RTCPeerConnection>(mozilla::dom::RTCPeerConnection::Constructor(global, cx, Constify(arg0), Constify(arg1), rv)));
4859 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4860 0 : return false;
4861 : }
4862 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
4863 : static_assert(!IsPointer<decltype(result)>::value,
4864 : "NewObject implies that we need to keep the object alive with a strong reference.");
4865 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
4866 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
4867 0 : return false;
4868 : }
4869 0 : return true;
4870 : }
4871 :
4872 : static const js::ClassOps sInterfaceObjectClassOps = {
4873 : nullptr, /* addProperty */
4874 : nullptr, /* delProperty */
4875 : nullptr, /* getProperty */
4876 : nullptr, /* setProperty */
4877 : nullptr, /* enumerate */
4878 : nullptr, /* newEnumerate */
4879 : nullptr, /* resolve */
4880 : nullptr, /* mayResolve */
4881 : nullptr, /* finalize */
4882 : _constructor, /* call */
4883 : nullptr, /* hasInstance */
4884 : _constructor, /* construct */
4885 : nullptr, /* trace */
4886 : };
4887 :
4888 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
4889 : {
4890 : "Function",
4891 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
4892 : &sInterfaceObjectClassOps,
4893 : JS_NULL_CLASS_SPEC,
4894 : JS_NULL_CLASS_EXT,
4895 : &sInterfaceObjectClassObjectOps
4896 : },
4897 : eInterface,
4898 : true,
4899 : prototypes::id::RTCPeerConnection,
4900 : PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth,
4901 : sNativePropertyHooks,
4902 : "function RTCPeerConnection() {\n [native code]\n}",
4903 : EventTargetBinding::GetConstructorObject
4904 : };
4905 :
4906 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
4907 : {
4908 : "RTCPeerConnectionPrototype",
4909 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
4910 : JS_NULL_CLASS_OPS,
4911 : JS_NULL_CLASS_SPEC,
4912 : JS_NULL_CLASS_EXT,
4913 : JS_NULL_OBJECT_OPS
4914 : },
4915 : eInterfacePrototype,
4916 : false,
4917 : prototypes::id::RTCPeerConnection,
4918 : PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth,
4919 : sNativePropertyHooks,
4920 : "[object RTCPeerConnectionPrototype]",
4921 : EventTargetBinding::GetProtoObject
4922 : };
4923 :
4924 : bool
4925 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
4926 : {
4927 : static bool sPrefValue;
4928 : static bool sPrefCacheSetUp = false;
4929 0 : if (!sPrefCacheSetUp) {
4930 0 : sPrefCacheSetUp = true;
4931 0 : Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
4932 : }
4933 :
4934 0 : return sPrefValue;
4935 : }
4936 :
4937 : JSObject*
4938 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
4939 : {
4940 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
4941 : }
4942 :
4943 : static const js::ClassOps sClassOps = {
4944 : _addProperty, /* addProperty */
4945 : nullptr, /* delProperty */
4946 : nullptr, /* getProperty */
4947 : nullptr, /* setProperty */
4948 : nullptr, /* enumerate */
4949 : nullptr, /* newEnumerate */
4950 : nullptr, /* resolve */
4951 : nullptr, /* mayResolve */
4952 : _finalize, /* finalize */
4953 : nullptr, /* call */
4954 : nullptr, /* hasInstance */
4955 : nullptr, /* construct */
4956 : nullptr, /* trace */
4957 : };
4958 :
4959 : static const js::ClassExtension sClassExtension = {
4960 : nullptr, /* weakmapKeyDelegateOp */
4961 : _objectMoved /* objectMovedOp */
4962 : };
4963 :
4964 : static const DOMJSClass sClass = {
4965 : { "RTCPeerConnection",
4966 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
4967 : &sClassOps,
4968 : JS_NULL_CLASS_SPEC,
4969 : &sClassExtension,
4970 : JS_NULL_OBJECT_OPS
4971 : },
4972 : { prototypes::id::EventTarget, prototypes::id::RTCPeerConnection, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
4973 : IsBaseOf<nsISupports, mozilla::dom::RTCPeerConnection >::value,
4974 : sNativePropertyHooks,
4975 : FindAssociatedGlobalForNative<mozilla::dom::RTCPeerConnection>::Get,
4976 : GetProtoObjectHandle,
4977 : GetCCParticipant<mozilla::dom::RTCPeerConnection>::Get()
4978 : };
4979 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
4980 : "Must have the right minimal number of reserved slots.");
4981 : static_assert(1 >= 1,
4982 : "Must have enough reserved slots.");
4983 :
4984 : const JSClass*
4985 0 : GetJSClass()
4986 : {
4987 0 : return sClass.ToJSClass();
4988 : }
4989 :
4990 : bool
4991 0 : Wrap(JSContext* aCx, mozilla::dom::RTCPeerConnection* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
4992 : {
4993 : MOZ_ASSERT(static_cast<mozilla::dom::RTCPeerConnection*>(aObject) ==
4994 : reinterpret_cast<mozilla::dom::RTCPeerConnection*>(aObject),
4995 : "Multiple inheritance for mozilla::dom::RTCPeerConnection is broken.");
4996 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
4997 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
4998 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
4999 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
5000 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
5001 0 : MOZ_ASSERT(!aCache->GetWrapper(),
5002 : "You should probably not be using Wrap() directly; use "
5003 : "GetOrCreateDOMReflector instead");
5004 :
5005 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
5006 : "nsISupports must be on our primary inheritance chain");
5007 :
5008 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
5009 0 : if (!global) {
5010 0 : return false;
5011 : }
5012 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
5013 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
5014 :
5015 : // That might have ended up wrapping us already, due to the wonders
5016 : // of XBL. Check for that, and bail out as needed.
5017 0 : aReflector.set(aCache->GetWrapper());
5018 0 : if (aReflector) {
5019 : #ifdef DEBUG
5020 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
5021 : #endif // DEBUG
5022 0 : return true;
5023 : }
5024 :
5025 0 : JSAutoCompartment ac(aCx, global);
5026 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
5027 0 : if (!canonicalProto) {
5028 0 : return false;
5029 : }
5030 0 : JS::Rooted<JSObject*> proto(aCx);
5031 0 : if (aGivenProto) {
5032 0 : proto = aGivenProto;
5033 : // Unfortunately, while aGivenProto was in the compartment of aCx
5034 : // coming in, we changed compartments to that of "parent" so may need
5035 : // to wrap the proto here.
5036 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
5037 0 : if (!JS_WrapObject(aCx, &proto)) {
5038 0 : return false;
5039 : }
5040 : }
5041 : } else {
5042 0 : proto = canonicalProto;
5043 : }
5044 :
5045 0 : BindingJSObjectCreator<mozilla::dom::RTCPeerConnection> creator(aCx);
5046 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
5047 0 : if (!aReflector) {
5048 0 : return false;
5049 : }
5050 :
5051 0 : aCache->SetWrapper(aReflector);
5052 0 : creator.InitializationSucceeded();
5053 :
5054 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
5055 : aCache->GetWrapperPreserveColor() == aReflector);
5056 : // If proto != canonicalProto, we have to preserve our wrapper;
5057 : // otherwise we won't be able to properly recreate it later, since
5058 : // we won't know what proto to use. Note that we don't check
5059 : // aGivenProto here, since it's entirely possible (and even
5060 : // somewhat common) to have a non-null aGivenProto which is the
5061 : // same as canonicalProto.
5062 0 : if (proto != canonicalProto) {
5063 0 : PreserveWrapper(aObject);
5064 : }
5065 :
5066 0 : return true;
5067 : }
5068 :
5069 : const NativePropertyHooks sNativePropertyHooks[] = { {
5070 : nullptr,
5071 : nullptr,
5072 : nullptr,
5073 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
5074 : prototypes::id::RTCPeerConnection,
5075 : constructors::id::RTCPeerConnection,
5076 : EventTargetBinding::sNativePropertyHooks,
5077 : &DefaultXrayExpandoObjectClass
5078 : } };
5079 :
5080 : void
5081 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
5082 : {
5083 0 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
5084 0 : if (!parentProto) {
5085 0 : return;
5086 : }
5087 :
5088 0 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
5089 0 : if (!constructorProto) {
5090 0 : return;
5091 : }
5092 :
5093 : static bool sIdsInited = false;
5094 0 : if (!sIdsInited && NS_IsMainThread()) {
5095 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
5096 0 : return;
5097 : }
5098 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
5099 0 : return;
5100 : }
5101 0 : sIdsInited = true;
5102 : }
5103 :
5104 : static bool sPrefCachesInited = false;
5105 0 : if (!sPrefCachesInited && NS_IsMainThread()) {
5106 0 : sPrefCachesInited = true;
5107 0 : Preferences::AddBoolVarCache(&sMethods[0].disablers->enabled, "media.peerconnection.identity.enabled");
5108 0 : Preferences::AddBoolVarCache(&sAttributes[1].disablers->enabled, "media.peerconnection.identity.enabled");
5109 : }
5110 :
5111 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCPeerConnection);
5112 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::RTCPeerConnection);
5113 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
5114 : &sPrototypeClass.mBase, protoCache,
5115 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
5116 : interfaceCache,
5117 : sNativeProperties.Upcast(),
5118 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
5119 : "RTCPeerConnection", aDefineOnGlobal,
5120 : nullptr,
5121 0 : false);
5122 : }
5123 :
5124 : JS::Handle<JSObject*>
5125 0 : GetProtoObjectHandle(JSContext* aCx)
5126 : {
5127 : /* Get the interface prototype object for this class. This will create the
5128 : object as needed. */
5129 0 : bool aDefineOnGlobal = true;
5130 :
5131 : /* Make sure our global is sane. Hopefully we can remove this sometime */
5132 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
5133 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
5134 0 : return nullptr;
5135 : }
5136 :
5137 : /* Check to see whether the interface objects are already installed */
5138 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
5139 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::RTCPeerConnection)) {
5140 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
5141 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
5142 : }
5143 :
5144 : /*
5145 : * The object might _still_ be null, but that's OK.
5146 : *
5147 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
5148 : * traced by TraceProtoAndIfaceCache() and its contents are never
5149 : * changed after they have been set.
5150 : *
5151 : * Calling address() avoids the read read barrier that does gray
5152 : * unmarking, but it's not possible for the object to be gray here.
5153 : */
5154 :
5155 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::RTCPeerConnection);
5156 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
5157 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
5158 : }
5159 :
5160 : JSObject*
5161 0 : GetProtoObject(JSContext* aCx)
5162 : {
5163 0 : return GetProtoObjectHandle(aCx);
5164 : }
5165 :
5166 : JS::Handle<JSObject*>
5167 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
5168 : {
5169 : /* Get the interface object for this class. This will create the object as
5170 : needed. */
5171 :
5172 : /* Make sure our global is sane. Hopefully we can remove this sometime */
5173 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
5174 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
5175 0 : return nullptr;
5176 : }
5177 :
5178 : /* Check to see whether the interface objects are already installed */
5179 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
5180 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::RTCPeerConnection)) {
5181 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
5182 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
5183 : }
5184 :
5185 : /*
5186 : * The object might _still_ be null, but that's OK.
5187 : *
5188 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
5189 : * traced by TraceProtoAndIfaceCache() and its contents are never
5190 : * changed after they have been set.
5191 : *
5192 : * Calling address() avoids the read read barrier that does gray
5193 : * unmarking, but it's not possible for the object to be gray here.
5194 : */
5195 :
5196 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::RTCPeerConnection);
5197 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
5198 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
5199 : }
5200 :
5201 : JSObject*
5202 0 : GetConstructorObject(JSContext* aCx)
5203 : {
5204 0 : return GetConstructorObjectHandle(aCx);
5205 : }
5206 :
5207 : } // namespace RTCPeerConnectionBinding
5208 :
5209 :
5210 :
5211 : void
5212 0 : RTCPeerConnectionJSImpl::SetIdentityProvider(const nsAString& provider, const Optional<nsAString>& protocol, const Optional<nsAString>& username, ErrorResult& aRv, JSCompartment* aCompartment)
5213 : {
5214 0 : CallSetup s(this, aRv, "RTCPeerConnection.setIdentityProvider", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5215 0 : JSContext* cx = s.GetContext();
5216 0 : if (!cx) {
5217 0 : MOZ_ASSERT(aRv.Failed());
5218 0 : return;
5219 : }
5220 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5221 0 : JS::AutoValueVector argv(cx);
5222 0 : if (!argv.resize(3)) {
5223 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5224 0 : return;
5225 : }
5226 0 : unsigned argc = 3;
5227 :
5228 : do {
5229 0 : if (username.WasPassed()) {
5230 0 : nsString mutableStr(username.Value());
5231 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[2])) {
5232 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5233 0 : return;
5234 : }
5235 0 : break;
5236 0 : } else if (argc == 3) {
5237 : // This is our current trailing argument; reduce argc
5238 0 : --argc;
5239 : } else {
5240 0 : argv[2].setUndefined();
5241 : }
5242 : } while (0);
5243 :
5244 : do {
5245 0 : if (protocol.WasPassed()) {
5246 0 : nsString mutableStr(protocol.Value());
5247 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) {
5248 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5249 0 : return;
5250 : }
5251 0 : break;
5252 0 : } else if (argc == 2) {
5253 : // This is our current trailing argument; reduce argc
5254 0 : --argc;
5255 : } else {
5256 0 : argv[1].setUndefined();
5257 : }
5258 : } while (0);
5259 :
5260 : do {
5261 0 : nsString mutableStr(provider);
5262 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
5263 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5264 0 : return;
5265 : }
5266 0 : break;
5267 : } while (0);
5268 :
5269 0 : JS::Rooted<JS::Value> callable(cx);
5270 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5271 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5272 0 : !GetCallableProperty(cx, atomsCache->setIdentityProvider_id, &callable)) {
5273 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5274 0 : return;
5275 : }
5276 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5277 0 : if (!JS::Call(cx, thisValue, callable,
5278 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5279 0 : aRv.NoteJSContextException(cx);
5280 0 : return;
5281 : }
5282 : }
5283 :
5284 : already_AddRefed<Promise>
5285 0 : RTCPeerConnectionJSImpl::GetIdentityAssertion(ErrorResult& aRv, JSCompartment* aCompartment)
5286 : {
5287 0 : CallSetup s(this, aRv, "RTCPeerConnection.getIdentityAssertion", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5288 0 : JSContext* cx = s.GetContext();
5289 0 : if (!cx) {
5290 0 : MOZ_ASSERT(aRv.Failed());
5291 0 : return nullptr;
5292 : }
5293 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5294 :
5295 0 : JS::Rooted<JS::Value> callable(cx);
5296 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5297 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5298 0 : !GetCallableProperty(cx, atomsCache->getIdentityAssertion_id, &callable)) {
5299 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5300 0 : return nullptr;
5301 : }
5302 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5303 0 : if (!JS::Call(cx, thisValue, callable,
5304 0 : JS::HandleValueArray::empty(), &rval)) {
5305 0 : aRv.NoteJSContextException(cx);
5306 0 : return nullptr;
5307 : }
5308 0 : RefPtr<Promise> rvalDecl;
5309 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5310 : // etc.
5311 :
5312 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5313 0 : if (!rval.isObject()) {
5314 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getIdentityAssertion"));
5315 0 : return nullptr;
5316 : }
5317 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5318 0 : if (!unwrappedVal) {
5319 : // A slight lie, but not much of one, for a dead object wrapper.
5320 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getIdentityAssertion"));
5321 0 : return nullptr;
5322 : }
5323 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5324 0 : JSAutoCompartment ac(cx, globalObj);
5325 0 : GlobalObject promiseGlobal(cx, globalObj);
5326 0 : if (promiseGlobal.Failed()) {
5327 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5328 0 : return nullptr;
5329 : }
5330 :
5331 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5332 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5333 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5334 0 : return nullptr;
5335 : }
5336 0 : binding_detail::FastErrorResult promiseRv;
5337 : nsCOMPtr<nsIGlobalObject> global =
5338 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5339 0 : if (!global) {
5340 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5341 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5342 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5343 0 : return nullptr;
5344 : }
5345 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5346 0 : promiseRv);
5347 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5348 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5349 0 : return nullptr;
5350 : }
5351 : }
5352 0 : return rvalDecl.forget();
5353 : }
5354 :
5355 : already_AddRefed<Promise>
5356 0 : RTCPeerConnectionJSImpl::CreateOffer(const RTCOfferOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
5357 : {
5358 0 : CallSetup s(this, aRv, "RTCPeerConnection.createOffer", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5359 0 : JSContext* cx = s.GetContext();
5360 0 : if (!cx) {
5361 0 : MOZ_ASSERT(aRv.Failed());
5362 0 : return nullptr;
5363 : }
5364 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5365 0 : JS::AutoValueVector argv(cx);
5366 0 : if (!argv.resize(1)) {
5367 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5368 0 : return nullptr;
5369 : }
5370 0 : unsigned argc = 1;
5371 :
5372 : do {
5373 0 : if (!options.ToObjectInternal(cx, argv[0])) {
5374 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5375 0 : return nullptr;
5376 : }
5377 0 : break;
5378 : } while (0);
5379 :
5380 0 : JS::Rooted<JS::Value> callable(cx);
5381 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5382 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5383 0 : !GetCallableProperty(cx, atomsCache->createOffer_id, &callable)) {
5384 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5385 0 : return nullptr;
5386 : }
5387 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5388 0 : if (!JS::Call(cx, thisValue, callable,
5389 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5390 0 : aRv.NoteJSContextException(cx);
5391 0 : return nullptr;
5392 : }
5393 0 : RefPtr<Promise> rvalDecl;
5394 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5395 : // etc.
5396 :
5397 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5398 0 : if (!rval.isObject()) {
5399 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
5400 0 : return nullptr;
5401 : }
5402 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5403 0 : if (!unwrappedVal) {
5404 : // A slight lie, but not much of one, for a dead object wrapper.
5405 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
5406 0 : return nullptr;
5407 : }
5408 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5409 0 : JSAutoCompartment ac(cx, globalObj);
5410 0 : GlobalObject promiseGlobal(cx, globalObj);
5411 0 : if (promiseGlobal.Failed()) {
5412 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5413 0 : return nullptr;
5414 : }
5415 :
5416 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5417 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5418 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5419 0 : return nullptr;
5420 : }
5421 0 : binding_detail::FastErrorResult promiseRv;
5422 : nsCOMPtr<nsIGlobalObject> global =
5423 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5424 0 : if (!global) {
5425 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5426 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5427 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5428 0 : return nullptr;
5429 : }
5430 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5431 0 : promiseRv);
5432 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5433 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5434 0 : return nullptr;
5435 : }
5436 : }
5437 0 : return rvalDecl.forget();
5438 : }
5439 :
5440 : already_AddRefed<Promise>
5441 0 : RTCPeerConnectionJSImpl::CreateOffer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, const RTCOfferOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
5442 : {
5443 0 : CallSetup s(this, aRv, "RTCPeerConnection.createOffer", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5444 0 : JSContext* cx = s.GetContext();
5445 0 : if (!cx) {
5446 0 : MOZ_ASSERT(aRv.Failed());
5447 0 : return nullptr;
5448 : }
5449 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5450 0 : JS::AutoValueVector argv(cx);
5451 0 : if (!argv.resize(3)) {
5452 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5453 0 : return nullptr;
5454 : }
5455 0 : unsigned argc = 3;
5456 :
5457 : do {
5458 0 : if (!options.ToObjectInternal(cx, argv[2])) {
5459 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5460 0 : return nullptr;
5461 : }
5462 0 : break;
5463 : } while (0);
5464 :
5465 : do {
5466 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
5467 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
5468 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5469 0 : return nullptr;
5470 : }
5471 0 : break;
5472 : } while (0);
5473 :
5474 : do {
5475 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
5476 0 : if (!MaybeWrapObjectValue(cx, argv[0])) {
5477 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5478 0 : return nullptr;
5479 : }
5480 0 : break;
5481 : } while (0);
5482 :
5483 0 : JS::Rooted<JS::Value> callable(cx);
5484 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5485 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5486 0 : !GetCallableProperty(cx, atomsCache->createOffer_id, &callable)) {
5487 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5488 0 : return nullptr;
5489 : }
5490 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5491 0 : if (!JS::Call(cx, thisValue, callable,
5492 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5493 0 : aRv.NoteJSContextException(cx);
5494 0 : return nullptr;
5495 : }
5496 0 : RefPtr<Promise> rvalDecl;
5497 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5498 : // etc.
5499 :
5500 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5501 0 : if (!rval.isObject()) {
5502 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
5503 0 : return nullptr;
5504 : }
5505 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5506 0 : if (!unwrappedVal) {
5507 : // A slight lie, but not much of one, for a dead object wrapper.
5508 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
5509 0 : return nullptr;
5510 : }
5511 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5512 0 : JSAutoCompartment ac(cx, globalObj);
5513 0 : GlobalObject promiseGlobal(cx, globalObj);
5514 0 : if (promiseGlobal.Failed()) {
5515 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5516 0 : return nullptr;
5517 : }
5518 :
5519 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5520 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5521 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5522 0 : return nullptr;
5523 : }
5524 0 : binding_detail::FastErrorResult promiseRv;
5525 : nsCOMPtr<nsIGlobalObject> global =
5526 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5527 0 : if (!global) {
5528 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5529 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5530 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5531 0 : return nullptr;
5532 : }
5533 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5534 0 : promiseRv);
5535 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5536 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5537 0 : return nullptr;
5538 : }
5539 : }
5540 0 : return rvalDecl.forget();
5541 : }
5542 :
5543 : already_AddRefed<Promise>
5544 0 : RTCPeerConnectionJSImpl::CreateAnswer(const RTCAnswerOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
5545 : {
5546 0 : CallSetup s(this, aRv, "RTCPeerConnection.createAnswer", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5547 0 : JSContext* cx = s.GetContext();
5548 0 : if (!cx) {
5549 0 : MOZ_ASSERT(aRv.Failed());
5550 0 : return nullptr;
5551 : }
5552 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5553 0 : JS::AutoValueVector argv(cx);
5554 0 : if (!argv.resize(1)) {
5555 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5556 0 : return nullptr;
5557 : }
5558 0 : unsigned argc = 1;
5559 :
5560 : do {
5561 0 : if (!options.ToObjectInternal(cx, argv[0])) {
5562 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5563 0 : return nullptr;
5564 : }
5565 0 : break;
5566 : } while (0);
5567 :
5568 0 : JS::Rooted<JS::Value> callable(cx);
5569 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5570 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5571 0 : !GetCallableProperty(cx, atomsCache->createAnswer_id, &callable)) {
5572 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5573 0 : return nullptr;
5574 : }
5575 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5576 0 : if (!JS::Call(cx, thisValue, callable,
5577 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5578 0 : aRv.NoteJSContextException(cx);
5579 0 : return nullptr;
5580 : }
5581 0 : RefPtr<Promise> rvalDecl;
5582 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5583 : // etc.
5584 :
5585 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5586 0 : if (!rval.isObject()) {
5587 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
5588 0 : return nullptr;
5589 : }
5590 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5591 0 : if (!unwrappedVal) {
5592 : // A slight lie, but not much of one, for a dead object wrapper.
5593 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
5594 0 : return nullptr;
5595 : }
5596 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5597 0 : JSAutoCompartment ac(cx, globalObj);
5598 0 : GlobalObject promiseGlobal(cx, globalObj);
5599 0 : if (promiseGlobal.Failed()) {
5600 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5601 0 : return nullptr;
5602 : }
5603 :
5604 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5605 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5606 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5607 0 : return nullptr;
5608 : }
5609 0 : binding_detail::FastErrorResult promiseRv;
5610 : nsCOMPtr<nsIGlobalObject> global =
5611 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5612 0 : if (!global) {
5613 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5614 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5615 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5616 0 : return nullptr;
5617 : }
5618 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5619 0 : promiseRv);
5620 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5621 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5622 0 : return nullptr;
5623 : }
5624 : }
5625 0 : return rvalDecl.forget();
5626 : }
5627 :
5628 : already_AddRefed<Promise>
5629 0 : RTCPeerConnectionJSImpl::CreateAnswer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
5630 : {
5631 0 : CallSetup s(this, aRv, "RTCPeerConnection.createAnswer", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5632 0 : JSContext* cx = s.GetContext();
5633 0 : if (!cx) {
5634 0 : MOZ_ASSERT(aRv.Failed());
5635 0 : return nullptr;
5636 : }
5637 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5638 0 : JS::AutoValueVector argv(cx);
5639 0 : if (!argv.resize(2)) {
5640 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5641 0 : return nullptr;
5642 : }
5643 0 : unsigned argc = 2;
5644 :
5645 : do {
5646 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
5647 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
5648 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5649 0 : return nullptr;
5650 : }
5651 0 : break;
5652 : } while (0);
5653 :
5654 : do {
5655 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
5656 0 : if (!MaybeWrapObjectValue(cx, argv[0])) {
5657 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5658 0 : return nullptr;
5659 : }
5660 0 : break;
5661 : } while (0);
5662 :
5663 0 : JS::Rooted<JS::Value> callable(cx);
5664 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5665 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5666 0 : !GetCallableProperty(cx, atomsCache->createAnswer_id, &callable)) {
5667 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5668 0 : return nullptr;
5669 : }
5670 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5671 0 : if (!JS::Call(cx, thisValue, callable,
5672 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5673 0 : aRv.NoteJSContextException(cx);
5674 0 : return nullptr;
5675 : }
5676 0 : RefPtr<Promise> rvalDecl;
5677 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5678 : // etc.
5679 :
5680 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5681 0 : if (!rval.isObject()) {
5682 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
5683 0 : return nullptr;
5684 : }
5685 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5686 0 : if (!unwrappedVal) {
5687 : // A slight lie, but not much of one, for a dead object wrapper.
5688 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
5689 0 : return nullptr;
5690 : }
5691 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5692 0 : JSAutoCompartment ac(cx, globalObj);
5693 0 : GlobalObject promiseGlobal(cx, globalObj);
5694 0 : if (promiseGlobal.Failed()) {
5695 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5696 0 : return nullptr;
5697 : }
5698 :
5699 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5700 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5701 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5702 0 : return nullptr;
5703 : }
5704 0 : binding_detail::FastErrorResult promiseRv;
5705 : nsCOMPtr<nsIGlobalObject> global =
5706 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5707 0 : if (!global) {
5708 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5709 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5710 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5711 0 : return nullptr;
5712 : }
5713 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5714 0 : promiseRv);
5715 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5716 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5717 0 : return nullptr;
5718 : }
5719 : }
5720 0 : return rvalDecl.forget();
5721 : }
5722 :
5723 : already_AddRefed<Promise>
5724 0 : RTCPeerConnectionJSImpl::SetLocalDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JSCompartment* aCompartment)
5725 : {
5726 0 : CallSetup s(this, aRv, "RTCPeerConnection.setLocalDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5727 0 : JSContext* cx = s.GetContext();
5728 0 : if (!cx) {
5729 0 : MOZ_ASSERT(aRv.Failed());
5730 0 : return nullptr;
5731 : }
5732 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5733 0 : JS::AutoValueVector argv(cx);
5734 0 : if (!argv.resize(1)) {
5735 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5736 0 : return nullptr;
5737 : }
5738 0 : unsigned argc = 1;
5739 :
5740 : do {
5741 0 : if (!description.ToObjectInternal(cx, argv[0])) {
5742 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5743 0 : return nullptr;
5744 : }
5745 0 : break;
5746 : } while (0);
5747 :
5748 0 : JS::Rooted<JS::Value> callable(cx);
5749 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5750 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5751 0 : !GetCallableProperty(cx, atomsCache->setLocalDescription_id, &callable)) {
5752 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5753 0 : return nullptr;
5754 : }
5755 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5756 0 : if (!JS::Call(cx, thisValue, callable,
5757 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5758 0 : aRv.NoteJSContextException(cx);
5759 0 : return nullptr;
5760 : }
5761 0 : RefPtr<Promise> rvalDecl;
5762 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5763 : // etc.
5764 :
5765 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5766 0 : if (!rval.isObject()) {
5767 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
5768 0 : return nullptr;
5769 : }
5770 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5771 0 : if (!unwrappedVal) {
5772 : // A slight lie, but not much of one, for a dead object wrapper.
5773 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
5774 0 : return nullptr;
5775 : }
5776 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5777 0 : JSAutoCompartment ac(cx, globalObj);
5778 0 : GlobalObject promiseGlobal(cx, globalObj);
5779 0 : if (promiseGlobal.Failed()) {
5780 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5781 0 : return nullptr;
5782 : }
5783 :
5784 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5785 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5786 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5787 0 : return nullptr;
5788 : }
5789 0 : binding_detail::FastErrorResult promiseRv;
5790 : nsCOMPtr<nsIGlobalObject> global =
5791 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5792 0 : if (!global) {
5793 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5794 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5795 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5796 0 : return nullptr;
5797 : }
5798 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5799 0 : promiseRv);
5800 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5801 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5802 0 : return nullptr;
5803 : }
5804 : }
5805 0 : return rvalDecl.forget();
5806 : }
5807 :
5808 : already_AddRefed<Promise>
5809 0 : RTCPeerConnectionJSImpl::SetLocalDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
5810 : {
5811 0 : CallSetup s(this, aRv, "RTCPeerConnection.setLocalDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5812 0 : JSContext* cx = s.GetContext();
5813 0 : if (!cx) {
5814 0 : MOZ_ASSERT(aRv.Failed());
5815 0 : return nullptr;
5816 : }
5817 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5818 0 : JS::AutoValueVector argv(cx);
5819 0 : if (!argv.resize(3)) {
5820 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5821 0 : return nullptr;
5822 : }
5823 0 : unsigned argc = 3;
5824 :
5825 : do {
5826 0 : argv[2].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
5827 0 : if (!MaybeWrapObjectValue(cx, argv[2])) {
5828 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5829 0 : return nullptr;
5830 : }
5831 0 : break;
5832 : } while (0);
5833 :
5834 : do {
5835 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
5836 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
5837 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5838 0 : return nullptr;
5839 : }
5840 0 : break;
5841 : } while (0);
5842 :
5843 : do {
5844 0 : if (!description.ToObjectInternal(cx, argv[0])) {
5845 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5846 0 : return nullptr;
5847 : }
5848 0 : break;
5849 : } while (0);
5850 :
5851 0 : JS::Rooted<JS::Value> callable(cx);
5852 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5853 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5854 0 : !GetCallableProperty(cx, atomsCache->setLocalDescription_id, &callable)) {
5855 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5856 0 : return nullptr;
5857 : }
5858 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5859 0 : if (!JS::Call(cx, thisValue, callable,
5860 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5861 0 : aRv.NoteJSContextException(cx);
5862 0 : return nullptr;
5863 : }
5864 0 : RefPtr<Promise> rvalDecl;
5865 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5866 : // etc.
5867 :
5868 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5869 0 : if (!rval.isObject()) {
5870 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
5871 0 : return nullptr;
5872 : }
5873 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5874 0 : if (!unwrappedVal) {
5875 : // A slight lie, but not much of one, for a dead object wrapper.
5876 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
5877 0 : return nullptr;
5878 : }
5879 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5880 0 : JSAutoCompartment ac(cx, globalObj);
5881 0 : GlobalObject promiseGlobal(cx, globalObj);
5882 0 : if (promiseGlobal.Failed()) {
5883 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5884 0 : return nullptr;
5885 : }
5886 :
5887 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5888 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5889 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5890 0 : return nullptr;
5891 : }
5892 0 : binding_detail::FastErrorResult promiseRv;
5893 : nsCOMPtr<nsIGlobalObject> global =
5894 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5895 0 : if (!global) {
5896 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5897 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5898 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5899 0 : return nullptr;
5900 : }
5901 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5902 0 : promiseRv);
5903 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5904 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5905 0 : return nullptr;
5906 : }
5907 : }
5908 0 : return rvalDecl.forget();
5909 : }
5910 :
5911 : already_AddRefed<Promise>
5912 0 : RTCPeerConnectionJSImpl::SetRemoteDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JSCompartment* aCompartment)
5913 : {
5914 0 : CallSetup s(this, aRv, "RTCPeerConnection.setRemoteDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
5915 0 : JSContext* cx = s.GetContext();
5916 0 : if (!cx) {
5917 0 : MOZ_ASSERT(aRv.Failed());
5918 0 : return nullptr;
5919 : }
5920 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
5921 0 : JS::AutoValueVector argv(cx);
5922 0 : if (!argv.resize(1)) {
5923 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
5924 0 : return nullptr;
5925 : }
5926 0 : unsigned argc = 1;
5927 :
5928 : do {
5929 0 : if (!description.ToObjectInternal(cx, argv[0])) {
5930 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5931 0 : return nullptr;
5932 : }
5933 0 : break;
5934 : } while (0);
5935 :
5936 0 : JS::Rooted<JS::Value> callable(cx);
5937 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
5938 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
5939 0 : !GetCallableProperty(cx, atomsCache->setRemoteDescription_id, &callable)) {
5940 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5941 0 : return nullptr;
5942 : }
5943 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
5944 0 : if (!JS::Call(cx, thisValue, callable,
5945 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
5946 0 : aRv.NoteJSContextException(cx);
5947 0 : return nullptr;
5948 : }
5949 0 : RefPtr<Promise> rvalDecl;
5950 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
5951 : // etc.
5952 :
5953 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
5954 0 : if (!rval.isObject()) {
5955 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
5956 0 : return nullptr;
5957 : }
5958 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
5959 0 : if (!unwrappedVal) {
5960 : // A slight lie, but not much of one, for a dead object wrapper.
5961 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
5962 0 : return nullptr;
5963 : }
5964 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
5965 0 : JSAutoCompartment ac(cx, globalObj);
5966 0 : GlobalObject promiseGlobal(cx, globalObj);
5967 0 : if (promiseGlobal.Failed()) {
5968 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5969 0 : return nullptr;
5970 : }
5971 :
5972 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
5973 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
5974 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5975 0 : return nullptr;
5976 : }
5977 0 : binding_detail::FastErrorResult promiseRv;
5978 : nsCOMPtr<nsIGlobalObject> global =
5979 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
5980 0 : if (!global) {
5981 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
5982 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
5983 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5984 0 : return nullptr;
5985 : }
5986 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
5987 0 : promiseRv);
5988 0 : if (promiseRv.MaybeSetPendingException(cx)) {
5989 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
5990 0 : return nullptr;
5991 : }
5992 : }
5993 0 : return rvalDecl.forget();
5994 : }
5995 :
5996 : already_AddRefed<Promise>
5997 0 : RTCPeerConnectionJSImpl::SetRemoteDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
5998 : {
5999 0 : CallSetup s(this, aRv, "RTCPeerConnection.setRemoteDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6000 0 : JSContext* cx = s.GetContext();
6001 0 : if (!cx) {
6002 0 : MOZ_ASSERT(aRv.Failed());
6003 0 : return nullptr;
6004 : }
6005 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6006 0 : JS::AutoValueVector argv(cx);
6007 0 : if (!argv.resize(3)) {
6008 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6009 0 : return nullptr;
6010 : }
6011 0 : unsigned argc = 3;
6012 :
6013 : do {
6014 0 : argv[2].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
6015 0 : if (!MaybeWrapObjectValue(cx, argv[2])) {
6016 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6017 0 : return nullptr;
6018 : }
6019 0 : break;
6020 : } while (0);
6021 :
6022 : do {
6023 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
6024 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
6025 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6026 0 : return nullptr;
6027 : }
6028 0 : break;
6029 : } while (0);
6030 :
6031 : do {
6032 0 : if (!description.ToObjectInternal(cx, argv[0])) {
6033 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6034 0 : return nullptr;
6035 : }
6036 0 : break;
6037 : } while (0);
6038 :
6039 0 : JS::Rooted<JS::Value> callable(cx);
6040 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6041 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6042 0 : !GetCallableProperty(cx, atomsCache->setRemoteDescription_id, &callable)) {
6043 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6044 0 : return nullptr;
6045 : }
6046 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6047 0 : if (!JS::Call(cx, thisValue, callable,
6048 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6049 0 : aRv.NoteJSContextException(cx);
6050 0 : return nullptr;
6051 : }
6052 0 : RefPtr<Promise> rvalDecl;
6053 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
6054 : // etc.
6055 :
6056 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
6057 0 : if (!rval.isObject()) {
6058 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6059 0 : return nullptr;
6060 : }
6061 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6062 0 : if (!unwrappedVal) {
6063 : // A slight lie, but not much of one, for a dead object wrapper.
6064 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6065 0 : return nullptr;
6066 : }
6067 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
6068 0 : JSAutoCompartment ac(cx, globalObj);
6069 0 : GlobalObject promiseGlobal(cx, globalObj);
6070 0 : if (promiseGlobal.Failed()) {
6071 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6072 0 : return nullptr;
6073 : }
6074 :
6075 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
6076 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
6077 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6078 0 : return nullptr;
6079 : }
6080 0 : binding_detail::FastErrorResult promiseRv;
6081 : nsCOMPtr<nsIGlobalObject> global =
6082 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
6083 0 : if (!global) {
6084 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6085 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6086 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6087 0 : return nullptr;
6088 : }
6089 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6090 0 : promiseRv);
6091 0 : if (promiseRv.MaybeSetPendingException(cx)) {
6092 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6093 0 : return nullptr;
6094 : }
6095 : }
6096 0 : return rvalDecl.forget();
6097 : }
6098 :
6099 : already_AddRefed<Promise>
6100 0 : RTCPeerConnectionJSImpl::AddIceCandidate(const Nullable<RTCIceCandidateInitOrRTCIceCandidate>& candidate, ErrorResult& aRv, JSCompartment* aCompartment)
6101 : {
6102 0 : CallSetup s(this, aRv, "RTCPeerConnection.addIceCandidate", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6103 0 : JSContext* cx = s.GetContext();
6104 0 : if (!cx) {
6105 0 : MOZ_ASSERT(aRv.Failed());
6106 0 : return nullptr;
6107 : }
6108 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6109 0 : JS::AutoValueVector argv(cx);
6110 0 : if (!argv.resize(1)) {
6111 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6112 0 : return nullptr;
6113 : }
6114 0 : unsigned argc = 1;
6115 :
6116 : do {
6117 0 : if (candidate.IsNull()) {
6118 0 : argv[0].setNull();
6119 0 : break;
6120 : }
6121 0 : if (!candidate.Value().ToJSVal(cx, CallbackKnownNotGray(), argv[0])) {
6122 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6123 0 : return nullptr;
6124 : }
6125 0 : break;
6126 : } while (0);
6127 :
6128 0 : JS::Rooted<JS::Value> callable(cx);
6129 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6130 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6131 0 : !GetCallableProperty(cx, atomsCache->addIceCandidate_id, &callable)) {
6132 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6133 0 : return nullptr;
6134 : }
6135 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6136 0 : if (!JS::Call(cx, thisValue, callable,
6137 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6138 0 : aRv.NoteJSContextException(cx);
6139 0 : return nullptr;
6140 : }
6141 0 : RefPtr<Promise> rvalDecl;
6142 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
6143 : // etc.
6144 :
6145 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
6146 0 : if (!rval.isObject()) {
6147 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6148 0 : return nullptr;
6149 : }
6150 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6151 0 : if (!unwrappedVal) {
6152 : // A slight lie, but not much of one, for a dead object wrapper.
6153 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6154 0 : return nullptr;
6155 : }
6156 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
6157 0 : JSAutoCompartment ac(cx, globalObj);
6158 0 : GlobalObject promiseGlobal(cx, globalObj);
6159 0 : if (promiseGlobal.Failed()) {
6160 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6161 0 : return nullptr;
6162 : }
6163 :
6164 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
6165 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
6166 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6167 0 : return nullptr;
6168 : }
6169 0 : binding_detail::FastErrorResult promiseRv;
6170 : nsCOMPtr<nsIGlobalObject> global =
6171 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
6172 0 : if (!global) {
6173 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6174 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6175 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6176 0 : return nullptr;
6177 : }
6178 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6179 0 : promiseRv);
6180 0 : if (promiseRv.MaybeSetPendingException(cx)) {
6181 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6182 0 : return nullptr;
6183 : }
6184 : }
6185 0 : return rvalDecl.forget();
6186 : }
6187 :
6188 : already_AddRefed<Promise>
6189 0 : RTCPeerConnectionJSImpl::AddIceCandidate(RTCIceCandidate& candidate, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
6190 : {
6191 0 : CallSetup s(this, aRv, "RTCPeerConnection.addIceCandidate", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6192 0 : JSContext* cx = s.GetContext();
6193 0 : if (!cx) {
6194 0 : MOZ_ASSERT(aRv.Failed());
6195 0 : return nullptr;
6196 : }
6197 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6198 0 : JS::AutoValueVector argv(cx);
6199 0 : if (!argv.resize(3)) {
6200 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6201 0 : return nullptr;
6202 : }
6203 0 : unsigned argc = 3;
6204 :
6205 : do {
6206 0 : argv[2].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
6207 0 : if (!MaybeWrapObjectValue(cx, argv[2])) {
6208 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6209 0 : return nullptr;
6210 : }
6211 0 : break;
6212 : } while (0);
6213 :
6214 : do {
6215 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
6216 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
6217 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6218 0 : return nullptr;
6219 : }
6220 0 : break;
6221 : } while (0);
6222 :
6223 : do {
6224 0 : if (!GetOrCreateDOMReflector(cx, candidate, argv[0])) {
6225 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6226 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6227 0 : return nullptr;
6228 : }
6229 0 : break;
6230 : } while (0);
6231 :
6232 0 : JS::Rooted<JS::Value> callable(cx);
6233 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6234 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6235 0 : !GetCallableProperty(cx, atomsCache->addIceCandidate_id, &callable)) {
6236 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6237 0 : return nullptr;
6238 : }
6239 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6240 0 : if (!JS::Call(cx, thisValue, callable,
6241 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6242 0 : aRv.NoteJSContextException(cx);
6243 0 : return nullptr;
6244 : }
6245 0 : RefPtr<Promise> rvalDecl;
6246 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
6247 : // etc.
6248 :
6249 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
6250 0 : if (!rval.isObject()) {
6251 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6252 0 : return nullptr;
6253 : }
6254 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6255 0 : if (!unwrappedVal) {
6256 : // A slight lie, but not much of one, for a dead object wrapper.
6257 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6258 0 : return nullptr;
6259 : }
6260 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
6261 0 : JSAutoCompartment ac(cx, globalObj);
6262 0 : GlobalObject promiseGlobal(cx, globalObj);
6263 0 : if (promiseGlobal.Failed()) {
6264 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6265 0 : return nullptr;
6266 : }
6267 :
6268 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
6269 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
6270 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6271 0 : return nullptr;
6272 : }
6273 0 : binding_detail::FastErrorResult promiseRv;
6274 : nsCOMPtr<nsIGlobalObject> global =
6275 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
6276 0 : if (!global) {
6277 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6278 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6279 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6280 0 : return nullptr;
6281 : }
6282 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6283 0 : promiseRv);
6284 0 : if (promiseRv.MaybeSetPendingException(cx)) {
6285 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6286 0 : return nullptr;
6287 : }
6288 : }
6289 0 : return rvalDecl.forget();
6290 : }
6291 :
6292 : void
6293 0 : RTCPeerConnectionJSImpl::GetConfiguration(RTCConfiguration& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
6294 : {
6295 0 : CallSetup s(this, aRv, "RTCPeerConnection.getConfiguration", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6296 0 : JSContext* cx = s.GetContext();
6297 0 : if (!cx) {
6298 0 : MOZ_ASSERT(aRv.Failed());
6299 0 : return;
6300 : }
6301 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6302 :
6303 0 : JS::Rooted<JS::Value> callable(cx);
6304 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6305 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6306 0 : !GetCallableProperty(cx, atomsCache->getConfiguration_id, &callable)) {
6307 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6308 0 : return;
6309 : }
6310 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6311 0 : if (!JS::Call(cx, thisValue, callable,
6312 0 : JS::HandleValueArray::empty(), &rval)) {
6313 0 : aRv.NoteJSContextException(cx);
6314 0 : return;
6315 : }
6316 0 : RTCConfiguration& rvalDecl(aRetVal);
6317 0 : if (!rvalDecl.Init(cx, rval, "Return value of RTCPeerConnection.getConfiguration", false)) {
6318 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6319 0 : return;
6320 : }
6321 : }
6322 :
6323 : void
6324 0 : RTCPeerConnectionJSImpl::GetLocalStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
6325 : {
6326 0 : CallSetup s(this, aRv, "RTCPeerConnection.getLocalStreams", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6327 0 : JSContext* cx = s.GetContext();
6328 0 : if (!cx) {
6329 0 : MOZ_ASSERT(aRv.Failed());
6330 0 : return;
6331 : }
6332 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6333 :
6334 0 : JS::Rooted<JS::Value> callable(cx);
6335 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6336 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6337 0 : !GetCallableProperty(cx, atomsCache->getLocalStreams_id, &callable)) {
6338 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6339 0 : return;
6340 : }
6341 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6342 0 : if (!JS::Call(cx, thisValue, callable,
6343 0 : JS::HandleValueArray::empty(), &rval)) {
6344 0 : aRv.NoteJSContextException(cx);
6345 0 : return;
6346 : }
6347 0 : Sequence<RefPtr<mozilla::DOMMediaStream>> rvalDecl;
6348 0 : if (rval.isObject()) {
6349 0 : JS::ForOfIterator iter(cx);
6350 0 : if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
6351 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6352 0 : return;
6353 : }
6354 0 : if (!iter.valueIsIterable()) {
6355 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getLocalStreams");
6356 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6357 0 : return;
6358 : }
6359 0 : Sequence<RefPtr<mozilla::DOMMediaStream>> &arr = rvalDecl;
6360 0 : JS::Rooted<JS::Value> temp(cx);
6361 : while (true) {
6362 : bool done;
6363 0 : if (!iter.next(&temp, &done)) {
6364 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6365 0 : return;
6366 : }
6367 0 : if (done) {
6368 0 : break;
6369 : }
6370 0 : RefPtr<mozilla::DOMMediaStream>* slotPtr = arr.AppendElement(mozilla::fallible);
6371 0 : if (!slotPtr) {
6372 0 : JS_ReportOutOfMemory(cx);
6373 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6374 0 : return;
6375 : }
6376 0 : RefPtr<mozilla::DOMMediaStream>& slot = *slotPtr;
6377 0 : if (temp.isObject()) {
6378 : static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
6379 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(&temp, slot);
6380 0 : if (NS_FAILED(rv)) {
6381 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getLocalStreams", "MediaStream");
6382 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6383 0 : return;
6384 : }
6385 : }
6386 : } else {
6387 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getLocalStreams");
6388 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6389 0 : return;
6390 : }
6391 0 : }
6392 : } else {
6393 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getLocalStreams");
6394 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6395 0 : return;
6396 : }
6397 0 : aRetVal.SwapElements(rvalDecl);
6398 : }
6399 :
6400 : void
6401 0 : RTCPeerConnectionJSImpl::GetRemoteStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
6402 : {
6403 0 : CallSetup s(this, aRv, "RTCPeerConnection.getRemoteStreams", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6404 0 : JSContext* cx = s.GetContext();
6405 0 : if (!cx) {
6406 0 : MOZ_ASSERT(aRv.Failed());
6407 0 : return;
6408 : }
6409 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6410 :
6411 0 : JS::Rooted<JS::Value> callable(cx);
6412 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6413 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6414 0 : !GetCallableProperty(cx, atomsCache->getRemoteStreams_id, &callable)) {
6415 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6416 0 : return;
6417 : }
6418 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6419 0 : if (!JS::Call(cx, thisValue, callable,
6420 0 : JS::HandleValueArray::empty(), &rval)) {
6421 0 : aRv.NoteJSContextException(cx);
6422 0 : return;
6423 : }
6424 0 : Sequence<RefPtr<mozilla::DOMMediaStream>> rvalDecl;
6425 0 : if (rval.isObject()) {
6426 0 : JS::ForOfIterator iter(cx);
6427 0 : if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
6428 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6429 0 : return;
6430 : }
6431 0 : if (!iter.valueIsIterable()) {
6432 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getRemoteStreams");
6433 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6434 0 : return;
6435 : }
6436 0 : Sequence<RefPtr<mozilla::DOMMediaStream>> &arr = rvalDecl;
6437 0 : JS::Rooted<JS::Value> temp(cx);
6438 : while (true) {
6439 : bool done;
6440 0 : if (!iter.next(&temp, &done)) {
6441 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6442 0 : return;
6443 : }
6444 0 : if (done) {
6445 0 : break;
6446 : }
6447 0 : RefPtr<mozilla::DOMMediaStream>* slotPtr = arr.AppendElement(mozilla::fallible);
6448 0 : if (!slotPtr) {
6449 0 : JS_ReportOutOfMemory(cx);
6450 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6451 0 : return;
6452 : }
6453 0 : RefPtr<mozilla::DOMMediaStream>& slot = *slotPtr;
6454 0 : if (temp.isObject()) {
6455 : static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
6456 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(&temp, slot);
6457 0 : if (NS_FAILED(rv)) {
6458 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getRemoteStreams", "MediaStream");
6459 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6460 0 : return;
6461 : }
6462 : }
6463 : } else {
6464 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getRemoteStreams");
6465 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6466 0 : return;
6467 : }
6468 0 : }
6469 : } else {
6470 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getRemoteStreams");
6471 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6472 0 : return;
6473 : }
6474 0 : aRetVal.SwapElements(rvalDecl);
6475 : }
6476 :
6477 : void
6478 0 : RTCPeerConnectionJSImpl::AddStream(DOMMediaStream& stream, ErrorResult& aRv, JSCompartment* aCompartment)
6479 : {
6480 0 : CallSetup s(this, aRv, "RTCPeerConnection.addStream", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6481 0 : JSContext* cx = s.GetContext();
6482 0 : if (!cx) {
6483 0 : MOZ_ASSERT(aRv.Failed());
6484 0 : return;
6485 : }
6486 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6487 0 : JS::AutoValueVector argv(cx);
6488 0 : if (!argv.resize(1)) {
6489 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6490 0 : return;
6491 : }
6492 0 : unsigned argc = 1;
6493 :
6494 : do {
6495 0 : if (!GetOrCreateDOMReflector(cx, stream, argv[0])) {
6496 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6497 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6498 0 : return;
6499 : }
6500 0 : break;
6501 : } while (0);
6502 :
6503 0 : JS::Rooted<JS::Value> callable(cx);
6504 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6505 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6506 0 : !GetCallableProperty(cx, atomsCache->addStream_id, &callable)) {
6507 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6508 0 : return;
6509 : }
6510 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6511 0 : if (!JS::Call(cx, thisValue, callable,
6512 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6513 0 : aRv.NoteJSContextException(cx);
6514 0 : return;
6515 : }
6516 : }
6517 :
6518 : already_AddRefed<RTCRtpSender>
6519 0 : RTCPeerConnectionJSImpl::AddTrack(MediaStreamTrack& track, DOMMediaStream& stream, const nsTArray<OwningNonNull<DOMMediaStream>>& moreStreams, ErrorResult& aRv, JSCompartment* aCompartment)
6520 : {
6521 0 : CallSetup s(this, aRv, "RTCPeerConnection.addTrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6522 0 : JSContext* cx = s.GetContext();
6523 0 : if (!cx) {
6524 0 : MOZ_ASSERT(aRv.Failed());
6525 0 : return nullptr;
6526 : }
6527 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6528 0 : JS::AutoValueVector argv(cx);
6529 0 : if (!argv.resize((3 - 1) + moreStreams.Length())) {
6530 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6531 0 : return nullptr;
6532 : }
6533 0 : unsigned argc = (3 - 1) + moreStreams.Length();
6534 :
6535 : do {
6536 0 : for (uint32_t idx = 0; idx < moreStreams.Length(); ++idx) {
6537 0 : if (!GetOrCreateDOMReflector(cx, moreStreams[idx], argv[2 + idx])) {
6538 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6539 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6540 0 : return nullptr;
6541 : }
6542 0 : continue;
6543 : }
6544 0 : break;
6545 : } while (0);
6546 :
6547 : do {
6548 0 : if (!GetOrCreateDOMReflector(cx, stream, argv[1])) {
6549 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6550 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6551 0 : return nullptr;
6552 : }
6553 0 : break;
6554 : } while (0);
6555 :
6556 : do {
6557 0 : if (!GetOrCreateDOMReflector(cx, track, argv[0])) {
6558 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6559 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6560 0 : return nullptr;
6561 : }
6562 0 : break;
6563 : } while (0);
6564 :
6565 0 : JS::Rooted<JS::Value> callable(cx);
6566 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6567 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6568 0 : !GetCallableProperty(cx, atomsCache->addTrack_id, &callable)) {
6569 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6570 0 : return nullptr;
6571 : }
6572 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6573 0 : if (!JS::Call(cx, thisValue, callable,
6574 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6575 0 : aRv.NoteJSContextException(cx);
6576 0 : return nullptr;
6577 : }
6578 0 : RefPtr<mozilla::dom::RTCRtpSender> rvalDecl;
6579 0 : if (rval.isObject()) {
6580 : static_assert(IsRefcounted<mozilla::dom::RTCRtpSender>::value, "We can only store refcounted classes.");{
6581 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(rval, rvalDecl);
6582 0 : if (NS_FAILED(rv)) {
6583 : // Be careful to not wrap random DOM objects here, even if
6584 : // they're wrapped in opaque security wrappers for some reason.
6585 : // XXXbz Wish we could check for a JS-implemented object
6586 : // that already has a content reflection...
6587 0 : if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
6588 0 : nsCOMPtr<nsIGlobalObject> contentGlobal;
6589 0 : JS::Handle<JSObject*> callback = CallbackOrNull();
6590 0 : if (!callback ||
6591 0 : !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
6592 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6593 0 : return nullptr;
6594 : }
6595 0 : JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
6596 0 : rvalDecl = new mozilla::dom::RTCRtpSender(jsImplSourceObj, contentGlobal);
6597 : } else {
6598 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.addTrack", "RTCRtpSender");
6599 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6600 0 : return nullptr;
6601 : }
6602 : }
6603 : }
6604 : } else {
6605 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.addTrack");
6606 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6607 0 : return nullptr;
6608 : }
6609 0 : return rvalDecl.forget();
6610 : }
6611 :
6612 : void
6613 0 : RTCPeerConnectionJSImpl::RemoveTrack(RTCRtpSender& sender, ErrorResult& aRv, JSCompartment* aCompartment)
6614 : {
6615 0 : CallSetup s(this, aRv, "RTCPeerConnection.removeTrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6616 0 : JSContext* cx = s.GetContext();
6617 0 : if (!cx) {
6618 0 : MOZ_ASSERT(aRv.Failed());
6619 0 : return;
6620 : }
6621 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6622 0 : JS::AutoValueVector argv(cx);
6623 0 : if (!argv.resize(1)) {
6624 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6625 0 : return;
6626 : }
6627 0 : unsigned argc = 1;
6628 :
6629 : do {
6630 0 : if (!GetOrCreateDOMReflector(cx, sender, argv[0])) {
6631 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6632 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6633 0 : return;
6634 : }
6635 0 : break;
6636 : } while (0);
6637 :
6638 0 : JS::Rooted<JS::Value> callable(cx);
6639 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6640 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6641 0 : !GetCallableProperty(cx, atomsCache->removeTrack_id, &callable)) {
6642 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6643 0 : return;
6644 : }
6645 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6646 0 : if (!JS::Call(cx, thisValue, callable,
6647 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6648 0 : aRv.NoteJSContextException(cx);
6649 0 : return;
6650 : }
6651 : }
6652 :
6653 : void
6654 0 : RTCPeerConnectionJSImpl::GetSenders(nsTArray<RefPtr<RTCRtpSender>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
6655 : {
6656 0 : CallSetup s(this, aRv, "RTCPeerConnection.getSenders", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6657 0 : JSContext* cx = s.GetContext();
6658 0 : if (!cx) {
6659 0 : MOZ_ASSERT(aRv.Failed());
6660 0 : return;
6661 : }
6662 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6663 :
6664 0 : JS::Rooted<JS::Value> callable(cx);
6665 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6666 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6667 0 : !GetCallableProperty(cx, atomsCache->getSenders_id, &callable)) {
6668 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6669 0 : return;
6670 : }
6671 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6672 0 : if (!JS::Call(cx, thisValue, callable,
6673 0 : JS::HandleValueArray::empty(), &rval)) {
6674 0 : aRv.NoteJSContextException(cx);
6675 0 : return;
6676 : }
6677 0 : Sequence<RefPtr<mozilla::dom::RTCRtpSender>> rvalDecl;
6678 0 : if (rval.isObject()) {
6679 0 : JS::ForOfIterator iter(cx);
6680 0 : if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
6681 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6682 0 : return;
6683 : }
6684 0 : if (!iter.valueIsIterable()) {
6685 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getSenders");
6686 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6687 0 : return;
6688 : }
6689 0 : Sequence<RefPtr<mozilla::dom::RTCRtpSender>> &arr = rvalDecl;
6690 0 : JS::Rooted<JS::Value> temp(cx);
6691 : while (true) {
6692 : bool done;
6693 0 : if (!iter.next(&temp, &done)) {
6694 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6695 0 : return;
6696 : }
6697 0 : if (done) {
6698 0 : break;
6699 : }
6700 0 : RefPtr<mozilla::dom::RTCRtpSender>* slotPtr = arr.AppendElement(mozilla::fallible);
6701 0 : if (!slotPtr) {
6702 0 : JS_ReportOutOfMemory(cx);
6703 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6704 0 : return;
6705 : }
6706 0 : RefPtr<mozilla::dom::RTCRtpSender>& slot = *slotPtr;
6707 0 : if (temp.isObject()) {
6708 : static_assert(IsRefcounted<mozilla::dom::RTCRtpSender>::value, "We can only store refcounted classes.");{
6709 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(&temp, slot);
6710 0 : if (NS_FAILED(rv)) {
6711 : // Be careful to not wrap random DOM objects here, even if
6712 : // they're wrapped in opaque security wrappers for some reason.
6713 : // XXXbz Wish we could check for a JS-implemented object
6714 : // that already has a content reflection...
6715 0 : if (!IsDOMObject(js::UncheckedUnwrap(&temp.toObject()))) {
6716 0 : nsCOMPtr<nsIGlobalObject> contentGlobal;
6717 0 : JS::Handle<JSObject*> callback = CallbackOrNull();
6718 0 : if (!callback ||
6719 0 : !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
6720 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6721 0 : return;
6722 : }
6723 0 : JS::Rooted<JSObject*> jsImplSourceObj(cx, &temp.toObject());
6724 0 : slot = new mozilla::dom::RTCRtpSender(jsImplSourceObj, contentGlobal);
6725 : } else {
6726 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getSenders", "RTCRtpSender");
6727 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6728 0 : return;
6729 : }
6730 : }
6731 : }
6732 : } else {
6733 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getSenders");
6734 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6735 0 : return;
6736 : }
6737 0 : }
6738 : } else {
6739 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getSenders");
6740 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6741 0 : return;
6742 : }
6743 0 : aRetVal.SwapElements(rvalDecl);
6744 : }
6745 :
6746 : void
6747 0 : RTCPeerConnectionJSImpl::GetReceivers(nsTArray<RefPtr<RTCRtpReceiver>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
6748 : {
6749 0 : CallSetup s(this, aRv, "RTCPeerConnection.getReceivers", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6750 0 : JSContext* cx = s.GetContext();
6751 0 : if (!cx) {
6752 0 : MOZ_ASSERT(aRv.Failed());
6753 0 : return;
6754 : }
6755 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6756 :
6757 0 : JS::Rooted<JS::Value> callable(cx);
6758 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6759 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6760 0 : !GetCallableProperty(cx, atomsCache->getReceivers_id, &callable)) {
6761 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6762 0 : return;
6763 : }
6764 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6765 0 : if (!JS::Call(cx, thisValue, callable,
6766 0 : JS::HandleValueArray::empty(), &rval)) {
6767 0 : aRv.NoteJSContextException(cx);
6768 0 : return;
6769 : }
6770 0 : Sequence<RefPtr<mozilla::dom::RTCRtpReceiver>> rvalDecl;
6771 0 : if (rval.isObject()) {
6772 0 : JS::ForOfIterator iter(cx);
6773 0 : if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
6774 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6775 0 : return;
6776 : }
6777 0 : if (!iter.valueIsIterable()) {
6778 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getReceivers");
6779 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6780 0 : return;
6781 : }
6782 0 : Sequence<RefPtr<mozilla::dom::RTCRtpReceiver>> &arr = rvalDecl;
6783 0 : JS::Rooted<JS::Value> temp(cx);
6784 : while (true) {
6785 : bool done;
6786 0 : if (!iter.next(&temp, &done)) {
6787 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6788 0 : return;
6789 : }
6790 0 : if (done) {
6791 0 : break;
6792 : }
6793 0 : RefPtr<mozilla::dom::RTCRtpReceiver>* slotPtr = arr.AppendElement(mozilla::fallible);
6794 0 : if (!slotPtr) {
6795 0 : JS_ReportOutOfMemory(cx);
6796 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6797 0 : return;
6798 : }
6799 0 : RefPtr<mozilla::dom::RTCRtpReceiver>& slot = *slotPtr;
6800 0 : if (temp.isObject()) {
6801 : static_assert(IsRefcounted<mozilla::dom::RTCRtpReceiver>::value, "We can only store refcounted classes.");{
6802 0 : nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(&temp, slot);
6803 0 : if (NS_FAILED(rv)) {
6804 : // Be careful to not wrap random DOM objects here, even if
6805 : // they're wrapped in opaque security wrappers for some reason.
6806 : // XXXbz Wish we could check for a JS-implemented object
6807 : // that already has a content reflection...
6808 0 : if (!IsDOMObject(js::UncheckedUnwrap(&temp.toObject()))) {
6809 0 : nsCOMPtr<nsIGlobalObject> contentGlobal;
6810 0 : JS::Handle<JSObject*> callback = CallbackOrNull();
6811 0 : if (!callback ||
6812 0 : !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
6813 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6814 0 : return;
6815 : }
6816 0 : JS::Rooted<JSObject*> jsImplSourceObj(cx, &temp.toObject());
6817 0 : slot = new mozilla::dom::RTCRtpReceiver(jsImplSourceObj, contentGlobal);
6818 : } else {
6819 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getReceivers", "RTCRtpReceiver");
6820 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6821 0 : return;
6822 : }
6823 : }
6824 : }
6825 : } else {
6826 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getReceivers");
6827 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6828 0 : return;
6829 : }
6830 0 : }
6831 : } else {
6832 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getReceivers");
6833 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6834 0 : return;
6835 : }
6836 0 : aRetVal.SwapElements(rvalDecl);
6837 : }
6838 :
6839 : void
6840 0 : RTCPeerConnectionJSImpl::MozAddRIDExtension(RTCRtpReceiver& receiver, uint16_t extensionId, ErrorResult& aRv, JSCompartment* aCompartment)
6841 : {
6842 0 : CallSetup s(this, aRv, "RTCPeerConnection.mozAddRIDExtension", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6843 0 : JSContext* cx = s.GetContext();
6844 0 : if (!cx) {
6845 0 : MOZ_ASSERT(aRv.Failed());
6846 0 : return;
6847 : }
6848 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6849 0 : JS::AutoValueVector argv(cx);
6850 0 : if (!argv.resize(2)) {
6851 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6852 0 : return;
6853 : }
6854 0 : unsigned argc = 2;
6855 :
6856 : do {
6857 0 : argv[1].setInt32(int32_t(extensionId));
6858 0 : break;
6859 : } while (0);
6860 :
6861 : do {
6862 0 : if (!GetOrCreateDOMReflector(cx, receiver, argv[0])) {
6863 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6864 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6865 0 : return;
6866 : }
6867 0 : break;
6868 : } while (0);
6869 :
6870 0 : JS::Rooted<JS::Value> callable(cx);
6871 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6872 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6873 0 : !GetCallableProperty(cx, atomsCache->mozAddRIDExtension_id, &callable)) {
6874 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6875 0 : return;
6876 : }
6877 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6878 0 : if (!JS::Call(cx, thisValue, callable,
6879 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6880 0 : aRv.NoteJSContextException(cx);
6881 0 : return;
6882 : }
6883 : }
6884 :
6885 : void
6886 0 : RTCPeerConnectionJSImpl::MozAddRIDFilter(RTCRtpReceiver& receiver, const nsAString& rid, ErrorResult& aRv, JSCompartment* aCompartment)
6887 : {
6888 0 : CallSetup s(this, aRv, "RTCPeerConnection.mozAddRIDFilter", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6889 0 : JSContext* cx = s.GetContext();
6890 0 : if (!cx) {
6891 0 : MOZ_ASSERT(aRv.Failed());
6892 0 : return;
6893 : }
6894 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6895 0 : JS::AutoValueVector argv(cx);
6896 0 : if (!argv.resize(2)) {
6897 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6898 0 : return;
6899 : }
6900 0 : unsigned argc = 2;
6901 :
6902 : do {
6903 0 : nsString mutableStr(rid);
6904 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) {
6905 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6906 0 : return;
6907 : }
6908 0 : break;
6909 : } while (0);
6910 :
6911 : do {
6912 0 : if (!GetOrCreateDOMReflector(cx, receiver, argv[0])) {
6913 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6914 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6915 0 : return;
6916 : }
6917 0 : break;
6918 : } while (0);
6919 :
6920 0 : JS::Rooted<JS::Value> callable(cx);
6921 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6922 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6923 0 : !GetCallableProperty(cx, atomsCache->mozAddRIDFilter_id, &callable)) {
6924 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6925 0 : return;
6926 : }
6927 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6928 0 : if (!JS::Call(cx, thisValue, callable,
6929 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6930 0 : aRv.NoteJSContextException(cx);
6931 0 : return;
6932 : }
6933 : }
6934 :
6935 : void
6936 0 : RTCPeerConnectionJSImpl::Close(ErrorResult& aRv, JSCompartment* aCompartment)
6937 : {
6938 0 : CallSetup s(this, aRv, "RTCPeerConnection.close", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6939 0 : JSContext* cx = s.GetContext();
6940 0 : if (!cx) {
6941 0 : MOZ_ASSERT(aRv.Failed());
6942 0 : return;
6943 : }
6944 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6945 :
6946 0 : JS::Rooted<JS::Value> callable(cx);
6947 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6948 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6949 0 : !GetCallableProperty(cx, atomsCache->close_id, &callable)) {
6950 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6951 0 : return;
6952 : }
6953 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6954 0 : if (!JS::Call(cx, thisValue, callable,
6955 0 : JS::HandleValueArray::empty(), &rval)) {
6956 0 : aRv.NoteJSContextException(cx);
6957 0 : return;
6958 : }
6959 : }
6960 :
6961 : already_AddRefed<Promise>
6962 0 : RTCPeerConnectionJSImpl::GetStats(const Optional<MediaStreamTrack*>& selector, ErrorResult& aRv, JSCompartment* aCompartment)
6963 : {
6964 0 : CallSetup s(this, aRv, "RTCPeerConnection.getStats", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
6965 0 : JSContext* cx = s.GetContext();
6966 0 : if (!cx) {
6967 0 : MOZ_ASSERT(aRv.Failed());
6968 0 : return nullptr;
6969 : }
6970 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6971 0 : JS::AutoValueVector argv(cx);
6972 0 : if (!argv.resize(1)) {
6973 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6974 0 : return nullptr;
6975 : }
6976 0 : unsigned argc = 1;
6977 :
6978 : do {
6979 0 : if (selector.WasPassed()) {
6980 0 : if (!selector.Value()) {
6981 0 : argv[0].setNull();
6982 0 : break;
6983 : }
6984 0 : if (!GetOrCreateDOMReflector(cx, selector.Value(), argv[0])) {
6985 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
6986 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
6987 0 : return nullptr;
6988 : }
6989 0 : break;
6990 0 : } else if (argc == 1) {
6991 : // This is our current trailing argument; reduce argc
6992 0 : --argc;
6993 : } else {
6994 0 : argv[0].setUndefined();
6995 : }
6996 : } while (0);
6997 :
6998 0 : JS::Rooted<JS::Value> callable(cx);
6999 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7000 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7001 0 : !GetCallableProperty(cx, atomsCache->getStats_id, &callable)) {
7002 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7003 0 : return nullptr;
7004 : }
7005 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7006 0 : if (!JS::Call(cx, thisValue, callable,
7007 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7008 0 : aRv.NoteJSContextException(cx);
7009 0 : return nullptr;
7010 : }
7011 0 : RefPtr<Promise> rvalDecl;
7012 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
7013 : // etc.
7014 :
7015 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
7016 0 : if (!rval.isObject()) {
7017 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
7018 0 : return nullptr;
7019 : }
7020 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
7021 0 : if (!unwrappedVal) {
7022 : // A slight lie, but not much of one, for a dead object wrapper.
7023 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
7024 0 : return nullptr;
7025 : }
7026 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
7027 0 : JSAutoCompartment ac(cx, globalObj);
7028 0 : GlobalObject promiseGlobal(cx, globalObj);
7029 0 : if (promiseGlobal.Failed()) {
7030 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7031 0 : return nullptr;
7032 : }
7033 :
7034 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
7035 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
7036 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7037 0 : return nullptr;
7038 : }
7039 0 : binding_detail::FastErrorResult promiseRv;
7040 : nsCOMPtr<nsIGlobalObject> global =
7041 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
7042 0 : if (!global) {
7043 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
7044 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
7045 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7046 0 : return nullptr;
7047 : }
7048 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
7049 0 : promiseRv);
7050 0 : if (promiseRv.MaybeSetPendingException(cx)) {
7051 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7052 0 : return nullptr;
7053 : }
7054 : }
7055 0 : return rvalDecl.forget();
7056 : }
7057 :
7058 : already_AddRefed<Promise>
7059 0 : RTCPeerConnectionJSImpl::GetStats(MediaStreamTrack* selector, RTCStatsCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
7060 : {
7061 0 : CallSetup s(this, aRv, "RTCPeerConnection.getStats", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7062 0 : JSContext* cx = s.GetContext();
7063 0 : if (!cx) {
7064 0 : MOZ_ASSERT(aRv.Failed());
7065 0 : return nullptr;
7066 : }
7067 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7068 0 : JS::AutoValueVector argv(cx);
7069 0 : if (!argv.resize(3)) {
7070 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7071 0 : return nullptr;
7072 : }
7073 0 : unsigned argc = 3;
7074 :
7075 : do {
7076 0 : argv[2].setObjectOrNull(GetCallbackFromCallbackObject(failureCallback));
7077 0 : if (!MaybeWrapObjectValue(cx, argv[2])) {
7078 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7079 0 : return nullptr;
7080 : }
7081 0 : break;
7082 : } while (0);
7083 :
7084 : do {
7085 0 : argv[1].setObjectOrNull(GetCallbackFromCallbackObject(successCallback));
7086 0 : if (!MaybeWrapObjectValue(cx, argv[1])) {
7087 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7088 0 : return nullptr;
7089 : }
7090 0 : break;
7091 : } while (0);
7092 :
7093 : do {
7094 0 : if (!selector) {
7095 0 : argv[0].setNull();
7096 0 : break;
7097 : }
7098 0 : if (!GetOrCreateDOMReflector(cx, selector, argv[0])) {
7099 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
7100 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7101 0 : return nullptr;
7102 : }
7103 0 : break;
7104 : } while (0);
7105 :
7106 0 : JS::Rooted<JS::Value> callable(cx);
7107 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7108 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7109 0 : !GetCallableProperty(cx, atomsCache->getStats_id, &callable)) {
7110 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7111 0 : return nullptr;
7112 : }
7113 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7114 0 : if (!JS::Call(cx, thisValue, callable,
7115 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7116 0 : aRv.NoteJSContextException(cx);
7117 0 : return nullptr;
7118 : }
7119 0 : RefPtr<Promise> rvalDecl;
7120 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
7121 : // etc.
7122 :
7123 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
7124 0 : if (!rval.isObject()) {
7125 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
7126 0 : return nullptr;
7127 : }
7128 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
7129 0 : if (!unwrappedVal) {
7130 : // A slight lie, but not much of one, for a dead object wrapper.
7131 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
7132 0 : return nullptr;
7133 : }
7134 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
7135 0 : JSAutoCompartment ac(cx, globalObj);
7136 0 : GlobalObject promiseGlobal(cx, globalObj);
7137 0 : if (promiseGlobal.Failed()) {
7138 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7139 0 : return nullptr;
7140 : }
7141 :
7142 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
7143 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
7144 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7145 0 : return nullptr;
7146 : }
7147 0 : binding_detail::FastErrorResult promiseRv;
7148 : nsCOMPtr<nsIGlobalObject> global =
7149 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
7150 0 : if (!global) {
7151 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
7152 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
7153 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7154 0 : return nullptr;
7155 : }
7156 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
7157 0 : promiseRv);
7158 0 : if (promiseRv.MaybeSetPendingException(cx)) {
7159 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7160 0 : return nullptr;
7161 : }
7162 : }
7163 0 : return rvalDecl.forget();
7164 : }
7165 :
7166 : already_AddRefed<nsIDOMDataChannel>
7167 0 : RTCPeerConnectionJSImpl::CreateDataChannel(const nsAString& label, const RTCDataChannelInit& dataChannelDict, ErrorResult& aRv, JSCompartment* aCompartment)
7168 : {
7169 0 : CallSetup s(this, aRv, "RTCPeerConnection.createDataChannel", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7170 0 : JSContext* cx = s.GetContext();
7171 0 : if (!cx) {
7172 0 : MOZ_ASSERT(aRv.Failed());
7173 0 : return nullptr;
7174 : }
7175 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7176 0 : JS::AutoValueVector argv(cx);
7177 0 : if (!argv.resize(2)) {
7178 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7179 0 : return nullptr;
7180 : }
7181 0 : unsigned argc = 2;
7182 :
7183 : do {
7184 0 : if (!dataChannelDict.ToObjectInternal(cx, argv[1])) {
7185 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7186 0 : return nullptr;
7187 : }
7188 0 : break;
7189 : } while (0);
7190 :
7191 : do {
7192 0 : nsString mutableStr(label);
7193 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
7194 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7195 0 : return nullptr;
7196 : }
7197 0 : break;
7198 : } while (0);
7199 :
7200 0 : JS::Rooted<JS::Value> callable(cx);
7201 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7202 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7203 0 : !GetCallableProperty(cx, atomsCache->createDataChannel_id, &callable)) {
7204 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7205 0 : return nullptr;
7206 : }
7207 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7208 0 : if (!JS::Call(cx, thisValue, callable,
7209 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7210 0 : aRv.NoteJSContextException(cx);
7211 0 : return nullptr;
7212 : }
7213 0 : RefPtr<nsIDOMDataChannel> rvalDecl;
7214 0 : if (rval.isObject()) {
7215 0 : static_assert(IsRefcounted<nsIDOMDataChannel>::value, "We can only store refcounted classes.");RefPtr<nsIDOMDataChannel> rvalHolder;
7216 0 : JS::Rooted<JSObject*> source(cx, &rval.toObject());
7217 0 : if (NS_FAILED(UnwrapArg<nsIDOMDataChannel>(cx, source, getter_AddRefs(rvalHolder)))) {
7218 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.createDataChannel", "RTCDataChannel");
7219 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7220 0 : return nullptr;
7221 : }
7222 0 : MOZ_ASSERT(rvalHolder);
7223 0 : rvalDecl = rvalHolder;
7224 : } else {
7225 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.createDataChannel");
7226 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7227 0 : return nullptr;
7228 : }
7229 0 : return rvalDecl.forget();
7230 : }
7231 :
7232 : void
7233 0 : RTCPeerConnectionJSImpl::__Init(const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv, JSCompartment* aCompartment)
7234 : {
7235 0 : CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7236 0 : JSContext* cx = s.GetContext();
7237 0 : if (!cx) {
7238 0 : MOZ_ASSERT(aRv.Failed());
7239 0 : return;
7240 : }
7241 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7242 0 : JS::AutoValueVector argv(cx);
7243 0 : if (!argv.resize(2)) {
7244 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7245 0 : return;
7246 : }
7247 0 : unsigned argc = 2;
7248 :
7249 : do {
7250 0 : if (constraints.WasPassed()) {
7251 0 : if (constraints.Value()) {
7252 0 : JS::ExposeObjectToActiveJS(constraints.Value());
7253 : }
7254 0 : argv[1].setObjectOrNull(constraints.Value());
7255 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[1])) {
7256 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7257 0 : return;
7258 : }
7259 0 : break;
7260 0 : } else if (argc == 2) {
7261 : // This is our current trailing argument; reduce argc
7262 0 : --argc;
7263 : } else {
7264 0 : argv[1].setUndefined();
7265 : }
7266 : } while (0);
7267 :
7268 : do {
7269 0 : if (!configuration.ToObjectInternal(cx, argv[0])) {
7270 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7271 0 : return;
7272 : }
7273 0 : break;
7274 : } while (0);
7275 :
7276 0 : JS::Rooted<JS::Value> callable(cx);
7277 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7278 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7279 0 : !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
7280 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7281 0 : return;
7282 : }
7283 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7284 0 : if (!JS::Call(cx, thisValue, callable,
7285 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7286 0 : aRv.NoteJSContextException(cx);
7287 0 : return;
7288 : }
7289 : }
7290 :
7291 : bool
7292 0 : RTCPeerConnectionJSImpl::InitIds(JSContext* cx, RTCPeerConnectionAtoms* atomsCache)
7293 : {
7294 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
7295 :
7296 : // Initialize these in reverse order so that any failure leaves the first one
7297 : // uninitialized.
7298 0 : if (!atomsCache->__init_id.init(cx, "__init") ||
7299 0 : !atomsCache->ondatachannel_id.init(cx, "ondatachannel") ||
7300 0 : !atomsCache->createDataChannel_id.init(cx, "createDataChannel") ||
7301 0 : !atomsCache->getStats_id.init(cx, "getStats") ||
7302 0 : !atomsCache->onicegatheringstatechange_id.init(cx, "onicegatheringstatechange") ||
7303 0 : !atomsCache->oniceconnectionstatechange_id.init(cx, "oniceconnectionstatechange") ||
7304 0 : !atomsCache->onremovestream_id.init(cx, "onremovestream") ||
7305 0 : !atomsCache->ontrack_id.init(cx, "ontrack") ||
7306 0 : !atomsCache->onaddtrack_id.init(cx, "onaddtrack") ||
7307 0 : !atomsCache->onaddstream_id.init(cx, "onaddstream") ||
7308 0 : !atomsCache->onsignalingstatechange_id.init(cx, "onsignalingstatechange") ||
7309 0 : !atomsCache->onicecandidate_id.init(cx, "onicecandidate") ||
7310 0 : !atomsCache->onnegotiationneeded_id.init(cx, "onnegotiationneeded") ||
7311 0 : !atomsCache->close_id.init(cx, "close") ||
7312 0 : !atomsCache->mozAddRIDFilter_id.init(cx, "mozAddRIDFilter") ||
7313 0 : !atomsCache->mozAddRIDExtension_id.init(cx, "mozAddRIDExtension") ||
7314 0 : !atomsCache->getReceivers_id.init(cx, "getReceivers") ||
7315 0 : !atomsCache->getSenders_id.init(cx, "getSenders") ||
7316 0 : !atomsCache->removeTrack_id.init(cx, "removeTrack") ||
7317 0 : !atomsCache->addTrack_id.init(cx, "addTrack") ||
7318 0 : !atomsCache->addStream_id.init(cx, "addStream") ||
7319 0 : !atomsCache->getRemoteStreams_id.init(cx, "getRemoteStreams") ||
7320 0 : !atomsCache->getLocalStreams_id.init(cx, "getLocalStreams") ||
7321 0 : !atomsCache->getConfiguration_id.init(cx, "getConfiguration") ||
7322 0 : !atomsCache->id_id.init(cx, "id") ||
7323 0 : !atomsCache->idpLoginUrl_id.init(cx, "idpLoginUrl") ||
7324 0 : !atomsCache->peerIdentity_id.init(cx, "peerIdentity") ||
7325 0 : !atomsCache->iceConnectionState_id.init(cx, "iceConnectionState") ||
7326 0 : !atomsCache->iceGatheringState_id.init(cx, "iceGatheringState") ||
7327 0 : !atomsCache->canTrickleIceCandidates_id.init(cx, "canTrickleIceCandidates") ||
7328 0 : !atomsCache->addIceCandidate_id.init(cx, "addIceCandidate") ||
7329 0 : !atomsCache->signalingState_id.init(cx, "signalingState") ||
7330 0 : !atomsCache->remoteDescription_id.init(cx, "remoteDescription") ||
7331 0 : !atomsCache->localDescription_id.init(cx, "localDescription") ||
7332 0 : !atomsCache->setRemoteDescription_id.init(cx, "setRemoteDescription") ||
7333 0 : !atomsCache->setLocalDescription_id.init(cx, "setLocalDescription") ||
7334 0 : !atomsCache->createAnswer_id.init(cx, "createAnswer") ||
7335 0 : !atomsCache->createOffer_id.init(cx, "createOffer") ||
7336 0 : !atomsCache->getIdentityAssertion_id.init(cx, "getIdentityAssertion") ||
7337 0 : !atomsCache->setIdentityProvider_id.init(cx, "setIdentityProvider") ||
7338 0 : !atomsCache->generateCertificate_id.init(cx, "generateCertificate")) {
7339 0 : return false;
7340 : }
7341 0 : return true;
7342 : }
7343 :
7344 :
7345 : already_AddRefed<RTCSessionDescription>
7346 0 : RTCPeerConnectionJSImpl::GetLocalDescription(ErrorResult& aRv, JSCompartment* aCompartment)
7347 : {
7348 0 : CallSetup s(this, aRv, "RTCPeerConnection.localDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7349 0 : JSContext* cx = s.GetContext();
7350 0 : if (!cx) {
7351 0 : MOZ_ASSERT(aRv.Failed());
7352 0 : return nullptr;
7353 : }
7354 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7355 :
7356 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7357 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7358 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7359 0 : !JS_GetPropertyById(cx, callback, atomsCache->localDescription_id, &rval)) {
7360 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7361 0 : return nullptr;
7362 : }
7363 0 : RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
7364 0 : if (rval.isObject()) {
7365 : static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
7366 0 : nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
7367 0 : if (NS_FAILED(rv)) {
7368 : // Be careful to not wrap random DOM objects here, even if
7369 : // they're wrapped in opaque security wrappers for some reason.
7370 : // XXXbz Wish we could check for a JS-implemented object
7371 : // that already has a content reflection...
7372 0 : if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
7373 0 : nsCOMPtr<nsIGlobalObject> contentGlobal;
7374 0 : JS::Handle<JSObject*> callback = CallbackOrNull();
7375 0 : if (!callback ||
7376 0 : !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7377 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7378 0 : return nullptr;
7379 : }
7380 0 : JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
7381 0 : rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, contentGlobal);
7382 : } else {
7383 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.localDescription", "RTCSessionDescription");
7384 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7385 0 : return nullptr;
7386 : }
7387 : }
7388 : }
7389 0 : } else if (rval.isNullOrUndefined()) {
7390 0 : rvalDecl = nullptr;
7391 : } else {
7392 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.localDescription");
7393 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7394 0 : return nullptr;
7395 : }
7396 0 : return rvalDecl.forget();
7397 : }
7398 :
7399 : already_AddRefed<RTCSessionDescription>
7400 0 : RTCPeerConnectionJSImpl::GetRemoteDescription(ErrorResult& aRv, JSCompartment* aCompartment)
7401 : {
7402 0 : CallSetup s(this, aRv, "RTCPeerConnection.remoteDescription", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7403 0 : JSContext* cx = s.GetContext();
7404 0 : if (!cx) {
7405 0 : MOZ_ASSERT(aRv.Failed());
7406 0 : return nullptr;
7407 : }
7408 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7409 :
7410 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7411 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7412 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7413 0 : !JS_GetPropertyById(cx, callback, atomsCache->remoteDescription_id, &rval)) {
7414 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7415 0 : return nullptr;
7416 : }
7417 0 : RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
7418 0 : if (rval.isObject()) {
7419 : static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
7420 0 : nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
7421 0 : if (NS_FAILED(rv)) {
7422 : // Be careful to not wrap random DOM objects here, even if
7423 : // they're wrapped in opaque security wrappers for some reason.
7424 : // XXXbz Wish we could check for a JS-implemented object
7425 : // that already has a content reflection...
7426 0 : if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
7427 0 : nsCOMPtr<nsIGlobalObject> contentGlobal;
7428 0 : JS::Handle<JSObject*> callback = CallbackOrNull();
7429 0 : if (!callback ||
7430 0 : !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7431 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7432 0 : return nullptr;
7433 : }
7434 0 : JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
7435 0 : rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, contentGlobal);
7436 : } else {
7437 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.remoteDescription", "RTCSessionDescription");
7438 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7439 0 : return nullptr;
7440 : }
7441 : }
7442 : }
7443 0 : } else if (rval.isNullOrUndefined()) {
7444 0 : rvalDecl = nullptr;
7445 : } else {
7446 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.remoteDescription");
7447 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7448 0 : return nullptr;
7449 : }
7450 0 : return rvalDecl.forget();
7451 : }
7452 :
7453 : RTCSignalingState
7454 0 : RTCPeerConnectionJSImpl::GetSignalingState(ErrorResult& aRv, JSCompartment* aCompartment)
7455 : {
7456 0 : CallSetup s(this, aRv, "RTCPeerConnection.signalingState", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7457 0 : JSContext* cx = s.GetContext();
7458 0 : if (!cx) {
7459 0 : MOZ_ASSERT(aRv.Failed());
7460 0 : return RTCSignalingState(0);
7461 : }
7462 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7463 :
7464 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7465 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7466 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7467 0 : !JS_GetPropertyById(cx, callback, atomsCache->signalingState_id, &rval)) {
7468 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7469 0 : return RTCSignalingState(0);
7470 : }
7471 : RTCSignalingState rvalDecl;
7472 : {
7473 : int index;
7474 0 : if (!FindEnumStringIndex<true>(cx, rval, RTCSignalingStateValues::strings, "RTCSignalingState", "Return value of RTCPeerConnection.signalingState", &index)) {
7475 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7476 0 : return RTCSignalingState(0);
7477 : }
7478 0 : MOZ_ASSERT(index >= 0);
7479 0 : rvalDecl = static_cast<RTCSignalingState>(index);
7480 : }
7481 0 : return rvalDecl;
7482 : }
7483 :
7484 : Nullable<bool>
7485 0 : RTCPeerConnectionJSImpl::GetCanTrickleIceCandidates(ErrorResult& aRv, JSCompartment* aCompartment)
7486 : {
7487 0 : CallSetup s(this, aRv, "RTCPeerConnection.canTrickleIceCandidates", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7488 0 : JSContext* cx = s.GetContext();
7489 0 : if (!cx) {
7490 0 : MOZ_ASSERT(aRv.Failed());
7491 0 : return Nullable<bool>();
7492 : }
7493 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7494 :
7495 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7496 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7497 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7498 0 : !JS_GetPropertyById(cx, callback, atomsCache->canTrickleIceCandidates_id, &rval)) {
7499 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7500 0 : return Nullable<bool>();
7501 : }
7502 0 : Nullable<bool> rvalDecl;
7503 0 : if (rval.isNullOrUndefined()) {
7504 0 : rvalDecl.SetNull();
7505 0 : } else if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl.SetValue())) {
7506 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7507 0 : return Nullable<bool>();
7508 : }
7509 0 : return rvalDecl;
7510 : }
7511 :
7512 : RTCIceGatheringState
7513 0 : RTCPeerConnectionJSImpl::GetIceGatheringState(ErrorResult& aRv, JSCompartment* aCompartment)
7514 : {
7515 0 : CallSetup s(this, aRv, "RTCPeerConnection.iceGatheringState", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7516 0 : JSContext* cx = s.GetContext();
7517 0 : if (!cx) {
7518 0 : MOZ_ASSERT(aRv.Failed());
7519 0 : return RTCIceGatheringState(0);
7520 : }
7521 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7522 :
7523 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7524 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7525 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7526 0 : !JS_GetPropertyById(cx, callback, atomsCache->iceGatheringState_id, &rval)) {
7527 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7528 0 : return RTCIceGatheringState(0);
7529 : }
7530 : RTCIceGatheringState rvalDecl;
7531 : {
7532 : int index;
7533 0 : if (!FindEnumStringIndex<true>(cx, rval, RTCIceGatheringStateValues::strings, "RTCIceGatheringState", "Return value of RTCPeerConnection.iceGatheringState", &index)) {
7534 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7535 0 : return RTCIceGatheringState(0);
7536 : }
7537 0 : MOZ_ASSERT(index >= 0);
7538 0 : rvalDecl = static_cast<RTCIceGatheringState>(index);
7539 : }
7540 0 : return rvalDecl;
7541 : }
7542 :
7543 : RTCIceConnectionState
7544 0 : RTCPeerConnectionJSImpl::GetIceConnectionState(ErrorResult& aRv, JSCompartment* aCompartment)
7545 : {
7546 0 : CallSetup s(this, aRv, "RTCPeerConnection.iceConnectionState", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7547 0 : JSContext* cx = s.GetContext();
7548 0 : if (!cx) {
7549 0 : MOZ_ASSERT(aRv.Failed());
7550 0 : return RTCIceConnectionState(0);
7551 : }
7552 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7553 :
7554 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7555 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7556 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7557 0 : !JS_GetPropertyById(cx, callback, atomsCache->iceConnectionState_id, &rval)) {
7558 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7559 0 : return RTCIceConnectionState(0);
7560 : }
7561 : RTCIceConnectionState rvalDecl;
7562 : {
7563 : int index;
7564 0 : if (!FindEnumStringIndex<true>(cx, rval, RTCIceConnectionStateValues::strings, "RTCIceConnectionState", "Return value of RTCPeerConnection.iceConnectionState", &index)) {
7565 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7566 0 : return RTCIceConnectionState(0);
7567 : }
7568 0 : MOZ_ASSERT(index >= 0);
7569 0 : rvalDecl = static_cast<RTCIceConnectionState>(index);
7570 : }
7571 0 : return rvalDecl;
7572 : }
7573 :
7574 : already_AddRefed<Promise>
7575 0 : RTCPeerConnectionJSImpl::GetPeerIdentity(ErrorResult& aRv, JSCompartment* aCompartment)
7576 : {
7577 0 : CallSetup s(this, aRv, "RTCPeerConnection.peerIdentity", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7578 0 : JSContext* cx = s.GetContext();
7579 0 : if (!cx) {
7580 0 : MOZ_ASSERT(aRv.Failed());
7581 0 : return nullptr;
7582 : }
7583 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7584 :
7585 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7586 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7587 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7588 0 : !JS_GetPropertyById(cx, callback, atomsCache->peerIdentity_id, &rval)) {
7589 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7590 0 : return nullptr;
7591 : }
7592 0 : RefPtr<Promise> rvalDecl;
7593 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
7594 : // etc.
7595 :
7596 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
7597 0 : if (!rval.isObject()) {
7598 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.peerIdentity"));
7599 0 : return nullptr;
7600 : }
7601 0 : JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
7602 0 : if (!unwrappedVal) {
7603 : // A slight lie, but not much of one, for a dead object wrapper.
7604 0 : aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.peerIdentity"));
7605 0 : return nullptr;
7606 : }
7607 0 : globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
7608 0 : JSAutoCompartment ac(cx, globalObj);
7609 0 : GlobalObject promiseGlobal(cx, globalObj);
7610 0 : if (promiseGlobal.Failed()) {
7611 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7612 0 : return nullptr;
7613 : }
7614 :
7615 0 : JS::Rooted<JS::Value> valueToResolve(cx, rval);
7616 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
7617 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7618 0 : return nullptr;
7619 : }
7620 0 : binding_detail::FastErrorResult promiseRv;
7621 : nsCOMPtr<nsIGlobalObject> global =
7622 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
7623 0 : if (!global) {
7624 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
7625 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
7626 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7627 0 : return nullptr;
7628 : }
7629 0 : rvalDecl = Promise::Resolve(global, cx, valueToResolve,
7630 0 : promiseRv);
7631 0 : if (promiseRv.MaybeSetPendingException(cx)) {
7632 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7633 0 : return nullptr;
7634 : }
7635 : }
7636 0 : return rvalDecl.forget();
7637 : }
7638 :
7639 : void
7640 0 : RTCPeerConnectionJSImpl::GetIdpLoginUrl(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
7641 : {
7642 0 : CallSetup s(this, aRv, "RTCPeerConnection.idpLoginUrl", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7643 0 : JSContext* cx = s.GetContext();
7644 0 : if (!cx) {
7645 0 : MOZ_ASSERT(aRv.Failed());
7646 0 : return;
7647 : }
7648 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7649 :
7650 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7651 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7652 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7653 0 : !JS_GetPropertyById(cx, callback, atomsCache->idpLoginUrl_id, &rval)) {
7654 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7655 0 : return;
7656 : }
7657 0 : binding_detail::FakeString rvalDecl;
7658 0 : if (!ConvertJSValueToString(cx, rval, eNull, eNull, rvalDecl)) {
7659 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7660 0 : return;
7661 : }
7662 0 : aRetVal = rvalDecl;
7663 : }
7664 :
7665 : void
7666 0 : RTCPeerConnectionJSImpl::GetId(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
7667 : {
7668 0 : CallSetup s(this, aRv, "RTCPeerConnection.id", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7669 0 : JSContext* cx = s.GetContext();
7670 0 : if (!cx) {
7671 0 : MOZ_ASSERT(aRv.Failed());
7672 0 : return;
7673 : }
7674 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7675 :
7676 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7677 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7678 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7679 0 : !JS_GetPropertyById(cx, callback, atomsCache->id_id, &rval)) {
7680 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7681 0 : return;
7682 : }
7683 0 : binding_detail::FakeString rvalDecl;
7684 0 : if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
7685 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7686 0 : return;
7687 : }
7688 0 : aRetVal = rvalDecl;
7689 : }
7690 :
7691 : already_AddRefed<EventHandlerNonNull>
7692 0 : RTCPeerConnectionJSImpl::GetOnnegotiationneeded(ErrorResult& aRv, JSCompartment* aCompartment)
7693 : {
7694 0 : CallSetup s(this, aRv, "RTCPeerConnection.onnegotiationneeded", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7695 0 : JSContext* cx = s.GetContext();
7696 0 : if (!cx) {
7697 0 : MOZ_ASSERT(aRv.Failed());
7698 0 : return nullptr;
7699 : }
7700 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7701 :
7702 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7703 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7704 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7705 0 : !JS_GetPropertyById(cx, callback, atomsCache->onnegotiationneeded_id, &rval)) {
7706 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7707 0 : return nullptr;
7708 : }
7709 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7710 0 : if (rval.isObject()) {
7711 : { // scope for tempRoot
7712 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7713 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7714 : }
7715 : } else {
7716 0 : rvalDecl = nullptr;
7717 : }
7718 0 : return rvalDecl.forget();
7719 : }
7720 :
7721 : already_AddRefed<EventHandlerNonNull>
7722 0 : RTCPeerConnectionJSImpl::GetOnicecandidate(ErrorResult& aRv, JSCompartment* aCompartment)
7723 : {
7724 0 : CallSetup s(this, aRv, "RTCPeerConnection.onicecandidate", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7725 0 : JSContext* cx = s.GetContext();
7726 0 : if (!cx) {
7727 0 : MOZ_ASSERT(aRv.Failed());
7728 0 : return nullptr;
7729 : }
7730 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7731 :
7732 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7733 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7734 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7735 0 : !JS_GetPropertyById(cx, callback, atomsCache->onicecandidate_id, &rval)) {
7736 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7737 0 : return nullptr;
7738 : }
7739 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7740 0 : if (rval.isObject()) {
7741 : { // scope for tempRoot
7742 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7743 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7744 : }
7745 : } else {
7746 0 : rvalDecl = nullptr;
7747 : }
7748 0 : return rvalDecl.forget();
7749 : }
7750 :
7751 : already_AddRefed<EventHandlerNonNull>
7752 0 : RTCPeerConnectionJSImpl::GetOnsignalingstatechange(ErrorResult& aRv, JSCompartment* aCompartment)
7753 : {
7754 0 : CallSetup s(this, aRv, "RTCPeerConnection.onsignalingstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7755 0 : JSContext* cx = s.GetContext();
7756 0 : if (!cx) {
7757 0 : MOZ_ASSERT(aRv.Failed());
7758 0 : return nullptr;
7759 : }
7760 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7761 :
7762 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7763 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7764 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7765 0 : !JS_GetPropertyById(cx, callback, atomsCache->onsignalingstatechange_id, &rval)) {
7766 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7767 0 : return nullptr;
7768 : }
7769 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7770 0 : if (rval.isObject()) {
7771 : { // scope for tempRoot
7772 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7773 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7774 : }
7775 : } else {
7776 0 : rvalDecl = nullptr;
7777 : }
7778 0 : return rvalDecl.forget();
7779 : }
7780 :
7781 : already_AddRefed<EventHandlerNonNull>
7782 0 : RTCPeerConnectionJSImpl::GetOnaddstream(ErrorResult& aRv, JSCompartment* aCompartment)
7783 : {
7784 0 : CallSetup s(this, aRv, "RTCPeerConnection.onaddstream", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7785 0 : JSContext* cx = s.GetContext();
7786 0 : if (!cx) {
7787 0 : MOZ_ASSERT(aRv.Failed());
7788 0 : return nullptr;
7789 : }
7790 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7791 :
7792 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7793 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7794 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7795 0 : !JS_GetPropertyById(cx, callback, atomsCache->onaddstream_id, &rval)) {
7796 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7797 0 : return nullptr;
7798 : }
7799 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7800 0 : if (rval.isObject()) {
7801 : { // scope for tempRoot
7802 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7803 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7804 : }
7805 : } else {
7806 0 : rvalDecl = nullptr;
7807 : }
7808 0 : return rvalDecl.forget();
7809 : }
7810 :
7811 : already_AddRefed<EventHandlerNonNull>
7812 0 : RTCPeerConnectionJSImpl::GetOnaddtrack(ErrorResult& aRv, JSCompartment* aCompartment)
7813 : {
7814 0 : CallSetup s(this, aRv, "RTCPeerConnection.onaddtrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7815 0 : JSContext* cx = s.GetContext();
7816 0 : if (!cx) {
7817 0 : MOZ_ASSERT(aRv.Failed());
7818 0 : return nullptr;
7819 : }
7820 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7821 :
7822 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7823 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7824 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7825 0 : !JS_GetPropertyById(cx, callback, atomsCache->onaddtrack_id, &rval)) {
7826 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7827 0 : return nullptr;
7828 : }
7829 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7830 0 : if (rval.isObject()) {
7831 : { // scope for tempRoot
7832 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7833 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7834 : }
7835 : } else {
7836 0 : rvalDecl = nullptr;
7837 : }
7838 0 : return rvalDecl.forget();
7839 : }
7840 :
7841 : already_AddRefed<EventHandlerNonNull>
7842 0 : RTCPeerConnectionJSImpl::GetOntrack(ErrorResult& aRv, JSCompartment* aCompartment)
7843 : {
7844 0 : CallSetup s(this, aRv, "RTCPeerConnection.ontrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7845 0 : JSContext* cx = s.GetContext();
7846 0 : if (!cx) {
7847 0 : MOZ_ASSERT(aRv.Failed());
7848 0 : return nullptr;
7849 : }
7850 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7851 :
7852 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7853 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7854 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7855 0 : !JS_GetPropertyById(cx, callback, atomsCache->ontrack_id, &rval)) {
7856 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7857 0 : return nullptr;
7858 : }
7859 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7860 0 : if (rval.isObject()) {
7861 : { // scope for tempRoot
7862 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7863 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7864 : }
7865 : } else {
7866 0 : rvalDecl = nullptr;
7867 : }
7868 0 : return rvalDecl.forget();
7869 : }
7870 :
7871 : already_AddRefed<EventHandlerNonNull>
7872 0 : RTCPeerConnectionJSImpl::GetOnremovestream(ErrorResult& aRv, JSCompartment* aCompartment)
7873 : {
7874 0 : CallSetup s(this, aRv, "RTCPeerConnection.onremovestream", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7875 0 : JSContext* cx = s.GetContext();
7876 0 : if (!cx) {
7877 0 : MOZ_ASSERT(aRv.Failed());
7878 0 : return nullptr;
7879 : }
7880 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7881 :
7882 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7883 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7884 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7885 0 : !JS_GetPropertyById(cx, callback, atomsCache->onremovestream_id, &rval)) {
7886 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7887 0 : return nullptr;
7888 : }
7889 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7890 0 : if (rval.isObject()) {
7891 : { // scope for tempRoot
7892 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7893 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7894 : }
7895 : } else {
7896 0 : rvalDecl = nullptr;
7897 : }
7898 0 : return rvalDecl.forget();
7899 : }
7900 :
7901 : already_AddRefed<EventHandlerNonNull>
7902 0 : RTCPeerConnectionJSImpl::GetOniceconnectionstatechange(ErrorResult& aRv, JSCompartment* aCompartment)
7903 : {
7904 0 : CallSetup s(this, aRv, "RTCPeerConnection.oniceconnectionstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7905 0 : JSContext* cx = s.GetContext();
7906 0 : if (!cx) {
7907 0 : MOZ_ASSERT(aRv.Failed());
7908 0 : return nullptr;
7909 : }
7910 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7911 :
7912 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7913 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7914 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7915 0 : !JS_GetPropertyById(cx, callback, atomsCache->oniceconnectionstatechange_id, &rval)) {
7916 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7917 0 : return nullptr;
7918 : }
7919 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7920 0 : if (rval.isObject()) {
7921 : { // scope for tempRoot
7922 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7923 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7924 : }
7925 : } else {
7926 0 : rvalDecl = nullptr;
7927 : }
7928 0 : return rvalDecl.forget();
7929 : }
7930 :
7931 : already_AddRefed<EventHandlerNonNull>
7932 0 : RTCPeerConnectionJSImpl::GetOnicegatheringstatechange(ErrorResult& aRv, JSCompartment* aCompartment)
7933 : {
7934 0 : CallSetup s(this, aRv, "RTCPeerConnection.onicegatheringstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7935 0 : JSContext* cx = s.GetContext();
7936 0 : if (!cx) {
7937 0 : MOZ_ASSERT(aRv.Failed());
7938 0 : return nullptr;
7939 : }
7940 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7941 :
7942 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7943 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7944 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7945 0 : !JS_GetPropertyById(cx, callback, atomsCache->onicegatheringstatechange_id, &rval)) {
7946 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7947 0 : return nullptr;
7948 : }
7949 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7950 0 : if (rval.isObject()) {
7951 : { // scope for tempRoot
7952 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7953 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7954 : }
7955 : } else {
7956 0 : rvalDecl = nullptr;
7957 : }
7958 0 : return rvalDecl.forget();
7959 : }
7960 :
7961 : already_AddRefed<EventHandlerNonNull>
7962 0 : RTCPeerConnectionJSImpl::GetOndatachannel(ErrorResult& aRv, JSCompartment* aCompartment)
7963 : {
7964 0 : CallSetup s(this, aRv, "RTCPeerConnection.ondatachannel", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7965 0 : JSContext* cx = s.GetContext();
7966 0 : if (!cx) {
7967 0 : MOZ_ASSERT(aRv.Failed());
7968 0 : return nullptr;
7969 : }
7970 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7971 :
7972 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
7973 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7974 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7975 0 : !JS_GetPropertyById(cx, callback, atomsCache->ondatachannel_id, &rval)) {
7976 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
7977 0 : return nullptr;
7978 : }
7979 0 : RefPtr<EventHandlerNonNull> rvalDecl;
7980 0 : if (rval.isObject()) {
7981 : { // scope for tempRoot
7982 0 : JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
7983 0 : rvalDecl = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
7984 : }
7985 : } else {
7986 0 : rvalDecl = nullptr;
7987 : }
7988 0 : return rvalDecl.forget();
7989 : }
7990 :
7991 : void
7992 0 : RTCPeerConnectionJSImpl::SetId(const nsAString& arg, ErrorResult& aRv, JSCompartment* aCompartment)
7993 : {
7994 0 : CallSetup s(this, aRv, "RTCPeerConnection.id", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
7995 0 : JSContext* cx = s.GetContext();
7996 0 : if (!cx) {
7997 0 : MOZ_ASSERT(aRv.Failed());
7998 0 : return;
7999 : }
8000 0 : JS::AutoValueVector argv(cx);
8001 0 : if (!argv.resize(1)) {
8002 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8003 0 : return;
8004 : }
8005 : do {
8006 0 : nsString mutableStr(arg);
8007 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
8008 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8009 0 : return;
8010 : }
8011 0 : break;
8012 : } while (0);
8013 :
8014 0 : MOZ_ASSERT(argv.length() == 1);
8015 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8016 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8017 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->id_id, argv[0])) {
8018 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8019 0 : return;
8020 : }
8021 : }
8022 :
8023 : void
8024 0 : RTCPeerConnectionJSImpl::SetOnnegotiationneeded(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8025 : {
8026 0 : CallSetup s(this, aRv, "RTCPeerConnection.onnegotiationneeded", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8027 0 : JSContext* cx = s.GetContext();
8028 0 : if (!cx) {
8029 0 : MOZ_ASSERT(aRv.Failed());
8030 0 : return;
8031 : }
8032 0 : JS::AutoValueVector argv(cx);
8033 0 : if (!argv.resize(1)) {
8034 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8035 0 : return;
8036 : }
8037 : do {
8038 0 : if (arg) {
8039 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8040 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8041 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8042 0 : return;
8043 : }
8044 0 : break;
8045 : } else {
8046 0 : argv[0].setNull();
8047 0 : break;
8048 : }
8049 : } while (0);
8050 :
8051 0 : MOZ_ASSERT(argv.length() == 1);
8052 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8053 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8054 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onnegotiationneeded_id, argv[0])) {
8055 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8056 0 : return;
8057 : }
8058 : }
8059 :
8060 : void
8061 0 : RTCPeerConnectionJSImpl::SetOnicecandidate(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8062 : {
8063 0 : CallSetup s(this, aRv, "RTCPeerConnection.onicecandidate", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8064 0 : JSContext* cx = s.GetContext();
8065 0 : if (!cx) {
8066 0 : MOZ_ASSERT(aRv.Failed());
8067 0 : return;
8068 : }
8069 0 : JS::AutoValueVector argv(cx);
8070 0 : if (!argv.resize(1)) {
8071 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8072 0 : return;
8073 : }
8074 : do {
8075 0 : if (arg) {
8076 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8077 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8078 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8079 0 : return;
8080 : }
8081 0 : break;
8082 : } else {
8083 0 : argv[0].setNull();
8084 0 : break;
8085 : }
8086 : } while (0);
8087 :
8088 0 : MOZ_ASSERT(argv.length() == 1);
8089 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8090 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8091 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onicecandidate_id, argv[0])) {
8092 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8093 0 : return;
8094 : }
8095 : }
8096 :
8097 : void
8098 0 : RTCPeerConnectionJSImpl::SetOnsignalingstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8099 : {
8100 0 : CallSetup s(this, aRv, "RTCPeerConnection.onsignalingstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8101 0 : JSContext* cx = s.GetContext();
8102 0 : if (!cx) {
8103 0 : MOZ_ASSERT(aRv.Failed());
8104 0 : return;
8105 : }
8106 0 : JS::AutoValueVector argv(cx);
8107 0 : if (!argv.resize(1)) {
8108 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8109 0 : return;
8110 : }
8111 : do {
8112 0 : if (arg) {
8113 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8114 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8115 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8116 0 : return;
8117 : }
8118 0 : break;
8119 : } else {
8120 0 : argv[0].setNull();
8121 0 : break;
8122 : }
8123 : } while (0);
8124 :
8125 0 : MOZ_ASSERT(argv.length() == 1);
8126 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8127 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8128 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onsignalingstatechange_id, argv[0])) {
8129 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8130 0 : return;
8131 : }
8132 : }
8133 :
8134 : void
8135 0 : RTCPeerConnectionJSImpl::SetOnaddstream(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8136 : {
8137 0 : CallSetup s(this, aRv, "RTCPeerConnection.onaddstream", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8138 0 : JSContext* cx = s.GetContext();
8139 0 : if (!cx) {
8140 0 : MOZ_ASSERT(aRv.Failed());
8141 0 : return;
8142 : }
8143 0 : JS::AutoValueVector argv(cx);
8144 0 : if (!argv.resize(1)) {
8145 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8146 0 : return;
8147 : }
8148 : do {
8149 0 : if (arg) {
8150 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8151 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8152 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8153 0 : return;
8154 : }
8155 0 : break;
8156 : } else {
8157 0 : argv[0].setNull();
8158 0 : break;
8159 : }
8160 : } while (0);
8161 :
8162 0 : MOZ_ASSERT(argv.length() == 1);
8163 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8164 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8165 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onaddstream_id, argv[0])) {
8166 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8167 0 : return;
8168 : }
8169 : }
8170 :
8171 : void
8172 0 : RTCPeerConnectionJSImpl::SetOnaddtrack(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8173 : {
8174 0 : CallSetup s(this, aRv, "RTCPeerConnection.onaddtrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8175 0 : JSContext* cx = s.GetContext();
8176 0 : if (!cx) {
8177 0 : MOZ_ASSERT(aRv.Failed());
8178 0 : return;
8179 : }
8180 0 : JS::AutoValueVector argv(cx);
8181 0 : if (!argv.resize(1)) {
8182 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8183 0 : return;
8184 : }
8185 : do {
8186 0 : if (arg) {
8187 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8188 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8189 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8190 0 : return;
8191 : }
8192 0 : break;
8193 : } else {
8194 0 : argv[0].setNull();
8195 0 : break;
8196 : }
8197 : } while (0);
8198 :
8199 0 : MOZ_ASSERT(argv.length() == 1);
8200 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8201 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8202 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onaddtrack_id, argv[0])) {
8203 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8204 0 : return;
8205 : }
8206 : }
8207 :
8208 : void
8209 0 : RTCPeerConnectionJSImpl::SetOntrack(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8210 : {
8211 0 : CallSetup s(this, aRv, "RTCPeerConnection.ontrack", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8212 0 : JSContext* cx = s.GetContext();
8213 0 : if (!cx) {
8214 0 : MOZ_ASSERT(aRv.Failed());
8215 0 : return;
8216 : }
8217 0 : JS::AutoValueVector argv(cx);
8218 0 : if (!argv.resize(1)) {
8219 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8220 0 : return;
8221 : }
8222 : do {
8223 0 : if (arg) {
8224 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8225 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8226 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8227 0 : return;
8228 : }
8229 0 : break;
8230 : } else {
8231 0 : argv[0].setNull();
8232 0 : break;
8233 : }
8234 : } while (0);
8235 :
8236 0 : MOZ_ASSERT(argv.length() == 1);
8237 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8238 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8239 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->ontrack_id, argv[0])) {
8240 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8241 0 : return;
8242 : }
8243 : }
8244 :
8245 : void
8246 0 : RTCPeerConnectionJSImpl::SetOnremovestream(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8247 : {
8248 0 : CallSetup s(this, aRv, "RTCPeerConnection.onremovestream", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8249 0 : JSContext* cx = s.GetContext();
8250 0 : if (!cx) {
8251 0 : MOZ_ASSERT(aRv.Failed());
8252 0 : return;
8253 : }
8254 0 : JS::AutoValueVector argv(cx);
8255 0 : if (!argv.resize(1)) {
8256 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8257 0 : return;
8258 : }
8259 : do {
8260 0 : if (arg) {
8261 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8262 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8263 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8264 0 : return;
8265 : }
8266 0 : break;
8267 : } else {
8268 0 : argv[0].setNull();
8269 0 : break;
8270 : }
8271 : } while (0);
8272 :
8273 0 : MOZ_ASSERT(argv.length() == 1);
8274 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8275 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8276 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onremovestream_id, argv[0])) {
8277 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8278 0 : return;
8279 : }
8280 : }
8281 :
8282 : void
8283 0 : RTCPeerConnectionJSImpl::SetOniceconnectionstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8284 : {
8285 0 : CallSetup s(this, aRv, "RTCPeerConnection.oniceconnectionstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8286 0 : JSContext* cx = s.GetContext();
8287 0 : if (!cx) {
8288 0 : MOZ_ASSERT(aRv.Failed());
8289 0 : return;
8290 : }
8291 0 : JS::AutoValueVector argv(cx);
8292 0 : if (!argv.resize(1)) {
8293 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8294 0 : return;
8295 : }
8296 : do {
8297 0 : if (arg) {
8298 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8299 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8300 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8301 0 : return;
8302 : }
8303 0 : break;
8304 : } else {
8305 0 : argv[0].setNull();
8306 0 : break;
8307 : }
8308 : } while (0);
8309 :
8310 0 : MOZ_ASSERT(argv.length() == 1);
8311 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8312 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8313 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->oniceconnectionstatechange_id, argv[0])) {
8314 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8315 0 : return;
8316 : }
8317 : }
8318 :
8319 : void
8320 0 : RTCPeerConnectionJSImpl::SetOnicegatheringstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8321 : {
8322 0 : CallSetup s(this, aRv, "RTCPeerConnection.onicegatheringstatechange", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8323 0 : JSContext* cx = s.GetContext();
8324 0 : if (!cx) {
8325 0 : MOZ_ASSERT(aRv.Failed());
8326 0 : return;
8327 : }
8328 0 : JS::AutoValueVector argv(cx);
8329 0 : if (!argv.resize(1)) {
8330 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8331 0 : return;
8332 : }
8333 : do {
8334 0 : if (arg) {
8335 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8336 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8337 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8338 0 : return;
8339 : }
8340 0 : break;
8341 : } else {
8342 0 : argv[0].setNull();
8343 0 : break;
8344 : }
8345 : } while (0);
8346 :
8347 0 : MOZ_ASSERT(argv.length() == 1);
8348 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8349 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8350 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onicegatheringstatechange_id, argv[0])) {
8351 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8352 0 : return;
8353 : }
8354 : }
8355 :
8356 : void
8357 0 : RTCPeerConnectionJSImpl::SetOndatachannel(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8358 : {
8359 0 : CallSetup s(this, aRv, "RTCPeerConnection.ondatachannel", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
8360 0 : JSContext* cx = s.GetContext();
8361 0 : if (!cx) {
8362 0 : MOZ_ASSERT(aRv.Failed());
8363 0 : return;
8364 : }
8365 0 : JS::AutoValueVector argv(cx);
8366 0 : if (!argv.resize(1)) {
8367 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8368 0 : return;
8369 : }
8370 : do {
8371 0 : if (arg) {
8372 0 : argv[0].setObjectOrNull(GetCallbackFromCallbackObject(arg));
8373 0 : if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
8374 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8375 0 : return;
8376 : }
8377 0 : break;
8378 : } else {
8379 0 : argv[0].setNull();
8380 0 : break;
8381 : }
8382 : } while (0);
8383 :
8384 0 : MOZ_ASSERT(argv.length() == 1);
8385 0 : RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8386 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8387 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->ondatachannel_id, argv[0])) {
8388 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8389 0 : return;
8390 : }
8391 : }
8392 :
8393 :
8394 0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper, mImpl, mParent)
8395 0 : NS_IMPL_ADDREF_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper)
8396 0 : NS_IMPL_RELEASE_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper)
8397 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(RTCPeerConnection)
8398 0 : NS_INTERFACE_MAP_END_INHERITING(mozilla::DOMEventTargetHelper)
8399 :
8400 0 : RTCPeerConnection::RTCPeerConnection(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent)
8401 : : mozilla::DOMEventTargetHelper(aParent),
8402 0 : mImpl(new RTCPeerConnectionJSImpl(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr)),
8403 0 : mParent(aParent)
8404 : {
8405 0 : }
8406 :
8407 :
8408 0 : RTCPeerConnection::~RTCPeerConnection()
8409 : {
8410 0 : }
8411 :
8412 : nsISupports*
8413 0 : RTCPeerConnection::GetParentObject() const
8414 : {
8415 0 : return mParent;
8416 : }
8417 :
8418 : JSObject*
8419 0 : RTCPeerConnection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
8420 : {
8421 0 : JS::Rooted<JSObject*> obj(aCx, RTCPeerConnectionBinding::Wrap(aCx, this, aGivenProto));
8422 0 : if (!obj) {
8423 0 : return nullptr;
8424 : }
8425 :
8426 : // Now define it on our chrome object
8427 0 : JSAutoCompartment ac(aCx, mImpl->CallbackOrNull());
8428 0 : if (!JS_WrapObject(aCx, &obj)) {
8429 0 : return nullptr;
8430 : }
8431 0 : if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
8432 0 : return nullptr;
8433 : }
8434 0 : return obj;
8435 : }
8436 :
8437 : already_AddRefed<RTCPeerConnection>
8438 0 : RTCPeerConnection::Constructor(const GlobalObject& global, JSContext* cx, const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv)
8439 : {
8440 0 : JS::Rooted<JSObject*> jsImplObj(cx);
8441 : nsCOMPtr<nsIGlobalObject> globalHolder =
8442 0 : ConstructJSImplementation("@mozilla.org/dom/peerconnection;1", global, &jsImplObj, aRv);
8443 0 : if (aRv.Failed()) {
8444 0 : return nullptr;
8445 : }
8446 : // Build the C++ implementation.
8447 0 : RefPtr<RTCPeerConnection> impl = new RTCPeerConnection(jsImplObj, globalHolder);
8448 : // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
8449 0 : JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
8450 0 : MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
8451 0 : JS::Rooted<JS::Value> wrappedVal(cx);
8452 0 : if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal)) {
8453 : //XXX Assertion disabled for now, see bug 991271.
8454 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
8455 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
8456 0 : return nullptr;
8457 : }
8458 : // Initialize the object with the constructor arguments.
8459 0 : impl->mImpl->__Init(configuration, constraints, aRv, js::GetObjectCompartment(scopeObj));
8460 0 : if (aRv.Failed()) {
8461 0 : return nullptr;
8462 : }
8463 0 : return impl.forget();
8464 : }
8465 :
8466 : void
8467 0 : RTCPeerConnection::SetIdentityProvider(const nsAString& provider, const Optional<nsAString>& protocol, const Optional<nsAString>& username, ErrorResult& aRv, JSCompartment* aCompartment)
8468 : {
8469 0 : return mImpl->SetIdentityProvider(provider, protocol, username, aRv, aCompartment);
8470 : }
8471 :
8472 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8473 : already_AddRefed<Promise>
8474 0 : RTCPeerConnection::GetIdentityAssertion(ErrorResult& aRv, JSCompartment* aCompartment)
8475 : {
8476 0 : return mImpl->GetIdentityAssertion(aRv, aCompartment);
8477 : }
8478 :
8479 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8480 : already_AddRefed<Promise>
8481 0 : RTCPeerConnection::CreateOffer(const RTCOfferOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
8482 : {
8483 0 : return mImpl->CreateOffer(options, aRv, aCompartment);
8484 : }
8485 :
8486 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8487 : already_AddRefed<Promise>
8488 0 : RTCPeerConnection::CreateOffer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, const RTCOfferOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
8489 : {
8490 0 : return mImpl->CreateOffer(successCallback, failureCallback, options, aRv, aCompartment);
8491 : }
8492 :
8493 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8494 : already_AddRefed<Promise>
8495 0 : RTCPeerConnection::CreateAnswer(const RTCAnswerOptions& options, ErrorResult& aRv, JSCompartment* aCompartment)
8496 : {
8497 0 : return mImpl->CreateAnswer(options, aRv, aCompartment);
8498 : }
8499 :
8500 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8501 : already_AddRefed<Promise>
8502 0 : RTCPeerConnection::CreateAnswer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
8503 : {
8504 0 : return mImpl->CreateAnswer(successCallback, failureCallback, aRv, aCompartment);
8505 : }
8506 :
8507 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8508 : already_AddRefed<Promise>
8509 0 : RTCPeerConnection::SetLocalDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JSCompartment* aCompartment)
8510 : {
8511 0 : return mImpl->SetLocalDescription(description, aRv, aCompartment);
8512 : }
8513 :
8514 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8515 : already_AddRefed<Promise>
8516 0 : RTCPeerConnection::SetLocalDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
8517 : {
8518 0 : return mImpl->SetLocalDescription(description, successCallback, failureCallback, aRv, aCompartment);
8519 : }
8520 :
8521 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8522 : already_AddRefed<Promise>
8523 0 : RTCPeerConnection::SetRemoteDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JSCompartment* aCompartment)
8524 : {
8525 0 : return mImpl->SetRemoteDescription(description, aRv, aCompartment);
8526 : }
8527 :
8528 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8529 : already_AddRefed<Promise>
8530 0 : RTCPeerConnection::SetRemoteDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
8531 : {
8532 0 : return mImpl->SetRemoteDescription(description, successCallback, failureCallback, aRv, aCompartment);
8533 : }
8534 :
8535 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8536 : already_AddRefed<RTCSessionDescription>
8537 0 : RTCPeerConnection::GetLocalDescription(ErrorResult& aRv, JSCompartment* aCompartment) const
8538 : {
8539 0 : return mImpl->GetLocalDescription(aRv, aCompartment);
8540 : }
8541 :
8542 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8543 : already_AddRefed<RTCSessionDescription>
8544 0 : RTCPeerConnection::GetRemoteDescription(ErrorResult& aRv, JSCompartment* aCompartment) const
8545 : {
8546 0 : return mImpl->GetRemoteDescription(aRv, aCompartment);
8547 : }
8548 :
8549 : RTCSignalingState
8550 0 : RTCPeerConnection::GetSignalingState(ErrorResult& aRv, JSCompartment* aCompartment) const
8551 : {
8552 0 : return mImpl->GetSignalingState(aRv, aCompartment);
8553 : }
8554 :
8555 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8556 : already_AddRefed<Promise>
8557 0 : RTCPeerConnection::AddIceCandidate(const Nullable<RTCIceCandidateInitOrRTCIceCandidate>& candidate, ErrorResult& aRv, JSCompartment* aCompartment)
8558 : {
8559 0 : return mImpl->AddIceCandidate(candidate, aRv, aCompartment);
8560 : }
8561 :
8562 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8563 : already_AddRefed<Promise>
8564 0 : RTCPeerConnection::AddIceCandidate(RTCIceCandidate& candidate, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
8565 : {
8566 0 : return mImpl->AddIceCandidate(candidate, successCallback, failureCallback, aRv, aCompartment);
8567 : }
8568 :
8569 : Nullable<bool>
8570 0 : RTCPeerConnection::GetCanTrickleIceCandidates(ErrorResult& aRv, JSCompartment* aCompartment) const
8571 : {
8572 0 : return mImpl->GetCanTrickleIceCandidates(aRv, aCompartment);
8573 : }
8574 :
8575 : RTCIceGatheringState
8576 0 : RTCPeerConnection::GetIceGatheringState(ErrorResult& aRv, JSCompartment* aCompartment) const
8577 : {
8578 0 : return mImpl->GetIceGatheringState(aRv, aCompartment);
8579 : }
8580 :
8581 : RTCIceConnectionState
8582 0 : RTCPeerConnection::GetIceConnectionState(ErrorResult& aRv, JSCompartment* aCompartment) const
8583 : {
8584 0 : return mImpl->GetIceConnectionState(aRv, aCompartment);
8585 : }
8586 :
8587 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8588 : already_AddRefed<Promise>
8589 0 : RTCPeerConnection::GetPeerIdentity(ErrorResult& aRv, JSCompartment* aCompartment) const
8590 : {
8591 0 : return mImpl->GetPeerIdentity(aRv, aCompartment);
8592 : }
8593 :
8594 : void
8595 0 : RTCPeerConnection::GetIdpLoginUrl(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment) const
8596 : {
8597 0 : return mImpl->GetIdpLoginUrl(aRetVal, aRv, aCompartment);
8598 : }
8599 :
8600 : void
8601 0 : RTCPeerConnection::GetId(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment) const
8602 : {
8603 0 : return mImpl->GetId(aRetVal, aRv, aCompartment);
8604 : }
8605 :
8606 : void
8607 0 : RTCPeerConnection::SetId(const nsAString& arg, ErrorResult& aRv, JSCompartment* aCompartment)
8608 : {
8609 0 : mImpl->SetId(arg, aRv, aCompartment);
8610 0 : }
8611 :
8612 : void
8613 0 : RTCPeerConnection::GetConfiguration(RTCConfiguration& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
8614 : {
8615 0 : return mImpl->GetConfiguration(aRetVal, aRv, aCompartment);
8616 : }
8617 :
8618 : void
8619 0 : RTCPeerConnection::GetLocalStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
8620 : {
8621 0 : return mImpl->GetLocalStreams(aRetVal, aRv, aCompartment);
8622 : }
8623 :
8624 : void
8625 0 : RTCPeerConnection::GetRemoteStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
8626 : {
8627 0 : return mImpl->GetRemoteStreams(aRetVal, aRv, aCompartment);
8628 : }
8629 :
8630 : void
8631 0 : RTCPeerConnection::AddStream(DOMMediaStream& stream, ErrorResult& aRv, JSCompartment* aCompartment)
8632 : {
8633 0 : return mImpl->AddStream(stream, aRv, aCompartment);
8634 : }
8635 :
8636 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8637 : already_AddRefed<RTCRtpSender>
8638 0 : RTCPeerConnection::AddTrack(MediaStreamTrack& track, DOMMediaStream& stream, const Sequence<OwningNonNull<DOMMediaStream>>& moreStreams, ErrorResult& aRv, JSCompartment* aCompartment)
8639 : {
8640 0 : return mImpl->AddTrack(track, stream, moreStreams, aRv, aCompartment);
8641 : }
8642 :
8643 : void
8644 0 : RTCPeerConnection::RemoveTrack(RTCRtpSender& sender, ErrorResult& aRv, JSCompartment* aCompartment)
8645 : {
8646 0 : return mImpl->RemoveTrack(sender, aRv, aCompartment);
8647 : }
8648 :
8649 : void
8650 0 : RTCPeerConnection::GetSenders(nsTArray<RefPtr<RTCRtpSender>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
8651 : {
8652 0 : return mImpl->GetSenders(aRetVal, aRv, aCompartment);
8653 : }
8654 :
8655 : void
8656 0 : RTCPeerConnection::GetReceivers(nsTArray<RefPtr<RTCRtpReceiver>>& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
8657 : {
8658 0 : return mImpl->GetReceivers(aRetVal, aRv, aCompartment);
8659 : }
8660 :
8661 : void
8662 0 : RTCPeerConnection::MozAddRIDExtension(RTCRtpReceiver& receiver, uint16_t extensionId, ErrorResult& aRv, JSCompartment* aCompartment)
8663 : {
8664 0 : return mImpl->MozAddRIDExtension(receiver, extensionId, aRv, aCompartment);
8665 : }
8666 :
8667 : void
8668 0 : RTCPeerConnection::MozAddRIDFilter(RTCRtpReceiver& receiver, const nsAString& rid, ErrorResult& aRv, JSCompartment* aCompartment)
8669 : {
8670 0 : return mImpl->MozAddRIDFilter(receiver, rid, aRv, aCompartment);
8671 : }
8672 :
8673 : void
8674 0 : RTCPeerConnection::Close(ErrorResult& aRv, JSCompartment* aCompartment)
8675 : {
8676 0 : return mImpl->Close(aRv, aCompartment);
8677 : }
8678 :
8679 : already_AddRefed<EventHandlerNonNull>
8680 0 : RTCPeerConnection::GetOnnegotiationneeded(ErrorResult& aRv, JSCompartment* aCompartment) const
8681 : {
8682 0 : return mImpl->GetOnnegotiationneeded(aRv, aCompartment);
8683 : }
8684 :
8685 : void
8686 0 : RTCPeerConnection::SetOnnegotiationneeded(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8687 : {
8688 0 : mImpl->SetOnnegotiationneeded(arg, aRv, aCompartment);
8689 0 : }
8690 :
8691 : already_AddRefed<EventHandlerNonNull>
8692 0 : RTCPeerConnection::GetOnicecandidate(ErrorResult& aRv, JSCompartment* aCompartment) const
8693 : {
8694 0 : return mImpl->GetOnicecandidate(aRv, aCompartment);
8695 : }
8696 :
8697 : void
8698 0 : RTCPeerConnection::SetOnicecandidate(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8699 : {
8700 0 : mImpl->SetOnicecandidate(arg, aRv, aCompartment);
8701 0 : }
8702 :
8703 : already_AddRefed<EventHandlerNonNull>
8704 0 : RTCPeerConnection::GetOnsignalingstatechange(ErrorResult& aRv, JSCompartment* aCompartment) const
8705 : {
8706 0 : return mImpl->GetOnsignalingstatechange(aRv, aCompartment);
8707 : }
8708 :
8709 : void
8710 0 : RTCPeerConnection::SetOnsignalingstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8711 : {
8712 0 : mImpl->SetOnsignalingstatechange(arg, aRv, aCompartment);
8713 0 : }
8714 :
8715 : already_AddRefed<EventHandlerNonNull>
8716 0 : RTCPeerConnection::GetOnaddstream(ErrorResult& aRv, JSCompartment* aCompartment) const
8717 : {
8718 0 : return mImpl->GetOnaddstream(aRv, aCompartment);
8719 : }
8720 :
8721 : void
8722 0 : RTCPeerConnection::SetOnaddstream(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8723 : {
8724 0 : mImpl->SetOnaddstream(arg, aRv, aCompartment);
8725 0 : }
8726 :
8727 : already_AddRefed<EventHandlerNonNull>
8728 0 : RTCPeerConnection::GetOnaddtrack(ErrorResult& aRv, JSCompartment* aCompartment) const
8729 : {
8730 0 : return mImpl->GetOnaddtrack(aRv, aCompartment);
8731 : }
8732 :
8733 : void
8734 0 : RTCPeerConnection::SetOnaddtrack(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8735 : {
8736 0 : mImpl->SetOnaddtrack(arg, aRv, aCompartment);
8737 0 : }
8738 :
8739 : already_AddRefed<EventHandlerNonNull>
8740 0 : RTCPeerConnection::GetOntrack(ErrorResult& aRv, JSCompartment* aCompartment) const
8741 : {
8742 0 : return mImpl->GetOntrack(aRv, aCompartment);
8743 : }
8744 :
8745 : void
8746 0 : RTCPeerConnection::SetOntrack(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8747 : {
8748 0 : mImpl->SetOntrack(arg, aRv, aCompartment);
8749 0 : }
8750 :
8751 : already_AddRefed<EventHandlerNonNull>
8752 0 : RTCPeerConnection::GetOnremovestream(ErrorResult& aRv, JSCompartment* aCompartment) const
8753 : {
8754 0 : return mImpl->GetOnremovestream(aRv, aCompartment);
8755 : }
8756 :
8757 : void
8758 0 : RTCPeerConnection::SetOnremovestream(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8759 : {
8760 0 : mImpl->SetOnremovestream(arg, aRv, aCompartment);
8761 0 : }
8762 :
8763 : already_AddRefed<EventHandlerNonNull>
8764 0 : RTCPeerConnection::GetOniceconnectionstatechange(ErrorResult& aRv, JSCompartment* aCompartment) const
8765 : {
8766 0 : return mImpl->GetOniceconnectionstatechange(aRv, aCompartment);
8767 : }
8768 :
8769 : void
8770 0 : RTCPeerConnection::SetOniceconnectionstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8771 : {
8772 0 : mImpl->SetOniceconnectionstatechange(arg, aRv, aCompartment);
8773 0 : }
8774 :
8775 : already_AddRefed<EventHandlerNonNull>
8776 0 : RTCPeerConnection::GetOnicegatheringstatechange(ErrorResult& aRv, JSCompartment* aCompartment) const
8777 : {
8778 0 : return mImpl->GetOnicegatheringstatechange(aRv, aCompartment);
8779 : }
8780 :
8781 : void
8782 0 : RTCPeerConnection::SetOnicegatheringstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8783 : {
8784 0 : mImpl->SetOnicegatheringstatechange(arg, aRv, aCompartment);
8785 0 : }
8786 :
8787 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8788 : already_AddRefed<Promise>
8789 0 : RTCPeerConnection::GetStats(const Optional<MediaStreamTrack*>& selector, ErrorResult& aRv, JSCompartment* aCompartment)
8790 : {
8791 0 : return mImpl->GetStats(selector, aRv, aCompartment);
8792 : }
8793 :
8794 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8795 : already_AddRefed<Promise>
8796 0 : RTCPeerConnection::GetStats(MediaStreamTrack* selector, RTCStatsCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JSCompartment* aCompartment)
8797 : {
8798 0 : return mImpl->GetStats(selector, successCallback, failureCallback, aRv, aCompartment);
8799 : }
8800 :
8801 : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
8802 : already_AddRefed<nsIDOMDataChannel>
8803 0 : RTCPeerConnection::CreateDataChannel(const nsAString& label, const RTCDataChannelInit& dataChannelDict, ErrorResult& aRv, JSCompartment* aCompartment)
8804 : {
8805 0 : return mImpl->CreateDataChannel(label, dataChannelDict, aRv, aCompartment);
8806 : }
8807 :
8808 : already_AddRefed<EventHandlerNonNull>
8809 0 : RTCPeerConnection::GetOndatachannel(ErrorResult& aRv, JSCompartment* aCompartment) const
8810 : {
8811 0 : return mImpl->GetOndatachannel(aRv, aCompartment);
8812 : }
8813 :
8814 : void
8815 0 : RTCPeerConnection::SetOndatachannel(EventHandlerNonNull* arg, ErrorResult& aRv, JSCompartment* aCompartment)
8816 : {
8817 0 : mImpl->SetOndatachannel(arg, aRv, aCompartment);
8818 0 : }
8819 :
8820 : bool
8821 0 : RTCPeerConnection::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
8822 : {
8823 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
8824 0 : if (args.length() < 2) {
8825 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection._create");
8826 : }
8827 0 : if (!args[0].isObject()) {
8828 0 : return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection._create");
8829 : }
8830 0 : if (!args[1].isObject()) {
8831 0 : return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection._create");
8832 : }
8833 :
8834 : // GlobalObject will go through wrappers as needed for us, and
8835 : // is simpler than the right UnwrapArg incantation.
8836 0 : GlobalObject global(cx, &args[0].toObject());
8837 0 : if (global.Failed()) {
8838 0 : return false;
8839 : }
8840 0 : nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
8841 0 : MOZ_ASSERT(globalHolder);
8842 0 : JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
8843 0 : RefPtr<RTCPeerConnection> impl = new RTCPeerConnection(arg, globalHolder);
8844 0 : MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
8845 0 : return GetOrCreateDOMReflector(cx, impl, args.rval());
8846 : }
8847 :
8848 :
8849 : } // namespace dom
8850 : } // namespace mozilla
|