/work/obj-fuzz/dom/bindings/EventHandlerBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM EventHandler.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "mozilla/OwningNonNull.h" |
5 | | #include "mozilla/dom/BindingUtils.h" |
6 | | #include "mozilla/dom/Event.h" |
7 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
8 | | #include "mozilla/dom/Nullable.h" |
9 | | #include "mozilla/dom/PrimitiveConversions.h" |
10 | | #include "mozilla/dom/UnionConversions.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 | | void |
20 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningEventOrString& aUnion, const char* aName, uint32_t aFlags) |
21 | 0 | { |
22 | 0 | if (aUnion.IsEvent()) { |
23 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsEvent(), "mEvent", aFlags); |
24 | 0 | } |
25 | 0 | } |
26 | | |
27 | | |
28 | | void |
29 | | ImplCycleCollectionUnlink(OwningEventOrString& aUnion) |
30 | 0 | { |
31 | 0 | aUnion.Uninit(); |
32 | 0 | } |
33 | | |
34 | | |
35 | | bool |
36 | | EventOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
37 | 0 | { |
38 | 0 | switch (mType) { |
39 | 0 | case eUninitialized: { |
40 | 0 | return false; |
41 | 0 | break; |
42 | 0 | } |
43 | 0 | case eEvent: { |
44 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mEvent.Value(), rval)) { |
45 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
46 | 0 | return false; |
47 | 0 | } |
48 | 0 | return true; |
49 | 0 | break; |
50 | 0 | } |
51 | 0 | case eString: { |
52 | 0 | if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | return true; |
56 | 0 | break; |
57 | 0 | } |
58 | 0 | default: { |
59 | 0 | return false; |
60 | 0 | break; |
61 | 0 | } |
62 | 0 | } |
63 | 0 | |
64 | 0 | return false; |
65 | 0 | } |
66 | | |
67 | | |
68 | | OwningNonNull<mozilla::dom::Event>& |
69 | | OwningEventOrString::RawSetAsEvent() |
70 | 0 | { |
71 | 0 | if (mType == eEvent) { |
72 | 0 | return mValue.mEvent.Value(); |
73 | 0 | } |
74 | 0 | MOZ_ASSERT(mType == eUninitialized); |
75 | 0 | mType = eEvent; |
76 | 0 | return mValue.mEvent.SetValue(); |
77 | 0 | } |
78 | | |
79 | | OwningNonNull<mozilla::dom::Event>& |
80 | | OwningEventOrString::SetAsEvent() |
81 | 0 | { |
82 | 0 | if (mType == eEvent) { |
83 | 0 | return mValue.mEvent.Value(); |
84 | 0 | } |
85 | 0 | Uninit(); |
86 | 0 | mType = eEvent; |
87 | 0 | return mValue.mEvent.SetValue(); |
88 | 0 | } |
89 | | |
90 | | bool |
91 | | OwningEventOrString::TrySetToEvent(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
92 | 0 | { |
93 | 0 | tryNext = false; |
94 | 0 | { // scope for memberSlot |
95 | 0 | OwningNonNull<mozilla::dom::Event>& memberSlot = RawSetAsEvent(); |
96 | 0 | static_assert(IsRefcounted<mozilla::dom::Event>::value, "We can only store refcounted classes.");{ |
97 | 0 | nsresult rv = UnwrapObject<prototypes::id::Event, mozilla::dom::Event>(value, memberSlot); |
98 | 0 | if (NS_FAILED(rv)) { |
99 | 0 | DestroyEvent(); |
100 | 0 | tryNext = true; |
101 | 0 | return true; |
102 | 0 | } |
103 | 0 | } |
104 | 0 | } |
105 | 0 | return true; |
106 | 0 | } |
107 | | |
108 | | void |
109 | | OwningEventOrString::DestroyEvent() |
110 | 0 | { |
111 | 0 | MOZ_ASSERT(IsEvent(), "Wrong type!"); |
112 | 0 | mValue.mEvent.Destroy(); |
113 | 0 | mType = eUninitialized; |
114 | 0 | } |
115 | | |
116 | | |
117 | | |
118 | | |
119 | | nsString& |
120 | | OwningEventOrString::RawSetAsString() |
121 | 0 | { |
122 | 0 | if (mType == eString) { |
123 | 0 | return mValue.mString.Value(); |
124 | 0 | } |
125 | 0 | MOZ_ASSERT(mType == eUninitialized); |
126 | 0 | mType = eString; |
127 | 0 | return mValue.mString.SetValue(); |
128 | 0 | } |
129 | | |
130 | | nsString& |
131 | | OwningEventOrString::SetAsString() |
132 | 0 | { |
133 | 0 | if (mType == eString) { |
134 | 0 | return mValue.mString.Value(); |
135 | 0 | } |
136 | 0 | Uninit(); |
137 | 0 | mType = eString; |
138 | 0 | return mValue.mString.SetValue(); |
139 | 0 | } |
140 | | |
141 | | bool |
142 | | OwningEventOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
143 | 0 | { |
144 | 0 | tryNext = false; |
145 | 0 | { // scope for memberSlot |
146 | 0 | nsString& memberSlot = RawSetAsString(); |
147 | 0 | if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) { |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | } |
151 | 0 | return true; |
152 | 0 | } |
153 | | |
154 | | |
155 | | void |
156 | | OwningEventOrString::DestroyString() |
157 | 0 | { |
158 | 0 | MOZ_ASSERT(IsString(), "Wrong type!"); |
159 | 0 | mValue.mString.Destroy(); |
160 | 0 | mType = eUninitialized; |
161 | 0 | } |
162 | | |
163 | | |
164 | | |
165 | | |
166 | | void |
167 | | OwningEventOrString::Uninit() |
168 | | { |
169 | | switch (mType) { |
170 | | case eUninitialized: { |
171 | | break; |
172 | | } |
173 | | case eEvent: { |
174 | | DestroyEvent(); |
175 | | break; |
176 | | } |
177 | | case eString: { |
178 | | DestroyString(); |
179 | | break; |
180 | | } |
181 | | } |
182 | | } |
183 | | |
184 | | bool |
185 | | OwningEventOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
186 | 0 | { |
187 | 0 | switch (mType) { |
188 | 0 | case eUninitialized: { |
189 | 0 | return false; |
190 | 0 | break; |
191 | 0 | } |
192 | 0 | case eEvent: { |
193 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mEvent.Value(), rval)) { |
194 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
195 | 0 | return false; |
196 | 0 | } |
197 | 0 | return true; |
198 | 0 | break; |
199 | 0 | } |
200 | 0 | case eString: { |
201 | 0 | if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { |
202 | 0 | return false; |
203 | 0 | } |
204 | 0 | return true; |
205 | 0 | break; |
206 | 0 | } |
207 | 0 | default: { |
208 | 0 | return false; |
209 | 0 | break; |
210 | 0 | } |
211 | 0 | } |
212 | 0 | |
213 | 0 | return false; |
214 | 0 | } |
215 | | |
216 | | void |
217 | | OwningEventOrString::TraceUnion(JSTracer* trc) |
218 | 0 | { |
219 | 0 | } |
220 | | |
221 | | OwningEventOrString& |
222 | | OwningEventOrString::operator=(const OwningEventOrString& aOther) |
223 | 0 | { |
224 | 0 | switch (aOther.mType) { |
225 | 0 | case eUninitialized: { |
226 | 0 | MOZ_ASSERT(mType == eUninitialized, |
227 | 0 | "We need to destroy ourselves?"); |
228 | 0 | break; |
229 | 0 | } |
230 | 0 | case eEvent: { |
231 | 0 | SetAsEvent() = aOther.GetAsEvent(); |
232 | 0 | break; |
233 | 0 | } |
234 | 0 | case eString: { |
235 | 0 | SetAsString() = aOther.GetAsString(); |
236 | 0 | break; |
237 | 0 | } |
238 | 0 | } |
239 | 0 | return *this; |
240 | 0 | } |
241 | | |
242 | | |
243 | | void |
244 | | EventHandlerNonNull::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, Event& event, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv) |
245 | 0 | { |
246 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
247 | 0 | JS::AutoValueVector argv(cx); |
248 | 0 | if (!argv.resize(1)) { |
249 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
250 | 0 | return; |
251 | 0 | } |
252 | 0 | unsigned argc = 1; |
253 | 0 |
|
254 | 0 | do { |
255 | 0 | if (!GetOrCreateDOMReflector(cx, event, argv[0])) { |
256 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
257 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
258 | 0 | return; |
259 | 0 | } |
260 | 0 | break; |
261 | 0 | } while (false); |
262 | 0 |
|
263 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
264 | 0 | if (JS::IsCallable(mCallback) && !JS::Call(cx, aThisVal, callable, |
265 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
266 | 0 | aRv.NoteJSContextException(cx); |
267 | 0 | return; |
268 | 0 | } |
269 | 0 | JS::Rooted<JS::Value> rvalDecl(cx); |
270 | 0 | #ifdef __clang__ |
271 | 0 | #pragma clang diagnostic push |
272 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
273 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
274 | 0 | #endif // __clang__ |
275 | 0 | if ((false) && !CallerSubsumes(rval)) { |
276 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "return value of EventHandlerNonNull"); |
277 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
278 | 0 | return; |
279 | 0 | } |
280 | 0 | #ifdef __clang__ |
281 | 0 | #pragma clang diagnostic pop |
282 | 0 | #endif // __clang__ |
283 | 0 | rvalDecl = rval; |
284 | 0 | aRetVal.set(rvalDecl); |
285 | 0 | } |
286 | | |
287 | | |
288 | | |
289 | | void |
290 | | OnBeforeUnloadEventHandlerNonNull::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, Event& event, nsString& aRetVal, ErrorResult& aRv) |
291 | 0 | { |
292 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
293 | 0 | JS::AutoValueVector argv(cx); |
294 | 0 | if (!argv.resize(1)) { |
295 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
296 | 0 | return; |
297 | 0 | } |
298 | 0 | unsigned argc = 1; |
299 | 0 |
|
300 | 0 | do { |
301 | 0 | if (!GetOrCreateDOMReflector(cx, event, argv[0])) { |
302 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
303 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
304 | 0 | return; |
305 | 0 | } |
306 | 0 | break; |
307 | 0 | } while (false); |
308 | 0 |
|
309 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
310 | 0 | if (JS::IsCallable(mCallback) && !JS::Call(cx, aThisVal, callable, |
311 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
312 | 0 | aRv.NoteJSContextException(cx); |
313 | 0 | return; |
314 | 0 | } |
315 | 0 | binding_detail::FakeString rvalDecl; |
316 | 0 | if (!ConvertJSValueToString(cx, rval, eNull, eNull, rvalDecl)) { |
317 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
318 | 0 | return; |
319 | 0 | } |
320 | 0 | aRetVal = rvalDecl; |
321 | 0 | } |
322 | | |
323 | | |
324 | | |
325 | | void |
326 | | OnErrorEventHandlerNonNull::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const EventOrString& event, const Optional<nsAString>& source, const Optional<uint32_t>& lineno, const Optional<uint32_t>& column, const Optional<JS::Handle<JS::Value>>& error, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv) |
327 | 0 | { |
328 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
329 | 0 | JS::AutoValueVector argv(cx); |
330 | 0 | if (!argv.resize(5)) { |
331 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
332 | 0 | return; |
333 | 0 | } |
334 | 0 | unsigned argc = 5; |
335 | 0 |
|
336 | 0 | do { |
337 | 0 | if (error.WasPassed()) { |
338 | 0 | JS::ExposeValueToActiveJS(error.Value()); |
339 | 0 | argv[4].set(error.Value()); |
340 | 0 | if (!MaybeWrapValue(cx, argv[4])) { |
341 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
342 | 0 | return; |
343 | 0 | } |
344 | 0 | break; |
345 | 0 | } else if (argc == 5) { |
346 | 0 | // This is our current trailing argument; reduce argc |
347 | 0 | --argc; |
348 | 0 | } else { |
349 | 0 | argv[4].setUndefined(); |
350 | 0 | } |
351 | 0 | } while (false); |
352 | 0 |
|
353 | 0 | do { |
354 | 0 | if (column.WasPassed()) { |
355 | 0 | argv[3].setNumber(column.Value()); |
356 | 0 | break; |
357 | 0 | } else if (argc == 4) { |
358 | 0 | // This is our current trailing argument; reduce argc |
359 | 0 | --argc; |
360 | 0 | } else { |
361 | 0 | argv[3].setUndefined(); |
362 | 0 | } |
363 | 0 | } while (false); |
364 | 0 |
|
365 | 0 | do { |
366 | 0 | if (lineno.WasPassed()) { |
367 | 0 | argv[2].setNumber(lineno.Value()); |
368 | 0 | break; |
369 | 0 | } else if (argc == 3) { |
370 | 0 | // This is our current trailing argument; reduce argc |
371 | 0 | --argc; |
372 | 0 | } else { |
373 | 0 | argv[2].setUndefined(); |
374 | 0 | } |
375 | 0 | } while (false); |
376 | 0 |
|
377 | 0 | do { |
378 | 0 | if (source.WasPassed()) { |
379 | 0 | nsString mutableStr(source.Value()); |
380 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) { |
381 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
382 | 0 | return; |
383 | 0 | } |
384 | 0 | break; |
385 | 0 | } else if (argc == 2) { |
386 | 0 | // This is our current trailing argument; reduce argc |
387 | 0 | --argc; |
388 | 0 | } else { |
389 | 0 | argv[1].setUndefined(); |
390 | 0 | } |
391 | 0 | } while (false); |
392 | 0 |
|
393 | 0 | do { |
394 | 0 | if (!event.ToJSVal(cx, CallbackKnownNotGray(), argv[0])) { |
395 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
396 | 0 | return; |
397 | 0 | } |
398 | 0 | break; |
399 | 0 | } while (false); |
400 | 0 |
|
401 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
402 | 0 | if (JS::IsCallable(mCallback) && !JS::Call(cx, aThisVal, callable, |
403 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
404 | 0 | aRv.NoteJSContextException(cx); |
405 | 0 | return; |
406 | 0 | } |
407 | 0 | JS::Rooted<JS::Value> rvalDecl(cx); |
408 | 0 | #ifdef __clang__ |
409 | 0 | #pragma clang diagnostic push |
410 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
411 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
412 | 0 | #endif // __clang__ |
413 | 0 | if ((false) && !CallerSubsumes(rval)) { |
414 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "return value of OnErrorEventHandlerNonNull"); |
415 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
416 | 0 | return; |
417 | 0 | } |
418 | 0 | #ifdef __clang__ |
419 | 0 | #pragma clang diagnostic pop |
420 | 0 | #endif // __clang__ |
421 | 0 | rvalDecl = rval; |
422 | 0 | aRetVal.set(rvalDecl); |
423 | 0 | } |
424 | | |
425 | | |
426 | | |
427 | | namespace binding_detail { |
428 | | } // namespace binding_detail |
429 | | |
430 | | |
431 | | namespace binding_detail { |
432 | | } // namespace binding_detail |
433 | | |
434 | | |
435 | | namespace binding_detail { |
436 | | } // namespace binding_detail |
437 | | |
438 | | |
439 | | } // namespace dom |
440 | | } // namespace mozilla |