/work/obj-fuzz/dom/bindings/RTCRtpSourcesBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM RTCRtpSources.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "RTCRtpSourcesBinding.h" |
5 | | #include "jsapi.h" |
6 | | #include "mozilla/FloatingPoint.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/PrimitiveConversions.h" |
11 | | #include "mozilla/dom/ScriptSettings.h" |
12 | | #include "mozilla/dom/SimpleGlobalObject.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
18 | | using namespace mozilla::dom::binding_detail; |
19 | | |
20 | | |
21 | | namespace RTCRtpSourceEntryTypeValues { |
22 | | extern const EnumEntry strings[3] = { |
23 | | {"contributing", 12}, |
24 | | {"synchronization", 15}, |
25 | | { nullptr, 0 } |
26 | | }; |
27 | | } // namespace RTCRtpSourceEntryTypeValues |
28 | | |
29 | | bool |
30 | | ToJSValue(JSContext* aCx, RTCRtpSourceEntryType aArgument, JS::MutableHandle<JS::Value> aValue) |
31 | 0 | { |
32 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCRtpSourceEntryTypeValues::strings)); |
33 | 0 | JSString* resultStr = |
34 | 0 | JS_NewStringCopyN(aCx, RTCRtpSourceEntryTypeValues::strings[uint32_t(aArgument)].value, |
35 | 0 | RTCRtpSourceEntryTypeValues::strings[uint32_t(aArgument)].length); |
36 | 0 | if (!resultStr) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | aValue.setString(resultStr); |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | |
44 | | |
45 | | RTCRtpContributingSource::RTCRtpContributingSource() |
46 | 0 | { |
47 | 0 | // Safe to pass a null context if we pass a null value |
48 | 0 | Init(nullptr, JS::NullHandleValue); |
49 | 0 | } |
50 | | |
51 | | |
52 | | |
53 | | bool |
54 | | RTCRtpContributingSource::InitIds(JSContext* cx, RTCRtpContributingSourceAtoms* atomsCache) |
55 | 0 | { |
56 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
57 | 0 |
|
58 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
59 | 0 | // uninitialized. |
60 | 0 | if (!atomsCache->timestamp_id.init(cx, "timestamp") || |
61 | 0 | !atomsCache->source_id.init(cx, "source") || |
62 | 0 | !atomsCache->audioLevel_id.init(cx, "audioLevel")) { |
63 | 0 | return false; |
64 | 0 | } |
65 | 0 | return true; |
66 | 0 | } |
67 | | |
68 | | bool |
69 | | RTCRtpContributingSource::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
70 | 0 | { |
71 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
72 | 0 | // Since in that case we will not have to do any property gets |
73 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
74 | 0 | // checkers by static analysis tools |
75 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
76 | 0 | RTCRtpContributingSourceAtoms* atomsCache = nullptr; |
77 | 0 | if (cx) { |
78 | 0 | atomsCache = GetAtomCache<RTCRtpContributingSourceAtoms>(cx); |
79 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | |
84 | 0 | if (!IsConvertibleToDictionary(val)) { |
85 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
86 | 0 | } |
87 | 0 | |
88 | 0 | bool isNull = val.isNullOrUndefined(); |
89 | 0 | // We only need these if !isNull, in which case we have |cx|. |
90 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
91 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
92 | 0 | if (!isNull) { |
93 | 0 | MOZ_ASSERT(cx); |
94 | 0 | object.emplace(cx, &val.toObject()); |
95 | 0 | temp.emplace(cx); |
96 | 0 | } |
97 | 0 | if (!isNull) { |
98 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->audioLevel_id, temp.ptr())) { |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | if (!isNull && !temp->isUndefined()) { |
103 | 0 | mAudioLevel.Construct(); |
104 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &(mAudioLevel.Value()))) { |
105 | 0 | return false; |
106 | 0 | } else if (!mozilla::IsFinite((mAudioLevel.Value()))) { |
107 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'audioLevel' member of RTCRtpContributingSource"); |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | mIsAnyMemberPresent = true; |
111 | 0 | } |
112 | 0 |
|
113 | 0 | if (!isNull) { |
114 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->source_id, temp.ptr())) { |
115 | 0 | return false; |
116 | 0 | } |
117 | 0 | } |
118 | 0 | if (!isNull && !temp->isUndefined()) { |
119 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mSource)) { |
120 | 0 | return false; |
121 | 0 | } |
122 | 0 | mIsAnyMemberPresent = true; |
123 | 0 | } else if (cx) { |
124 | 0 | // Don't error out if we have no cx. In that |
125 | 0 | // situation the caller is default-constructing us and we'll |
126 | 0 | // just assume they know what they're doing. |
127 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
128 | 0 | "'source' member of RTCRtpContributingSource"); |
129 | 0 | } |
130 | 0 | |
131 | 0 | if (!isNull) { |
132 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->timestamp_id, temp.ptr())) { |
133 | 0 | return false; |
134 | 0 | } |
135 | 0 | } |
136 | 0 | if (!isNull && !temp->isUndefined()) { |
137 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mTimestamp)) { |
138 | 0 | return false; |
139 | 0 | } else if (!mozilla::IsFinite(mTimestamp)) { |
140 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'timestamp' member of RTCRtpContributingSource"); |
141 | 0 | return false; |
142 | 0 | } |
143 | 0 | mIsAnyMemberPresent = true; |
144 | 0 | } else if (cx) { |
145 | 0 | // Don't error out if we have no cx. In that |
146 | 0 | // situation the caller is default-constructing us and we'll |
147 | 0 | // just assume they know what they're doing. |
148 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
149 | 0 | "'timestamp' member of RTCRtpContributingSource"); |
150 | 0 | } |
151 | 0 | return true; |
152 | 0 | } |
153 | | |
154 | | bool |
155 | | RTCRtpContributingSource::Init(const nsAString& aJSON) |
156 | 0 | { |
157 | 0 | AutoJSAPI jsapi; |
158 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
159 | 0 | if (!cleanGlobal) { |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | if (!jsapi.Init(cleanGlobal)) { |
163 | 0 | return false; |
164 | 0 | } |
165 | 0 | JSContext* cx = jsapi.cx(); |
166 | 0 | JS::Rooted<JS::Value> json(cx); |
167 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
168 | 0 | NS_ENSURE_TRUE(ok, false); |
169 | 0 | return Init(cx, json); |
170 | 0 | } |
171 | | |
172 | | bool |
173 | | RTCRtpContributingSource::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
174 | 0 | { |
175 | 0 | RTCRtpContributingSourceAtoms* atomsCache = GetAtomCache<RTCRtpContributingSourceAtoms>(cx); |
176 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | |
180 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
181 | 0 | if (!obj) { |
182 | 0 | return false; |
183 | 0 | } |
184 | 0 | rval.set(JS::ObjectValue(*obj)); |
185 | 0 |
|
186 | 0 | if (mAudioLevel.WasPassed()) { |
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 | double const & currentValue = mAudioLevel.InternalValue(); |
191 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
192 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->audioLevel_id, temp, JSPROP_ENUMERATE)) { |
193 | 0 | return false; |
194 | 0 | } |
195 | 0 | break; |
196 | 0 | } while(false); |
197 | 0 | } |
198 | 0 |
|
199 | 0 | do { |
200 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
201 | 0 | JS::Rooted<JS::Value> temp(cx); |
202 | 0 | uint32_t const & currentValue = mSource; |
203 | 0 | temp.setNumber(currentValue); |
204 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) { |
205 | 0 | return false; |
206 | 0 | } |
207 | 0 | break; |
208 | 0 | } while(false); |
209 | 0 |
|
210 | 0 | do { |
211 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
212 | 0 | JS::Rooted<JS::Value> temp(cx); |
213 | 0 | double const & currentValue = mTimestamp; |
214 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
215 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->timestamp_id, temp, JSPROP_ENUMERATE)) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | break; |
219 | 0 | } while(false); |
220 | 0 |
|
221 | 0 | return true; |
222 | 0 | } |
223 | | |
224 | | bool |
225 | | RTCRtpContributingSource::ToJSON(nsAString& aJSON) const |
226 | 0 | { |
227 | 0 | AutoJSAPI jsapi; |
228 | 0 | jsapi.Init(); |
229 | 0 | JSContext *cx = jsapi.cx(); |
230 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
231 | 0 | // because we'll only be creating objects, in ways that have no |
232 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
233 | 0 | // which likewise guarantees no side-effects for the sorts of |
234 | 0 | // things we will pass it. |
235 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
236 | 0 | JS::Rooted<JS::Value> val(cx); |
237 | 0 | if (!ToObjectInternal(cx, &val)) { |
238 | 0 | return false; |
239 | 0 | } |
240 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
241 | 0 | return StringifyToJSON(cx, obj, aJSON); |
242 | 0 | } |
243 | | |
244 | | void |
245 | | RTCRtpContributingSource::TraceDictionary(JSTracer* trc) |
246 | 0 | { |
247 | 0 | } |
248 | | |
249 | | RTCRtpContributingSource& |
250 | | RTCRtpContributingSource::operator=(const RTCRtpContributingSource& aOther) |
251 | 0 | { |
252 | 0 | DictionaryBase::operator=(aOther); |
253 | 0 | mAudioLevel.Reset(); |
254 | 0 | if (aOther.mAudioLevel.WasPassed()) { |
255 | 0 | mAudioLevel.Construct(aOther.mAudioLevel.Value()); |
256 | 0 | } |
257 | 0 | mSource = aOther.mSource; |
258 | 0 | mTimestamp = aOther.mTimestamp; |
259 | 0 | return *this; |
260 | 0 | } |
261 | | |
262 | | namespace binding_detail { |
263 | | } // namespace binding_detail |
264 | | |
265 | | |
266 | | |
267 | | RTCRtpSynchronizationSource::RTCRtpSynchronizationSource() |
268 | | : RTCRtpContributingSource(FastDictionaryInitializer()) |
269 | 0 | { |
270 | 0 | // Safe to pass a null context if we pass a null value |
271 | 0 | Init(nullptr, JS::NullHandleValue); |
272 | 0 | } |
273 | | |
274 | | |
275 | | |
276 | | bool |
277 | | RTCRtpSynchronizationSource::InitIds(JSContext* cx, RTCRtpSynchronizationSourceAtoms* atomsCache) |
278 | 0 | { |
279 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
280 | 0 |
|
281 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
282 | 0 | // uninitialized. |
283 | 0 | if (!atomsCache->voiceActivityFlag_id.init(cx, "voiceActivityFlag")) { |
284 | 0 | return false; |
285 | 0 | } |
286 | 0 | return true; |
287 | 0 | } |
288 | | |
289 | | bool |
290 | | RTCRtpSynchronizationSource::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
291 | 0 | { |
292 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
293 | 0 | // Since in that case we will not have to do any property gets |
294 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
295 | 0 | // checkers by static analysis tools |
296 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
297 | 0 | RTCRtpSynchronizationSourceAtoms* atomsCache = nullptr; |
298 | 0 | if (cx) { |
299 | 0 | atomsCache = GetAtomCache<RTCRtpSynchronizationSourceAtoms>(cx); |
300 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
301 | 0 | return false; |
302 | 0 | } |
303 | 0 | } |
304 | 0 | |
305 | 0 | // Per spec, we init the parent's members first |
306 | 0 | if (!RTCRtpContributingSource::Init(cx, val)) { |
307 | 0 | return false; |
308 | 0 | } |
309 | 0 | |
310 | 0 | bool isNull = val.isNullOrUndefined(); |
311 | 0 | // We only need these if !isNull, in which case we have |cx|. |
312 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
313 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
314 | 0 | if (!isNull) { |
315 | 0 | MOZ_ASSERT(cx); |
316 | 0 | object.emplace(cx, &val.toObject()); |
317 | 0 | temp.emplace(cx); |
318 | 0 | } |
319 | 0 | if (!isNull) { |
320 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->voiceActivityFlag_id, temp.ptr())) { |
321 | 0 | return false; |
322 | 0 | } |
323 | 0 | } |
324 | 0 | if (!isNull && !temp->isUndefined()) { |
325 | 0 | mVoiceActivityFlag.Construct(); |
326 | 0 | if (temp.ref().isNullOrUndefined()) { |
327 | 0 | (mVoiceActivityFlag.Value()).SetNull(); |
328 | 0 | } else if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mVoiceActivityFlag.Value()).SetValue())) { |
329 | 0 | return false; |
330 | 0 | } |
331 | 0 | mIsAnyMemberPresent = true; |
332 | 0 | } |
333 | 0 | return true; |
334 | 0 | } |
335 | | |
336 | | bool |
337 | | RTCRtpSynchronizationSource::Init(const nsAString& aJSON) |
338 | 0 | { |
339 | 0 | AutoJSAPI jsapi; |
340 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
341 | 0 | if (!cleanGlobal) { |
342 | 0 | return false; |
343 | 0 | } |
344 | 0 | if (!jsapi.Init(cleanGlobal)) { |
345 | 0 | return false; |
346 | 0 | } |
347 | 0 | JSContext* cx = jsapi.cx(); |
348 | 0 | JS::Rooted<JS::Value> json(cx); |
349 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
350 | 0 | NS_ENSURE_TRUE(ok, false); |
351 | 0 | return Init(cx, json); |
352 | 0 | } |
353 | | |
354 | | bool |
355 | | RTCRtpSynchronizationSource::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
356 | 0 | { |
357 | 0 | RTCRtpSynchronizationSourceAtoms* atomsCache = GetAtomCache<RTCRtpSynchronizationSourceAtoms>(cx); |
358 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
359 | 0 | return false; |
360 | 0 | } |
361 | 0 | |
362 | 0 | // Per spec, we define the parent's members first |
363 | 0 | if (!RTCRtpContributingSource::ToObjectInternal(cx, rval)) { |
364 | 0 | return false; |
365 | 0 | } |
366 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
367 | 0 |
|
368 | 0 | if (mVoiceActivityFlag.WasPassed()) { |
369 | 0 | do { |
370 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
371 | 0 | JS::Rooted<JS::Value> temp(cx); |
372 | 0 | Nullable<bool> const & currentValue = mVoiceActivityFlag.InternalValue(); |
373 | 0 | if (currentValue.IsNull()) { |
374 | 0 | temp.setNull(); |
375 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->voiceActivityFlag_id, temp, JSPROP_ENUMERATE)) { |
376 | 0 | return false; |
377 | 0 | } |
378 | 0 | break; |
379 | 0 | } |
380 | 0 | temp.setBoolean(currentValue.Value()); |
381 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->voiceActivityFlag_id, temp, JSPROP_ENUMERATE)) { |
382 | 0 | return false; |
383 | 0 | } |
384 | 0 | break; |
385 | 0 | } while(false); |
386 | 0 | } |
387 | 0 |
|
388 | 0 | return true; |
389 | 0 | } |
390 | | |
391 | | bool |
392 | | RTCRtpSynchronizationSource::ToJSON(nsAString& aJSON) const |
393 | 0 | { |
394 | 0 | AutoJSAPI jsapi; |
395 | 0 | jsapi.Init(); |
396 | 0 | JSContext *cx = jsapi.cx(); |
397 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
398 | 0 | // because we'll only be creating objects, in ways that have no |
399 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
400 | 0 | // which likewise guarantees no side-effects for the sorts of |
401 | 0 | // things we will pass it. |
402 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
403 | 0 | JS::Rooted<JS::Value> val(cx); |
404 | 0 | if (!ToObjectInternal(cx, &val)) { |
405 | 0 | return false; |
406 | 0 | } |
407 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
408 | 0 | return StringifyToJSON(cx, obj, aJSON); |
409 | 0 | } |
410 | | |
411 | | void |
412 | | RTCRtpSynchronizationSource::TraceDictionary(JSTracer* trc) |
413 | 0 | { |
414 | 0 | RTCRtpContributingSource::TraceDictionary(trc); |
415 | 0 | } |
416 | | |
417 | | RTCRtpSynchronizationSource& |
418 | | RTCRtpSynchronizationSource::operator=(const RTCRtpSynchronizationSource& aOther) |
419 | 0 | { |
420 | 0 | RTCRtpContributingSource::operator=(aOther); |
421 | 0 | mVoiceActivityFlag.Reset(); |
422 | 0 | if (aOther.mVoiceActivityFlag.WasPassed()) { |
423 | 0 | mVoiceActivityFlag.Construct(aOther.mVoiceActivityFlag.Value()); |
424 | 0 | } |
425 | 0 | return *this; |
426 | 0 | } |
427 | | |
428 | | namespace binding_detail { |
429 | | } // namespace binding_detail |
430 | | |
431 | | |
432 | | |
433 | | RTCRtpSourceEntry::RTCRtpSourceEntry() |
434 | | : RTCRtpSynchronizationSource(FastDictionaryInitializer()) |
435 | 0 | { |
436 | 0 | // Safe to pass a null context if we pass a null value |
437 | 0 | Init(nullptr, JS::NullHandleValue); |
438 | 0 | } |
439 | | |
440 | | |
441 | | |
442 | | bool |
443 | | RTCRtpSourceEntry::InitIds(JSContext* cx, RTCRtpSourceEntryAtoms* atomsCache) |
444 | 0 | { |
445 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
446 | 0 |
|
447 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
448 | 0 | // uninitialized. |
449 | 0 | if (!atomsCache->sourceType_id.init(cx, "sourceType")) { |
450 | 0 | return false; |
451 | 0 | } |
452 | 0 | return true; |
453 | 0 | } |
454 | | |
455 | | bool |
456 | | RTCRtpSourceEntry::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
457 | 0 | { |
458 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
459 | 0 | // Since in that case we will not have to do any property gets |
460 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
461 | 0 | // checkers by static analysis tools |
462 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
463 | 0 | RTCRtpSourceEntryAtoms* atomsCache = nullptr; |
464 | 0 | if (cx) { |
465 | 0 | atomsCache = GetAtomCache<RTCRtpSourceEntryAtoms>(cx); |
466 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
467 | 0 | return false; |
468 | 0 | } |
469 | 0 | } |
470 | 0 | |
471 | 0 | // Per spec, we init the parent's members first |
472 | 0 | if (!RTCRtpSynchronizationSource::Init(cx, val)) { |
473 | 0 | return false; |
474 | 0 | } |
475 | 0 | |
476 | 0 | bool isNull = val.isNullOrUndefined(); |
477 | 0 | // We only need these if !isNull, in which case we have |cx|. |
478 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
479 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
480 | 0 | if (!isNull) { |
481 | 0 | MOZ_ASSERT(cx); |
482 | 0 | object.emplace(cx, &val.toObject()); |
483 | 0 | temp.emplace(cx); |
484 | 0 | } |
485 | 0 | if (!isNull) { |
486 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sourceType_id, temp.ptr())) { |
487 | 0 | return false; |
488 | 0 | } |
489 | 0 | } |
490 | 0 | if (!isNull && !temp->isUndefined()) { |
491 | 0 | { |
492 | 0 | int index; |
493 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), RTCRtpSourceEntryTypeValues::strings, "RTCRtpSourceEntryType", "'sourceType' member of RTCRtpSourceEntry", &index)) { |
494 | 0 | return false; |
495 | 0 | } |
496 | 0 | MOZ_ASSERT(index >= 0); |
497 | 0 | mSourceType = static_cast<RTCRtpSourceEntryType>(index); |
498 | 0 | } |
499 | 0 | mIsAnyMemberPresent = true; |
500 | 0 | } else if (cx) { |
501 | 0 | // Don't error out if we have no cx. In that |
502 | 0 | // situation the caller is default-constructing us and we'll |
503 | 0 | // just assume they know what they're doing. |
504 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
505 | 0 | "'sourceType' member of RTCRtpSourceEntry"); |
506 | 0 | } |
507 | 0 | return true; |
508 | 0 | } |
509 | | |
510 | | bool |
511 | | RTCRtpSourceEntry::Init(const nsAString& aJSON) |
512 | 0 | { |
513 | 0 | AutoJSAPI jsapi; |
514 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
515 | 0 | if (!cleanGlobal) { |
516 | 0 | return false; |
517 | 0 | } |
518 | 0 | if (!jsapi.Init(cleanGlobal)) { |
519 | 0 | return false; |
520 | 0 | } |
521 | 0 | JSContext* cx = jsapi.cx(); |
522 | 0 | JS::Rooted<JS::Value> json(cx); |
523 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
524 | 0 | NS_ENSURE_TRUE(ok, false); |
525 | 0 | return Init(cx, json); |
526 | 0 | } |
527 | | |
528 | | bool |
529 | | RTCRtpSourceEntry::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
530 | 0 | { |
531 | 0 | RTCRtpSourceEntryAtoms* atomsCache = GetAtomCache<RTCRtpSourceEntryAtoms>(cx); |
532 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
533 | 0 | return false; |
534 | 0 | } |
535 | 0 | |
536 | 0 | // Per spec, we define the parent's members first |
537 | 0 | if (!RTCRtpSynchronizationSource::ToObjectInternal(cx, rval)) { |
538 | 0 | return false; |
539 | 0 | } |
540 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
541 | 0 |
|
542 | 0 | do { |
543 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
544 | 0 | JS::Rooted<JS::Value> temp(cx); |
545 | 0 | RTCRtpSourceEntryType const & currentValue = mSourceType; |
546 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
547 | 0 | return false; |
548 | 0 | } |
549 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sourceType_id, temp, JSPROP_ENUMERATE)) { |
550 | 0 | return false; |
551 | 0 | } |
552 | 0 | break; |
553 | 0 | } while(false); |
554 | 0 |
|
555 | 0 | return true; |
556 | 0 | } |
557 | | |
558 | | bool |
559 | | RTCRtpSourceEntry::ToJSON(nsAString& aJSON) const |
560 | 0 | { |
561 | 0 | AutoJSAPI jsapi; |
562 | 0 | jsapi.Init(); |
563 | 0 | JSContext *cx = jsapi.cx(); |
564 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
565 | 0 | // because we'll only be creating objects, in ways that have no |
566 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
567 | 0 | // which likewise guarantees no side-effects for the sorts of |
568 | 0 | // things we will pass it. |
569 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
570 | 0 | JS::Rooted<JS::Value> val(cx); |
571 | 0 | if (!ToObjectInternal(cx, &val)) { |
572 | 0 | return false; |
573 | 0 | } |
574 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
575 | 0 | return StringifyToJSON(cx, obj, aJSON); |
576 | 0 | } |
577 | | |
578 | | void |
579 | | RTCRtpSourceEntry::TraceDictionary(JSTracer* trc) |
580 | 0 | { |
581 | 0 | RTCRtpSynchronizationSource::TraceDictionary(trc); |
582 | 0 | } |
583 | | |
584 | | RTCRtpSourceEntry& |
585 | | RTCRtpSourceEntry::operator=(const RTCRtpSourceEntry& aOther) |
586 | 0 | { |
587 | 0 | RTCRtpSynchronizationSource::operator=(aOther); |
588 | 0 | mSourceType = aOther.mSourceType; |
589 | 0 | return *this; |
590 | 0 | } |
591 | | |
592 | | namespace binding_detail { |
593 | | } // namespace binding_detail |
594 | | |
595 | | |
596 | | } // namespace dom |
597 | | } // namespace mozilla |