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