/work/obj-fuzz/dom/bindings/MediaKeySystemAccessBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MediaKeySystemAccess.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "MediaKeySystemAccessBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "jsapi.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/MediaKeySystemAccess.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/Promise.h" |
13 | | #include "mozilla/dom/ScriptSettings.h" |
14 | | #include "mozilla/dom/SimpleGlobalObject.h" |
15 | | #include "mozilla/dom/ToJSValue.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.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 MediaKeysRequirementValues { |
26 | | extern const EnumEntry strings[4] = { |
27 | | {"required", 8}, |
28 | | {"optional", 8}, |
29 | | {"not-allowed", 11}, |
30 | | { nullptr, 0 } |
31 | | }; |
32 | | } // namespace MediaKeysRequirementValues |
33 | | |
34 | | bool |
35 | | ToJSValue(JSContext* aCx, MediaKeysRequirement aArgument, JS::MutableHandle<JS::Value> aValue) |
36 | 0 | { |
37 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaKeysRequirementValues::strings)); |
38 | 0 | JSString* resultStr = |
39 | 0 | JS_NewStringCopyN(aCx, MediaKeysRequirementValues::strings[uint32_t(aArgument)].value, |
40 | 0 | MediaKeysRequirementValues::strings[uint32_t(aArgument)].length); |
41 | 0 | if (!resultStr) { |
42 | 0 | return false; |
43 | 0 | } |
44 | 0 | aValue.setString(resultStr); |
45 | 0 | return true; |
46 | 0 | } |
47 | | |
48 | | |
49 | | |
50 | | MediaKeySystemMediaCapability::MediaKeySystemMediaCapability() |
51 | 0 | { |
52 | 0 | // Safe to pass a null context if we pass a null value |
53 | 0 | Init(nullptr, JS::NullHandleValue); |
54 | 0 | } |
55 | | |
56 | | |
57 | | |
58 | | bool |
59 | | MediaKeySystemMediaCapability::InitIds(JSContext* cx, MediaKeySystemMediaCapabilityAtoms* atomsCache) |
60 | 0 | { |
61 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
62 | 0 |
|
63 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
64 | 0 | // uninitialized. |
65 | 0 | if (!atomsCache->robustness_id.init(cx, "robustness") || |
66 | 0 | !atomsCache->contentType_id.init(cx, "contentType")) { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | bool |
73 | | MediaKeySystemMediaCapability::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
74 | 0 | { |
75 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
76 | 0 | // Since in that case we will not have to do any property gets |
77 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
78 | 0 | // checkers by static analysis tools |
79 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
80 | 0 | MediaKeySystemMediaCapabilityAtoms* atomsCache = nullptr; |
81 | 0 | if (cx) { |
82 | 0 | atomsCache = GetAtomCache<MediaKeySystemMediaCapabilityAtoms>(cx); |
83 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
84 | 0 | return false; |
85 | 0 | } |
86 | 0 | } |
87 | 0 | |
88 | 0 | if (!IsConvertibleToDictionary(val)) { |
89 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
90 | 0 | } |
91 | 0 | |
92 | 0 | bool isNull = val.isNullOrUndefined(); |
93 | 0 | // We only need these if !isNull, in which case we have |cx|. |
94 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
95 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
96 | 0 | if (!isNull) { |
97 | 0 | MOZ_ASSERT(cx); |
98 | 0 | object.emplace(cx, &val.toObject()); |
99 | 0 | temp.emplace(cx); |
100 | 0 | } |
101 | 0 | if (!isNull) { |
102 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->contentType_id, temp.ptr())) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | if (!isNull && !temp->isUndefined()) { |
107 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mContentType)) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | } else { |
111 | 0 | static const char16_t data[] = { 0 }; |
112 | 0 | mContentType.Rebind(data, ArrayLength(data) - 1); |
113 | 0 | } |
114 | 0 | mIsAnyMemberPresent = true; |
115 | 0 |
|
116 | 0 | if (!isNull) { |
117 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->robustness_id, temp.ptr())) { |
118 | 0 | return false; |
119 | 0 | } |
120 | 0 | } |
121 | 0 | if (!isNull && !temp->isUndefined()) { |
122 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mRobustness)) { |
123 | 0 | return false; |
124 | 0 | } |
125 | 0 | } else { |
126 | 0 | static const char16_t data[] = { 0 }; |
127 | 0 | mRobustness.Rebind(data, ArrayLength(data) - 1); |
128 | 0 | } |
129 | 0 | mIsAnyMemberPresent = true; |
130 | 0 | return true; |
131 | 0 | } |
132 | | |
133 | | bool |
134 | | MediaKeySystemMediaCapability::Init(const nsAString& aJSON) |
135 | 0 | { |
136 | 0 | AutoJSAPI jsapi; |
137 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
138 | 0 | if (!cleanGlobal) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | if (!jsapi.Init(cleanGlobal)) { |
142 | 0 | return false; |
143 | 0 | } |
144 | 0 | JSContext* cx = jsapi.cx(); |
145 | 0 | JS::Rooted<JS::Value> json(cx); |
146 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
147 | 0 | NS_ENSURE_TRUE(ok, false); |
148 | 0 | return Init(cx, json); |
149 | 0 | } |
150 | | |
151 | | bool |
152 | | MediaKeySystemMediaCapability::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
153 | 0 | { |
154 | 0 | MediaKeySystemMediaCapabilityAtoms* atomsCache = GetAtomCache<MediaKeySystemMediaCapabilityAtoms>(cx); |
155 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
156 | 0 | return false; |
157 | 0 | } |
158 | 0 | |
159 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
160 | 0 | if (!obj) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | rval.set(JS::ObjectValue(*obj)); |
164 | 0 |
|
165 | 0 | do { |
166 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
167 | 0 | JS::Rooted<JS::Value> temp(cx); |
168 | 0 | nsString const & currentValue = mContentType; |
169 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
170 | 0 | return false; |
171 | 0 | } |
172 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->contentType_id, temp, JSPROP_ENUMERATE)) { |
173 | 0 | return false; |
174 | 0 | } |
175 | 0 | break; |
176 | 0 | } while(false); |
177 | 0 |
|
178 | 0 | do { |
179 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
180 | 0 | JS::Rooted<JS::Value> temp(cx); |
181 | 0 | nsString const & currentValue = mRobustness; |
182 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->robustness_id, temp, JSPROP_ENUMERATE)) { |
186 | 0 | return false; |
187 | 0 | } |
188 | 0 | break; |
189 | 0 | } while(false); |
190 | 0 |
|
191 | 0 | return true; |
192 | 0 | } |
193 | | |
194 | | bool |
195 | | MediaKeySystemMediaCapability::ToJSON(nsAString& aJSON) const |
196 | 0 | { |
197 | 0 | AutoJSAPI jsapi; |
198 | 0 | jsapi.Init(); |
199 | 0 | JSContext *cx = jsapi.cx(); |
200 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
201 | 0 | // because we'll only be creating objects, in ways that have no |
202 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
203 | 0 | // which likewise guarantees no side-effects for the sorts of |
204 | 0 | // things we will pass it. |
205 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
206 | 0 | JS::Rooted<JS::Value> val(cx); |
207 | 0 | if (!ToObjectInternal(cx, &val)) { |
208 | 0 | return false; |
209 | 0 | } |
210 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
211 | 0 | return StringifyToJSON(cx, obj, aJSON); |
212 | 0 | } |
213 | | |
214 | | void |
215 | | MediaKeySystemMediaCapability::TraceDictionary(JSTracer* trc) |
216 | 0 | { |
217 | 0 | } |
218 | | |
219 | | MediaKeySystemMediaCapability& |
220 | | MediaKeySystemMediaCapability::operator=(const MediaKeySystemMediaCapability& aOther) |
221 | 0 | { |
222 | 0 | DictionaryBase::operator=(aOther); |
223 | 0 | mContentType = aOther.mContentType; |
224 | 0 | mRobustness = aOther.mRobustness; |
225 | 0 | return *this; |
226 | 0 | } |
227 | | |
228 | | namespace binding_detail { |
229 | | } // namespace binding_detail |
230 | | |
231 | | |
232 | | |
233 | | MediaKeySystemConfiguration::MediaKeySystemConfiguration() |
234 | 0 | { |
235 | 0 | // Safe to pass a null context if we pass a null value |
236 | 0 | Init(nullptr, JS::NullHandleValue); |
237 | 0 | } |
238 | | |
239 | | |
240 | | |
241 | | bool |
242 | | MediaKeySystemConfiguration::InitIds(JSContext* cx, MediaKeySystemConfigurationAtoms* atomsCache) |
243 | 0 | { |
244 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
245 | 0 |
|
246 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
247 | 0 | // uninitialized. |
248 | 0 | if (!atomsCache->videoCapabilities_id.init(cx, "videoCapabilities") || |
249 | 0 | !atomsCache->sessionTypes_id.init(cx, "sessionTypes") || |
250 | 0 | !atomsCache->persistentState_id.init(cx, "persistentState") || |
251 | 0 | !atomsCache->label_id.init(cx, "label") || |
252 | 0 | !atomsCache->initDataTypes_id.init(cx, "initDataTypes") || |
253 | 0 | !atomsCache->distinctiveIdentifier_id.init(cx, "distinctiveIdentifier") || |
254 | 0 | !atomsCache->audioCapabilities_id.init(cx, "audioCapabilities")) { |
255 | 0 | return false; |
256 | 0 | } |
257 | 0 | return true; |
258 | 0 | } |
259 | | |
260 | | bool |
261 | | MediaKeySystemConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
262 | 0 | { |
263 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
264 | 0 | // Since in that case we will not have to do any property gets |
265 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
266 | 0 | // checkers by static analysis tools |
267 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
268 | 0 | MediaKeySystemConfigurationAtoms* atomsCache = nullptr; |
269 | 0 | if (cx) { |
270 | 0 | atomsCache = GetAtomCache<MediaKeySystemConfigurationAtoms>(cx); |
271 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
272 | 0 | return false; |
273 | 0 | } |
274 | 0 | } |
275 | 0 | |
276 | 0 | if (!IsConvertibleToDictionary(val)) { |
277 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
278 | 0 | } |
279 | 0 | |
280 | 0 | bool isNull = val.isNullOrUndefined(); |
281 | 0 | // We only need these if !isNull, in which case we have |cx|. |
282 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
283 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
284 | 0 | if (!isNull) { |
285 | 0 | MOZ_ASSERT(cx); |
286 | 0 | object.emplace(cx, &val.toObject()); |
287 | 0 | temp.emplace(cx); |
288 | 0 | } |
289 | 0 | if (!isNull) { |
290 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->audioCapabilities_id, temp.ptr())) { |
291 | 0 | return false; |
292 | 0 | } |
293 | 0 | } |
294 | 0 | if (!isNull && !temp->isUndefined()) { |
295 | 0 | if (temp.ref().isObject()) { |
296 | 0 | JS::ForOfIterator iter(cx); |
297 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
298 | 0 | return false; |
299 | 0 | } |
300 | 0 | if (!iter.valueIsIterable()) { |
301 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'audioCapabilities' member of MediaKeySystemConfiguration"); |
302 | 0 | return false; |
303 | 0 | } |
304 | 0 | Sequence<MediaKeySystemMediaCapability> &arr = mAudioCapabilities; |
305 | 0 | JS::Rooted<JS::Value> temp(cx); |
306 | 0 | while (true) { |
307 | 0 | bool done; |
308 | 0 | if (!iter.next(&temp, &done)) { |
309 | 0 | return false; |
310 | 0 | } |
311 | 0 | if (done) { |
312 | 0 | break; |
313 | 0 | } |
314 | 0 | MediaKeySystemMediaCapability* slotPtr = arr.AppendElement(mozilla::fallible); |
315 | 0 | if (!slotPtr) { |
316 | 0 | JS_ReportOutOfMemory(cx); |
317 | 0 | return false; |
318 | 0 | } |
319 | 0 | MediaKeySystemMediaCapability& slot = *slotPtr; |
320 | 0 | if (!slot.Init(cx, temp, "Element of 'audioCapabilities' member of MediaKeySystemConfiguration", passedToJSImpl)) { |
321 | 0 | return false; |
322 | 0 | } |
323 | 0 | } |
324 | 0 | } else { |
325 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'audioCapabilities' member of MediaKeySystemConfiguration"); |
326 | 0 | return false; |
327 | 0 | } |
328 | 0 | } else { |
329 | 0 | /* Array is already empty; nothing to do */ |
330 | 0 | } |
331 | 0 | mIsAnyMemberPresent = true; |
332 | 0 |
|
333 | 0 | if (!isNull) { |
334 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->distinctiveIdentifier_id, temp.ptr())) { |
335 | 0 | return false; |
336 | 0 | } |
337 | 0 | } |
338 | 0 | if (!isNull && !temp->isUndefined()) { |
339 | 0 | { |
340 | 0 | int index; |
341 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaKeysRequirementValues::strings, "MediaKeysRequirement", "'distinctiveIdentifier' member of MediaKeySystemConfiguration", &index)) { |
342 | 0 | return false; |
343 | 0 | } |
344 | 0 | MOZ_ASSERT(index >= 0); |
345 | 0 | mDistinctiveIdentifier = static_cast<MediaKeysRequirement>(index); |
346 | 0 | } |
347 | 0 | } else { |
348 | 0 | mDistinctiveIdentifier = MediaKeysRequirement::Optional; |
349 | 0 | } |
350 | 0 | mIsAnyMemberPresent = true; |
351 | 0 |
|
352 | 0 | if (!isNull) { |
353 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->initDataTypes_id, temp.ptr())) { |
354 | 0 | return false; |
355 | 0 | } |
356 | 0 | } |
357 | 0 | if (!isNull && !temp->isUndefined()) { |
358 | 0 | if (temp.ref().isObject()) { |
359 | 0 | JS::ForOfIterator iter(cx); |
360 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
361 | 0 | return false; |
362 | 0 | } |
363 | 0 | if (!iter.valueIsIterable()) { |
364 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'initDataTypes' member of MediaKeySystemConfiguration"); |
365 | 0 | return false; |
366 | 0 | } |
367 | 0 | Sequence<nsString> &arr = mInitDataTypes; |
368 | 0 | JS::Rooted<JS::Value> temp(cx); |
369 | 0 | while (true) { |
370 | 0 | bool done; |
371 | 0 | if (!iter.next(&temp, &done)) { |
372 | 0 | return false; |
373 | 0 | } |
374 | 0 | if (done) { |
375 | 0 | break; |
376 | 0 | } |
377 | 0 | nsString* slotPtr = arr.AppendElement(mozilla::fallible); |
378 | 0 | if (!slotPtr) { |
379 | 0 | JS_ReportOutOfMemory(cx); |
380 | 0 | return false; |
381 | 0 | } |
382 | 0 | nsString& slot = *slotPtr; |
383 | 0 | if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { |
384 | 0 | return false; |
385 | 0 | } |
386 | 0 | } |
387 | 0 | } else { |
388 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'initDataTypes' member of MediaKeySystemConfiguration"); |
389 | 0 | return false; |
390 | 0 | } |
391 | 0 | } else { |
392 | 0 | /* Array is already empty; nothing to do */ |
393 | 0 | } |
394 | 0 | mIsAnyMemberPresent = true; |
395 | 0 |
|
396 | 0 | if (!isNull) { |
397 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->label_id, temp.ptr())) { |
398 | 0 | return false; |
399 | 0 | } |
400 | 0 | } |
401 | 0 | if (!isNull && !temp->isUndefined()) { |
402 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLabel)) { |
403 | 0 | return false; |
404 | 0 | } |
405 | 0 | } else { |
406 | 0 | static const char16_t data[] = { 0 }; |
407 | 0 | mLabel.Rebind(data, ArrayLength(data) - 1); |
408 | 0 | } |
409 | 0 | mIsAnyMemberPresent = true; |
410 | 0 |
|
411 | 0 | if (!isNull) { |
412 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->persistentState_id, temp.ptr())) { |
413 | 0 | return false; |
414 | 0 | } |
415 | 0 | } |
416 | 0 | if (!isNull && !temp->isUndefined()) { |
417 | 0 | { |
418 | 0 | int index; |
419 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaKeysRequirementValues::strings, "MediaKeysRequirement", "'persistentState' member of MediaKeySystemConfiguration", &index)) { |
420 | 0 | return false; |
421 | 0 | } |
422 | 0 | MOZ_ASSERT(index >= 0); |
423 | 0 | mPersistentState = static_cast<MediaKeysRequirement>(index); |
424 | 0 | } |
425 | 0 | } else { |
426 | 0 | mPersistentState = MediaKeysRequirement::Optional; |
427 | 0 | } |
428 | 0 | mIsAnyMemberPresent = true; |
429 | 0 |
|
430 | 0 | if (!isNull) { |
431 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sessionTypes_id, temp.ptr())) { |
432 | 0 | return false; |
433 | 0 | } |
434 | 0 | } |
435 | 0 | if (!isNull && !temp->isUndefined()) { |
436 | 0 | mSessionTypes.Construct(); |
437 | 0 | if (temp.ref().isObject()) { |
438 | 0 | JS::ForOfIterator iter(cx); |
439 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
440 | 0 | return false; |
441 | 0 | } |
442 | 0 | if (!iter.valueIsIterable()) { |
443 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'sessionTypes' member of MediaKeySystemConfiguration"); |
444 | 0 | return false; |
445 | 0 | } |
446 | 0 | Sequence<nsString> &arr = (mSessionTypes.Value()); |
447 | 0 | JS::Rooted<JS::Value> temp(cx); |
448 | 0 | while (true) { |
449 | 0 | bool done; |
450 | 0 | if (!iter.next(&temp, &done)) { |
451 | 0 | return false; |
452 | 0 | } |
453 | 0 | if (done) { |
454 | 0 | break; |
455 | 0 | } |
456 | 0 | nsString* slotPtr = arr.AppendElement(mozilla::fallible); |
457 | 0 | if (!slotPtr) { |
458 | 0 | JS_ReportOutOfMemory(cx); |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | nsString& slot = *slotPtr; |
462 | 0 | if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 0 | } |
466 | 0 | } else { |
467 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'sessionTypes' member of MediaKeySystemConfiguration"); |
468 | 0 | return false; |
469 | 0 | } |
470 | 0 | mIsAnyMemberPresent = true; |
471 | 0 | } |
472 | 0 |
|
473 | 0 | if (!isNull) { |
474 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->videoCapabilities_id, temp.ptr())) { |
475 | 0 | return false; |
476 | 0 | } |
477 | 0 | } |
478 | 0 | if (!isNull && !temp->isUndefined()) { |
479 | 0 | if (temp.ref().isObject()) { |
480 | 0 | JS::ForOfIterator iter(cx); |
481 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
482 | 0 | return false; |
483 | 0 | } |
484 | 0 | if (!iter.valueIsIterable()) { |
485 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'videoCapabilities' member of MediaKeySystemConfiguration"); |
486 | 0 | return false; |
487 | 0 | } |
488 | 0 | Sequence<MediaKeySystemMediaCapability> &arr = mVideoCapabilities; |
489 | 0 | JS::Rooted<JS::Value> temp(cx); |
490 | 0 | while (true) { |
491 | 0 | bool done; |
492 | 0 | if (!iter.next(&temp, &done)) { |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | if (done) { |
496 | 0 | break; |
497 | 0 | } |
498 | 0 | MediaKeySystemMediaCapability* slotPtr = arr.AppendElement(mozilla::fallible); |
499 | 0 | if (!slotPtr) { |
500 | 0 | JS_ReportOutOfMemory(cx); |
501 | 0 | return false; |
502 | 0 | } |
503 | 0 | MediaKeySystemMediaCapability& slot = *slotPtr; |
504 | 0 | if (!slot.Init(cx, temp, "Element of 'videoCapabilities' member of MediaKeySystemConfiguration", passedToJSImpl)) { |
505 | 0 | return false; |
506 | 0 | } |
507 | 0 | } |
508 | 0 | } else { |
509 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'videoCapabilities' member of MediaKeySystemConfiguration"); |
510 | 0 | return false; |
511 | 0 | } |
512 | 0 | } else { |
513 | 0 | /* Array is already empty; nothing to do */ |
514 | 0 | } |
515 | 0 | mIsAnyMemberPresent = true; |
516 | 0 | return true; |
517 | 0 | } |
518 | | |
519 | | bool |
520 | | MediaKeySystemConfiguration::Init(const nsAString& aJSON) |
521 | 0 | { |
522 | 0 | AutoJSAPI jsapi; |
523 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
524 | 0 | if (!cleanGlobal) { |
525 | 0 | return false; |
526 | 0 | } |
527 | 0 | if (!jsapi.Init(cleanGlobal)) { |
528 | 0 | return false; |
529 | 0 | } |
530 | 0 | JSContext* cx = jsapi.cx(); |
531 | 0 | JS::Rooted<JS::Value> json(cx); |
532 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
533 | 0 | NS_ENSURE_TRUE(ok, false); |
534 | 0 | return Init(cx, json); |
535 | 0 | } |
536 | | |
537 | | bool |
538 | | MediaKeySystemConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
539 | 0 | { |
540 | 0 | MediaKeySystemConfigurationAtoms* atomsCache = GetAtomCache<MediaKeySystemConfigurationAtoms>(cx); |
541 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
542 | 0 | return false; |
543 | 0 | } |
544 | 0 | |
545 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
546 | 0 | if (!obj) { |
547 | 0 | return false; |
548 | 0 | } |
549 | 0 | rval.set(JS::ObjectValue(*obj)); |
550 | 0 |
|
551 | 0 | do { |
552 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
553 | 0 | JS::Rooted<JS::Value> temp(cx); |
554 | 0 | Sequence<MediaKeySystemMediaCapability> const & currentValue = mAudioCapabilities; |
555 | 0 |
|
556 | 0 | uint32_t length = currentValue.Length(); |
557 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
558 | 0 | if (!returnArray) { |
559 | 0 | return false; |
560 | 0 | } |
561 | 0 | // Scope for 'tmp' |
562 | 0 | { |
563 | 0 | JS::Rooted<JS::Value> tmp(cx); |
564 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
565 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
566 | 0 | // are different ways to succeed at wrapping the object. |
567 | 0 | do { |
568 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | break; |
572 | 0 | } while (false); |
573 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
574 | 0 | JSPROP_ENUMERATE)) { |
575 | 0 | return false; |
576 | 0 | } |
577 | 0 | } |
578 | 0 | } |
579 | 0 | temp.setObject(*returnArray); |
580 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->audioCapabilities_id, temp, JSPROP_ENUMERATE)) { |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | break; |
584 | 0 | } while(false); |
585 | 0 |
|
586 | 0 | do { |
587 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
588 | 0 | JS::Rooted<JS::Value> temp(cx); |
589 | 0 | MediaKeysRequirement const & currentValue = mDistinctiveIdentifier; |
590 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
591 | 0 | return false; |
592 | 0 | } |
593 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->distinctiveIdentifier_id, temp, JSPROP_ENUMERATE)) { |
594 | 0 | return false; |
595 | 0 | } |
596 | 0 | break; |
597 | 0 | } while(false); |
598 | 0 |
|
599 | 0 | do { |
600 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
601 | 0 | JS::Rooted<JS::Value> temp(cx); |
602 | 0 | Sequence<nsString> const & currentValue = mInitDataTypes; |
603 | 0 |
|
604 | 0 | uint32_t length = currentValue.Length(); |
605 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
606 | 0 | if (!returnArray) { |
607 | 0 | return false; |
608 | 0 | } |
609 | 0 | // Scope for 'tmp' |
610 | 0 | { |
611 | 0 | JS::Rooted<JS::Value> tmp(cx); |
612 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
613 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
614 | 0 | // are different ways to succeed at wrapping the object. |
615 | 0 | do { |
616 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) { |
617 | 0 | return false; |
618 | 0 | } |
619 | 0 | break; |
620 | 0 | } while (false); |
621 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
622 | 0 | JSPROP_ENUMERATE)) { |
623 | 0 | return false; |
624 | 0 | } |
625 | 0 | } |
626 | 0 | } |
627 | 0 | temp.setObject(*returnArray); |
628 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->initDataTypes_id, temp, JSPROP_ENUMERATE)) { |
629 | 0 | return false; |
630 | 0 | } |
631 | 0 | break; |
632 | 0 | } while(false); |
633 | 0 |
|
634 | 0 | do { |
635 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
636 | 0 | JS::Rooted<JS::Value> temp(cx); |
637 | 0 | nsString const & currentValue = mLabel; |
638 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
639 | 0 | return false; |
640 | 0 | } |
641 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->label_id, temp, JSPROP_ENUMERATE)) { |
642 | 0 | return false; |
643 | 0 | } |
644 | 0 | break; |
645 | 0 | } while(false); |
646 | 0 |
|
647 | 0 | do { |
648 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
649 | 0 | JS::Rooted<JS::Value> temp(cx); |
650 | 0 | MediaKeysRequirement const & currentValue = mPersistentState; |
651 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
652 | 0 | return false; |
653 | 0 | } |
654 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->persistentState_id, temp, JSPROP_ENUMERATE)) { |
655 | 0 | return false; |
656 | 0 | } |
657 | 0 | break; |
658 | 0 | } while(false); |
659 | 0 |
|
660 | 0 | if (mSessionTypes.WasPassed()) { |
661 | 0 | do { |
662 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
663 | 0 | JS::Rooted<JS::Value> temp(cx); |
664 | 0 | Sequence<nsString> const & currentValue = mSessionTypes.InternalValue(); |
665 | 0 |
|
666 | 0 | uint32_t length = currentValue.Length(); |
667 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
668 | 0 | if (!returnArray) { |
669 | 0 | return false; |
670 | 0 | } |
671 | 0 | // Scope for 'tmp' |
672 | 0 | { |
673 | 0 | JS::Rooted<JS::Value> tmp(cx); |
674 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
675 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
676 | 0 | // are different ways to succeed at wrapping the object. |
677 | 0 | do { |
678 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) { |
679 | 0 | return false; |
680 | 0 | } |
681 | 0 | break; |
682 | 0 | } while (false); |
683 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
684 | 0 | JSPROP_ENUMERATE)) { |
685 | 0 | return false; |
686 | 0 | } |
687 | 0 | } |
688 | 0 | } |
689 | 0 | temp.setObject(*returnArray); |
690 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sessionTypes_id, temp, JSPROP_ENUMERATE)) { |
691 | 0 | return false; |
692 | 0 | } |
693 | 0 | break; |
694 | 0 | } while(false); |
695 | 0 | } |
696 | 0 |
|
697 | 0 | do { |
698 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
699 | 0 | JS::Rooted<JS::Value> temp(cx); |
700 | 0 | Sequence<MediaKeySystemMediaCapability> const & currentValue = mVideoCapabilities; |
701 | 0 |
|
702 | 0 | uint32_t length = currentValue.Length(); |
703 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
704 | 0 | if (!returnArray) { |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | // Scope for 'tmp' |
708 | 0 | { |
709 | 0 | JS::Rooted<JS::Value> tmp(cx); |
710 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
711 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
712 | 0 | // are different ways to succeed at wrapping the object. |
713 | 0 | do { |
714 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
715 | 0 | return false; |
716 | 0 | } |
717 | 0 | break; |
718 | 0 | } while (false); |
719 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
720 | 0 | JSPROP_ENUMERATE)) { |
721 | 0 | return false; |
722 | 0 | } |
723 | 0 | } |
724 | 0 | } |
725 | 0 | temp.setObject(*returnArray); |
726 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->videoCapabilities_id, temp, JSPROP_ENUMERATE)) { |
727 | 0 | return false; |
728 | 0 | } |
729 | 0 | break; |
730 | 0 | } while(false); |
731 | 0 |
|
732 | 0 | return true; |
733 | 0 | } |
734 | | |
735 | | bool |
736 | | MediaKeySystemConfiguration::ToJSON(nsAString& aJSON) const |
737 | 0 | { |
738 | 0 | AutoJSAPI jsapi; |
739 | 0 | jsapi.Init(); |
740 | 0 | JSContext *cx = jsapi.cx(); |
741 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
742 | 0 | // because we'll only be creating objects, in ways that have no |
743 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
744 | 0 | // which likewise guarantees no side-effects for the sorts of |
745 | 0 | // things we will pass it. |
746 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
747 | 0 | JS::Rooted<JS::Value> val(cx); |
748 | 0 | if (!ToObjectInternal(cx, &val)) { |
749 | 0 | return false; |
750 | 0 | } |
751 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
752 | 0 | return StringifyToJSON(cx, obj, aJSON); |
753 | 0 | } |
754 | | |
755 | | void |
756 | | MediaKeySystemConfiguration::TraceDictionary(JSTracer* trc) |
757 | 0 | { |
758 | 0 | } |
759 | | |
760 | | MediaKeySystemConfiguration& |
761 | | MediaKeySystemConfiguration::operator=(const MediaKeySystemConfiguration& aOther) |
762 | 0 | { |
763 | 0 | DictionaryBase::operator=(aOther); |
764 | 0 | mAudioCapabilities = aOther.mAudioCapabilities; |
765 | 0 | mDistinctiveIdentifier = aOther.mDistinctiveIdentifier; |
766 | 0 | mInitDataTypes = aOther.mInitDataTypes; |
767 | 0 | mLabel = aOther.mLabel; |
768 | 0 | mPersistentState = aOther.mPersistentState; |
769 | 0 | mSessionTypes.Reset(); |
770 | 0 | if (aOther.mSessionTypes.WasPassed()) { |
771 | 0 | mSessionTypes.Construct(aOther.mSessionTypes.Value()); |
772 | 0 | } |
773 | 0 | mVideoCapabilities = aOther.mVideoCapabilities; |
774 | 0 | return *this; |
775 | 0 | } |
776 | | |
777 | | namespace binding_detail { |
778 | | } // namespace binding_detail |
779 | | |
780 | | |
781 | | namespace MediaKeySystemAccess_Binding { |
782 | | |
783 | | MOZ_CAN_RUN_SCRIPT static bool |
784 | | get_keySystem(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeySystemAccess* self, JSJitGetterCallArgs args) |
785 | 0 | { |
786 | 0 | AUTO_PROFILER_LABEL_FAST("get MediaKeySystemAccess.keySystem", DOM, cx); |
787 | 0 |
|
788 | 0 | DOMString result; |
789 | 0 | self->GetKeySystem(result); |
790 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
791 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
792 | 0 | return false; |
793 | 0 | } |
794 | 0 | return true; |
795 | 0 | } |
796 | | |
797 | | static const JSJitInfo keySystem_getterinfo = { |
798 | | { (JSJitGetterOp)get_keySystem }, |
799 | | { prototypes::id::MediaKeySystemAccess }, |
800 | | { PrototypeTraits<prototypes::id::MediaKeySystemAccess>::Depth }, |
801 | | JSJitInfo::Getter, |
802 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
803 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
804 | | false, /* isInfallible. False in setters. */ |
805 | | false, /* isMovable. Not relevant for setters. */ |
806 | | false, /* isEliminatable. Not relevant for setters. */ |
807 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
808 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
809 | | false, /* isTypedMethod. Only relevant for methods. */ |
810 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
811 | | }; |
812 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
813 | | static_assert(0 < 1, "There is no slot for us"); |
814 | | |
815 | | MOZ_CAN_RUN_SCRIPT static bool |
816 | | getConfiguration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeySystemAccess* self, const JSJitMethodCallArgs& args) |
817 | 0 | { |
818 | 0 | AUTO_PROFILER_LABEL_FAST("MediaKeySystemAccess.getConfiguration", DOM, cx); |
819 | 0 |
|
820 | 0 | MediaKeySystemConfiguration result; |
821 | 0 | self->GetConfiguration(result); |
822 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
823 | 0 | if (!result.ToObjectInternal(cx, args.rval())) { |
824 | 0 | return false; |
825 | 0 | } |
826 | 0 | return true; |
827 | 0 | } |
828 | | |
829 | | static const JSJitInfo getConfiguration_methodinfo = { |
830 | | { (JSJitGetterOp)getConfiguration }, |
831 | | { prototypes::id::MediaKeySystemAccess }, |
832 | | { PrototypeTraits<prototypes::id::MediaKeySystemAccess>::Depth }, |
833 | | JSJitInfo::Method, |
834 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
835 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
836 | | false, /* isInfallible. False in setters. */ |
837 | | false, /* isMovable. Not relevant for setters. */ |
838 | | false, /* isEliminatable. Not relevant for setters. */ |
839 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
840 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
841 | | false, /* isTypedMethod. Only relevant for methods. */ |
842 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
843 | | }; |
844 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
845 | | static_assert(0 < 1, "There is no slot for us"); |
846 | | |
847 | | MOZ_CAN_RUN_SCRIPT static bool |
848 | | createMediaKeys(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeySystemAccess* self, const JSJitMethodCallArgs& args) |
849 | 0 | { |
850 | 0 | AUTO_PROFILER_LABEL_FAST("MediaKeySystemAccess.createMediaKeys", DOM, cx); |
851 | 0 |
|
852 | 0 | FastErrorResult rv; |
853 | 0 | auto result(StrongOrRawPtr<Promise>(self->CreateMediaKeys(rv))); |
854 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
855 | 0 | return false; |
856 | 0 | } |
857 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
858 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
859 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
860 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
861 | 0 | return false; |
862 | 0 | } |
863 | 0 | return true; |
864 | 0 | } |
865 | | |
866 | | MOZ_CAN_RUN_SCRIPT static bool |
867 | | createMediaKeys_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeySystemAccess* self, const JSJitMethodCallArgs& args) |
868 | 0 | { |
869 | 0 | bool ok = createMediaKeys(cx, obj, self, args); |
870 | 0 | if (ok) { |
871 | 0 | return true; |
872 | 0 | } |
873 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
874 | 0 | } |
875 | | |
876 | | static const JSJitInfo createMediaKeys_methodinfo = { |
877 | | { (JSJitGetterOp)createMediaKeys_promiseWrapper }, |
878 | | { prototypes::id::MediaKeySystemAccess }, |
879 | | { PrototypeTraits<prototypes::id::MediaKeySystemAccess>::Depth }, |
880 | | JSJitInfo::Method, |
881 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
882 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
883 | | false, /* isInfallible. False in setters. */ |
884 | | false, /* isMovable. Not relevant for setters. */ |
885 | | false, /* isEliminatable. Not relevant for setters. */ |
886 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
887 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
888 | | false, /* isTypedMethod. Only relevant for methods. */ |
889 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
890 | | }; |
891 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
892 | | static_assert(0 < 1, "There is no slot for us"); |
893 | | |
894 | | static bool |
895 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
896 | 0 | { |
897 | 0 | mozilla::dom::MediaKeySystemAccess* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeySystemAccess>(obj); |
898 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
899 | 0 | // obviously can't preserve if we're not initialized. |
900 | 0 | if (self && self->GetWrapperPreserveColor()) { |
901 | 0 | PreserveWrapper(self); |
902 | 0 | } |
903 | 0 | return true; |
904 | 0 | } |
905 | | |
906 | | static void |
907 | | _finalize(js::FreeOp* fop, JSObject* obj) |
908 | 0 | { |
909 | 0 | mozilla::dom::MediaKeySystemAccess* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeySystemAccess>(obj); |
910 | 0 | if (self) { |
911 | 0 | ClearWrapper(self, self, obj); |
912 | 0 | AddForDeferredFinalization<mozilla::dom::MediaKeySystemAccess>(self); |
913 | 0 | } |
914 | 0 | } |
915 | | |
916 | | static size_t |
917 | | _objectMoved(JSObject* obj, JSObject* old) |
918 | 0 | { |
919 | 0 | mozilla::dom::MediaKeySystemAccess* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeySystemAccess>(obj); |
920 | 0 | if (self) { |
921 | 0 | UpdateWrapper(self, self, obj, old); |
922 | 0 | } |
923 | 0 |
|
924 | 0 | return 0; |
925 | 0 | } |
926 | | |
927 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
928 | | #if defined(__clang__) |
929 | | #pragma clang diagnostic push |
930 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
931 | | #endif |
932 | | static const JSFunctionSpec sMethods_specs[] = { |
933 | | JS_FNSPEC("getConfiguration", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getConfiguration_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
934 | | JS_FNSPEC("createMediaKeys", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&createMediaKeys_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
935 | | JS_FS_END |
936 | | }; |
937 | | #if defined(__clang__) |
938 | | #pragma clang diagnostic pop |
939 | | #endif |
940 | | |
941 | | |
942 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
943 | | { nullptr, &sMethods_specs[0] }, |
944 | | { nullptr, nullptr } |
945 | | }; |
946 | | |
947 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
948 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
949 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
950 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
951 | | |
952 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
953 | | #if defined(__clang__) |
954 | | #pragma clang diagnostic push |
955 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
956 | | #endif |
957 | | static const JSPropertySpec sAttributes_specs[] = { |
958 | | { "keySystem", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &keySystem_getterinfo, nullptr, nullptr }, |
959 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
960 | | }; |
961 | | #if defined(__clang__) |
962 | | #pragma clang diagnostic pop |
963 | | #endif |
964 | | |
965 | | |
966 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
967 | | { nullptr, &sAttributes_specs[0] }, |
968 | | { nullptr, nullptr } |
969 | | }; |
970 | | |
971 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
972 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
973 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
974 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
975 | | |
976 | | |
977 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
978 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
979 | | |
980 | | static const NativePropertiesN<2> sNativeProperties = { |
981 | | false, 0, |
982 | | false, 0, |
983 | | true, 0 /* sMethods */, |
984 | | true, 1 /* sAttributes */, |
985 | | false, 0, |
986 | | false, 0, |
987 | | false, 0, |
988 | | -1, |
989 | | 3, |
990 | | sNativeProperties_sortedPropertyIndices, |
991 | | { |
992 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
993 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
994 | | } |
995 | | }; |
996 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
997 | | "We have a property info count that is oversized"); |
998 | | |
999 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1000 | | { |
1001 | | "Function", |
1002 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1003 | | &sBoringInterfaceObjectClassClassOps, |
1004 | | JS_NULL_CLASS_SPEC, |
1005 | | JS_NULL_CLASS_EXT, |
1006 | | &sInterfaceObjectClassObjectOps |
1007 | | }, |
1008 | | eInterface, |
1009 | | true, |
1010 | | prototypes::id::MediaKeySystemAccess, |
1011 | | PrototypeTraits<prototypes::id::MediaKeySystemAccess>::Depth, |
1012 | | sNativePropertyHooks, |
1013 | | "function MediaKeySystemAccess() {\n [native code]\n}", |
1014 | | JS::GetRealmFunctionPrototype |
1015 | | }; |
1016 | | |
1017 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1018 | | { |
1019 | | "MediaKeySystemAccessPrototype", |
1020 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1021 | | JS_NULL_CLASS_OPS, |
1022 | | JS_NULL_CLASS_SPEC, |
1023 | | JS_NULL_CLASS_EXT, |
1024 | | JS_NULL_OBJECT_OPS |
1025 | | }, |
1026 | | eInterfacePrototype, |
1027 | | false, |
1028 | | prototypes::id::MediaKeySystemAccess, |
1029 | | PrototypeTraits<prototypes::id::MediaKeySystemAccess>::Depth, |
1030 | | sNativePropertyHooks, |
1031 | | "[object MediaKeySystemAccessPrototype]", |
1032 | | JS::GetRealmObjectPrototype |
1033 | | }; |
1034 | | |
1035 | | static const js::ClassOps sClassOps = { |
1036 | | _addProperty, /* addProperty */ |
1037 | | nullptr, /* delProperty */ |
1038 | | nullptr, /* enumerate */ |
1039 | | nullptr, /* newEnumerate */ |
1040 | | nullptr, /* resolve */ |
1041 | | nullptr, /* mayResolve */ |
1042 | | _finalize, /* finalize */ |
1043 | | nullptr, /* call */ |
1044 | | nullptr, /* hasInstance */ |
1045 | | nullptr, /* construct */ |
1046 | | nullptr, /* trace */ |
1047 | | }; |
1048 | | |
1049 | | static const js::ClassExtension sClassExtension = { |
1050 | | nullptr, /* weakmapKeyDelegateOp */ |
1051 | | _objectMoved /* objectMovedOp */ |
1052 | | }; |
1053 | | |
1054 | | static const DOMJSClass sClass = { |
1055 | | { "MediaKeySystemAccess", |
1056 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1057 | | &sClassOps, |
1058 | | JS_NULL_CLASS_SPEC, |
1059 | | &sClassExtension, |
1060 | | JS_NULL_OBJECT_OPS |
1061 | | }, |
1062 | | { prototypes::id::MediaKeySystemAccess, 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 }, |
1063 | | IsBaseOf<nsISupports, mozilla::dom::MediaKeySystemAccess >::value, |
1064 | | sNativePropertyHooks, |
1065 | | FindAssociatedGlobalForNative<mozilla::dom::MediaKeySystemAccess>::Get, |
1066 | | GetProtoObjectHandle, |
1067 | | GetCCParticipant<mozilla::dom::MediaKeySystemAccess>::Get() |
1068 | | }; |
1069 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1070 | | "Must have the right minimal number of reserved slots."); |
1071 | | static_assert(1 >= 1, |
1072 | | "Must have enough reserved slots."); |
1073 | | |
1074 | | const JSClass* |
1075 | | GetJSClass() |
1076 | 0 | { |
1077 | 0 | return sClass.ToJSClass(); |
1078 | 0 | } |
1079 | | |
1080 | | bool |
1081 | | Wrap(JSContext* aCx, mozilla::dom::MediaKeySystemAccess* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1082 | 0 | { |
1083 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaKeySystemAccess>::value, |
1084 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1085 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MediaKeySystemAccess*>(aObject) == |
1086 | 0 | reinterpret_cast<mozilla::dom::MediaKeySystemAccess*>(aObject), |
1087 | 0 | "Multiple inheritance for mozilla::dom::MediaKeySystemAccess is broken."); |
1088 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1089 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1090 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1091 | 0 | "You should probably not be using Wrap() directly; use " |
1092 | 0 | "GetOrCreateDOMReflector instead"); |
1093 | 0 |
|
1094 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1095 | 0 | "nsISupports must be on our primary inheritance chain"); |
1096 | 0 |
|
1097 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1098 | 0 | if (!global) { |
1099 | 0 | return false; |
1100 | 0 | } |
1101 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1102 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1103 | 0 |
|
1104 | 0 | // That might have ended up wrapping us already, due to the wonders |
1105 | 0 | // of XBL. Check for that, and bail out as needed. |
1106 | 0 | aReflector.set(aCache->GetWrapper()); |
1107 | 0 | if (aReflector) { |
1108 | | #ifdef DEBUG |
1109 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1110 | | #endif // DEBUG |
1111 | | return true; |
1112 | 0 | } |
1113 | 0 |
|
1114 | 0 | JSAutoRealm ar(aCx, global); |
1115 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1116 | 0 | if (!canonicalProto) { |
1117 | 0 | return false; |
1118 | 0 | } |
1119 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1120 | 0 | if (aGivenProto) { |
1121 | 0 | proto = aGivenProto; |
1122 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1123 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1124 | 0 | // to wrap the proto here. |
1125 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1126 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1127 | 0 | return false; |
1128 | 0 | } |
1129 | 0 | } |
1130 | 0 | } else { |
1131 | 0 | proto = canonicalProto; |
1132 | 0 | } |
1133 | 0 |
|
1134 | 0 | BindingJSObjectCreator<mozilla::dom::MediaKeySystemAccess> creator(aCx); |
1135 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1136 | 0 | if (!aReflector) { |
1137 | 0 | return false; |
1138 | 0 | } |
1139 | 0 | |
1140 | 0 | aCache->SetWrapper(aReflector); |
1141 | 0 | creator.InitializationSucceeded(); |
1142 | 0 |
|
1143 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1144 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1145 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1146 | 0 | // otherwise we won't be able to properly recreate it later, since |
1147 | 0 | // we won't know what proto to use. Note that we don't check |
1148 | 0 | // aGivenProto here, since it's entirely possible (and even |
1149 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1150 | 0 | // same as canonicalProto. |
1151 | 0 | if (proto != canonicalProto) { |
1152 | 0 | PreserveWrapper(aObject); |
1153 | 0 | } |
1154 | 0 |
|
1155 | 0 | return true; |
1156 | 0 | } |
1157 | | |
1158 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1159 | | nullptr, |
1160 | | nullptr, |
1161 | | nullptr, |
1162 | | { sNativeProperties.Upcast(), nullptr }, |
1163 | | prototypes::id::MediaKeySystemAccess, |
1164 | | constructors::id::MediaKeySystemAccess, |
1165 | | nullptr, |
1166 | | &DefaultXrayExpandoObjectClass |
1167 | | } }; |
1168 | | |
1169 | | void |
1170 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1171 | 0 | { |
1172 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1173 | 0 | if (!parentProto) { |
1174 | 0 | return; |
1175 | 0 | } |
1176 | 0 | |
1177 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
1178 | 0 | if (!constructorProto) { |
1179 | 0 | return; |
1180 | 0 | } |
1181 | 0 | |
1182 | 0 | static bool sIdsInited = false; |
1183 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1184 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1185 | 0 | return; |
1186 | 0 | } |
1187 | 0 | sIdsInited = true; |
1188 | 0 | } |
1189 | 0 |
|
1190 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaKeySystemAccess); |
1191 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaKeySystemAccess); |
1192 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1193 | 0 | &sPrototypeClass.mBase, protoCache, |
1194 | 0 | nullptr, |
1195 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1196 | 0 | interfaceCache, |
1197 | 0 | sNativeProperties.Upcast(), |
1198 | 0 | nullptr, |
1199 | 0 | "MediaKeySystemAccess", aDefineOnGlobal, |
1200 | 0 | nullptr, |
1201 | 0 | false); |
1202 | 0 | } |
1203 | | |
1204 | | JSObject* |
1205 | | GetConstructorObject(JSContext* aCx) |
1206 | 0 | { |
1207 | 0 | return GetConstructorObjectHandle(aCx); |
1208 | 0 | } |
1209 | | |
1210 | | } // namespace MediaKeySystemAccess_Binding |
1211 | | |
1212 | | |
1213 | | |
1214 | | } // namespace dom |
1215 | | } // namespace mozilla |