/work/obj-fuzz/dom/bindings/BrowserElementBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM BrowserElement.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "BrowserElementBinding.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 BrowserFindCaseSensitivityValues { |
20 | | extern const EnumEntry strings[3] = { |
21 | | {"case-sensitive", 14}, |
22 | | {"case-insensitive", 16}, |
23 | | { nullptr, 0 } |
24 | | }; |
25 | | } // namespace BrowserFindCaseSensitivityValues |
26 | | |
27 | | bool |
28 | | ToJSValue(JSContext* aCx, BrowserFindCaseSensitivity aArgument, JS::MutableHandle<JS::Value> aValue) |
29 | 0 | { |
30 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(BrowserFindCaseSensitivityValues::strings)); |
31 | 0 | JSString* resultStr = |
32 | 0 | JS_NewStringCopyN(aCx, BrowserFindCaseSensitivityValues::strings[uint32_t(aArgument)].value, |
33 | 0 | BrowserFindCaseSensitivityValues::strings[uint32_t(aArgument)].length); |
34 | 0 | if (!resultStr) { |
35 | 0 | return false; |
36 | 0 | } |
37 | 0 | aValue.setString(resultStr); |
38 | 0 | return true; |
39 | 0 | } |
40 | | |
41 | | |
42 | | namespace BrowserFindDirectionValues { |
43 | | extern const EnumEntry strings[3] = { |
44 | | {"forward", 7}, |
45 | | {"backward", 8}, |
46 | | { nullptr, 0 } |
47 | | }; |
48 | | } // namespace BrowserFindDirectionValues |
49 | | |
50 | | bool |
51 | | ToJSValue(JSContext* aCx, BrowserFindDirection aArgument, JS::MutableHandle<JS::Value> aValue) |
52 | 0 | { |
53 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(BrowserFindDirectionValues::strings)); |
54 | 0 | JSString* resultStr = |
55 | 0 | JS_NewStringCopyN(aCx, BrowserFindDirectionValues::strings[uint32_t(aArgument)].value, |
56 | 0 | BrowserFindDirectionValues::strings[uint32_t(aArgument)].length); |
57 | 0 | if (!resultStr) { |
58 | 0 | return false; |
59 | 0 | } |
60 | 0 | aValue.setString(resultStr); |
61 | 0 | return true; |
62 | 0 | } |
63 | | |
64 | | |
65 | | |
66 | | BrowserElementDownloadOptions::BrowserElementDownloadOptions() |
67 | 0 | { |
68 | 0 | // Safe to pass a null context if we pass a null value |
69 | 0 | Init(nullptr, JS::NullHandleValue); |
70 | 0 | } |
71 | | |
72 | | |
73 | | |
74 | | bool |
75 | | BrowserElementDownloadOptions::InitIds(JSContext* cx, BrowserElementDownloadOptionsAtoms* atomsCache) |
76 | 0 | { |
77 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
78 | 0 |
|
79 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
80 | 0 | // uninitialized. |
81 | 0 | if (!atomsCache->referrer_id.init(cx, "referrer") || |
82 | 0 | !atomsCache->filename_id.init(cx, "filename")) { |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | return true; |
86 | 0 | } |
87 | | |
88 | | bool |
89 | | BrowserElementDownloadOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
90 | 0 | { |
91 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
92 | 0 | // Since in that case we will not have to do any property gets |
93 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
94 | 0 | // checkers by static analysis tools |
95 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
96 | 0 | BrowserElementDownloadOptionsAtoms* atomsCache = nullptr; |
97 | 0 | if (cx) { |
98 | 0 | atomsCache = GetAtomCache<BrowserElementDownloadOptionsAtoms>(cx); |
99 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | } |
103 | 0 | |
104 | 0 | if (!IsConvertibleToDictionary(val)) { |
105 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
106 | 0 | } |
107 | 0 | |
108 | 0 | bool isNull = val.isNullOrUndefined(); |
109 | 0 | // We only need these if !isNull, in which case we have |cx|. |
110 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
111 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
112 | 0 | if (!isNull) { |
113 | 0 | MOZ_ASSERT(cx); |
114 | 0 | object.emplace(cx, &val.toObject()); |
115 | 0 | temp.emplace(cx); |
116 | 0 | } |
117 | 0 | if (!isNull) { |
118 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->filename_id, temp.ptr())) { |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | } |
122 | 0 | if (!isNull && !temp->isUndefined()) { |
123 | 0 | mFilename.Construct(); |
124 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mFilename.Value()))) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | mIsAnyMemberPresent = true; |
128 | 0 | } |
129 | 0 |
|
130 | 0 | if (!isNull) { |
131 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->referrer_id, temp.ptr())) { |
132 | 0 | return false; |
133 | 0 | } |
134 | 0 | } |
135 | 0 | if (!isNull && !temp->isUndefined()) { |
136 | 0 | mReferrer.Construct(); |
137 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mReferrer.Value()))) { |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | mIsAnyMemberPresent = true; |
141 | 0 | } |
142 | 0 | return true; |
143 | 0 | } |
144 | | |
145 | | bool |
146 | | BrowserElementDownloadOptions::Init(const nsAString& aJSON) |
147 | 0 | { |
148 | 0 | AutoJSAPI jsapi; |
149 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
150 | 0 | if (!cleanGlobal) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | if (!jsapi.Init(cleanGlobal)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | JSContext* cx = jsapi.cx(); |
157 | 0 | JS::Rooted<JS::Value> json(cx); |
158 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
159 | 0 | NS_ENSURE_TRUE(ok, false); |
160 | 0 | return Init(cx, json); |
161 | 0 | } |
162 | | |
163 | | bool |
164 | | BrowserElementDownloadOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
165 | 0 | { |
166 | 0 | BrowserElementDownloadOptionsAtoms* atomsCache = GetAtomCache<BrowserElementDownloadOptionsAtoms>(cx); |
167 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
168 | 0 | return false; |
169 | 0 | } |
170 | 0 | |
171 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
172 | 0 | if (!obj) { |
173 | 0 | return false; |
174 | 0 | } |
175 | 0 | rval.set(JS::ObjectValue(*obj)); |
176 | 0 |
|
177 | 0 | if (mFilename.WasPassed()) { |
178 | 0 | do { |
179 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
180 | 0 | JS::Rooted<JS::Value> temp(cx); |
181 | 0 | nsString const & currentValue = mFilename.InternalValue(); |
182 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->filename_id, temp, JSPROP_ENUMERATE)) { |
186 | 0 | return false; |
187 | 0 | } |
188 | 0 | break; |
189 | 0 | } while(false); |
190 | 0 | } |
191 | 0 |
|
192 | 0 | if (mReferrer.WasPassed()) { |
193 | 0 | do { |
194 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
195 | 0 | JS::Rooted<JS::Value> temp(cx); |
196 | 0 | nsString const & currentValue = mReferrer.InternalValue(); |
197 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
198 | 0 | return false; |
199 | 0 | } |
200 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->referrer_id, temp, JSPROP_ENUMERATE)) { |
201 | 0 | return false; |
202 | 0 | } |
203 | 0 | break; |
204 | 0 | } while(false); |
205 | 0 | } |
206 | 0 |
|
207 | 0 | return true; |
208 | 0 | } |
209 | | |
210 | | bool |
211 | | BrowserElementDownloadOptions::ToJSON(nsAString& aJSON) const |
212 | 0 | { |
213 | 0 | AutoJSAPI jsapi; |
214 | 0 | jsapi.Init(); |
215 | 0 | JSContext *cx = jsapi.cx(); |
216 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
217 | 0 | // because we'll only be creating objects, in ways that have no |
218 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
219 | 0 | // which likewise guarantees no side-effects for the sorts of |
220 | 0 | // things we will pass it. |
221 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
222 | 0 | JS::Rooted<JS::Value> val(cx); |
223 | 0 | if (!ToObjectInternal(cx, &val)) { |
224 | 0 | return false; |
225 | 0 | } |
226 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
227 | 0 | return StringifyToJSON(cx, obj, aJSON); |
228 | 0 | } |
229 | | |
230 | | void |
231 | | BrowserElementDownloadOptions::TraceDictionary(JSTracer* trc) |
232 | 0 | { |
233 | 0 | } |
234 | | |
235 | | BrowserElementDownloadOptions& |
236 | | BrowserElementDownloadOptions::operator=(const BrowserElementDownloadOptions& aOther) |
237 | 0 | { |
238 | 0 | DictionaryBase::operator=(aOther); |
239 | 0 | mFilename.Reset(); |
240 | 0 | if (aOther.mFilename.WasPassed()) { |
241 | 0 | mFilename.Construct(aOther.mFilename.Value()); |
242 | 0 | } |
243 | 0 | mReferrer.Reset(); |
244 | 0 | if (aOther.mReferrer.WasPassed()) { |
245 | 0 | mReferrer.Construct(aOther.mReferrer.Value()); |
246 | 0 | } |
247 | 0 | return *this; |
248 | 0 | } |
249 | | |
250 | | namespace binding_detail { |
251 | | } // namespace binding_detail |
252 | | |
253 | | |
254 | | |
255 | | BrowserElementExecuteScriptOptions::BrowserElementExecuteScriptOptions() |
256 | 0 | { |
257 | 0 | // Safe to pass a null context if we pass a null value |
258 | 0 | Init(nullptr, JS::NullHandleValue); |
259 | 0 | } |
260 | | |
261 | | |
262 | | |
263 | | bool |
264 | | BrowserElementExecuteScriptOptions::InitIds(JSContext* cx, BrowserElementExecuteScriptOptionsAtoms* atomsCache) |
265 | 0 | { |
266 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
267 | 0 |
|
268 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
269 | 0 | // uninitialized. |
270 | 0 | if (!atomsCache->url_id.init(cx, "url") || |
271 | 0 | !atomsCache->origin_id.init(cx, "origin")) { |
272 | 0 | return false; |
273 | 0 | } |
274 | 0 | return true; |
275 | 0 | } |
276 | | |
277 | | bool |
278 | | BrowserElementExecuteScriptOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
279 | 0 | { |
280 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
281 | 0 | // Since in that case we will not have to do any property gets |
282 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
283 | 0 | // checkers by static analysis tools |
284 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
285 | 0 | BrowserElementExecuteScriptOptionsAtoms* atomsCache = nullptr; |
286 | 0 | if (cx) { |
287 | 0 | atomsCache = GetAtomCache<BrowserElementExecuteScriptOptionsAtoms>(cx); |
288 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
289 | 0 | return false; |
290 | 0 | } |
291 | 0 | } |
292 | 0 | |
293 | 0 | if (!IsConvertibleToDictionary(val)) { |
294 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
295 | 0 | } |
296 | 0 | |
297 | 0 | bool isNull = val.isNullOrUndefined(); |
298 | 0 | // We only need these if !isNull, in which case we have |cx|. |
299 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
300 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
301 | 0 | if (!isNull) { |
302 | 0 | MOZ_ASSERT(cx); |
303 | 0 | object.emplace(cx, &val.toObject()); |
304 | 0 | temp.emplace(cx); |
305 | 0 | } |
306 | 0 | if (!isNull) { |
307 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->origin_id, temp.ptr())) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | } |
311 | 0 | if (!isNull && !temp->isUndefined()) { |
312 | 0 | mOrigin.Construct(); |
313 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mOrigin.Value()))) { |
314 | 0 | return false; |
315 | 0 | } |
316 | 0 | mIsAnyMemberPresent = true; |
317 | 0 | } |
318 | 0 |
|
319 | 0 | if (!isNull) { |
320 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->url_id, temp.ptr())) { |
321 | 0 | return false; |
322 | 0 | } |
323 | 0 | } |
324 | 0 | if (!isNull && !temp->isUndefined()) { |
325 | 0 | mUrl.Construct(); |
326 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mUrl.Value()))) { |
327 | 0 | return false; |
328 | 0 | } |
329 | 0 | mIsAnyMemberPresent = true; |
330 | 0 | } |
331 | 0 | return true; |
332 | 0 | } |
333 | | |
334 | | bool |
335 | | BrowserElementExecuteScriptOptions::Init(const nsAString& aJSON) |
336 | 0 | { |
337 | 0 | AutoJSAPI jsapi; |
338 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
339 | 0 | if (!cleanGlobal) { |
340 | 0 | return false; |
341 | 0 | } |
342 | 0 | if (!jsapi.Init(cleanGlobal)) { |
343 | 0 | return false; |
344 | 0 | } |
345 | 0 | JSContext* cx = jsapi.cx(); |
346 | 0 | JS::Rooted<JS::Value> json(cx); |
347 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
348 | 0 | NS_ENSURE_TRUE(ok, false); |
349 | 0 | return Init(cx, json); |
350 | 0 | } |
351 | | |
352 | | bool |
353 | | BrowserElementExecuteScriptOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
354 | 0 | { |
355 | 0 | BrowserElementExecuteScriptOptionsAtoms* atomsCache = GetAtomCache<BrowserElementExecuteScriptOptionsAtoms>(cx); |
356 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | |
360 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
361 | 0 | if (!obj) { |
362 | 0 | return false; |
363 | 0 | } |
364 | 0 | rval.set(JS::ObjectValue(*obj)); |
365 | 0 |
|
366 | 0 | if (mOrigin.WasPassed()) { |
367 | 0 | do { |
368 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
369 | 0 | JS::Rooted<JS::Value> temp(cx); |
370 | 0 | nsString const & currentValue = mOrigin.InternalValue(); |
371 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
372 | 0 | return false; |
373 | 0 | } |
374 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->origin_id, temp, JSPROP_ENUMERATE)) { |
375 | 0 | return false; |
376 | 0 | } |
377 | 0 | break; |
378 | 0 | } while(false); |
379 | 0 | } |
380 | 0 |
|
381 | 0 | if (mUrl.WasPassed()) { |
382 | 0 | do { |
383 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
384 | 0 | JS::Rooted<JS::Value> temp(cx); |
385 | 0 | nsString const & currentValue = mUrl.InternalValue(); |
386 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
387 | 0 | return false; |
388 | 0 | } |
389 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->url_id, temp, JSPROP_ENUMERATE)) { |
390 | 0 | return false; |
391 | 0 | } |
392 | 0 | break; |
393 | 0 | } while(false); |
394 | 0 | } |
395 | 0 |
|
396 | 0 | return true; |
397 | 0 | } |
398 | | |
399 | | bool |
400 | | BrowserElementExecuteScriptOptions::ToJSON(nsAString& aJSON) const |
401 | 0 | { |
402 | 0 | AutoJSAPI jsapi; |
403 | 0 | jsapi.Init(); |
404 | 0 | JSContext *cx = jsapi.cx(); |
405 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
406 | 0 | // because we'll only be creating objects, in ways that have no |
407 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
408 | 0 | // which likewise guarantees no side-effects for the sorts of |
409 | 0 | // things we will pass it. |
410 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
411 | 0 | JS::Rooted<JS::Value> val(cx); |
412 | 0 | if (!ToObjectInternal(cx, &val)) { |
413 | 0 | return false; |
414 | 0 | } |
415 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
416 | 0 | return StringifyToJSON(cx, obj, aJSON); |
417 | 0 | } |
418 | | |
419 | | void |
420 | | BrowserElementExecuteScriptOptions::TraceDictionary(JSTracer* trc) |
421 | 0 | { |
422 | 0 | } |
423 | | |
424 | | BrowserElementExecuteScriptOptions& |
425 | | BrowserElementExecuteScriptOptions::operator=(const BrowserElementExecuteScriptOptions& aOther) |
426 | 0 | { |
427 | 0 | DictionaryBase::operator=(aOther); |
428 | 0 | mOrigin.Reset(); |
429 | 0 | if (aOther.mOrigin.WasPassed()) { |
430 | 0 | mOrigin.Construct(aOther.mOrigin.Value()); |
431 | 0 | } |
432 | 0 | mUrl.Reset(); |
433 | 0 | if (aOther.mUrl.WasPassed()) { |
434 | 0 | mUrl.Construct(aOther.mUrl.Value()); |
435 | 0 | } |
436 | 0 | return *this; |
437 | 0 | } |
438 | | |
439 | | namespace binding_detail { |
440 | | } // namespace binding_detail |
441 | | |
442 | | |
443 | | void |
444 | | BrowserElementNextPaintEventCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv) |
445 | 0 | { |
446 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
447 | 0 |
|
448 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
449 | 0 | if (!JS::Call(cx, aThisVal, callable, |
450 | 0 | JS::HandleValueArray::empty(), &rval)) { |
451 | 0 | aRv.NoteJSContextException(cx); |
452 | 0 | return; |
453 | 0 | } |
454 | 0 | } |
455 | | |
456 | | |
457 | | |
458 | | namespace binding_detail { |
459 | | } // namespace binding_detail |
460 | | |
461 | | |
462 | | } // namespace dom |
463 | | } // namespace mozilla |