Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM RTCSessionDescription.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "RTCSessionDescriptionBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "jsapi.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/Preferences.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/ScriptSettings.h"
13 : #include "mozilla/dom/SimpleGlobalObject.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 : #include "nsContentUtils.h"
16 : #include "nsIGlobalObject.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace RTCSdpTypeValues {
22 : extern const EnumEntry strings[5] = {
23 : {"offer", 5},
24 : {"pranswer", 8},
25 : {"answer", 6},
26 : {"rollback", 8},
27 : { nullptr, 0 }
28 : };
29 : } // namespace RTCSdpTypeValues
30 :
31 : bool
32 0 : ToJSValue(JSContext* aCx, RTCSdpType aArgument, JS::MutableHandle<JS::Value> aValue)
33 : {
34 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCSdpTypeValues::strings));
35 : JSString* resultStr =
36 0 : JS_NewStringCopyN(aCx, RTCSdpTypeValues::strings[uint32_t(aArgument)].value,
37 0 : RTCSdpTypeValues::strings[uint32_t(aArgument)].length);
38 0 : if (!resultStr) {
39 0 : return false;
40 : }
41 0 : aValue.setString(resultStr);
42 0 : return true;
43 : }
44 :
45 :
46 :
47 0 : RTCSessionDescriptionInit::RTCSessionDescriptionInit()
48 : {
49 : // Safe to pass a null context if we pass a null value
50 0 : Init(nullptr, JS::NullHandleValue);
51 0 : }
52 :
53 :
54 :
55 : bool
56 0 : RTCSessionDescriptionInit::InitIds(JSContext* cx, RTCSessionDescriptionInitAtoms* atomsCache)
57 : {
58 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
59 :
60 : // Initialize these in reverse order so that any failure leaves the first one
61 : // uninitialized.
62 0 : if (!atomsCache->type_id.init(cx, "type") ||
63 0 : !atomsCache->sdp_id.init(cx, "sdp")) {
64 0 : return false;
65 : }
66 0 : return true;
67 : }
68 :
69 : bool
70 0 : RTCSessionDescriptionInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
71 : {
72 : // Passing a null JSContext is OK only if we're initing from null,
73 : // Since in that case we will not have to do any property gets
74 : // Also evaluate isNullOrUndefined in order to avoid false-positive
75 : // checkers by static analysis tools
76 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
77 0 : RTCSessionDescriptionInitAtoms* atomsCache = nullptr;
78 0 : if (cx) {
79 0 : atomsCache = GetAtomCache<RTCSessionDescriptionInitAtoms>(cx);
80 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
81 0 : return false;
82 : }
83 : }
84 :
85 0 : if (!IsConvertibleToDictionary(val)) {
86 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
87 : }
88 :
89 0 : bool isNull = val.isNullOrUndefined();
90 : // We only need these if !isNull, in which case we have |cx|.
91 0 : Maybe<JS::Rooted<JSObject *> > object;
92 0 : Maybe<JS::Rooted<JS::Value> > temp;
93 0 : if (!isNull) {
94 0 : MOZ_ASSERT(cx);
95 0 : object.emplace(cx, &val.toObject());
96 0 : temp.emplace(cx);
97 : }
98 0 : if (!isNull) {
99 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->sdp_id, temp.ptr())) {
100 0 : return false;
101 : }
102 : }
103 0 : if (!isNull && !temp->isUndefined()) {
104 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSdp)) {
105 0 : return false;
106 : }
107 : } else {
108 : static const char16_t data[] = { 0 };
109 0 : mSdp.Rebind(data, ArrayLength(data) - 1);
110 : }
111 0 : mIsAnyMemberPresent = true;
112 :
113 0 : if (!isNull) {
114 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
115 0 : return false;
116 : }
117 : }
118 0 : if (!isNull && !temp->isUndefined()) {
119 : {
120 : int index;
121 0 : if (!FindEnumStringIndex<true>(cx, temp.ref(), RTCSdpTypeValues::strings, "RTCSdpType", "'type' member of RTCSessionDescriptionInit", &index)) {
122 0 : return false;
123 : }
124 0 : MOZ_ASSERT(index >= 0);
125 0 : mType = static_cast<RTCSdpType>(index);
126 : }
127 0 : mIsAnyMemberPresent = true;
128 0 : } else if (cx) {
129 : // Don't error out if we have no cx. In that
130 : // situation the caller is default-constructing us and we'll
131 : // just assume they know what they're doing.
132 0 : return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
133 0 : "'type' member of RTCSessionDescriptionInit");
134 : }
135 0 : return true;
136 : }
137 :
138 : bool
139 0 : RTCSessionDescriptionInit::Init(const nsAString& aJSON)
140 : {
141 0 : AutoJSAPI jsapi;
142 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
143 0 : if (!cleanGlobal) {
144 0 : return false;
145 : }
146 0 : if (!jsapi.Init(cleanGlobal)) {
147 0 : return false;
148 : }
149 0 : JSContext* cx = jsapi.cx();
150 0 : JS::Rooted<JS::Value> json(cx);
151 0 : bool ok = ParseJSON(cx, aJSON, &json);
152 0 : NS_ENSURE_TRUE(ok, false);
153 0 : return Init(cx, json);
154 : }
155 :
156 : bool
157 0 : RTCSessionDescriptionInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
158 : {
159 0 : RTCSessionDescriptionInitAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionInitAtoms>(cx);
160 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
161 0 : return false;
162 : }
163 :
164 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
165 0 : if (!obj) {
166 0 : return false;
167 : }
168 0 : rval.set(JS::ObjectValue(*obj));
169 :
170 : do {
171 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
172 0 : JS::Rooted<JS::Value> temp(cx);
173 0 : nsString const & currentValue = mSdp;
174 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
175 0 : return false;
176 : }
177 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->sdp_id, temp, JSPROP_ENUMERATE)) {
178 0 : return false;
179 : }
180 0 : break;
181 : } while(0);
182 :
183 : do {
184 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
185 0 : JS::Rooted<JS::Value> temp(cx);
186 0 : RTCSdpType const & currentValue = mType;
187 0 : if (!ToJSValue(cx, currentValue, &temp)) {
188 0 : return false;
189 : }
190 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
191 0 : return false;
192 : }
193 0 : break;
194 : } while(0);
195 :
196 0 : return true;
197 : }
198 :
199 : bool
200 0 : RTCSessionDescriptionInit::ToJSON(nsAString& aJSON) const
201 : {
202 0 : AutoJSAPI jsapi;
203 0 : jsapi.Init();
204 0 : JSContext *cx = jsapi.cx();
205 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
206 : // because we'll only be creating objects, in ways that have no
207 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
208 : // which likewise guarantees no side-effects for the sorts of
209 : // things we will pass it.
210 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
211 0 : JS::Rooted<JS::Value> val(cx);
212 0 : if (!ToObjectInternal(cx, &val)) {
213 0 : return false;
214 : }
215 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
216 0 : return StringifyToJSON(cx, obj, aJSON);
217 : }
218 :
219 : void
220 0 : RTCSessionDescriptionInit::TraceDictionary(JSTracer* trc)
221 : {
222 0 : }
223 :
224 : RTCSessionDescriptionInit&
225 0 : RTCSessionDescriptionInit::operator=(const RTCSessionDescriptionInit& aOther)
226 : {
227 0 : mSdp = aOther.mSdp;
228 0 : mType = aOther.mType;
229 0 : return *this;
230 : }
231 :
232 : namespace binding_detail {
233 : } // namespace binding_detail
234 :
235 :
236 : namespace RTCSessionDescriptionBinding {
237 :
238 : static bool
239 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, JSJitGetterCallArgs args)
240 : {
241 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
242 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
243 0 : if (objIsXray) {
244 0 : unwrappedObj.emplace(cx, obj);
245 : }
246 0 : if (objIsXray) {
247 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
248 0 : if (!unwrappedObj.ref()) {
249 0 : return false;
250 : }
251 : }
252 0 : binding_detail::FastErrorResult rv;
253 0 : RTCSdpType result(self->GetType(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
254 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
255 0 : return false;
256 : }
257 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
258 0 : if (!ToJSValue(cx, result, args.rval())) {
259 0 : return false;
260 : }
261 0 : return true;
262 : }
263 :
264 : static bool
265 0 : set_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, JSJitSetterCallArgs args)
266 : {
267 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
268 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
269 0 : if (objIsXray) {
270 0 : unwrappedObj.emplace(cx, obj);
271 : }
272 : RTCSdpType arg0;
273 : {
274 : int index;
275 0 : if (!FindEnumStringIndex<false>(cx, args[0], RTCSdpTypeValues::strings, "RTCSdpType", "Value being assigned to RTCSessionDescription.type", &index)) {
276 0 : return false;
277 : }
278 0 : if (index < 0) {
279 0 : return true;
280 : }
281 0 : arg0 = static_cast<RTCSdpType>(index);
282 : }
283 0 : if (objIsXray) {
284 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
285 0 : if (!unwrappedObj.ref()) {
286 0 : return false;
287 : }
288 : }
289 0 : binding_detail::FastErrorResult rv;
290 0 : self->SetType(arg0, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
291 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
292 0 : return false;
293 : }
294 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
295 :
296 0 : return true;
297 : }
298 :
299 : static const JSJitInfo type_getterinfo = {
300 : { (JSJitGetterOp)get_type },
301 : { prototypes::id::RTCSessionDescription },
302 : { PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth },
303 : JSJitInfo::Getter,
304 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
305 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
306 : false, /* isInfallible. False in setters. */
307 : false, /* isMovable. Not relevant for setters. */
308 : false, /* isEliminatable. Not relevant for setters. */
309 : false, /* isAlwaysInSlot. Only relevant for getters. */
310 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
311 : false, /* isTypedMethod. Only relevant for methods. */
312 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
313 : };
314 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
315 : static_assert(0 < 1, "There is no slot for us");
316 : static const JSJitInfo type_setterinfo = {
317 : { (JSJitGetterOp)set_type },
318 : { prototypes::id::RTCSessionDescription },
319 : { PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth },
320 : JSJitInfo::Setter,
321 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
322 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
323 : false, /* isInfallible. False in setters. */
324 : false, /* isMovable. Not relevant for setters. */
325 : false, /* isEliminatable. Not relevant for setters. */
326 : false, /* isAlwaysInSlot. Only relevant for getters. */
327 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
328 : false, /* isTypedMethod. Only relevant for methods. */
329 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
330 : };
331 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
332 : static_assert(0 < 1, "There is no slot for us");
333 :
334 : static bool
335 0 : get_sdp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, JSJitGetterCallArgs args)
336 : {
337 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
338 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
339 0 : if (objIsXray) {
340 0 : unwrappedObj.emplace(cx, obj);
341 : }
342 0 : if (objIsXray) {
343 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
344 0 : if (!unwrappedObj.ref()) {
345 0 : return false;
346 : }
347 : }
348 0 : binding_detail::FastErrorResult rv;
349 0 : DOMString result;
350 0 : self->GetSdp(result, rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
351 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
352 0 : return false;
353 : }
354 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
355 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
356 0 : return false;
357 : }
358 0 : return true;
359 : }
360 :
361 : static bool
362 0 : set_sdp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, JSJitSetterCallArgs args)
363 : {
364 0 : Maybe<JS::Rooted<JSObject*> > unwrappedObj;
365 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
366 0 : if (objIsXray) {
367 0 : unwrappedObj.emplace(cx, obj);
368 : }
369 0 : binding_detail::FakeString arg0;
370 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
371 0 : return false;
372 : }
373 0 : if (objIsXray) {
374 0 : unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
375 0 : if (!unwrappedObj.ref()) {
376 0 : return false;
377 : }
378 : }
379 0 : binding_detail::FastErrorResult rv;
380 0 : self->SetSdp(NonNullHelper(Constify(arg0)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
381 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
382 0 : return false;
383 : }
384 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
385 :
386 0 : return true;
387 : }
388 :
389 : static const JSJitInfo sdp_getterinfo = {
390 : { (JSJitGetterOp)get_sdp },
391 : { prototypes::id::RTCSessionDescription },
392 : { PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth },
393 : JSJitInfo::Getter,
394 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
395 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
396 : false, /* isInfallible. False in setters. */
397 : false, /* isMovable. Not relevant for setters. */
398 : false, /* isEliminatable. Not relevant for setters. */
399 : false, /* isAlwaysInSlot. Only relevant for getters. */
400 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
401 : false, /* isTypedMethod. Only relevant for methods. */
402 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
403 : };
404 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
405 : static_assert(0 < 1, "There is no slot for us");
406 : static const JSJitInfo sdp_setterinfo = {
407 : { (JSJitGetterOp)set_sdp },
408 : { prototypes::id::RTCSessionDescription },
409 : { PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth },
410 : JSJitInfo::Setter,
411 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
412 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
413 : false, /* isInfallible. False in setters. */
414 : false, /* isMovable. Not relevant for setters. */
415 : false, /* isEliminatable. Not relevant for setters. */
416 : false, /* isAlwaysInSlot. Only relevant for getters. */
417 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
418 : false, /* isTypedMethod. Only relevant for methods. */
419 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
420 : };
421 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
422 : static_assert(0 < 1, "There is no slot for us");
423 :
424 : bool
425 0 : JsonifyAttributes(JSContext* aCx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, JS::Rooted<JSObject*>& aResult)
426 : {
427 : { // scope for "temp"
428 0 : JS::Rooted<JS::Value> temp(aCx);
429 0 : if (!get_type(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
430 0 : return false;
431 : }
432 0 : if (!JS_DefineProperty(aCx, aResult, "type", temp, JSPROP_ENUMERATE)) {
433 0 : return false;
434 : }
435 : }
436 : { // scope for "temp"
437 0 : JS::Rooted<JS::Value> temp(aCx);
438 0 : if (!get_sdp(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
439 0 : return false;
440 : }
441 0 : if (!JS_DefineProperty(aCx, aResult, "sdp", temp, JSPROP_ENUMERATE)) {
442 0 : return false;
443 : }
444 : }
445 0 : return true;
446 : }
447 :
448 : static bool
449 0 : __jsonifier(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCSessionDescription* self, const JSJitMethodCallArgs& args)
450 : {
451 0 : JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
452 0 : if (!result) {
453 0 : return false;
454 : }
455 0 : if (!RTCSessionDescriptionBinding::JsonifyAttributes(cx, obj, self, result)) {
456 0 : return false;
457 : }
458 0 : args.rval().setObject(*result);
459 0 : return true;
460 : }
461 :
462 : static const JSJitInfo __jsonifier_methodinfo = {
463 : { (JSJitGetterOp)__jsonifier },
464 : { prototypes::id::RTCSessionDescription },
465 : { PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth },
466 : JSJitInfo::Method,
467 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
468 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
469 : false, /* isInfallible. False in setters. */
470 : false, /* isMovable. Not relevant for setters. */
471 : false, /* isEliminatable. Not relevant for setters. */
472 : false, /* isAlwaysInSlot. Only relevant for getters. */
473 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
474 : false, /* isTypedMethod. Only relevant for methods. */
475 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
476 : };
477 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
478 : static_assert(0 < 1, "There is no slot for us");
479 :
480 : static bool
481 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
482 : {
483 0 : mozilla::dom::RTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCSessionDescription>(obj);
484 : // We don't want to preserve if we don't have a wrapper, and we
485 : // obviously can't preserve if we're not initialized.
486 0 : if (self && self->GetWrapperPreserveColor()) {
487 0 : PreserveWrapper(self);
488 : }
489 0 : return true;
490 : }
491 :
492 : static void
493 0 : _finalize(js::FreeOp* fop, JSObject* obj)
494 : {
495 0 : mozilla::dom::RTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCSessionDescription>(obj);
496 0 : if (self) {
497 0 : ClearWrapper(self, self, obj);
498 0 : AddForDeferredFinalization<mozilla::dom::RTCSessionDescription>(self);
499 : }
500 0 : }
501 :
502 : static void
503 0 : _objectMoved(JSObject* obj, const JSObject* old)
504 : {
505 0 : mozilla::dom::RTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCSessionDescription>(obj);
506 0 : if (self) {
507 0 : UpdateWrapper(self, self, obj, old);
508 : }
509 0 : }
510 :
511 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
512 : #if defined(__clang__)
513 : #pragma clang diagnostic push
514 : #pragma clang diagnostic ignored "-Wmissing-braces"
515 : #endif
516 : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
517 : JS_FNSPEC("_create", RTCSessionDescription::_Create, nullptr, 2, 0, nullptr),
518 : JS_FS_END
519 : };
520 : #if defined(__clang__)
521 : #pragma clang diagnostic pop
522 : #endif
523 :
524 :
525 : // Can't be const because the pref-enabled boolean needs to be writable
526 : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
527 : { nullptr, &sChromeStaticMethods_specs[0] },
528 : { nullptr, nullptr }
529 : };
530 :
531 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
532 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
533 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
534 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
535 :
536 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
537 : #if defined(__clang__)
538 : #pragma clang diagnostic push
539 : #pragma clang diagnostic ignored "-Wmissing-braces"
540 : #endif
541 : static const JSFunctionSpec sMethods_specs[] = {
542 : JS_FNSPEC("toJSON", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&__jsonifier_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
543 : JS_FS_END
544 : };
545 : #if defined(__clang__)
546 : #pragma clang diagnostic pop
547 : #endif
548 :
549 :
550 : // Can't be const because the pref-enabled boolean needs to be writable
551 : static Prefable<const JSFunctionSpec> sMethods[] = {
552 : { nullptr, &sMethods_specs[0] },
553 : { nullptr, nullptr }
554 : };
555 :
556 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
557 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
558 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
559 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
560 :
561 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
562 : #if defined(__clang__)
563 : #pragma clang diagnostic push
564 : #pragma clang diagnostic ignored "-Wmissing-braces"
565 : #endif
566 : static const JSPropertySpec sAttributes_specs[] = {
567 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, GenericBindingSetter, &type_setterinfo },
568 : { "sdp", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &sdp_getterinfo, GenericBindingSetter, &sdp_setterinfo },
569 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
570 : };
571 : #if defined(__clang__)
572 : #pragma clang diagnostic pop
573 : #endif
574 :
575 :
576 : // Can't be const because the pref-enabled boolean needs to be writable
577 : static Prefable<const JSPropertySpec> sAttributes[] = {
578 : { nullptr, &sAttributes_specs[0] },
579 : { nullptr, nullptr }
580 : };
581 :
582 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
583 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
584 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
585 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
586 :
587 :
588 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
589 : static PropertyInfo sNativeProperties_propertyInfos[3];
590 :
591 : static const NativePropertiesN<2> sNativeProperties = {
592 : false, 0,
593 : false, 0,
594 : true, 0 /* sMethods */,
595 : true, 1 /* sAttributes */,
596 : false, 0,
597 : false, 0,
598 : false, 0,
599 : -1,
600 : 3,
601 : sNativeProperties_sortedPropertyIndices,
602 : {
603 : { sMethods, &sNativeProperties_propertyInfos[0] },
604 : { sAttributes, &sNativeProperties_propertyInfos[1] }
605 : }
606 : };
607 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
608 : "We have a property info count that is oversized");
609 :
610 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
611 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
612 :
613 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
614 : true, 0 /* sChromeStaticMethods */,
615 : false, 0,
616 : false, 0,
617 : false, 0,
618 : false, 0,
619 : false, 0,
620 : false, 0,
621 : -1,
622 : 1,
623 : sChromeOnlyNativeProperties_sortedPropertyIndices,
624 : {
625 : { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
626 : }
627 : };
628 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
629 : "We have a property info count that is oversized");
630 :
631 : static bool
632 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
633 : {
634 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
635 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
636 0 : if (!args.isConstructing()) {
637 : // XXXbz wish I could get the name from the callee instead of
638 : // Adding more relocations
639 0 : return ThrowConstructorWithoutNew(cx, "RTCSessionDescription");
640 : }
641 :
642 0 : GlobalObject global(cx, obj);
643 0 : if (global.Failed()) {
644 0 : return false;
645 : }
646 :
647 0 : JS::Rooted<JSObject*> desiredProto(cx);
648 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
649 0 : return false;
650 : }
651 :
652 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
653 0 : binding_detail::FastRTCSessionDescriptionInit arg0;
654 0 : if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of RTCSessionDescription.constructor", true)) {
655 0 : return false;
656 : }
657 0 : Maybe<JSAutoCompartment> ac;
658 0 : if (objIsXray) {
659 0 : obj = js::CheckedUnwrap(obj);
660 0 : if (!obj) {
661 0 : return false;
662 : }
663 0 : ac.emplace(cx, obj);
664 0 : if (!JS_WrapObject(cx, &desiredProto)) {
665 0 : return false;
666 : }
667 : }
668 0 : binding_detail::FastErrorResult rv;
669 0 : auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(mozilla::dom::RTCSessionDescription::Constructor(global, cx, Constify(arg0), rv)));
670 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
671 0 : return false;
672 : }
673 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
674 : static_assert(!IsPointer<decltype(result)>::value,
675 : "NewObject implies that we need to keep the object alive with a strong reference.");
676 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
677 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
678 0 : return false;
679 : }
680 0 : return true;
681 : }
682 :
683 : static const js::ClassOps sInterfaceObjectClassOps = {
684 : nullptr, /* addProperty */
685 : nullptr, /* delProperty */
686 : nullptr, /* getProperty */
687 : nullptr, /* setProperty */
688 : nullptr, /* enumerate */
689 : nullptr, /* newEnumerate */
690 : nullptr, /* resolve */
691 : nullptr, /* mayResolve */
692 : nullptr, /* finalize */
693 : _constructor, /* call */
694 : nullptr, /* hasInstance */
695 : _constructor, /* construct */
696 : nullptr, /* trace */
697 : };
698 :
699 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
700 : {
701 : "Function",
702 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
703 : &sInterfaceObjectClassOps,
704 : JS_NULL_CLASS_SPEC,
705 : JS_NULL_CLASS_EXT,
706 : &sInterfaceObjectClassObjectOps
707 : },
708 : eInterface,
709 : true,
710 : prototypes::id::RTCSessionDescription,
711 : PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth,
712 : sNativePropertyHooks,
713 : "function RTCSessionDescription() {\n [native code]\n}",
714 : JS::GetRealmFunctionPrototype
715 : };
716 :
717 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
718 : {
719 : "RTCSessionDescriptionPrototype",
720 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
721 : JS_NULL_CLASS_OPS,
722 : JS_NULL_CLASS_SPEC,
723 : JS_NULL_CLASS_EXT,
724 : JS_NULL_OBJECT_OPS
725 : },
726 : eInterfacePrototype,
727 : false,
728 : prototypes::id::RTCSessionDescription,
729 : PrototypeTraits<prototypes::id::RTCSessionDescription>::Depth,
730 : sNativePropertyHooks,
731 : "[object RTCSessionDescriptionPrototype]",
732 : JS::GetRealmObjectPrototype
733 : };
734 :
735 : bool
736 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
737 : {
738 : static bool sPrefValue;
739 : static bool sPrefCacheSetUp = false;
740 0 : if (!sPrefCacheSetUp) {
741 0 : sPrefCacheSetUp = true;
742 0 : Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
743 : }
744 :
745 0 : return sPrefValue;
746 : }
747 :
748 : JSObject*
749 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
750 : {
751 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
752 : }
753 :
754 : static const js::ClassOps sClassOps = {
755 : _addProperty, /* addProperty */
756 : nullptr, /* delProperty */
757 : nullptr, /* getProperty */
758 : nullptr, /* setProperty */
759 : nullptr, /* enumerate */
760 : nullptr, /* newEnumerate */
761 : nullptr, /* resolve */
762 : nullptr, /* mayResolve */
763 : _finalize, /* finalize */
764 : nullptr, /* call */
765 : nullptr, /* hasInstance */
766 : nullptr, /* construct */
767 : nullptr, /* trace */
768 : };
769 :
770 : static const js::ClassExtension sClassExtension = {
771 : nullptr, /* weakmapKeyDelegateOp */
772 : _objectMoved /* objectMovedOp */
773 : };
774 :
775 : static const DOMJSClass sClass = {
776 : { "RTCSessionDescription",
777 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
778 : &sClassOps,
779 : JS_NULL_CLASS_SPEC,
780 : &sClassExtension,
781 : JS_NULL_OBJECT_OPS
782 : },
783 : { prototypes::id::RTCSessionDescription, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
784 : IsBaseOf<nsISupports, mozilla::dom::RTCSessionDescription >::value,
785 : sNativePropertyHooks,
786 : FindAssociatedGlobalForNative<mozilla::dom::RTCSessionDescription>::Get,
787 : GetProtoObjectHandle,
788 : GetCCParticipant<mozilla::dom::RTCSessionDescription>::Get()
789 : };
790 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
791 : "Must have the right minimal number of reserved slots.");
792 : static_assert(1 >= 1,
793 : "Must have enough reserved slots.");
794 :
795 : const JSClass*
796 0 : GetJSClass()
797 : {
798 0 : return sClass.ToJSClass();
799 : }
800 :
801 : bool
802 0 : Wrap(JSContext* aCx, mozilla::dom::RTCSessionDescription* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
803 : {
804 : MOZ_ASSERT(static_cast<mozilla::dom::RTCSessionDescription*>(aObject) ==
805 : reinterpret_cast<mozilla::dom::RTCSessionDescription*>(aObject),
806 : "Multiple inheritance for mozilla::dom::RTCSessionDescription is broken.");
807 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
808 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
809 0 : MOZ_ASSERT(!aCache->GetWrapper(),
810 : "You should probably not be using Wrap() directly; use "
811 : "GetOrCreateDOMReflector instead");
812 :
813 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
814 : "nsISupports must be on our primary inheritance chain");
815 :
816 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
817 0 : if (!global) {
818 0 : return false;
819 : }
820 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
821 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
822 :
823 : // That might have ended up wrapping us already, due to the wonders
824 : // of XBL. Check for that, and bail out as needed.
825 0 : aReflector.set(aCache->GetWrapper());
826 0 : if (aReflector) {
827 : #ifdef DEBUG
828 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
829 : #endif // DEBUG
830 0 : return true;
831 : }
832 :
833 0 : JSAutoCompartment ac(aCx, global);
834 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
835 0 : if (!canonicalProto) {
836 0 : return false;
837 : }
838 0 : JS::Rooted<JSObject*> proto(aCx);
839 0 : if (aGivenProto) {
840 0 : proto = aGivenProto;
841 : // Unfortunately, while aGivenProto was in the compartment of aCx
842 : // coming in, we changed compartments to that of "parent" so may need
843 : // to wrap the proto here.
844 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
845 0 : if (!JS_WrapObject(aCx, &proto)) {
846 0 : return false;
847 : }
848 : }
849 : } else {
850 0 : proto = canonicalProto;
851 : }
852 :
853 0 : BindingJSObjectCreator<mozilla::dom::RTCSessionDescription> creator(aCx);
854 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
855 0 : if (!aReflector) {
856 0 : return false;
857 : }
858 :
859 0 : aCache->SetWrapper(aReflector);
860 0 : creator.InitializationSucceeded();
861 :
862 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
863 : aCache->GetWrapperPreserveColor() == aReflector);
864 : // If proto != canonicalProto, we have to preserve our wrapper;
865 : // otherwise we won't be able to properly recreate it later, since
866 : // we won't know what proto to use. Note that we don't check
867 : // aGivenProto here, since it's entirely possible (and even
868 : // somewhat common) to have a non-null aGivenProto which is the
869 : // same as canonicalProto.
870 0 : if (proto != canonicalProto) {
871 0 : PreserveWrapper(aObject);
872 : }
873 :
874 0 : return true;
875 : }
876 :
877 : const NativePropertyHooks sNativePropertyHooks[] = { {
878 : nullptr,
879 : nullptr,
880 : nullptr,
881 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
882 : prototypes::id::RTCSessionDescription,
883 : constructors::id::RTCSessionDescription,
884 : nullptr,
885 : &DefaultXrayExpandoObjectClass
886 : } };
887 :
888 : void
889 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
890 : {
891 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
892 0 : if (!parentProto) {
893 0 : return;
894 : }
895 :
896 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
897 0 : if (!constructorProto) {
898 0 : return;
899 : }
900 :
901 : static bool sIdsInited = false;
902 0 : if (!sIdsInited && NS_IsMainThread()) {
903 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
904 0 : return;
905 : }
906 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
907 0 : return;
908 : }
909 0 : sIdsInited = true;
910 : }
911 :
912 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCSessionDescription);
913 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::RTCSessionDescription);
914 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
915 : &sPrototypeClass.mBase, protoCache,
916 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
917 : interfaceCache,
918 : sNativeProperties.Upcast(),
919 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
920 : "RTCSessionDescription", aDefineOnGlobal,
921 : nullptr,
922 0 : false);
923 : }
924 :
925 : JS::Handle<JSObject*>
926 0 : GetProtoObjectHandle(JSContext* aCx)
927 : {
928 : /* Get the interface prototype object for this class. This will create the
929 : object as needed. */
930 0 : bool aDefineOnGlobal = true;
931 :
932 : /* Make sure our global is sane. Hopefully we can remove this sometime */
933 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
934 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
935 0 : return nullptr;
936 : }
937 :
938 : /* Check to see whether the interface objects are already installed */
939 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
940 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::RTCSessionDescription)) {
941 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
942 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
943 : }
944 :
945 : /*
946 : * The object might _still_ be null, but that's OK.
947 : *
948 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
949 : * traced by TraceProtoAndIfaceCache() and its contents are never
950 : * changed after they have been set.
951 : *
952 : * Calling address() avoids the read read barrier that does gray
953 : * unmarking, but it's not possible for the object to be gray here.
954 : */
955 :
956 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::RTCSessionDescription);
957 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
958 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
959 : }
960 :
961 : JSObject*
962 0 : GetProtoObject(JSContext* aCx)
963 : {
964 0 : return GetProtoObjectHandle(aCx);
965 : }
966 :
967 : JS::Handle<JSObject*>
968 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
969 : {
970 : /* Get the interface object for this class. This will create the object as
971 : needed. */
972 :
973 : /* Make sure our global is sane. Hopefully we can remove this sometime */
974 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
975 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
976 0 : return nullptr;
977 : }
978 :
979 : /* Check to see whether the interface objects are already installed */
980 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
981 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::RTCSessionDescription)) {
982 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
983 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
984 : }
985 :
986 : /*
987 : * The object might _still_ be null, but that's OK.
988 : *
989 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
990 : * traced by TraceProtoAndIfaceCache() and its contents are never
991 : * changed after they have been set.
992 : *
993 : * Calling address() avoids the read read barrier that does gray
994 : * unmarking, but it's not possible for the object to be gray here.
995 : */
996 :
997 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::RTCSessionDescription);
998 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
999 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1000 : }
1001 :
1002 : JSObject*
1003 0 : GetConstructorObject(JSContext* aCx)
1004 : {
1005 0 : return GetConstructorObjectHandle(aCx);
1006 : }
1007 :
1008 : } // namespace RTCSessionDescriptionBinding
1009 :
1010 :
1011 :
1012 : void
1013 0 : RTCSessionDescriptionJSImpl::__Init(const RTCSessionDescriptionInit& descriptionInitDict, ErrorResult& aRv, JSCompartment* aCompartment)
1014 : {
1015 0 : CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
1016 0 : JSContext* cx = s.GetContext();
1017 0 : if (!cx) {
1018 0 : MOZ_ASSERT(aRv.Failed());
1019 0 : return;
1020 : }
1021 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1022 0 : JS::AutoValueVector argv(cx);
1023 0 : if (!argv.resize(1)) {
1024 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1025 0 : return;
1026 : }
1027 0 : unsigned argc = 1;
1028 :
1029 : do {
1030 0 : if (!descriptionInitDict.ToObjectInternal(cx, argv[0])) {
1031 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1032 0 : return;
1033 : }
1034 0 : break;
1035 : } while (0);
1036 :
1037 0 : JS::Rooted<JS::Value> callable(cx);
1038 0 : RTCSessionDescriptionAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionAtoms>(cx);
1039 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1040 0 : !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
1041 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1042 0 : return;
1043 : }
1044 0 : JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
1045 0 : if (!JS::Call(cx, thisValue, callable,
1046 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1047 0 : aRv.NoteJSContextException(cx);
1048 0 : return;
1049 : }
1050 : }
1051 :
1052 : bool
1053 0 : RTCSessionDescriptionJSImpl::InitIds(JSContext* cx, RTCSessionDescriptionAtoms* atomsCache)
1054 : {
1055 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1056 :
1057 : // Initialize these in reverse order so that any failure leaves the first one
1058 : // uninitialized.
1059 0 : if (!atomsCache->__init_id.init(cx, "__init") ||
1060 0 : !atomsCache->__jsonifier_id.init(cx, "__jsonifier") ||
1061 0 : !atomsCache->sdp_id.init(cx, "sdp") ||
1062 0 : !atomsCache->type_id.init(cx, "type")) {
1063 0 : return false;
1064 : }
1065 0 : return true;
1066 : }
1067 :
1068 :
1069 : RTCSdpType
1070 0 : RTCSessionDescriptionJSImpl::GetType(ErrorResult& aRv, JSCompartment* aCompartment)
1071 : {
1072 0 : CallSetup s(this, aRv, "RTCSessionDescription.type", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
1073 0 : JSContext* cx = s.GetContext();
1074 0 : if (!cx) {
1075 0 : MOZ_ASSERT(aRv.Failed());
1076 0 : return RTCSdpType(0);
1077 : }
1078 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1079 :
1080 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
1081 0 : RTCSessionDescriptionAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionAtoms>(cx);
1082 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1083 0 : !JS_GetPropertyById(cx, callback, atomsCache->type_id, &rval)) {
1084 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1085 0 : return RTCSdpType(0);
1086 : }
1087 : RTCSdpType rvalDecl;
1088 : {
1089 : int index;
1090 0 : if (!FindEnumStringIndex<true>(cx, rval, RTCSdpTypeValues::strings, "RTCSdpType", "Return value of RTCSessionDescription.type", &index)) {
1091 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1092 0 : return RTCSdpType(0);
1093 : }
1094 0 : MOZ_ASSERT(index >= 0);
1095 0 : rvalDecl = static_cast<RTCSdpType>(index);
1096 : }
1097 0 : return rvalDecl;
1098 : }
1099 :
1100 : void
1101 0 : RTCSessionDescriptionJSImpl::GetSdp(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment)
1102 : {
1103 0 : CallSetup s(this, aRv, "RTCSessionDescription.sdp", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
1104 0 : JSContext* cx = s.GetContext();
1105 0 : if (!cx) {
1106 0 : MOZ_ASSERT(aRv.Failed());
1107 0 : return;
1108 : }
1109 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1110 :
1111 0 : JS::Rooted<JSObject *> callback(cx, mCallback);
1112 0 : RTCSessionDescriptionAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionAtoms>(cx);
1113 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1114 0 : !JS_GetPropertyById(cx, callback, atomsCache->sdp_id, &rval)) {
1115 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1116 0 : return;
1117 : }
1118 0 : binding_detail::FakeString rvalDecl;
1119 0 : if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
1120 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1121 0 : return;
1122 : }
1123 0 : aRetVal = rvalDecl;
1124 : }
1125 :
1126 : void
1127 0 : RTCSessionDescriptionJSImpl::SetType(RTCSdpType arg, ErrorResult& aRv, JSCompartment* aCompartment)
1128 : {
1129 0 : CallSetup s(this, aRv, "RTCSessionDescription.type", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
1130 0 : JSContext* cx = s.GetContext();
1131 0 : if (!cx) {
1132 0 : MOZ_ASSERT(aRv.Failed());
1133 0 : return;
1134 : }
1135 0 : JS::AutoValueVector argv(cx);
1136 0 : if (!argv.resize(1)) {
1137 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1138 0 : return;
1139 : }
1140 : do {
1141 0 : if (!ToJSValue(cx, arg, argv[0])) {
1142 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1143 0 : return;
1144 : }
1145 0 : break;
1146 : } while (0);
1147 :
1148 0 : MOZ_ASSERT(argv.length() == 1);
1149 0 : RTCSessionDescriptionAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionAtoms>(cx);
1150 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1151 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->type_id, argv[0])) {
1152 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1153 0 : return;
1154 : }
1155 : }
1156 :
1157 : void
1158 0 : RTCSessionDescriptionJSImpl::SetSdp(const nsAString& arg, ErrorResult& aRv, JSCompartment* aCompartment)
1159 : {
1160 0 : CallSetup s(this, aRv, "RTCSessionDescription.sdp", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
1161 0 : JSContext* cx = s.GetContext();
1162 0 : if (!cx) {
1163 0 : MOZ_ASSERT(aRv.Failed());
1164 0 : return;
1165 : }
1166 0 : JS::AutoValueVector argv(cx);
1167 0 : if (!argv.resize(1)) {
1168 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1169 0 : return;
1170 : }
1171 : do {
1172 0 : nsString mutableStr(arg);
1173 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
1174 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1175 0 : return;
1176 : }
1177 0 : break;
1178 : } while (0);
1179 :
1180 0 : MOZ_ASSERT(argv.length() == 1);
1181 0 : RTCSessionDescriptionAtoms* atomsCache = GetAtomCache<RTCSessionDescriptionAtoms>(cx);
1182 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1183 0 : !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->sdp_id, argv[0])) {
1184 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1185 0 : return;
1186 : }
1187 : }
1188 :
1189 :
1190 : NS_IMPL_CYCLE_COLLECTION_CLASS(RTCSessionDescription)
1191 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(RTCSessionDescription)
1192 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl)
1193 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
1194 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
1195 0 : tmp->ClearWeakReferences();
1196 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
1197 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(RTCSessionDescription)
1198 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl)
1199 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
1200 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
1201 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(RTCSessionDescription)
1202 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(RTCSessionDescription)
1203 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(RTCSessionDescription)
1204 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RTCSessionDescription)
1205 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
1206 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
1207 0 : NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
1208 0 : NS_INTERFACE_MAP_END
1209 :
1210 0 : RTCSessionDescription::RTCSessionDescription(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent)
1211 0 : : mImpl(new RTCSessionDescriptionJSImpl(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr)),
1212 0 : mParent(aParent)
1213 : {
1214 0 : }
1215 :
1216 :
1217 0 : RTCSessionDescription::~RTCSessionDescription()
1218 : {
1219 0 : }
1220 :
1221 : nsISupports*
1222 0 : RTCSessionDescription::GetParentObject() const
1223 : {
1224 0 : return mParent;
1225 : }
1226 :
1227 : JSObject*
1228 0 : RTCSessionDescription::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
1229 : {
1230 0 : JS::Rooted<JSObject*> obj(aCx, RTCSessionDescriptionBinding::Wrap(aCx, this, aGivenProto));
1231 0 : if (!obj) {
1232 0 : return nullptr;
1233 : }
1234 :
1235 : // Now define it on our chrome object
1236 0 : JSAutoCompartment ac(aCx, mImpl->CallbackOrNull());
1237 0 : if (!JS_WrapObject(aCx, &obj)) {
1238 0 : return nullptr;
1239 : }
1240 0 : if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
1241 0 : return nullptr;
1242 : }
1243 0 : return obj;
1244 : }
1245 :
1246 : already_AddRefed<RTCSessionDescription>
1247 0 : RTCSessionDescription::Constructor(const GlobalObject& global, JSContext* cx, const RTCSessionDescriptionInit& descriptionInitDict, ErrorResult& aRv)
1248 : {
1249 0 : JS::Rooted<JSObject*> jsImplObj(cx);
1250 : nsCOMPtr<nsIGlobalObject> globalHolder =
1251 0 : ConstructJSImplementation("@mozilla.org/dom/rtcsessiondescription;1", global, &jsImplObj, aRv);
1252 0 : if (aRv.Failed()) {
1253 0 : return nullptr;
1254 : }
1255 : // Build the C++ implementation.
1256 0 : RefPtr<RTCSessionDescription> impl = new RTCSessionDescription(jsImplObj, globalHolder);
1257 : // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
1258 0 : JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
1259 0 : MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
1260 0 : JS::Rooted<JS::Value> wrappedVal(cx);
1261 0 : if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal)) {
1262 : //XXX Assertion disabled for now, see bug 991271.
1263 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1264 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
1265 0 : return nullptr;
1266 : }
1267 : // Initialize the object with the constructor arguments.
1268 0 : impl->mImpl->__Init(descriptionInitDict, aRv, js::GetObjectCompartment(scopeObj));
1269 0 : if (aRv.Failed()) {
1270 0 : return nullptr;
1271 : }
1272 0 : return impl.forget();
1273 : }
1274 :
1275 : RTCSdpType
1276 0 : RTCSessionDescription::GetType(ErrorResult& aRv, JSCompartment* aCompartment) const
1277 : {
1278 0 : return mImpl->GetType(aRv, aCompartment);
1279 : }
1280 :
1281 : void
1282 0 : RTCSessionDescription::SetType(RTCSdpType arg, ErrorResult& aRv, JSCompartment* aCompartment)
1283 : {
1284 0 : mImpl->SetType(arg, aRv, aCompartment);
1285 0 : }
1286 :
1287 : void
1288 0 : RTCSessionDescription::GetSdp(nsString& aRetVal, ErrorResult& aRv, JSCompartment* aCompartment) const
1289 : {
1290 0 : return mImpl->GetSdp(aRetVal, aRv, aCompartment);
1291 : }
1292 :
1293 : void
1294 0 : RTCSessionDescription::SetSdp(const nsAString& arg, ErrorResult& aRv, JSCompartment* aCompartment)
1295 : {
1296 0 : mImpl->SetSdp(arg, aRv, aCompartment);
1297 0 : }
1298 :
1299 : bool
1300 0 : RTCSessionDescription::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
1301 : {
1302 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1303 0 : if (args.length() < 2) {
1304 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCSessionDescription._create");
1305 : }
1306 0 : if (!args[0].isObject()) {
1307 0 : return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCSessionDescription._create");
1308 : }
1309 0 : if (!args[1].isObject()) {
1310 0 : return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCSessionDescription._create");
1311 : }
1312 :
1313 : // GlobalObject will go through wrappers as needed for us, and
1314 : // is simpler than the right UnwrapArg incantation.
1315 0 : GlobalObject global(cx, &args[0].toObject());
1316 0 : if (global.Failed()) {
1317 0 : return false;
1318 : }
1319 0 : nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
1320 0 : MOZ_ASSERT(globalHolder);
1321 0 : JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
1322 0 : RefPtr<RTCSessionDescription> impl = new RTCSessionDescription(arg, globalHolder);
1323 0 : MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
1324 0 : return GetOrCreateDOMReflector(cx, impl, args.rval());
1325 : }
1326 :
1327 :
1328 : } // namespace dom
1329 : } // namespace mozilla
|