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