/work/obj-fuzz/dom/bindings/MediaKeysRequestStatusBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MediaKeysRequestStatus.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "MediaKeysRequestStatusBinding.h" |
5 | | #include "jsapi.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
9 | | #include "mozilla/dom/ScriptSettings.h" |
10 | | #include "mozilla/dom/SimpleGlobalObject.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
16 | | using namespace mozilla::dom::binding_detail; |
17 | | |
18 | | |
19 | | namespace MediaKeySystemStatusValues { |
20 | | extern const EnumEntry strings[7] = { |
21 | | {"available", 9}, |
22 | | {"api-disabled", 12}, |
23 | | {"cdm-disabled", 12}, |
24 | | {"cdm-not-supported", 17}, |
25 | | {"cdm-not-installed", 17}, |
26 | | {"cdm-created", 11}, |
27 | | { nullptr, 0 } |
28 | | }; |
29 | | } // namespace MediaKeySystemStatusValues |
30 | | |
31 | | bool |
32 | | ToJSValue(JSContext* aCx, MediaKeySystemStatus aArgument, JS::MutableHandle<JS::Value> aValue) |
33 | 0 | { |
34 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaKeySystemStatusValues::strings)); |
35 | 0 | JSString* resultStr = |
36 | 0 | JS_NewStringCopyN(aCx, MediaKeySystemStatusValues::strings[uint32_t(aArgument)].value, |
37 | 0 | MediaKeySystemStatusValues::strings[uint32_t(aArgument)].length); |
38 | 0 | if (!resultStr) { |
39 | 0 | return false; |
40 | 0 | } |
41 | 0 | aValue.setString(resultStr); |
42 | 0 | return true; |
43 | 0 | } |
44 | | |
45 | | |
46 | | |
47 | | RequestMediaKeySystemAccessNotification::RequestMediaKeySystemAccessNotification() |
48 | 0 | { |
49 | 0 | // Safe to pass a null context if we pass a null value |
50 | 0 | Init(nullptr, JS::NullHandleValue); |
51 | 0 | } |
52 | | |
53 | | |
54 | | |
55 | | bool |
56 | | RequestMediaKeySystemAccessNotification::InitIds(JSContext* cx, RequestMediaKeySystemAccessNotificationAtoms* atomsCache) |
57 | 0 | { |
58 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
59 | 0 |
|
60 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
61 | 0 | // uninitialized. |
62 | 0 | if (!atomsCache->status_id.init(cx, "status") || |
63 | 0 | !atomsCache->keySystem_id.init(cx, "keySystem")) { |
64 | 0 | return false; |
65 | 0 | } |
66 | 0 | return true; |
67 | 0 | } |
68 | | |
69 | | bool |
70 | | RequestMediaKeySystemAccessNotification::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
71 | 0 | { |
72 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
73 | 0 | // Since in that case we will not have to do any property gets |
74 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
75 | 0 | // checkers by static analysis tools |
76 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
77 | 0 | RequestMediaKeySystemAccessNotificationAtoms* atomsCache = nullptr; |
78 | 0 | if (cx) { |
79 | 0 | atomsCache = GetAtomCache<RequestMediaKeySystemAccessNotificationAtoms>(cx); |
80 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | |
85 | 0 | if (!IsConvertibleToDictionary(val)) { |
86 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
87 | 0 | } |
88 | 0 | |
89 | 0 | bool isNull = val.isNullOrUndefined(); |
90 | 0 | // We only need these if !isNull, in which case we have |cx|. |
91 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
92 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
93 | 0 | if (!isNull) { |
94 | 0 | MOZ_ASSERT(cx); |
95 | 0 | object.emplace(cx, &val.toObject()); |
96 | 0 | temp.emplace(cx); |
97 | 0 | } |
98 | 0 | if (!isNull) { |
99 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->keySystem_id, temp.ptr())) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | } |
103 | 0 | if (!isNull && !temp->isUndefined()) { |
104 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mKeySystem)) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | mIsAnyMemberPresent = true; |
108 | 0 | } else if (cx) { |
109 | 0 | // Don't error out if we have no cx. In that |
110 | 0 | // situation the caller is default-constructing us and we'll |
111 | 0 | // just assume they know what they're doing. |
112 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
113 | 0 | "'keySystem' member of RequestMediaKeySystemAccessNotification"); |
114 | 0 | } |
115 | 0 | |
116 | 0 | if (!isNull) { |
117 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->status_id, temp.ptr())) { |
118 | 0 | return false; |
119 | 0 | } |
120 | 0 | } |
121 | 0 | if (!isNull && !temp->isUndefined()) { |
122 | 0 | { |
123 | 0 | int index; |
124 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaKeySystemStatusValues::strings, "MediaKeySystemStatus", "'status' member of RequestMediaKeySystemAccessNotification", &index)) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | MOZ_ASSERT(index >= 0); |
128 | 0 | mStatus = static_cast<MediaKeySystemStatus>(index); |
129 | 0 | } |
130 | 0 | mIsAnyMemberPresent = true; |
131 | 0 | } else if (cx) { |
132 | 0 | // Don't error out if we have no cx. In that |
133 | 0 | // situation the caller is default-constructing us and we'll |
134 | 0 | // just assume they know what they're doing. |
135 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
136 | 0 | "'status' member of RequestMediaKeySystemAccessNotification"); |
137 | 0 | } |
138 | 0 | return true; |
139 | 0 | } |
140 | | |
141 | | bool |
142 | | RequestMediaKeySystemAccessNotification::Init(const nsAString& aJSON) |
143 | 0 | { |
144 | 0 | AutoJSAPI jsapi; |
145 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
146 | 0 | if (!cleanGlobal) { |
147 | 0 | return false; |
148 | 0 | } |
149 | 0 | if (!jsapi.Init(cleanGlobal)) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | JSContext* cx = jsapi.cx(); |
153 | 0 | JS::Rooted<JS::Value> json(cx); |
154 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
155 | 0 | NS_ENSURE_TRUE(ok, false); |
156 | 0 | return Init(cx, json); |
157 | 0 | } |
158 | | |
159 | | bool |
160 | | RequestMediaKeySystemAccessNotification::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
161 | 0 | { |
162 | 0 | RequestMediaKeySystemAccessNotificationAtoms* atomsCache = GetAtomCache<RequestMediaKeySystemAccessNotificationAtoms>(cx); |
163 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
164 | 0 | return false; |
165 | 0 | } |
166 | 0 | |
167 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
168 | 0 | if (!obj) { |
169 | 0 | return false; |
170 | 0 | } |
171 | 0 | rval.set(JS::ObjectValue(*obj)); |
172 | 0 |
|
173 | 0 | do { |
174 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
175 | 0 | JS::Rooted<JS::Value> temp(cx); |
176 | 0 | nsString const & currentValue = mKeySystem; |
177 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
178 | 0 | return false; |
179 | 0 | } |
180 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->keySystem_id, temp, JSPROP_ENUMERATE)) { |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | break; |
184 | 0 | } while(false); |
185 | 0 |
|
186 | 0 | do { |
187 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
188 | 0 | JS::Rooted<JS::Value> temp(cx); |
189 | 0 | MediaKeySystemStatus const & currentValue = mStatus; |
190 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->status_id, temp, JSPROP_ENUMERATE)) { |
194 | 0 | return false; |
195 | 0 | } |
196 | 0 | break; |
197 | 0 | } while(false); |
198 | 0 |
|
199 | 0 | return true; |
200 | 0 | } |
201 | | |
202 | | bool |
203 | | RequestMediaKeySystemAccessNotification::ToJSON(nsAString& aJSON) const |
204 | 0 | { |
205 | 0 | AutoJSAPI jsapi; |
206 | 0 | jsapi.Init(); |
207 | 0 | JSContext *cx = jsapi.cx(); |
208 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
209 | 0 | // because we'll only be creating objects, in ways that have no |
210 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
211 | 0 | // which likewise guarantees no side-effects for the sorts of |
212 | 0 | // things we will pass it. |
213 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
214 | 0 | JS::Rooted<JS::Value> val(cx); |
215 | 0 | if (!ToObjectInternal(cx, &val)) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
219 | 0 | return StringifyToJSON(cx, obj, aJSON); |
220 | 0 | } |
221 | | |
222 | | void |
223 | | RequestMediaKeySystemAccessNotification::TraceDictionary(JSTracer* trc) |
224 | 0 | { |
225 | 0 | } |
226 | | |
227 | | RequestMediaKeySystemAccessNotification& |
228 | | RequestMediaKeySystemAccessNotification::operator=(const RequestMediaKeySystemAccessNotification& aOther) |
229 | 0 | { |
230 | 0 | DictionaryBase::operator=(aOther); |
231 | 0 | mKeySystem = aOther.mKeySystem; |
232 | 0 | mStatus = aOther.mStatus; |
233 | 0 | return *this; |
234 | 0 | } |
235 | | |
236 | | namespace binding_detail { |
237 | | } // namespace binding_detail |
238 | | |
239 | | |
240 | | } // namespace dom |
241 | | } // namespace mozilla |