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