/work/obj-fuzz/dom/bindings/AppNotificationServiceOptionsBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM AppNotificationServiceOptions.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AppNotificationServiceOptionsBinding.h" |
4 | | #include "AtomList.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
8 | | #include "mozilla/dom/PrimitiveConversions.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 | | |
20 | | AppNotificationServiceOptions::AppNotificationServiceOptions() |
21 | | : mMozbehavior(FastDictionaryInitializer()) |
22 | 0 | { |
23 | 0 | // Safe to pass a null context if we pass a null value |
24 | 0 | Init(nullptr, JS::NullHandleValue); |
25 | 0 | } |
26 | | |
27 | | |
28 | | |
29 | | bool |
30 | | AppNotificationServiceOptions::InitIds(JSContext* cx, AppNotificationServiceOptionsAtoms* atomsCache) |
31 | 0 | { |
32 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
33 | 0 |
|
34 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
35 | 0 | // uninitialized. |
36 | 0 | if (!atomsCache->textClickable_id.init(cx, "textClickable") || |
37 | 0 | !atomsCache->tag_id.init(cx, "tag") || |
38 | 0 | !atomsCache->mozbehavior_id.init(cx, "mozbehavior") || |
39 | 0 | !atomsCache->manifestURL_id.init(cx, "manifestURL") || |
40 | 0 | !atomsCache->lang_id.init(cx, "lang") || |
41 | 0 | !atomsCache->id_id.init(cx, "id") || |
42 | 0 | !atomsCache->dir_id.init(cx, "dir") || |
43 | 0 | !atomsCache->dbId_id.init(cx, "dbId") || |
44 | 0 | !atomsCache->data_id.init(cx, "data")) { |
45 | 0 | return false; |
46 | 0 | } |
47 | 0 | return true; |
48 | 0 | } |
49 | | |
50 | | bool |
51 | | AppNotificationServiceOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
52 | 0 | { |
53 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
54 | 0 | // Since in that case we will not have to do any property gets |
55 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
56 | 0 | // checkers by static analysis tools |
57 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
58 | 0 | AppNotificationServiceOptionsAtoms* atomsCache = nullptr; |
59 | 0 | if (cx) { |
60 | 0 | atomsCache = GetAtomCache<AppNotificationServiceOptionsAtoms>(cx); |
61 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
62 | 0 | return false; |
63 | 0 | } |
64 | 0 | } |
65 | 0 | |
66 | 0 | if (!IsConvertibleToDictionary(val)) { |
67 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
68 | 0 | } |
69 | 0 | |
70 | 0 | bool isNull = val.isNullOrUndefined(); |
71 | 0 | // We only need these if !isNull, in which case we have |cx|. |
72 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
73 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
74 | 0 | if (!isNull) { |
75 | 0 | MOZ_ASSERT(cx); |
76 | 0 | object.emplace(cx, &val.toObject()); |
77 | 0 | temp.emplace(cx); |
78 | 0 | } |
79 | 0 | if (!isNull) { |
80 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) { |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | if (!isNull && !temp->isUndefined()) { |
85 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mData)) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | } else { |
89 | 0 | static const char16_t data[] = { 0 }; |
90 | 0 | mData.Rebind(data, ArrayLength(data) - 1); |
91 | 0 | } |
92 | 0 | mIsAnyMemberPresent = true; |
93 | 0 |
|
94 | 0 | if (!isNull) { |
95 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->dbId_id, temp.ptr())) { |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | } |
99 | 0 | if (!isNull && !temp->isUndefined()) { |
100 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDbId)) { |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | } else { |
104 | 0 | static const char16_t data[] = { 0 }; |
105 | 0 | mDbId.Rebind(data, ArrayLength(data) - 1); |
106 | 0 | } |
107 | 0 | mIsAnyMemberPresent = true; |
108 | 0 |
|
109 | 0 | if (!isNull) { |
110 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->dir_id, temp.ptr())) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | } |
114 | 0 | if (!isNull && !temp->isUndefined()) { |
115 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDir)) { |
116 | 0 | return false; |
117 | 0 | } |
118 | 0 | } else { |
119 | 0 | static const char16_t data[] = { 0 }; |
120 | 0 | mDir.Rebind(data, ArrayLength(data) - 1); |
121 | 0 | } |
122 | 0 | mIsAnyMemberPresent = true; |
123 | 0 |
|
124 | 0 | if (!isNull) { |
125 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | } |
129 | 0 | if (!isNull && !temp->isUndefined()) { |
130 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) { |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | } else { |
134 | 0 | static const char16_t data[] = { 0 }; |
135 | 0 | mId.Rebind(data, ArrayLength(data) - 1); |
136 | 0 | } |
137 | 0 | mIsAnyMemberPresent = true; |
138 | 0 |
|
139 | 0 | if (!isNull) { |
140 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->lang_id, temp.ptr())) { |
141 | 0 | return false; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | if (!isNull && !temp->isUndefined()) { |
145 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLang)) { |
146 | 0 | return false; |
147 | 0 | } |
148 | 0 | } else { |
149 | 0 | static const char16_t data[] = { 0 }; |
150 | 0 | mLang.Rebind(data, ArrayLength(data) - 1); |
151 | 0 | } |
152 | 0 | mIsAnyMemberPresent = true; |
153 | 0 |
|
154 | 0 | if (!isNull) { |
155 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->manifestURL_id, temp.ptr())) { |
156 | 0 | return false; |
157 | 0 | } |
158 | 0 | } |
159 | 0 | if (!isNull && !temp->isUndefined()) { |
160 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mManifestURL)) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | } else { |
164 | 0 | static const char16_t data[] = { 0 }; |
165 | 0 | mManifestURL.Rebind(data, ArrayLength(data) - 1); |
166 | 0 | } |
167 | 0 | mIsAnyMemberPresent = true; |
168 | 0 |
|
169 | 0 | if (!isNull) { |
170 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->mozbehavior_id, temp.ptr())) { |
171 | 0 | return false; |
172 | 0 | } |
173 | 0 | } |
174 | 0 | if (!mMozbehavior.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'mozbehavior' member of AppNotificationServiceOptions", passedToJSImpl)) { |
175 | 0 | return false; |
176 | 0 | } |
177 | 0 | mIsAnyMemberPresent = true; |
178 | 0 |
|
179 | 0 | if (!isNull) { |
180 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->tag_id, temp.ptr())) { |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | } |
184 | 0 | if (!isNull && !temp->isUndefined()) { |
185 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mTag)) { |
186 | 0 | return false; |
187 | 0 | } |
188 | 0 | } else { |
189 | 0 | static const char16_t data[] = { 0 }; |
190 | 0 | mTag.Rebind(data, ArrayLength(data) - 1); |
191 | 0 | } |
192 | 0 | mIsAnyMemberPresent = true; |
193 | 0 |
|
194 | 0 | if (!isNull) { |
195 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->textClickable_id, temp.ptr())) { |
196 | 0 | return false; |
197 | 0 | } |
198 | 0 | } |
199 | 0 | if (!isNull && !temp->isUndefined()) { |
200 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mTextClickable)) { |
201 | 0 | return false; |
202 | 0 | } |
203 | 0 | } else { |
204 | 0 | mTextClickable = false; |
205 | 0 | } |
206 | 0 | mIsAnyMemberPresent = true; |
207 | 0 | return true; |
208 | 0 | } |
209 | | |
210 | | bool |
211 | | AppNotificationServiceOptions::Init(const nsAString& aJSON) |
212 | 0 | { |
213 | 0 | AutoJSAPI jsapi; |
214 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
215 | 0 | if (!cleanGlobal) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | if (!jsapi.Init(cleanGlobal)) { |
219 | 0 | return false; |
220 | 0 | } |
221 | 0 | JSContext* cx = jsapi.cx(); |
222 | 0 | JS::Rooted<JS::Value> json(cx); |
223 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
224 | 0 | NS_ENSURE_TRUE(ok, false); |
225 | 0 | return Init(cx, json); |
226 | 0 | } |
227 | | |
228 | | bool |
229 | | AppNotificationServiceOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
230 | 0 | { |
231 | 0 | AppNotificationServiceOptionsAtoms* atomsCache = GetAtomCache<AppNotificationServiceOptionsAtoms>(cx); |
232 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
233 | 0 | return false; |
234 | 0 | } |
235 | 0 | |
236 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
237 | 0 | if (!obj) { |
238 | 0 | return false; |
239 | 0 | } |
240 | 0 | rval.set(JS::ObjectValue(*obj)); |
241 | 0 |
|
242 | 0 | do { |
243 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
244 | 0 | JS::Rooted<JS::Value> temp(cx); |
245 | 0 | nsString const & currentValue = mData; |
246 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
247 | 0 | return false; |
248 | 0 | } |
249 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) { |
250 | 0 | return false; |
251 | 0 | } |
252 | 0 | break; |
253 | 0 | } while(false); |
254 | 0 |
|
255 | 0 | do { |
256 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
257 | 0 | JS::Rooted<JS::Value> temp(cx); |
258 | 0 | nsString const & currentValue = mDbId; |
259 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
260 | 0 | return false; |
261 | 0 | } |
262 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->dbId_id, temp, JSPROP_ENUMERATE)) { |
263 | 0 | return false; |
264 | 0 | } |
265 | 0 | break; |
266 | 0 | } while(false); |
267 | 0 |
|
268 | 0 | do { |
269 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
270 | 0 | JS::Rooted<JS::Value> temp(cx); |
271 | 0 | nsString const & currentValue = mDir; |
272 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
273 | 0 | return false; |
274 | 0 | } |
275 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->dir_id, temp, JSPROP_ENUMERATE)) { |
276 | 0 | return false; |
277 | 0 | } |
278 | 0 | break; |
279 | 0 | } while(false); |
280 | 0 |
|
281 | 0 | do { |
282 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
283 | 0 | JS::Rooted<JS::Value> temp(cx); |
284 | 0 | nsString const & currentValue = mId; |
285 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
286 | 0 | return false; |
287 | 0 | } |
288 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) { |
289 | 0 | return false; |
290 | 0 | } |
291 | 0 | break; |
292 | 0 | } while(false); |
293 | 0 |
|
294 | 0 | do { |
295 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
296 | 0 | JS::Rooted<JS::Value> temp(cx); |
297 | 0 | nsString const & currentValue = mLang; |
298 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
299 | 0 | return false; |
300 | 0 | } |
301 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->lang_id, temp, JSPROP_ENUMERATE)) { |
302 | 0 | return false; |
303 | 0 | } |
304 | 0 | break; |
305 | 0 | } while(false); |
306 | 0 |
|
307 | 0 | do { |
308 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
309 | 0 | JS::Rooted<JS::Value> temp(cx); |
310 | 0 | nsString const & currentValue = mManifestURL; |
311 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
312 | 0 | return false; |
313 | 0 | } |
314 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->manifestURL_id, temp, JSPROP_ENUMERATE)) { |
315 | 0 | return false; |
316 | 0 | } |
317 | 0 | break; |
318 | 0 | } while(false); |
319 | 0 |
|
320 | 0 | do { |
321 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
322 | 0 | JS::Rooted<JS::Value> temp(cx); |
323 | 0 | NotificationBehavior const & currentValue = mMozbehavior; |
324 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
325 | 0 | return false; |
326 | 0 | } |
327 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->mozbehavior_id, temp, JSPROP_ENUMERATE)) { |
328 | 0 | return false; |
329 | 0 | } |
330 | 0 | break; |
331 | 0 | } while(false); |
332 | 0 |
|
333 | 0 | do { |
334 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
335 | 0 | JS::Rooted<JS::Value> temp(cx); |
336 | 0 | nsString const & currentValue = mTag; |
337 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
338 | 0 | return false; |
339 | 0 | } |
340 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->tag_id, temp, JSPROP_ENUMERATE)) { |
341 | 0 | return false; |
342 | 0 | } |
343 | 0 | break; |
344 | 0 | } while(false); |
345 | 0 |
|
346 | 0 | do { |
347 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
348 | 0 | JS::Rooted<JS::Value> temp(cx); |
349 | 0 | bool const & currentValue = mTextClickable; |
350 | 0 | temp.setBoolean(currentValue); |
351 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->textClickable_id, temp, JSPROP_ENUMERATE)) { |
352 | 0 | return false; |
353 | 0 | } |
354 | 0 | break; |
355 | 0 | } while(false); |
356 | 0 |
|
357 | 0 | return true; |
358 | 0 | } |
359 | | |
360 | | bool |
361 | | AppNotificationServiceOptions::ToJSON(nsAString& aJSON) const |
362 | 0 | { |
363 | 0 | AutoJSAPI jsapi; |
364 | 0 | jsapi.Init(); |
365 | 0 | JSContext *cx = jsapi.cx(); |
366 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
367 | 0 | // because we'll only be creating objects, in ways that have no |
368 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
369 | 0 | // which likewise guarantees no side-effects for the sorts of |
370 | 0 | // things we will pass it. |
371 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
372 | 0 | JS::Rooted<JS::Value> val(cx); |
373 | 0 | if (!ToObjectInternal(cx, &val)) { |
374 | 0 | return false; |
375 | 0 | } |
376 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
377 | 0 | return StringifyToJSON(cx, obj, aJSON); |
378 | 0 | } |
379 | | |
380 | | void |
381 | | AppNotificationServiceOptions::TraceDictionary(JSTracer* trc) |
382 | 0 | { |
383 | 0 | } |
384 | | |
385 | | AppNotificationServiceOptions& |
386 | | AppNotificationServiceOptions::operator=(const AppNotificationServiceOptions& aOther) |
387 | 0 | { |
388 | 0 | DictionaryBase::operator=(aOther); |
389 | 0 | mData = aOther.mData; |
390 | 0 | mDbId = aOther.mDbId; |
391 | 0 | mDir = aOther.mDir; |
392 | 0 | mId = aOther.mId; |
393 | 0 | mLang = aOther.mLang; |
394 | 0 | mManifestURL = aOther.mManifestURL; |
395 | 0 | mMozbehavior = aOther.mMozbehavior; |
396 | 0 | mTag = aOther.mTag; |
397 | 0 | mTextClickable = aOther.mTextClickable; |
398 | 0 | return *this; |
399 | 0 | } |
400 | | |
401 | | namespace binding_detail { |
402 | | } // namespace binding_detail |
403 | | |
404 | | |
405 | | } // namespace dom |
406 | | } // namespace mozilla |