/work/obj-fuzz/dom/bindings/MediaKeysBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MediaKeys.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "MediaKeysBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "jsapi.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/Preferences.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/MediaKeySession.h" |
12 | | #include "mozilla/dom/MediaKeys.h" |
13 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
14 | | #include "mozilla/dom/Promise.h" |
15 | | #include "mozilla/dom/ScriptSettings.h" |
16 | | #include "mozilla/dom/SimpleGlobalObject.h" |
17 | | #include "mozilla/dom/ToJSValue.h" |
18 | | #include "mozilla/dom/UnionConversions.h" |
19 | | #include "mozilla/dom/UnionTypes.h" |
20 | | #include "mozilla/dom/XrayExpandoClass.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | namespace MediaKeySessionTypeValues { |
30 | | extern const EnumEntry strings[3] = { |
31 | | {"temporary", 9}, |
32 | | {"persistent-license", 18}, |
33 | | { nullptr, 0 } |
34 | | }; |
35 | | } // namespace MediaKeySessionTypeValues |
36 | | |
37 | | bool |
38 | | ToJSValue(JSContext* aCx, MediaKeySessionType aArgument, JS::MutableHandle<JS::Value> aValue) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaKeySessionTypeValues::strings)); |
41 | 0 | JSString* resultStr = |
42 | 0 | JS_NewStringCopyN(aCx, MediaKeySessionTypeValues::strings[uint32_t(aArgument)].value, |
43 | 0 | MediaKeySessionTypeValues::strings[uint32_t(aArgument)].length); |
44 | 0 | if (!resultStr) { |
45 | 0 | return false; |
46 | 0 | } |
47 | 0 | aValue.setString(resultStr); |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | |
52 | | |
53 | | MediaKeysPolicy::MediaKeysPolicy() |
54 | 0 | { |
55 | 0 | // Safe to pass a null context if we pass a null value |
56 | 0 | Init(nullptr, JS::NullHandleValue); |
57 | 0 | } |
58 | | |
59 | | |
60 | | |
61 | | bool |
62 | | MediaKeysPolicy::InitIds(JSContext* cx, MediaKeysPolicyAtoms* atomsCache) |
63 | 0 | { |
64 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
65 | 0 |
|
66 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
67 | 0 | // uninitialized. |
68 | 0 | if (!atomsCache->minHdcpVersion_id.init(cx, "minHdcpVersion")) { |
69 | 0 | return false; |
70 | 0 | } |
71 | 0 | return true; |
72 | 0 | } |
73 | | |
74 | | bool |
75 | | MediaKeysPolicy::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
76 | 0 | { |
77 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
78 | 0 | // Since in that case we will not have to do any property gets |
79 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
80 | 0 | // checkers by static analysis tools |
81 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
82 | 0 | MediaKeysPolicyAtoms* atomsCache = nullptr; |
83 | 0 | if (cx) { |
84 | 0 | atomsCache = GetAtomCache<MediaKeysPolicyAtoms>(cx); |
85 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | } |
89 | 0 | |
90 | 0 | if (!IsConvertibleToDictionary(val)) { |
91 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
92 | 0 | } |
93 | 0 | |
94 | 0 | bool isNull = val.isNullOrUndefined(); |
95 | 0 | // We only need these if !isNull, in which case we have |cx|. |
96 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
97 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
98 | 0 | if (!isNull) { |
99 | 0 | MOZ_ASSERT(cx); |
100 | 0 | object.emplace(cx, &val.toObject()); |
101 | 0 | temp.emplace(cx); |
102 | 0 | } |
103 | 0 | if (!isNull) { |
104 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->minHdcpVersion_id, temp.ptr())) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | } |
108 | 0 | if (!isNull && !temp->isUndefined()) { |
109 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mMinHdcpVersion)) { |
110 | 0 | return false; |
111 | 0 | } |
112 | 0 | } else { |
113 | 0 | static const char16_t data[] = { 0 }; |
114 | 0 | mMinHdcpVersion.Rebind(data, ArrayLength(data) - 1); |
115 | 0 | } |
116 | 0 | mIsAnyMemberPresent = true; |
117 | 0 | return true; |
118 | 0 | } |
119 | | |
120 | | bool |
121 | | MediaKeysPolicy::Init(const nsAString& aJSON) |
122 | 0 | { |
123 | 0 | AutoJSAPI jsapi; |
124 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
125 | 0 | if (!cleanGlobal) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | if (!jsapi.Init(cleanGlobal)) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | JSContext* cx = jsapi.cx(); |
132 | 0 | JS::Rooted<JS::Value> json(cx); |
133 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
134 | 0 | NS_ENSURE_TRUE(ok, false); |
135 | 0 | return Init(cx, json); |
136 | 0 | } |
137 | | |
138 | | bool |
139 | | MediaKeysPolicy::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
140 | 0 | { |
141 | 0 | MediaKeysPolicyAtoms* atomsCache = GetAtomCache<MediaKeysPolicyAtoms>(cx); |
142 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | |
146 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
147 | 0 | if (!obj) { |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | rval.set(JS::ObjectValue(*obj)); |
151 | 0 |
|
152 | 0 | do { |
153 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
154 | 0 | JS::Rooted<JS::Value> temp(cx); |
155 | 0 | nsString const & currentValue = mMinHdcpVersion; |
156 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
157 | 0 | return false; |
158 | 0 | } |
159 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->minHdcpVersion_id, temp, JSPROP_ENUMERATE)) { |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | break; |
163 | 0 | } while(false); |
164 | 0 |
|
165 | 0 | return true; |
166 | 0 | } |
167 | | |
168 | | bool |
169 | | MediaKeysPolicy::ToJSON(nsAString& aJSON) const |
170 | 0 | { |
171 | 0 | AutoJSAPI jsapi; |
172 | 0 | jsapi.Init(); |
173 | 0 | JSContext *cx = jsapi.cx(); |
174 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
175 | 0 | // because we'll only be creating objects, in ways that have no |
176 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
177 | 0 | // which likewise guarantees no side-effects for the sorts of |
178 | 0 | // things we will pass it. |
179 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
180 | 0 | JS::Rooted<JS::Value> val(cx); |
181 | 0 | if (!ToObjectInternal(cx, &val)) { |
182 | 0 | return false; |
183 | 0 | } |
184 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
185 | 0 | return StringifyToJSON(cx, obj, aJSON); |
186 | 0 | } |
187 | | |
188 | | void |
189 | | MediaKeysPolicy::TraceDictionary(JSTracer* trc) |
190 | 0 | { |
191 | 0 | } |
192 | | |
193 | | MediaKeysPolicy& |
194 | | MediaKeysPolicy::operator=(const MediaKeysPolicy& aOther) |
195 | 0 | { |
196 | 0 | DictionaryBase::operator=(aOther); |
197 | 0 | mMinHdcpVersion = aOther.mMinHdcpVersion; |
198 | 0 | return *this; |
199 | 0 | } |
200 | | |
201 | | namespace binding_detail { |
202 | | } // namespace binding_detail |
203 | | |
204 | | |
205 | | namespace MediaKeys_Binding { |
206 | | |
207 | | MOZ_CAN_RUN_SCRIPT static bool |
208 | | get_keySystem(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, JSJitGetterCallArgs args) |
209 | 0 | { |
210 | 0 | AUTO_PROFILER_LABEL_FAST("get MediaKeys.keySystem", DOM, cx); |
211 | 0 |
|
212 | 0 | DOMString result; |
213 | 0 | self->GetKeySystem(result); |
214 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
215 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | return true; |
219 | 0 | } |
220 | | |
221 | | static const JSJitInfo keySystem_getterinfo = { |
222 | | { (JSJitGetterOp)get_keySystem }, |
223 | | { prototypes::id::MediaKeys }, |
224 | | { PrototypeTraits<prototypes::id::MediaKeys>::Depth }, |
225 | | JSJitInfo::Getter, |
226 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
227 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
228 | | false, /* isInfallible. False in setters. */ |
229 | | false, /* isMovable. Not relevant for setters. */ |
230 | | false, /* isEliminatable. Not relevant for setters. */ |
231 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
232 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
233 | | false, /* isTypedMethod. Only relevant for methods. */ |
234 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
235 | | }; |
236 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
237 | | static_assert(0 < 1, "There is no slot for us"); |
238 | | |
239 | | MOZ_CAN_RUN_SCRIPT static bool |
240 | | createSession(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, const JSJitMethodCallArgs& args) |
241 | 0 | { |
242 | 0 | AUTO_PROFILER_LABEL_FAST("MediaKeys.createSession", DOM, cx); |
243 | 0 |
|
244 | 0 | MediaKeySessionType arg0; |
245 | 0 | if (args.hasDefined(0)) { |
246 | 0 | { |
247 | 0 | int index; |
248 | 0 | if (!FindEnumStringIndex<true>(cx, args[0], MediaKeySessionTypeValues::strings, "MediaKeySessionType", "Argument 1 of MediaKeys.createSession", &index)) { |
249 | 0 | return false; |
250 | 0 | } |
251 | 0 | MOZ_ASSERT(index >= 0); |
252 | 0 | arg0 = static_cast<MediaKeySessionType>(index); |
253 | 0 | } |
254 | 0 | } else { |
255 | 0 | arg0 = MediaKeySessionType::Temporary; |
256 | 0 | } |
257 | 0 | FastErrorResult rv; |
258 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MediaKeySession>(self->CreateSession(cx, arg0, rv))); |
259 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
260 | 0 | return false; |
261 | 0 | } |
262 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
263 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
264 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
265 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
266 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | return true; |
270 | 0 | } |
271 | | |
272 | | static const JSJitInfo createSession_methodinfo = { |
273 | | { (JSJitGetterOp)createSession }, |
274 | | { prototypes::id::MediaKeys }, |
275 | | { PrototypeTraits<prototypes::id::MediaKeys>::Depth }, |
276 | | JSJitInfo::Method, |
277 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
278 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
279 | | false, /* isInfallible. False in setters. */ |
280 | | false, /* isMovable. Not relevant for setters. */ |
281 | | false, /* isEliminatable. Not relevant for setters. */ |
282 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
283 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
284 | | false, /* isTypedMethod. Only relevant for methods. */ |
285 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
286 | | }; |
287 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
288 | | static_assert(0 < 1, "There is no slot for us"); |
289 | | |
290 | | MOZ_CAN_RUN_SCRIPT static bool |
291 | | setServerCertificate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, const JSJitMethodCallArgs& args) |
292 | 0 | { |
293 | 0 | AUTO_PROFILER_LABEL_FAST("MediaKeys.setServerCertificate", DOM, cx); |
294 | 0 |
|
295 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
296 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaKeys.setServerCertificate"); |
297 | 0 | } |
298 | 0 | ArrayBufferViewOrArrayBuffer arg0; |
299 | 0 | ArrayBufferViewOrArrayBufferArgument arg0_holder(arg0); |
300 | 0 | { |
301 | 0 | bool done = false, failed = false, tryNext; |
302 | 0 | if (args[0].isObject()) { |
303 | 0 | done = (failed = !arg0_holder.TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext || |
304 | 0 | (failed = !arg0_holder.TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext; |
305 | 0 |
|
306 | 0 | } |
307 | 0 | if (failed) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | if (!done) { |
311 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of MediaKeys.setServerCertificate", "ArrayBufferView, ArrayBuffer"); |
312 | 0 | return false; |
313 | 0 | } |
314 | 0 | } |
315 | 0 | FastErrorResult rv; |
316 | 0 | auto result(StrongOrRawPtr<Promise>(self->SetServerCertificate(Constify(arg0), rv))); |
317 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
318 | 0 | return false; |
319 | 0 | } |
320 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
321 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
322 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
323 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
324 | 0 | return false; |
325 | 0 | } |
326 | 0 | return true; |
327 | 0 | } |
328 | | |
329 | | MOZ_CAN_RUN_SCRIPT static bool |
330 | | setServerCertificate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, const JSJitMethodCallArgs& args) |
331 | 0 | { |
332 | 0 | bool ok = setServerCertificate(cx, obj, self, args); |
333 | 0 | if (ok) { |
334 | 0 | return true; |
335 | 0 | } |
336 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
337 | 0 | } |
338 | | |
339 | | static const JSJitInfo setServerCertificate_methodinfo = { |
340 | | { (JSJitGetterOp)setServerCertificate_promiseWrapper }, |
341 | | { prototypes::id::MediaKeys }, |
342 | | { PrototypeTraits<prototypes::id::MediaKeys>::Depth }, |
343 | | JSJitInfo::Method, |
344 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
345 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
346 | | false, /* isInfallible. False in setters. */ |
347 | | false, /* isMovable. Not relevant for setters. */ |
348 | | false, /* isEliminatable. Not relevant for setters. */ |
349 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
350 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
351 | | false, /* isTypedMethod. Only relevant for methods. */ |
352 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
353 | | }; |
354 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
355 | | static_assert(0 < 1, "There is no slot for us"); |
356 | | |
357 | | MOZ_CAN_RUN_SCRIPT static bool |
358 | | getStatusForPolicy(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, const JSJitMethodCallArgs& args) |
359 | 0 | { |
360 | 0 | AUTO_PROFILER_LABEL_FAST("MediaKeys.getStatusForPolicy", DOM, cx); |
361 | 0 |
|
362 | 0 | binding_detail::FastMediaKeysPolicy arg0; |
363 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of MediaKeys.getStatusForPolicy", false)) { |
364 | 0 | return false; |
365 | 0 | } |
366 | 0 | FastErrorResult rv; |
367 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetStatusForPolicy(Constify(arg0), rv))); |
368 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
369 | 0 | return false; |
370 | 0 | } |
371 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
372 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
373 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
374 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
375 | 0 | return false; |
376 | 0 | } |
377 | 0 | return true; |
378 | 0 | } |
379 | | |
380 | | MOZ_CAN_RUN_SCRIPT static bool |
381 | | getStatusForPolicy_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaKeys* self, const JSJitMethodCallArgs& args) |
382 | 0 | { |
383 | 0 | bool ok = getStatusForPolicy(cx, obj, self, args); |
384 | 0 | if (ok) { |
385 | 0 | return true; |
386 | 0 | } |
387 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
388 | 0 | } |
389 | | |
390 | | static const JSJitInfo getStatusForPolicy_methodinfo = { |
391 | | { (JSJitGetterOp)getStatusForPolicy_promiseWrapper }, |
392 | | { prototypes::id::MediaKeys }, |
393 | | { PrototypeTraits<prototypes::id::MediaKeys>::Depth }, |
394 | | JSJitInfo::Method, |
395 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
396 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
397 | | false, /* isInfallible. False in setters. */ |
398 | | false, /* isMovable. Not relevant for setters. */ |
399 | | false, /* isEliminatable. Not relevant for setters. */ |
400 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
401 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
402 | | false, /* isTypedMethod. Only relevant for methods. */ |
403 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
404 | | }; |
405 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
406 | | static_assert(0 < 1, "There is no slot for us"); |
407 | | |
408 | | static bool |
409 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
410 | 0 | { |
411 | 0 | mozilla::dom::MediaKeys* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeys>(obj); |
412 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
413 | 0 | // obviously can't preserve if we're not initialized. |
414 | 0 | if (self && self->GetWrapperPreserveColor()) { |
415 | 0 | PreserveWrapper(self); |
416 | 0 | } |
417 | 0 | return true; |
418 | 0 | } |
419 | | |
420 | | static void |
421 | | _finalize(js::FreeOp* fop, JSObject* obj) |
422 | 0 | { |
423 | 0 | mozilla::dom::MediaKeys* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeys>(obj); |
424 | 0 | if (self) { |
425 | 0 | ClearWrapper(self, self, obj); |
426 | 0 | AddForDeferredFinalization<mozilla::dom::MediaKeys>(self); |
427 | 0 | } |
428 | 0 | } |
429 | | |
430 | | static size_t |
431 | | _objectMoved(JSObject* obj, JSObject* old) |
432 | 0 | { |
433 | 0 | mozilla::dom::MediaKeys* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaKeys>(obj); |
434 | 0 | if (self) { |
435 | 0 | UpdateWrapper(self, self, obj, old); |
436 | 0 | } |
437 | 0 |
|
438 | 0 | return 0; |
439 | 0 | } |
440 | | |
441 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
442 | | #if defined(__clang__) |
443 | | #pragma clang diagnostic push |
444 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
445 | | #endif |
446 | | static const JSFunctionSpec sMethods_specs[] = { |
447 | | JS_FNSPEC("createSession", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createSession_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
448 | | JS_FNSPEC("setServerCertificate", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&setServerCertificate_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
449 | | JS_FS_END, |
450 | | JS_FNSPEC("getStatusForPolicy", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getStatusForPolicy_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
451 | | JS_FS_END |
452 | | }; |
453 | | #if defined(__clang__) |
454 | | #pragma clang diagnostic pop |
455 | | #endif |
456 | | |
457 | | // Can't be const because the pref-enabled boolean needs to be writable |
458 | | static PrefableDisablers sMethods_disablers3 = { |
459 | | true, false, 0, nullptr |
460 | | }; |
461 | | |
462 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
463 | | { nullptr, &sMethods_specs[0] }, |
464 | | { &sMethods_disablers3, &sMethods_specs[3] }, |
465 | | { nullptr, nullptr } |
466 | | }; |
467 | | |
468 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
469 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
470 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
471 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
472 | | |
473 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
474 | | #if defined(__clang__) |
475 | | #pragma clang diagnostic push |
476 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
477 | | #endif |
478 | | static const JSPropertySpec sAttributes_specs[] = { |
479 | | { "keySystem", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &keySystem_getterinfo, nullptr, nullptr }, |
480 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
481 | | }; |
482 | | #if defined(__clang__) |
483 | | #pragma clang diagnostic pop |
484 | | #endif |
485 | | |
486 | | |
487 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
488 | | { nullptr, &sAttributes_specs[0] }, |
489 | | { nullptr, nullptr } |
490 | | }; |
491 | | |
492 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
493 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
494 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
495 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
496 | | |
497 | | |
498 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
499 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
500 | | |
501 | | static const NativePropertiesN<2> sNativeProperties = { |
502 | | false, 0, |
503 | | false, 0, |
504 | | true, 0 /* sMethods */, |
505 | | true, 1 /* sAttributes */, |
506 | | false, 0, |
507 | | false, 0, |
508 | | false, 0, |
509 | | -1, |
510 | | 4, |
511 | | sNativeProperties_sortedPropertyIndices, |
512 | | { |
513 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
514 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
515 | | } |
516 | | }; |
517 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
518 | | "We have a property info count that is oversized"); |
519 | | |
520 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
521 | | { |
522 | | "Function", |
523 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
524 | | &sBoringInterfaceObjectClassClassOps, |
525 | | JS_NULL_CLASS_SPEC, |
526 | | JS_NULL_CLASS_EXT, |
527 | | &sInterfaceObjectClassObjectOps |
528 | | }, |
529 | | eInterface, |
530 | | true, |
531 | | prototypes::id::MediaKeys, |
532 | | PrototypeTraits<prototypes::id::MediaKeys>::Depth, |
533 | | sNativePropertyHooks, |
534 | | "function MediaKeys() {\n [native code]\n}", |
535 | | JS::GetRealmFunctionPrototype |
536 | | }; |
537 | | |
538 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
539 | | { |
540 | | "MediaKeysPrototype", |
541 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
542 | | JS_NULL_CLASS_OPS, |
543 | | JS_NULL_CLASS_SPEC, |
544 | | JS_NULL_CLASS_EXT, |
545 | | JS_NULL_OBJECT_OPS |
546 | | }, |
547 | | eInterfacePrototype, |
548 | | false, |
549 | | prototypes::id::MediaKeys, |
550 | | PrototypeTraits<prototypes::id::MediaKeys>::Depth, |
551 | | sNativePropertyHooks, |
552 | | "[object MediaKeysPrototype]", |
553 | | JS::GetRealmObjectPrototype |
554 | | }; |
555 | | |
556 | | static const js::ClassOps sClassOps = { |
557 | | _addProperty, /* addProperty */ |
558 | | nullptr, /* delProperty */ |
559 | | nullptr, /* enumerate */ |
560 | | nullptr, /* newEnumerate */ |
561 | | nullptr, /* resolve */ |
562 | | nullptr, /* mayResolve */ |
563 | | _finalize, /* finalize */ |
564 | | nullptr, /* call */ |
565 | | nullptr, /* hasInstance */ |
566 | | nullptr, /* construct */ |
567 | | nullptr, /* trace */ |
568 | | }; |
569 | | |
570 | | static const js::ClassExtension sClassExtension = { |
571 | | nullptr, /* weakmapKeyDelegateOp */ |
572 | | _objectMoved /* objectMovedOp */ |
573 | | }; |
574 | | |
575 | | static const DOMJSClass sClass = { |
576 | | { "MediaKeys", |
577 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
578 | | &sClassOps, |
579 | | JS_NULL_CLASS_SPEC, |
580 | | &sClassExtension, |
581 | | JS_NULL_OBJECT_OPS |
582 | | }, |
583 | | { prototypes::id::MediaKeys, 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 }, |
584 | | IsBaseOf<nsISupports, mozilla::dom::MediaKeys >::value, |
585 | | sNativePropertyHooks, |
586 | | FindAssociatedGlobalForNative<mozilla::dom::MediaKeys>::Get, |
587 | | GetProtoObjectHandle, |
588 | | GetCCParticipant<mozilla::dom::MediaKeys>::Get() |
589 | | }; |
590 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
591 | | "Must have the right minimal number of reserved slots."); |
592 | | static_assert(1 >= 1, |
593 | | "Must have enough reserved slots."); |
594 | | |
595 | | const JSClass* |
596 | | GetJSClass() |
597 | 0 | { |
598 | 0 | return sClass.ToJSClass(); |
599 | 0 | } |
600 | | |
601 | | bool |
602 | | Wrap(JSContext* aCx, mozilla::dom::MediaKeys* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
603 | 0 | { |
604 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaKeys>::value, |
605 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
606 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MediaKeys*>(aObject) == |
607 | 0 | reinterpret_cast<mozilla::dom::MediaKeys*>(aObject), |
608 | 0 | "Multiple inheritance for mozilla::dom::MediaKeys is broken."); |
609 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
610 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
611 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
612 | 0 | "You should probably not be using Wrap() directly; use " |
613 | 0 | "GetOrCreateDOMReflector instead"); |
614 | 0 |
|
615 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
616 | 0 | "nsISupports must be on our primary inheritance chain"); |
617 | 0 |
|
618 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
619 | 0 | if (!global) { |
620 | 0 | return false; |
621 | 0 | } |
622 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
623 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
624 | 0 |
|
625 | 0 | // That might have ended up wrapping us already, due to the wonders |
626 | 0 | // of XBL. Check for that, and bail out as needed. |
627 | 0 | aReflector.set(aCache->GetWrapper()); |
628 | 0 | if (aReflector) { |
629 | | #ifdef DEBUG |
630 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
631 | | #endif // DEBUG |
632 | | return true; |
633 | 0 | } |
634 | 0 |
|
635 | 0 | JSAutoRealm ar(aCx, global); |
636 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
637 | 0 | if (!canonicalProto) { |
638 | 0 | return false; |
639 | 0 | } |
640 | 0 | JS::Rooted<JSObject*> proto(aCx); |
641 | 0 | if (aGivenProto) { |
642 | 0 | proto = aGivenProto; |
643 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
644 | 0 | // coming in, we changed compartments to that of "parent" so may need |
645 | 0 | // to wrap the proto here. |
646 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
647 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
648 | 0 | return false; |
649 | 0 | } |
650 | 0 | } |
651 | 0 | } else { |
652 | 0 | proto = canonicalProto; |
653 | 0 | } |
654 | 0 |
|
655 | 0 | BindingJSObjectCreator<mozilla::dom::MediaKeys> creator(aCx); |
656 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
657 | 0 | if (!aReflector) { |
658 | 0 | return false; |
659 | 0 | } |
660 | 0 | |
661 | 0 | aCache->SetWrapper(aReflector); |
662 | 0 | creator.InitializationSucceeded(); |
663 | 0 |
|
664 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
665 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
666 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
667 | 0 | // otherwise we won't be able to properly recreate it later, since |
668 | 0 | // we won't know what proto to use. Note that we don't check |
669 | 0 | // aGivenProto here, since it's entirely possible (and even |
670 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
671 | 0 | // same as canonicalProto. |
672 | 0 | if (proto != canonicalProto) { |
673 | 0 | PreserveWrapper(aObject); |
674 | 0 | } |
675 | 0 |
|
676 | 0 | return true; |
677 | 0 | } |
678 | | |
679 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
680 | | nullptr, |
681 | | nullptr, |
682 | | nullptr, |
683 | | { sNativeProperties.Upcast(), nullptr }, |
684 | | prototypes::id::MediaKeys, |
685 | | constructors::id::MediaKeys, |
686 | | nullptr, |
687 | | &DefaultXrayExpandoObjectClass |
688 | | } }; |
689 | | |
690 | | void |
691 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
692 | 0 | { |
693 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
694 | 0 | if (!parentProto) { |
695 | 0 | return; |
696 | 0 | } |
697 | 0 | |
698 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
699 | 0 | if (!constructorProto) { |
700 | 0 | return; |
701 | 0 | } |
702 | 0 | |
703 | 0 | static bool sIdsInited = false; |
704 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
705 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
706 | 0 | return; |
707 | 0 | } |
708 | 0 | sIdsInited = true; |
709 | 0 | } |
710 | 0 |
|
711 | 0 | static bool sPrefCachesInited = false; |
712 | 0 | if (!sPrefCachesInited && NS_IsMainThread()) { |
713 | 0 | sPrefCachesInited = true; |
714 | 0 | Preferences::AddBoolVarCache(&sMethods[1].disablers->enabled, "media.eme.hdcp-policy-check.enabled"); |
715 | 0 | } |
716 | 0 |
|
717 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaKeys); |
718 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaKeys); |
719 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
720 | 0 | &sPrototypeClass.mBase, protoCache, |
721 | 0 | nullptr, |
722 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
723 | 0 | interfaceCache, |
724 | 0 | sNativeProperties.Upcast(), |
725 | 0 | nullptr, |
726 | 0 | "MediaKeys", aDefineOnGlobal, |
727 | 0 | nullptr, |
728 | 0 | false); |
729 | 0 | } |
730 | | |
731 | | JSObject* |
732 | | GetConstructorObject(JSContext* aCx) |
733 | 0 | { |
734 | 0 | return GetConstructorObjectHandle(aCx); |
735 | 0 | } |
736 | | |
737 | | } // namespace MediaKeys_Binding |
738 | | |
739 | | |
740 | | |
741 | | } // namespace dom |
742 | | } // namespace mozilla |