Line data Source code
1 : #ifndef mozilla_dom_UnionConversions_h
2 : #define mozilla_dom_UnionConversions_h
3 :
4 : #include "AnimatableBinding.h"
5 : #include "AudioTrackBinding.h"
6 : #include "BlobBinding.h"
7 : #include "CSSPseudoElementBinding.h"
8 : #include "CanvasRenderingContext2DBinding.h"
9 : #include "ClientBinding.h"
10 : #include "ConsoleBinding.h"
11 : #include "CustomEventBinding.h"
12 : #include "DirectoryBinding.h"
13 : #include "DocumentBinding.h"
14 : #include "ElementBinding.h"
15 : #include "EventBinding.h"
16 : #include "EventHandlerBinding.h"
17 : #include "EventTargetBinding.h"
18 : #include "ExtendableMessageEventBinding.h"
19 : #include "ExternalBinding.h"
20 : #include "FetchBinding.h"
21 : #include "FileBinding.h"
22 : #include "FontFaceBinding.h"
23 : #include "FormDataBinding.h"
24 : #include "GeometryUtilsBinding.h"
25 : #include "HTMLAllCollectionBinding.h"
26 : #include "HTMLCanvasElementBinding.h"
27 : #include "HTMLCollectionBinding.h"
28 : #include "HTMLElementBinding.h"
29 : #include "HTMLFormControlsCollectionBinding.h"
30 : #include "HTMLImageElementBinding.h"
31 : #include "HTMLOptGroupElementBinding.h"
32 : #include "HTMLOptionElementBinding.h"
33 : #include "HTMLVideoElementBinding.h"
34 : #include "HeadersBinding.h"
35 : #include "IDBCursorBinding.h"
36 : #include "IDBFileHandleBinding.h"
37 : #include "IDBIndexBinding.h"
38 : #include "IDBObjectStoreBinding.h"
39 : #include "IDBRequestBinding.h"
40 : #include "ImageBitmapBinding.h"
41 : #include "ImageDataBinding.h"
42 : #include "InstallTriggerBinding.h"
43 : #include "IntersectionObserverBinding.h"
44 : #include "KeyframeAnimationOptionsBinding.h"
45 : #include "KeyframeEffectBinding.h"
46 : #include "LocationBinding.h"
47 : #include "MatchPatternBinding.h"
48 : #include "MediaStreamBinding.h"
49 : #include "MediaStreamTrackBinding.h"
50 : #include "MediaTrackConstraintSetBinding.h"
51 : #include "MessageEventBinding.h"
52 : #include "MessagePortBinding.h"
53 : #include "NodeBinding.h"
54 : #include "OffscreenCanvasBinding.h"
55 : #include "PushEventBinding.h"
56 : #include "PushManagerBinding.h"
57 : #include "RTCIceCandidateBinding.h"
58 : #include "RTCPeerConnectionBinding.h"
59 : #include "RadioNodeListBinding.h"
60 : #include "RequestBinding.h"
61 : #include "ServiceWorkerBinding.h"
62 : #include "SharedWorkerBinding.h"
63 : #include "TestInterfaceJSBinding.h"
64 : #include "TestInterfaceJSMaplikeSetlikeIterableBinding.h"
65 : #include "TextBinding.h"
66 : #include "TextTrackBinding.h"
67 : #include "TrackEventBinding.h"
68 : #include "UDPSocketBinding.h"
69 : #include "URLSearchParamsBinding.h"
70 : #include "VTTCueBinding.h"
71 : #include "VideoTrackBinding.h"
72 : #include "WebAuthenticationBinding.h"
73 : #include "WebGL2RenderingContextBinding.h"
74 : #include "WebGLRenderingContextBinding.h"
75 : #include "WindowBinding.h"
76 : #include "WorkerBinding.h"
77 : #include "jsfriendapi.h"
78 : #include "mozilla/FloatingPoint.h"
79 : #include "mozilla/dom/PrimitiveConversions.h"
80 : #include "mozilla/dom/Record.h"
81 : #include "mozilla/dom/TypedArray.h"
82 : #include "mozilla/dom/UnionTypes.h"
83 : #include "nsDebug.h"
84 : #include "nsPIDOMWindow.h"
85 :
86 : namespace mozilla {
87 : namespace dom {
88 : class AddEventListenerOptionsOrBooleanArgument
89 : {
90 : AddEventListenerOptionsOrBoolean& mUnion;
91 :
92 : AddEventListenerOptionsOrBooleanArgument(const AddEventListenerOptionsOrBooleanArgument&) = delete;
93 : AddEventListenerOptionsOrBooleanArgument& operator=(const AddEventListenerOptionsOrBooleanArgument&) = delete;
94 : public:
95 176 : explicit inline AddEventListenerOptionsOrBooleanArgument(const AddEventListenerOptionsOrBoolean& aUnion)
96 176 : : mUnion(const_cast<AddEventListenerOptionsOrBoolean&>(aUnion))
97 : {
98 176 : }
99 :
100 : inline bool
101 47 : TrySetToAddEventListenerOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
102 : {
103 47 : tryNext = false;
104 : { // scope for memberSlot
105 47 : binding_detail::FastAddEventListenerOptions& memberSlot = RawSetAsAddEventListenerOptions();
106 47 : if (!IsConvertibleToDictionary(value)) {
107 41 : mUnion.DestroyAddEventListenerOptions();
108 41 : tryNext = true;
109 41 : return true;
110 : }
111 6 : if (!memberSlot.Init(cx, value, "Member of AddEventListenerOptionsOrBoolean", passedToJSImpl)) {
112 0 : return false;
113 : }
114 : }
115 6 : return true;
116 : }
117 :
118 : inline bool
119 41 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
120 : {
121 41 : tryNext = false;
122 : { // scope for memberSlot
123 41 : bool& memberSlot = RawSetAsBoolean();
124 41 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
125 0 : return false;
126 : }
127 : }
128 41 : return true;
129 : }
130 :
131 : private:
132 : inline binding_detail::FastAddEventListenerOptions&
133 47 : RawSetAsAddEventListenerOptions()
134 : {
135 47 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
136 47 : mUnion.mType = mUnion.eAddEventListenerOptions;
137 47 : return mUnion.mValue.mAddEventListenerOptions.SetValue();
138 : }
139 :
140 : inline bool&
141 41 : RawSetAsBoolean()
142 : {
143 41 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
144 41 : mUnion.mType = mUnion.eBoolean;
145 41 : return mUnion.mValue.mBoolean.SetValue();
146 : }
147 : };
148 :
149 : class ArrayBufferOrLongArgument
150 : {
151 : ArrayBufferOrLong& mUnion;
152 :
153 : ArrayBufferOrLongArgument(const ArrayBufferOrLongArgument&) = delete;
154 : ArrayBufferOrLongArgument& operator=(const ArrayBufferOrLongArgument&) = delete;
155 : public:
156 : explicit inline ArrayBufferOrLongArgument(const ArrayBufferOrLong& aUnion)
157 : : mUnion(const_cast<ArrayBufferOrLong&>(aUnion))
158 : {
159 : }
160 :
161 : inline bool
162 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
163 : {
164 : tryNext = false;
165 : { // scope for memberSlot
166 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
167 : if (!memberSlot.Init(&value.toObject())) {
168 : mUnion.DestroyArrayBuffer();
169 : tryNext = true;
170 : return true;
171 : }
172 : }
173 : return true;
174 : }
175 :
176 : inline bool
177 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
178 : {
179 : tryNext = false;
180 : { // scope for memberSlot
181 : int32_t& memberSlot = RawSetAsLong();
182 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
183 : return false;
184 : }
185 : }
186 : return true;
187 : }
188 :
189 : private:
190 : inline RootedTypedArray<ArrayBuffer>&
191 : RawSetAsArrayBuffer(JSContext* cx)
192 : {
193 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
194 : mUnion.mType = mUnion.eArrayBuffer;
195 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
196 : }
197 :
198 : inline int32_t&
199 : RawSetAsLong()
200 : {
201 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
202 : mUnion.mType = mUnion.eLong;
203 : return mUnion.mValue.mLong.SetValue();
204 : }
205 : };
206 :
207 : class ArrayBufferViewOrArrayBufferArgument
208 : {
209 : ArrayBufferViewOrArrayBuffer& mUnion;
210 :
211 : ArrayBufferViewOrArrayBufferArgument(const ArrayBufferViewOrArrayBufferArgument&) = delete;
212 : ArrayBufferViewOrArrayBufferArgument& operator=(const ArrayBufferViewOrArrayBufferArgument&) = delete;
213 : public:
214 0 : explicit inline ArrayBufferViewOrArrayBufferArgument(const ArrayBufferViewOrArrayBuffer& aUnion)
215 0 : : mUnion(const_cast<ArrayBufferViewOrArrayBuffer&>(aUnion))
216 : {
217 0 : }
218 :
219 : inline bool
220 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
221 : {
222 0 : tryNext = false;
223 : { // scope for memberSlot
224 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
225 0 : if (!memberSlot.Init(&value.toObject())) {
226 0 : mUnion.DestroyArrayBufferView();
227 0 : tryNext = true;
228 0 : return true;
229 : }
230 : }
231 0 : return true;
232 : }
233 :
234 : inline bool
235 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
236 : {
237 0 : tryNext = false;
238 : { // scope for memberSlot
239 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
240 0 : if (!memberSlot.Init(&value.toObject())) {
241 0 : mUnion.DestroyArrayBuffer();
242 0 : tryNext = true;
243 0 : return true;
244 : }
245 : }
246 0 : return true;
247 : }
248 :
249 : private:
250 : inline RootedTypedArray<ArrayBufferView>&
251 0 : RawSetAsArrayBufferView(JSContext* cx)
252 : {
253 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
254 0 : mUnion.mType = mUnion.eArrayBufferView;
255 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
256 : }
257 :
258 : inline RootedTypedArray<ArrayBuffer>&
259 0 : RawSetAsArrayBuffer(JSContext* cx)
260 : {
261 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
262 0 : mUnion.mType = mUnion.eArrayBuffer;
263 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
264 : }
265 : };
266 :
267 : class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument
268 : {
269 : ArrayBufferViewOrArrayBufferOrBlobOrUSVString& mUnion;
270 :
271 : ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument(const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument&) = delete;
272 : ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument& operator=(const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument&) = delete;
273 : public:
274 : explicit inline ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument(const ArrayBufferViewOrArrayBufferOrBlobOrUSVString& aUnion)
275 : : mUnion(const_cast<ArrayBufferViewOrArrayBufferOrBlobOrUSVString&>(aUnion))
276 : {
277 : }
278 :
279 : inline bool
280 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
281 : {
282 : tryNext = false;
283 : { // scope for memberSlot
284 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
285 : if (!memberSlot.Init(&value.toObject())) {
286 : mUnion.DestroyArrayBufferView();
287 : tryNext = true;
288 : return true;
289 : }
290 : }
291 : return true;
292 : }
293 :
294 : inline bool
295 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
296 : {
297 : tryNext = false;
298 : { // scope for memberSlot
299 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
300 : if (!memberSlot.Init(&value.toObject())) {
301 : mUnion.DestroyArrayBuffer();
302 : tryNext = true;
303 : return true;
304 : }
305 : }
306 : return true;
307 : }
308 :
309 : inline bool
310 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
311 : {
312 : tryNext = false;
313 : { // scope for memberSlot
314 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
315 : {
316 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
317 : if (NS_FAILED(rv)) {
318 : mUnion.DestroyBlob();
319 : tryNext = true;
320 : return true;
321 : }
322 : }
323 : }
324 : return true;
325 : }
326 :
327 : inline bool
328 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
329 : {
330 : tryNext = false;
331 : { // scope for memberSlot
332 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
333 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
334 : return false;
335 : }
336 : NormalizeUSVString(memberSlot);
337 : }
338 : return true;
339 : }
340 :
341 : inline void
342 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
343 : {
344 : RawSetAsUSVString().Rebind(aData, aLength);
345 : }
346 :
347 : private:
348 : inline RootedTypedArray<ArrayBufferView>&
349 : RawSetAsArrayBufferView(JSContext* cx)
350 : {
351 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
352 : mUnion.mType = mUnion.eArrayBufferView;
353 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
354 : }
355 :
356 : inline RootedTypedArray<ArrayBuffer>&
357 : RawSetAsArrayBuffer(JSContext* cx)
358 : {
359 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
360 : mUnion.mType = mUnion.eArrayBuffer;
361 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
362 : }
363 :
364 : inline NonNull<mozilla::dom::Blob>&
365 : RawSetAsBlob()
366 : {
367 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
368 : mUnion.mType = mUnion.eBlob;
369 : return mUnion.mValue.mBlob.SetValue();
370 : }
371 :
372 : inline binding_detail::FakeString&
373 : RawSetAsUSVString()
374 : {
375 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
376 : mUnion.mType = mUnion.eUSVString;
377 : return mUnion.mValue.mUSVString.SetValue();
378 : }
379 : };
380 :
381 : class ArrayBufferViewOrArrayBufferOrStringArgument
382 : {
383 : ArrayBufferViewOrArrayBufferOrString& mUnion;
384 :
385 : ArrayBufferViewOrArrayBufferOrStringArgument(const ArrayBufferViewOrArrayBufferOrStringArgument&) = delete;
386 : ArrayBufferViewOrArrayBufferOrStringArgument& operator=(const ArrayBufferViewOrArrayBufferOrStringArgument&) = delete;
387 : public:
388 : explicit inline ArrayBufferViewOrArrayBufferOrStringArgument(const ArrayBufferViewOrArrayBufferOrString& aUnion)
389 : : mUnion(const_cast<ArrayBufferViewOrArrayBufferOrString&>(aUnion))
390 : {
391 : }
392 :
393 : inline bool
394 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
395 : {
396 : tryNext = false;
397 : { // scope for memberSlot
398 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
399 : if (!memberSlot.Init(&value.toObject())) {
400 : mUnion.DestroyArrayBufferView();
401 : tryNext = true;
402 : return true;
403 : }
404 : }
405 : return true;
406 : }
407 :
408 : inline bool
409 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
410 : {
411 : tryNext = false;
412 : { // scope for memberSlot
413 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
414 : if (!memberSlot.Init(&value.toObject())) {
415 : mUnion.DestroyArrayBuffer();
416 : tryNext = true;
417 : return true;
418 : }
419 : }
420 : return true;
421 : }
422 :
423 : inline bool
424 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
425 : {
426 : tryNext = false;
427 : { // scope for memberSlot
428 : binding_detail::FakeString& memberSlot = RawSetAsString();
429 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
430 : return false;
431 : }
432 : }
433 : return true;
434 : }
435 :
436 : inline void
437 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
438 : {
439 : RawSetAsString().Rebind(aData, aLength);
440 : }
441 :
442 : private:
443 : inline RootedTypedArray<ArrayBufferView>&
444 : RawSetAsArrayBufferView(JSContext* cx)
445 : {
446 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
447 : mUnion.mType = mUnion.eArrayBufferView;
448 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
449 : }
450 :
451 : inline RootedTypedArray<ArrayBuffer>&
452 : RawSetAsArrayBuffer(JSContext* cx)
453 : {
454 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
455 : mUnion.mType = mUnion.eArrayBuffer;
456 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
457 : }
458 :
459 : inline binding_detail::FakeString&
460 : RawSetAsString()
461 : {
462 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
463 : mUnion.mType = mUnion.eString;
464 : return mUnion.mValue.mString.SetValue();
465 : }
466 : };
467 :
468 : class ArrayBufferViewOrArrayBufferOrUSVStringArgument
469 : {
470 : ArrayBufferViewOrArrayBufferOrUSVString& mUnion;
471 :
472 : ArrayBufferViewOrArrayBufferOrUSVStringArgument(const ArrayBufferViewOrArrayBufferOrUSVStringArgument&) = delete;
473 : ArrayBufferViewOrArrayBufferOrUSVStringArgument& operator=(const ArrayBufferViewOrArrayBufferOrUSVStringArgument&) = delete;
474 : public:
475 : explicit inline ArrayBufferViewOrArrayBufferOrUSVStringArgument(const ArrayBufferViewOrArrayBufferOrUSVString& aUnion)
476 : : mUnion(const_cast<ArrayBufferViewOrArrayBufferOrUSVString&>(aUnion))
477 : {
478 : }
479 :
480 : inline bool
481 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
482 : {
483 : tryNext = false;
484 : { // scope for memberSlot
485 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
486 : if (!memberSlot.Init(&value.toObject())) {
487 : mUnion.DestroyArrayBufferView();
488 : tryNext = true;
489 : return true;
490 : }
491 : }
492 : return true;
493 : }
494 :
495 : inline bool
496 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
497 : {
498 : tryNext = false;
499 : { // scope for memberSlot
500 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
501 : if (!memberSlot.Init(&value.toObject())) {
502 : mUnion.DestroyArrayBuffer();
503 : tryNext = true;
504 : return true;
505 : }
506 : }
507 : return true;
508 : }
509 :
510 : inline bool
511 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
512 : {
513 : tryNext = false;
514 : { // scope for memberSlot
515 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
516 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
517 : return false;
518 : }
519 : NormalizeUSVString(memberSlot);
520 : }
521 : return true;
522 : }
523 :
524 : inline void
525 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
526 : {
527 : RawSetAsUSVString().Rebind(aData, aLength);
528 : }
529 :
530 : private:
531 : inline RootedTypedArray<ArrayBufferView>&
532 : RawSetAsArrayBufferView(JSContext* cx)
533 : {
534 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
535 : mUnion.mType = mUnion.eArrayBufferView;
536 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
537 : }
538 :
539 : inline RootedTypedArray<ArrayBuffer>&
540 : RawSetAsArrayBuffer(JSContext* cx)
541 : {
542 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
543 : mUnion.mType = mUnion.eArrayBuffer;
544 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
545 : }
546 :
547 : inline binding_detail::FakeString&
548 : RawSetAsUSVString()
549 : {
550 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
551 : mUnion.mType = mUnion.eUSVString;
552 : return mUnion.mValue.mUSVString.SetValue();
553 : }
554 : };
555 :
556 : class BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument
557 : {
558 : BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& mUnion;
559 :
560 : BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument(const BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument&) = delete;
561 : BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument& operator=(const BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument&) = delete;
562 : public:
563 0 : explicit inline BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument(const BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion)
564 0 : : mUnion(const_cast<BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString&>(aUnion))
565 : {
566 0 : }
567 :
568 : inline bool
569 0 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
570 : {
571 0 : tryNext = false;
572 : { // scope for memberSlot
573 0 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
574 : {
575 0 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
576 0 : if (NS_FAILED(rv)) {
577 0 : mUnion.DestroyBlob();
578 0 : tryNext = true;
579 0 : return true;
580 : }
581 : }
582 : }
583 0 : return true;
584 : }
585 :
586 : inline bool
587 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
588 : {
589 0 : tryNext = false;
590 : { // scope for memberSlot
591 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
592 0 : if (!memberSlot.Init(&value.toObject())) {
593 0 : mUnion.DestroyArrayBufferView();
594 0 : tryNext = true;
595 0 : return true;
596 : }
597 : }
598 0 : return true;
599 : }
600 :
601 : inline bool
602 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
603 : {
604 0 : tryNext = false;
605 : { // scope for memberSlot
606 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
607 0 : if (!memberSlot.Init(&value.toObject())) {
608 0 : mUnion.DestroyArrayBuffer();
609 0 : tryNext = true;
610 0 : return true;
611 : }
612 : }
613 0 : return true;
614 : }
615 :
616 : inline bool
617 0 : TrySetToFormData(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
618 : {
619 0 : tryNext = false;
620 : { // scope for memberSlot
621 0 : NonNull<mozilla::dom::FormData>& memberSlot = RawSetAsFormData();
622 : {
623 0 : nsresult rv = UnwrapObject<prototypes::id::FormData, mozilla::dom::FormData>(value, memberSlot);
624 0 : if (NS_FAILED(rv)) {
625 0 : mUnion.DestroyFormData();
626 0 : tryNext = true;
627 0 : return true;
628 : }
629 : }
630 : }
631 0 : return true;
632 : }
633 :
634 : inline bool
635 0 : TrySetToURLSearchParams(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
636 : {
637 0 : tryNext = false;
638 : { // scope for memberSlot
639 0 : NonNull<mozilla::dom::URLSearchParams>& memberSlot = RawSetAsURLSearchParams();
640 : {
641 0 : nsresult rv = UnwrapObject<prototypes::id::URLSearchParams, mozilla::dom::URLSearchParams>(value, memberSlot);
642 0 : if (NS_FAILED(rv)) {
643 0 : mUnion.DestroyURLSearchParams();
644 0 : tryNext = true;
645 0 : return true;
646 : }
647 : }
648 : }
649 0 : return true;
650 : }
651 :
652 : inline bool
653 0 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
654 : {
655 0 : tryNext = false;
656 : { // scope for memberSlot
657 0 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
658 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
659 0 : return false;
660 : }
661 0 : NormalizeUSVString(memberSlot);
662 : }
663 0 : return true;
664 : }
665 :
666 : inline void
667 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
668 : {
669 : RawSetAsUSVString().Rebind(aData, aLength);
670 : }
671 :
672 : private:
673 : inline NonNull<mozilla::dom::Blob>&
674 0 : RawSetAsBlob()
675 : {
676 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
677 0 : mUnion.mType = mUnion.eBlob;
678 0 : return mUnion.mValue.mBlob.SetValue();
679 : }
680 :
681 : inline RootedTypedArray<ArrayBufferView>&
682 0 : RawSetAsArrayBufferView(JSContext* cx)
683 : {
684 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
685 0 : mUnion.mType = mUnion.eArrayBufferView;
686 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
687 : }
688 :
689 : inline RootedTypedArray<ArrayBuffer>&
690 0 : RawSetAsArrayBuffer(JSContext* cx)
691 : {
692 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
693 0 : mUnion.mType = mUnion.eArrayBuffer;
694 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
695 : }
696 :
697 : inline NonNull<mozilla::dom::FormData>&
698 0 : RawSetAsFormData()
699 : {
700 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
701 0 : mUnion.mType = mUnion.eFormData;
702 0 : return mUnion.mValue.mFormData.SetValue();
703 : }
704 :
705 : inline NonNull<mozilla::dom::URLSearchParams>&
706 0 : RawSetAsURLSearchParams()
707 : {
708 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
709 0 : mUnion.mType = mUnion.eURLSearchParams;
710 0 : return mUnion.mValue.mURLSearchParams.SetValue();
711 : }
712 :
713 : inline binding_detail::FakeString&
714 0 : RawSetAsUSVString()
715 : {
716 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
717 0 : mUnion.mType = mUnion.eUSVString;
718 0 : return mUnion.mValue.mUSVString.SetValue();
719 : }
720 : };
721 :
722 : class BlobOrDirectoryOrUSVStringArgument
723 : {
724 : BlobOrDirectoryOrUSVString& mUnion;
725 :
726 : BlobOrDirectoryOrUSVStringArgument(const BlobOrDirectoryOrUSVStringArgument&) = delete;
727 : BlobOrDirectoryOrUSVStringArgument& operator=(const BlobOrDirectoryOrUSVStringArgument&) = delete;
728 : public:
729 : explicit inline BlobOrDirectoryOrUSVStringArgument(const BlobOrDirectoryOrUSVString& aUnion)
730 : : mUnion(const_cast<BlobOrDirectoryOrUSVString&>(aUnion))
731 : {
732 : }
733 :
734 : inline bool
735 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
736 : {
737 : tryNext = false;
738 : { // scope for memberSlot
739 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
740 : {
741 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
742 : if (NS_FAILED(rv)) {
743 : mUnion.DestroyBlob();
744 : tryNext = true;
745 : return true;
746 : }
747 : }
748 : }
749 : return true;
750 : }
751 :
752 : inline bool
753 : TrySetToDirectory(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
754 : {
755 : tryNext = false;
756 : { // scope for memberSlot
757 : NonNull<mozilla::dom::Directory>& memberSlot = RawSetAsDirectory();
758 : {
759 : nsresult rv = UnwrapObject<prototypes::id::Directory, mozilla::dom::Directory>(value, memberSlot);
760 : if (NS_FAILED(rv)) {
761 : mUnion.DestroyDirectory();
762 : tryNext = true;
763 : return true;
764 : }
765 : }
766 : }
767 : return true;
768 : }
769 :
770 : inline bool
771 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
772 : {
773 : tryNext = false;
774 : { // scope for memberSlot
775 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
776 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
777 : return false;
778 : }
779 : NormalizeUSVString(memberSlot);
780 : }
781 : return true;
782 : }
783 :
784 : inline void
785 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
786 : {
787 : RawSetAsUSVString().Rebind(aData, aLength);
788 : }
789 :
790 : private:
791 : inline NonNull<mozilla::dom::Blob>&
792 : RawSetAsBlob()
793 : {
794 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
795 : mUnion.mType = mUnion.eBlob;
796 : return mUnion.mValue.mBlob.SetValue();
797 : }
798 :
799 : inline NonNull<mozilla::dom::Directory>&
800 : RawSetAsDirectory()
801 : {
802 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
803 : mUnion.mType = mUnion.eDirectory;
804 : return mUnion.mValue.mDirectory.SetValue();
805 : }
806 :
807 : inline binding_detail::FakeString&
808 : RawSetAsUSVString()
809 : {
810 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
811 : mUnion.mType = mUnion.eUSVString;
812 : return mUnion.mValue.mUSVString.SetValue();
813 : }
814 : };
815 :
816 : class BooleanOrConstrainBooleanParametersArgument
817 : {
818 : BooleanOrConstrainBooleanParameters& mUnion;
819 :
820 : BooleanOrConstrainBooleanParametersArgument(const BooleanOrConstrainBooleanParametersArgument&) = delete;
821 : BooleanOrConstrainBooleanParametersArgument& operator=(const BooleanOrConstrainBooleanParametersArgument&) = delete;
822 : public:
823 : explicit inline BooleanOrConstrainBooleanParametersArgument(const BooleanOrConstrainBooleanParameters& aUnion)
824 : : mUnion(const_cast<BooleanOrConstrainBooleanParameters&>(aUnion))
825 : {
826 : }
827 :
828 : inline bool
829 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
830 : {
831 : tryNext = false;
832 : { // scope for memberSlot
833 : bool& memberSlot = RawSetAsBoolean();
834 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
835 : return false;
836 : }
837 : }
838 : return true;
839 : }
840 :
841 : inline bool
842 : TrySetToConstrainBooleanParameters(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
843 : {
844 : tryNext = false;
845 : { // scope for memberSlot
846 : binding_detail::FastConstrainBooleanParameters& memberSlot = RawSetAsConstrainBooleanParameters();
847 : if (!IsConvertibleToDictionary(value)) {
848 : mUnion.DestroyConstrainBooleanParameters();
849 : tryNext = true;
850 : return true;
851 : }
852 : if (!memberSlot.Init(cx, value, "Member of BooleanOrConstrainBooleanParameters", passedToJSImpl)) {
853 : return false;
854 : }
855 : }
856 : return true;
857 : }
858 :
859 : private:
860 : inline bool&
861 : RawSetAsBoolean()
862 : {
863 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
864 : mUnion.mType = mUnion.eBoolean;
865 : return mUnion.mValue.mBoolean.SetValue();
866 : }
867 :
868 : inline binding_detail::FastConstrainBooleanParameters&
869 : RawSetAsConstrainBooleanParameters()
870 : {
871 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
872 : mUnion.mType = mUnion.eConstrainBooleanParameters;
873 : return mUnion.mValue.mConstrainBooleanParameters.SetValue();
874 : }
875 : };
876 :
877 : class BooleanOrMediaTrackConstraintsArgument
878 : {
879 : BooleanOrMediaTrackConstraints& mUnion;
880 :
881 : BooleanOrMediaTrackConstraintsArgument(const BooleanOrMediaTrackConstraintsArgument&) = delete;
882 : BooleanOrMediaTrackConstraintsArgument& operator=(const BooleanOrMediaTrackConstraintsArgument&) = delete;
883 : public:
884 : explicit inline BooleanOrMediaTrackConstraintsArgument(const BooleanOrMediaTrackConstraints& aUnion)
885 : : mUnion(const_cast<BooleanOrMediaTrackConstraints&>(aUnion))
886 : {
887 : }
888 :
889 : inline bool
890 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
891 : {
892 : tryNext = false;
893 : { // scope for memberSlot
894 : bool& memberSlot = RawSetAsBoolean();
895 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
896 : return false;
897 : }
898 : }
899 : return true;
900 : }
901 :
902 : inline bool
903 : TrySetToMediaTrackConstraints(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
904 : {
905 : tryNext = false;
906 : { // scope for memberSlot
907 : binding_detail::FastMediaTrackConstraints& memberSlot = RawSetAsMediaTrackConstraints();
908 : if (!IsConvertibleToDictionary(value)) {
909 : mUnion.DestroyMediaTrackConstraints();
910 : tryNext = true;
911 : return true;
912 : }
913 : if (!memberSlot.Init(cx, value, "Member of BooleanOrMediaTrackConstraints", passedToJSImpl)) {
914 : return false;
915 : }
916 : }
917 : return true;
918 : }
919 :
920 : private:
921 : inline bool&
922 : RawSetAsBoolean()
923 : {
924 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
925 : mUnion.mType = mUnion.eBoolean;
926 : return mUnion.mValue.mBoolean.SetValue();
927 : }
928 :
929 : inline binding_detail::FastMediaTrackConstraints&
930 : RawSetAsMediaTrackConstraints()
931 : {
932 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
933 : mUnion.mType = mUnion.eMediaTrackConstraints;
934 : return mUnion.mValue.mMediaTrackConstraints.SetValue();
935 : }
936 : };
937 :
938 : class BooleanOrStringArgument
939 : {
940 : BooleanOrString& mUnion;
941 :
942 : BooleanOrStringArgument(const BooleanOrStringArgument&) = delete;
943 : BooleanOrStringArgument& operator=(const BooleanOrStringArgument&) = delete;
944 : public:
945 : explicit inline BooleanOrStringArgument(const BooleanOrString& aUnion)
946 : : mUnion(const_cast<BooleanOrString&>(aUnion))
947 : {
948 : }
949 :
950 : inline bool
951 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
952 : {
953 : tryNext = false;
954 : { // scope for memberSlot
955 : bool& memberSlot = RawSetAsBoolean();
956 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
957 : return false;
958 : }
959 : }
960 : return true;
961 : }
962 :
963 : inline bool
964 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
965 : {
966 : tryNext = false;
967 : { // scope for memberSlot
968 : binding_detail::FakeString& memberSlot = RawSetAsString();
969 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
970 : return false;
971 : }
972 : }
973 : return true;
974 : }
975 :
976 : inline void
977 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
978 : {
979 : RawSetAsString().Rebind(aData, aLength);
980 : }
981 :
982 : private:
983 : inline bool&
984 : RawSetAsBoolean()
985 : {
986 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
987 : mUnion.mType = mUnion.eBoolean;
988 : return mUnion.mValue.mBoolean.SetValue();
989 : }
990 :
991 : inline binding_detail::FakeString&
992 : RawSetAsString()
993 : {
994 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
995 : mUnion.mType = mUnion.eString;
996 : return mUnion.mValue.mString.SetValue();
997 : }
998 : };
999 :
1000 : class ByteStringOrLongArgument
1001 : {
1002 : ByteStringOrLong& mUnion;
1003 :
1004 : ByteStringOrLongArgument(const ByteStringOrLongArgument&) = delete;
1005 : ByteStringOrLongArgument& operator=(const ByteStringOrLongArgument&) = delete;
1006 : public:
1007 : explicit inline ByteStringOrLongArgument(const ByteStringOrLong& aUnion)
1008 : : mUnion(const_cast<ByteStringOrLong&>(aUnion))
1009 : {
1010 : }
1011 :
1012 : inline bool
1013 : TrySetToByteString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1014 : {
1015 : tryNext = false;
1016 : { // scope for memberSlot
1017 : nsCString& memberSlot = RawSetAsByteString();
1018 : if (!ConvertJSValueToByteString(cx, value, false, memberSlot)) {
1019 : return false;
1020 : }
1021 : }
1022 : return true;
1023 : }
1024 :
1025 : inline void
1026 : SetStringData(const nsDependentCString::char_type* aData, nsDependentCString::size_type aLength)
1027 : {
1028 : RawSetAsByteString().Rebind(aData, aLength);
1029 : }
1030 :
1031 : inline bool
1032 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1033 : {
1034 : tryNext = false;
1035 : { // scope for memberSlot
1036 : int32_t& memberSlot = RawSetAsLong();
1037 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
1038 : return false;
1039 : }
1040 : }
1041 : return true;
1042 : }
1043 :
1044 : private:
1045 : inline nsCString&
1046 : RawSetAsByteString()
1047 : {
1048 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1049 : mUnion.mType = mUnion.eByteString;
1050 : return mUnion.mValue.mByteString.SetValue();
1051 : }
1052 :
1053 : inline int32_t&
1054 : RawSetAsLong()
1055 : {
1056 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1057 : mUnion.mType = mUnion.eLong;
1058 : return mUnion.mValue.mLong.SetValue();
1059 : }
1060 : };
1061 :
1062 : class CanvasPatternOrCanvasGradientArgument
1063 : {
1064 : CanvasPatternOrCanvasGradient& mUnion;
1065 :
1066 : CanvasPatternOrCanvasGradientArgument(const CanvasPatternOrCanvasGradientArgument&) = delete;
1067 : CanvasPatternOrCanvasGradientArgument& operator=(const CanvasPatternOrCanvasGradientArgument&) = delete;
1068 : public:
1069 : explicit inline CanvasPatternOrCanvasGradientArgument(const CanvasPatternOrCanvasGradient& aUnion)
1070 : : mUnion(const_cast<CanvasPatternOrCanvasGradient&>(aUnion))
1071 : {
1072 : }
1073 :
1074 : inline bool
1075 : TrySetToCanvasPattern(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1076 : {
1077 : tryNext = false;
1078 : { // scope for memberSlot
1079 : NonNull<mozilla::dom::CanvasPattern>& memberSlot = RawSetAsCanvasPattern();
1080 : {
1081 : nsresult rv = UnwrapObject<prototypes::id::CanvasPattern, mozilla::dom::CanvasPattern>(value, memberSlot);
1082 : if (NS_FAILED(rv)) {
1083 : mUnion.DestroyCanvasPattern();
1084 : tryNext = true;
1085 : return true;
1086 : }
1087 : }
1088 : }
1089 : return true;
1090 : }
1091 :
1092 : inline bool
1093 : TrySetToCanvasGradient(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1094 : {
1095 : tryNext = false;
1096 : { // scope for memberSlot
1097 : NonNull<mozilla::dom::CanvasGradient>& memberSlot = RawSetAsCanvasGradient();
1098 : {
1099 : nsresult rv = UnwrapObject<prototypes::id::CanvasGradient, mozilla::dom::CanvasGradient>(value, memberSlot);
1100 : if (NS_FAILED(rv)) {
1101 : mUnion.DestroyCanvasGradient();
1102 : tryNext = true;
1103 : return true;
1104 : }
1105 : }
1106 : }
1107 : return true;
1108 : }
1109 :
1110 : private:
1111 : inline NonNull<mozilla::dom::CanvasPattern>&
1112 : RawSetAsCanvasPattern()
1113 : {
1114 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1115 : mUnion.mType = mUnion.eCanvasPattern;
1116 : return mUnion.mValue.mCanvasPattern.SetValue();
1117 : }
1118 :
1119 : inline NonNull<mozilla::dom::CanvasGradient>&
1120 : RawSetAsCanvasGradient()
1121 : {
1122 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1123 : mUnion.mType = mUnion.eCanvasGradient;
1124 : return mUnion.mValue.mCanvasGradient.SetValue();
1125 : }
1126 : };
1127 :
1128 : class CanvasPatternOrNullOrCanvasGradientArgument
1129 : {
1130 : CanvasPatternOrNullOrCanvasGradient& mUnion;
1131 :
1132 : CanvasPatternOrNullOrCanvasGradientArgument(const CanvasPatternOrNullOrCanvasGradientArgument&) = delete;
1133 : CanvasPatternOrNullOrCanvasGradientArgument& operator=(const CanvasPatternOrNullOrCanvasGradientArgument&) = delete;
1134 : public:
1135 : explicit inline CanvasPatternOrNullOrCanvasGradientArgument(const CanvasPatternOrNullOrCanvasGradient& aUnion)
1136 : : mUnion(const_cast<CanvasPatternOrNullOrCanvasGradient&>(aUnion))
1137 : {
1138 : }
1139 :
1140 : inline bool
1141 : SetNull()
1142 : {
1143 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1144 : mUnion.mType = mUnion.eNull;
1145 : return true;
1146 : }
1147 :
1148 : inline bool
1149 : TrySetToCanvasPattern(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1150 : {
1151 : tryNext = false;
1152 : { // scope for memberSlot
1153 : NonNull<mozilla::dom::CanvasPattern>& memberSlot = RawSetAsCanvasPattern();
1154 : {
1155 : nsresult rv = UnwrapObject<prototypes::id::CanvasPattern, mozilla::dom::CanvasPattern>(value, memberSlot);
1156 : if (NS_FAILED(rv)) {
1157 : mUnion.DestroyCanvasPattern();
1158 : tryNext = true;
1159 : return true;
1160 : }
1161 : }
1162 : }
1163 : return true;
1164 : }
1165 :
1166 : inline bool
1167 : TrySetToCanvasGradient(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1168 : {
1169 : tryNext = false;
1170 : { // scope for memberSlot
1171 : NonNull<mozilla::dom::CanvasGradient>& memberSlot = RawSetAsCanvasGradient();
1172 : {
1173 : nsresult rv = UnwrapObject<prototypes::id::CanvasGradient, mozilla::dom::CanvasGradient>(value, memberSlot);
1174 : if (NS_FAILED(rv)) {
1175 : mUnion.DestroyCanvasGradient();
1176 : tryNext = true;
1177 : return true;
1178 : }
1179 : }
1180 : }
1181 : return true;
1182 : }
1183 :
1184 : private:
1185 : inline NonNull<mozilla::dom::CanvasPattern>&
1186 : RawSetAsCanvasPattern()
1187 : {
1188 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1189 : mUnion.mType = mUnion.eCanvasPattern;
1190 : return mUnion.mValue.mCanvasPattern.SetValue();
1191 : }
1192 :
1193 : inline NonNull<mozilla::dom::CanvasGradient>&
1194 : RawSetAsCanvasGradient()
1195 : {
1196 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1197 : mUnion.mType = mUnion.eCanvasGradient;
1198 : return mUnion.mValue.mCanvasGradient.SetValue();
1199 : }
1200 : };
1201 :
1202 : class ClientOrServiceWorkerOrMessagePortArgument
1203 : {
1204 : ClientOrServiceWorkerOrMessagePort& mUnion;
1205 :
1206 : ClientOrServiceWorkerOrMessagePortArgument(const ClientOrServiceWorkerOrMessagePortArgument&) = delete;
1207 : ClientOrServiceWorkerOrMessagePortArgument& operator=(const ClientOrServiceWorkerOrMessagePortArgument&) = delete;
1208 : public:
1209 : explicit inline ClientOrServiceWorkerOrMessagePortArgument(const ClientOrServiceWorkerOrMessagePort& aUnion)
1210 : : mUnion(const_cast<ClientOrServiceWorkerOrMessagePort&>(aUnion))
1211 : {
1212 : }
1213 :
1214 : inline bool
1215 : TrySetToClient(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1216 : {
1217 : tryNext = false;
1218 : { // scope for memberSlot
1219 : NonNull<mozilla::dom::workers::ServiceWorkerClient>& memberSlot = RawSetAsClient();
1220 : {
1221 : nsresult rv = UnwrapObject<prototypes::id::Client, mozilla::dom::workers::ServiceWorkerClient>(value, memberSlot);
1222 : if (NS_FAILED(rv)) {
1223 : mUnion.DestroyClient();
1224 : tryNext = true;
1225 : return true;
1226 : }
1227 : }
1228 : }
1229 : return true;
1230 : }
1231 :
1232 : inline bool
1233 : TrySetToServiceWorker(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1234 : {
1235 : tryNext = false;
1236 : { // scope for memberSlot
1237 : NonNull<mozilla::dom::workers::ServiceWorker>& memberSlot = RawSetAsServiceWorker();
1238 : {
1239 : nsresult rv = UnwrapObject<prototypes::id::ServiceWorker, mozilla::dom::workers::ServiceWorker>(value, memberSlot);
1240 : if (NS_FAILED(rv)) {
1241 : mUnion.DestroyServiceWorker();
1242 : tryNext = true;
1243 : return true;
1244 : }
1245 : }
1246 : }
1247 : return true;
1248 : }
1249 :
1250 : inline bool
1251 : TrySetToMessagePort(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1252 : {
1253 : tryNext = false;
1254 : { // scope for memberSlot
1255 : NonNull<mozilla::dom::MessagePort>& memberSlot = RawSetAsMessagePort();
1256 : {
1257 : nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(value, memberSlot);
1258 : if (NS_FAILED(rv)) {
1259 : mUnion.DestroyMessagePort();
1260 : tryNext = true;
1261 : return true;
1262 : }
1263 : }
1264 : }
1265 : return true;
1266 : }
1267 :
1268 : private:
1269 : inline NonNull<mozilla::dom::workers::ServiceWorkerClient>&
1270 : RawSetAsClient()
1271 : {
1272 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1273 : mUnion.mType = mUnion.eClient;
1274 : return mUnion.mValue.mClient.SetValue();
1275 : }
1276 :
1277 : inline NonNull<mozilla::dom::workers::ServiceWorker>&
1278 : RawSetAsServiceWorker()
1279 : {
1280 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1281 : mUnion.mType = mUnion.eServiceWorker;
1282 : return mUnion.mValue.mServiceWorker.SetValue();
1283 : }
1284 :
1285 : inline NonNull<mozilla::dom::MessagePort>&
1286 : RawSetAsMessagePort()
1287 : {
1288 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1289 : mUnion.mType = mUnion.eMessagePort;
1290 : return mUnion.mValue.mMessagePort.SetValue();
1291 : }
1292 : };
1293 :
1294 : class CustomEventInitOrLongArgument
1295 : {
1296 : CustomEventInitOrLong& mUnion;
1297 :
1298 : CustomEventInitOrLongArgument(const CustomEventInitOrLongArgument&) = delete;
1299 : CustomEventInitOrLongArgument& operator=(const CustomEventInitOrLongArgument&) = delete;
1300 : public:
1301 : explicit inline CustomEventInitOrLongArgument(const CustomEventInitOrLong& aUnion)
1302 : : mUnion(const_cast<CustomEventInitOrLong&>(aUnion))
1303 : {
1304 : }
1305 :
1306 : inline bool
1307 : TrySetToCustomEventInit(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1308 : {
1309 : tryNext = false;
1310 : { // scope for memberSlot
1311 : RootedDictionary<binding_detail::FastCustomEventInit>& memberSlot = RawSetAsCustomEventInit(cx);
1312 : if (!IsConvertibleToDictionary(value)) {
1313 : mUnion.DestroyCustomEventInit();
1314 : tryNext = true;
1315 : return true;
1316 : }
1317 : if (!memberSlot.Init(cx, value, "Member of CustomEventInitOrLong", passedToJSImpl)) {
1318 : return false;
1319 : }
1320 : }
1321 : return true;
1322 : }
1323 :
1324 : inline bool
1325 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1326 : {
1327 : tryNext = false;
1328 : { // scope for memberSlot
1329 : int32_t& memberSlot = RawSetAsLong();
1330 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
1331 : return false;
1332 : }
1333 : }
1334 : return true;
1335 : }
1336 :
1337 : private:
1338 : inline RootedDictionary<binding_detail::FastCustomEventInit>&
1339 : RawSetAsCustomEventInit(JSContext* cx)
1340 : {
1341 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1342 : mUnion.mType = mUnion.eCustomEventInit;
1343 : return mUnion.mValue.mCustomEventInit.SetValue(cx);
1344 : }
1345 :
1346 : inline int32_t&
1347 : RawSetAsLong()
1348 : {
1349 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1350 : mUnion.mType = mUnion.eLong;
1351 : return mUnion.mValue.mLong.SetValue();
1352 : }
1353 : };
1354 :
1355 : class DoubleOrAutoKeywordArgument
1356 : {
1357 : DoubleOrAutoKeyword& mUnion;
1358 :
1359 : DoubleOrAutoKeywordArgument(const DoubleOrAutoKeywordArgument&) = delete;
1360 : DoubleOrAutoKeywordArgument& operator=(const DoubleOrAutoKeywordArgument&) = delete;
1361 : public:
1362 0 : explicit inline DoubleOrAutoKeywordArgument(const DoubleOrAutoKeyword& aUnion)
1363 0 : : mUnion(const_cast<DoubleOrAutoKeyword&>(aUnion))
1364 : {
1365 0 : }
1366 :
1367 : inline bool
1368 0 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1369 : {
1370 0 : tryNext = false;
1371 : { // scope for memberSlot
1372 0 : double& memberSlot = RawSetAsDouble();
1373 0 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1374 0 : return false;
1375 0 : } else if (!mozilla::IsFinite(memberSlot)) {
1376 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrAutoKeyword");
1377 0 : return false;
1378 : }
1379 : }
1380 0 : return true;
1381 : }
1382 :
1383 : inline bool
1384 0 : TrySetToAutoKeyword(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1385 : {
1386 0 : tryNext = false;
1387 : { // scope for memberSlot
1388 0 : AutoKeyword& memberSlot = RawSetAsAutoKeyword();
1389 : {
1390 : int index;
1391 0 : if (!FindEnumStringIndex<true>(cx, value, AutoKeywordValues::strings, "AutoKeyword", "Member of DoubleOrAutoKeyword", &index)) {
1392 0 : return false;
1393 : }
1394 0 : MOZ_ASSERT(index >= 0);
1395 0 : memberSlot = static_cast<AutoKeyword>(index);
1396 : }
1397 : }
1398 0 : return true;
1399 : }
1400 :
1401 : private:
1402 : inline double&
1403 0 : RawSetAsDouble()
1404 : {
1405 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1406 0 : mUnion.mType = mUnion.eDouble;
1407 0 : return mUnion.mValue.mDouble.SetValue();
1408 : }
1409 :
1410 : inline AutoKeyword&
1411 0 : RawSetAsAutoKeyword()
1412 : {
1413 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1414 0 : mUnion.mType = mUnion.eAutoKeyword;
1415 0 : return mUnion.mValue.mAutoKeyword.SetValue();
1416 : }
1417 : };
1418 :
1419 : class DoubleOrByteStringArgument
1420 : {
1421 : DoubleOrByteString& mUnion;
1422 :
1423 : DoubleOrByteStringArgument(const DoubleOrByteStringArgument&) = delete;
1424 : DoubleOrByteStringArgument& operator=(const DoubleOrByteStringArgument&) = delete;
1425 : public:
1426 : explicit inline DoubleOrByteStringArgument(const DoubleOrByteString& aUnion)
1427 : : mUnion(const_cast<DoubleOrByteString&>(aUnion))
1428 : {
1429 : }
1430 :
1431 : inline bool
1432 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1433 : {
1434 : tryNext = false;
1435 : { // scope for memberSlot
1436 : double& memberSlot = RawSetAsDouble();
1437 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1438 : return false;
1439 : } else if (!mozilla::IsFinite(memberSlot)) {
1440 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrByteString");
1441 : return false;
1442 : }
1443 : }
1444 : return true;
1445 : }
1446 :
1447 : inline bool
1448 : TrySetToByteString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1449 : {
1450 : tryNext = false;
1451 : { // scope for memberSlot
1452 : nsCString& memberSlot = RawSetAsByteString();
1453 : if (!ConvertJSValueToByteString(cx, value, false, memberSlot)) {
1454 : return false;
1455 : }
1456 : }
1457 : return true;
1458 : }
1459 :
1460 : inline void
1461 : SetStringData(const nsDependentCString::char_type* aData, nsDependentCString::size_type aLength)
1462 : {
1463 : RawSetAsByteString().Rebind(aData, aLength);
1464 : }
1465 :
1466 : private:
1467 : inline double&
1468 : RawSetAsDouble()
1469 : {
1470 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1471 : mUnion.mType = mUnion.eDouble;
1472 : return mUnion.mValue.mDouble.SetValue();
1473 : }
1474 :
1475 : inline nsCString&
1476 : RawSetAsByteString()
1477 : {
1478 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1479 : mUnion.mType = mUnion.eByteString;
1480 : return mUnion.mValue.mByteString.SetValue();
1481 : }
1482 : };
1483 :
1484 : class DoubleOrConstrainDoubleRangeArgument
1485 : {
1486 : DoubleOrConstrainDoubleRange& mUnion;
1487 :
1488 : DoubleOrConstrainDoubleRangeArgument(const DoubleOrConstrainDoubleRangeArgument&) = delete;
1489 : DoubleOrConstrainDoubleRangeArgument& operator=(const DoubleOrConstrainDoubleRangeArgument&) = delete;
1490 : public:
1491 : explicit inline DoubleOrConstrainDoubleRangeArgument(const DoubleOrConstrainDoubleRange& aUnion)
1492 : : mUnion(const_cast<DoubleOrConstrainDoubleRange&>(aUnion))
1493 : {
1494 : }
1495 :
1496 : inline bool
1497 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1498 : {
1499 : tryNext = false;
1500 : { // scope for memberSlot
1501 : double& memberSlot = RawSetAsDouble();
1502 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1503 : return false;
1504 : } else if (!mozilla::IsFinite(memberSlot)) {
1505 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrConstrainDoubleRange");
1506 : return false;
1507 : }
1508 : }
1509 : return true;
1510 : }
1511 :
1512 : inline bool
1513 : TrySetToConstrainDoubleRange(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1514 : {
1515 : tryNext = false;
1516 : { // scope for memberSlot
1517 : binding_detail::FastConstrainDoubleRange& memberSlot = RawSetAsConstrainDoubleRange();
1518 : if (!IsConvertibleToDictionary(value)) {
1519 : mUnion.DestroyConstrainDoubleRange();
1520 : tryNext = true;
1521 : return true;
1522 : }
1523 : if (!memberSlot.Init(cx, value, "Member of DoubleOrConstrainDoubleRange", passedToJSImpl)) {
1524 : return false;
1525 : }
1526 : }
1527 : return true;
1528 : }
1529 :
1530 : private:
1531 : inline double&
1532 : RawSetAsDouble()
1533 : {
1534 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1535 : mUnion.mType = mUnion.eDouble;
1536 : return mUnion.mValue.mDouble.SetValue();
1537 : }
1538 :
1539 : inline binding_detail::FastConstrainDoubleRange&
1540 : RawSetAsConstrainDoubleRange()
1541 : {
1542 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1543 : mUnion.mType = mUnion.eConstrainDoubleRange;
1544 : return mUnion.mValue.mConstrainDoubleRange.SetValue();
1545 : }
1546 : };
1547 :
1548 : class DoubleOrDoubleSequenceArgument
1549 : {
1550 : DoubleOrDoubleSequence& mUnion;
1551 :
1552 : DoubleOrDoubleSequenceArgument(const DoubleOrDoubleSequenceArgument&) = delete;
1553 : DoubleOrDoubleSequenceArgument& operator=(const DoubleOrDoubleSequenceArgument&) = delete;
1554 : public:
1555 : explicit inline DoubleOrDoubleSequenceArgument(const DoubleOrDoubleSequence& aUnion)
1556 : : mUnion(const_cast<DoubleOrDoubleSequence&>(aUnion))
1557 : {
1558 : }
1559 :
1560 : inline bool
1561 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1562 : {
1563 : tryNext = false;
1564 : { // scope for memberSlot
1565 : double& memberSlot = RawSetAsDouble();
1566 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1567 : return false;
1568 : } else if (!mozilla::IsFinite(memberSlot)) {
1569 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrDoubleSequence");
1570 : return false;
1571 : }
1572 : }
1573 : return true;
1574 : }
1575 :
1576 : inline bool
1577 : TrySetToDoubleSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1578 : {
1579 : tryNext = false;
1580 : { // scope for memberSlot
1581 : binding_detail::AutoSequence<double>& memberSlot = RawSetAsDoubleSequence();
1582 : JS::ForOfIterator iter(cx);
1583 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
1584 : return false;
1585 : }
1586 : if (!iter.valueIsIterable()) {
1587 : mUnion.DestroyDoubleSequence();
1588 : tryNext = true;
1589 : return true;
1590 : }
1591 : binding_detail::AutoSequence<double> &arr = memberSlot;
1592 : JS::Rooted<JS::Value> temp(cx);
1593 : while (true) {
1594 : bool done;
1595 : if (!iter.next(&temp, &done)) {
1596 : return false;
1597 : }
1598 : if (done) {
1599 : break;
1600 : }
1601 : double* slotPtr = arr.AppendElement(mozilla::fallible);
1602 : if (!slotPtr) {
1603 : JS_ReportOutOfMemory(cx);
1604 : return false;
1605 : }
1606 : double& slot = *slotPtr;
1607 : if (!ValueToPrimitive<double, eDefault>(cx, temp, &slot)) {
1608 : return false;
1609 : } else if (!mozilla::IsFinite(slot)) {
1610 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Element of member of DoubleOrDoubleSequence");
1611 : return false;
1612 : }
1613 : }
1614 : }
1615 : return true;
1616 : }
1617 :
1618 : private:
1619 : inline double&
1620 : RawSetAsDouble()
1621 : {
1622 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1623 : mUnion.mType = mUnion.eDouble;
1624 : return mUnion.mValue.mDouble.SetValue();
1625 : }
1626 :
1627 : inline binding_detail::AutoSequence<double>&
1628 : RawSetAsDoubleSequence()
1629 : {
1630 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1631 : mUnion.mType = mUnion.eDoubleSequence;
1632 : return mUnion.mValue.mDoubleSequence.SetValue();
1633 : }
1634 : };
1635 :
1636 : class DoubleOrStringArgument
1637 : {
1638 : DoubleOrString& mUnion;
1639 :
1640 : DoubleOrStringArgument(const DoubleOrStringArgument&) = delete;
1641 : DoubleOrStringArgument& operator=(const DoubleOrStringArgument&) = delete;
1642 : public:
1643 : explicit inline DoubleOrStringArgument(const DoubleOrString& aUnion)
1644 : : mUnion(const_cast<DoubleOrString&>(aUnion))
1645 : {
1646 : }
1647 :
1648 : inline bool
1649 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1650 : {
1651 : tryNext = false;
1652 : { // scope for memberSlot
1653 : double& memberSlot = RawSetAsDouble();
1654 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1655 : return false;
1656 : } else if (!mozilla::IsFinite(memberSlot)) {
1657 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrString");
1658 : return false;
1659 : }
1660 : }
1661 : return true;
1662 : }
1663 :
1664 : inline bool
1665 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1666 : {
1667 : tryNext = false;
1668 : { // scope for memberSlot
1669 : binding_detail::FakeString& memberSlot = RawSetAsString();
1670 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
1671 : return false;
1672 : }
1673 : }
1674 : return true;
1675 : }
1676 :
1677 : inline void
1678 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
1679 : {
1680 : RawSetAsString().Rebind(aData, aLength);
1681 : }
1682 :
1683 : private:
1684 : inline double&
1685 : RawSetAsDouble()
1686 : {
1687 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1688 : mUnion.mType = mUnion.eDouble;
1689 : return mUnion.mValue.mDouble.SetValue();
1690 : }
1691 :
1692 : inline binding_detail::FakeString&
1693 : RawSetAsString()
1694 : {
1695 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1696 : mUnion.mType = mUnion.eString;
1697 : return mUnion.mValue.mString.SetValue();
1698 : }
1699 : };
1700 :
1701 : class DoubleOrSupportedTypeArgument
1702 : {
1703 : DoubleOrSupportedType& mUnion;
1704 :
1705 : DoubleOrSupportedTypeArgument(const DoubleOrSupportedTypeArgument&) = delete;
1706 : DoubleOrSupportedTypeArgument& operator=(const DoubleOrSupportedTypeArgument&) = delete;
1707 : public:
1708 : explicit inline DoubleOrSupportedTypeArgument(const DoubleOrSupportedType& aUnion)
1709 : : mUnion(const_cast<DoubleOrSupportedType&>(aUnion))
1710 : {
1711 : }
1712 :
1713 : inline bool
1714 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1715 : {
1716 : tryNext = false;
1717 : { // scope for memberSlot
1718 : double& memberSlot = RawSetAsDouble();
1719 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1720 : return false;
1721 : } else if (!mozilla::IsFinite(memberSlot)) {
1722 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrSupportedType");
1723 : return false;
1724 : }
1725 : }
1726 : return true;
1727 : }
1728 :
1729 : inline bool
1730 : TrySetToSupportedType(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1731 : {
1732 : tryNext = false;
1733 : { // scope for memberSlot
1734 : SupportedType& memberSlot = RawSetAsSupportedType();
1735 : {
1736 : int index;
1737 : if (!FindEnumStringIndex<true>(cx, value, SupportedTypeValues::strings, "SupportedType", "Member of DoubleOrSupportedType", &index)) {
1738 : return false;
1739 : }
1740 : MOZ_ASSERT(index >= 0);
1741 : memberSlot = static_cast<SupportedType>(index);
1742 : }
1743 : }
1744 : return true;
1745 : }
1746 :
1747 : private:
1748 : inline double&
1749 : RawSetAsDouble()
1750 : {
1751 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1752 : mUnion.mType = mUnion.eDouble;
1753 : return mUnion.mValue.mDouble.SetValue();
1754 : }
1755 :
1756 : inline SupportedType&
1757 : RawSetAsSupportedType()
1758 : {
1759 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1760 : mUnion.mType = mUnion.eSupportedType;
1761 : return mUnion.mValue.mSupportedType.SetValue();
1762 : }
1763 : };
1764 :
1765 : class DoubleOrUSVStringArgument
1766 : {
1767 : DoubleOrUSVString& mUnion;
1768 :
1769 : DoubleOrUSVStringArgument(const DoubleOrUSVStringArgument&) = delete;
1770 : DoubleOrUSVStringArgument& operator=(const DoubleOrUSVStringArgument&) = delete;
1771 : public:
1772 : explicit inline DoubleOrUSVStringArgument(const DoubleOrUSVString& aUnion)
1773 : : mUnion(const_cast<DoubleOrUSVString&>(aUnion))
1774 : {
1775 : }
1776 :
1777 : inline bool
1778 : TrySetToDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1779 : {
1780 : tryNext = false;
1781 : { // scope for memberSlot
1782 : double& memberSlot = RawSetAsDouble();
1783 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
1784 : return false;
1785 : } else if (!mozilla::IsFinite(memberSlot)) {
1786 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrUSVString");
1787 : return false;
1788 : }
1789 : }
1790 : return true;
1791 : }
1792 :
1793 : inline bool
1794 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1795 : {
1796 : tryNext = false;
1797 : { // scope for memberSlot
1798 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
1799 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
1800 : return false;
1801 : }
1802 : NormalizeUSVString(memberSlot);
1803 : }
1804 : return true;
1805 : }
1806 :
1807 : inline void
1808 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
1809 : {
1810 : RawSetAsUSVString().Rebind(aData, aLength);
1811 : }
1812 :
1813 : private:
1814 : inline double&
1815 : RawSetAsDouble()
1816 : {
1817 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1818 : mUnion.mType = mUnion.eDouble;
1819 : return mUnion.mValue.mDouble.SetValue();
1820 : }
1821 :
1822 : inline binding_detail::FakeString&
1823 : RawSetAsUSVString()
1824 : {
1825 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1826 : mUnion.mType = mUnion.eUSVString;
1827 : return mUnion.mValue.mUSVString.SetValue();
1828 : }
1829 : };
1830 :
1831 : class ElementCreationOptionsOrStringArgument
1832 : {
1833 : ElementCreationOptionsOrString& mUnion;
1834 :
1835 : ElementCreationOptionsOrStringArgument(const ElementCreationOptionsOrStringArgument&) = delete;
1836 : ElementCreationOptionsOrStringArgument& operator=(const ElementCreationOptionsOrStringArgument&) = delete;
1837 : public:
1838 56 : explicit inline ElementCreationOptionsOrStringArgument(const ElementCreationOptionsOrString& aUnion)
1839 56 : : mUnion(const_cast<ElementCreationOptionsOrString&>(aUnion))
1840 : {
1841 56 : }
1842 :
1843 : inline bool
1844 0 : TrySetToElementCreationOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1845 : {
1846 0 : tryNext = false;
1847 : { // scope for memberSlot
1848 0 : binding_detail::FastElementCreationOptions& memberSlot = RawSetAsElementCreationOptions();
1849 0 : if (!IsConvertibleToDictionary(value)) {
1850 0 : mUnion.DestroyElementCreationOptions();
1851 0 : tryNext = true;
1852 0 : return true;
1853 : }
1854 0 : if (!memberSlot.Init(cx, value, "Member of ElementCreationOptionsOrString", passedToJSImpl)) {
1855 0 : return false;
1856 : }
1857 : }
1858 0 : return true;
1859 : }
1860 :
1861 : inline bool
1862 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1863 : {
1864 0 : tryNext = false;
1865 : { // scope for memberSlot
1866 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
1867 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
1868 0 : return false;
1869 : }
1870 : }
1871 0 : return true;
1872 : }
1873 :
1874 : inline void
1875 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
1876 : {
1877 : RawSetAsString().Rebind(aData, aLength);
1878 : }
1879 :
1880 : private:
1881 : inline binding_detail::FastElementCreationOptions&
1882 0 : RawSetAsElementCreationOptions()
1883 : {
1884 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1885 0 : mUnion.mType = mUnion.eElementCreationOptions;
1886 0 : return mUnion.mValue.mElementCreationOptions.SetValue();
1887 : }
1888 :
1889 : inline binding_detail::FakeString&
1890 0 : RawSetAsString()
1891 : {
1892 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1893 0 : mUnion.mType = mUnion.eString;
1894 0 : return mUnion.mValue.mString.SetValue();
1895 : }
1896 : };
1897 :
1898 : class ElementOrCSSPseudoElementArgument
1899 : {
1900 : ElementOrCSSPseudoElement& mUnion;
1901 :
1902 : ElementOrCSSPseudoElementArgument(const ElementOrCSSPseudoElementArgument&) = delete;
1903 : ElementOrCSSPseudoElementArgument& operator=(const ElementOrCSSPseudoElementArgument&) = delete;
1904 : public:
1905 0 : explicit inline ElementOrCSSPseudoElementArgument(const ElementOrCSSPseudoElement& aUnion)
1906 0 : : mUnion(const_cast<ElementOrCSSPseudoElement&>(aUnion))
1907 : {
1908 0 : }
1909 :
1910 : inline bool
1911 0 : TrySetToElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1912 : {
1913 0 : tryNext = false;
1914 : { // scope for memberSlot
1915 0 : NonNull<mozilla::dom::Element>& memberSlot = RawSetAsElement();
1916 : {
1917 0 : nsresult rv = UnwrapObject<prototypes::id::Element, mozilla::dom::Element>(value, memberSlot);
1918 0 : if (NS_FAILED(rv)) {
1919 0 : mUnion.DestroyElement();
1920 0 : tryNext = true;
1921 0 : return true;
1922 : }
1923 : }
1924 : }
1925 0 : return true;
1926 : }
1927 :
1928 : inline bool
1929 0 : TrySetToCSSPseudoElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1930 : {
1931 0 : tryNext = false;
1932 : { // scope for memberSlot
1933 0 : NonNull<mozilla::dom::CSSPseudoElement>& memberSlot = RawSetAsCSSPseudoElement();
1934 : {
1935 0 : nsresult rv = UnwrapObject<prototypes::id::CSSPseudoElement, mozilla::dom::CSSPseudoElement>(value, memberSlot);
1936 0 : if (NS_FAILED(rv)) {
1937 0 : mUnion.DestroyCSSPseudoElement();
1938 0 : tryNext = true;
1939 0 : return true;
1940 : }
1941 : }
1942 : }
1943 0 : return true;
1944 : }
1945 :
1946 : private:
1947 : inline NonNull<mozilla::dom::Element>&
1948 0 : RawSetAsElement()
1949 : {
1950 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1951 0 : mUnion.mType = mUnion.eElement;
1952 0 : return mUnion.mValue.mElement.SetValue();
1953 : }
1954 :
1955 : inline NonNull<mozilla::dom::CSSPseudoElement>&
1956 0 : RawSetAsCSSPseudoElement()
1957 : {
1958 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1959 0 : mUnion.mType = mUnion.eCSSPseudoElement;
1960 0 : return mUnion.mValue.mCSSPseudoElement.SetValue();
1961 : }
1962 : };
1963 :
1964 : class EventHandlerNonNullOrNullOrLongArgument
1965 : {
1966 : EventHandlerNonNullOrNullOrLong& mUnion;
1967 :
1968 : EventHandlerNonNullOrNullOrLongArgument(const EventHandlerNonNullOrNullOrLongArgument&) = delete;
1969 : EventHandlerNonNullOrNullOrLongArgument& operator=(const EventHandlerNonNullOrNullOrLongArgument&) = delete;
1970 : public:
1971 : explicit inline EventHandlerNonNullOrNullOrLongArgument(const EventHandlerNonNullOrNullOrLong& aUnion)
1972 : : mUnion(const_cast<EventHandlerNonNullOrNullOrLong&>(aUnion))
1973 : {
1974 : }
1975 :
1976 : inline bool
1977 : SetNull()
1978 : {
1979 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
1980 : mUnion.mType = mUnion.eNull;
1981 : return true;
1982 : }
1983 :
1984 : inline bool
1985 : TrySetToEventHandlerNonNull(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
1986 : {
1987 : tryNext = false;
1988 : { // scope for memberSlot
1989 : RootedCallback<OwningNonNull<binding_detail::FastEventHandlerNonNull>>& memberSlot = RawSetAsEventHandlerNonNull(cx);
1990 : if (JS::IsCallable(&value.toObject())) {
1991 : { // scope for tempRoot
1992 : JS::Rooted<JSObject*> tempRoot(cx, &value.toObject());
1993 : memberSlot = new binding_detail::FastEventHandlerNonNull(tempRoot);
1994 : }
1995 : } else {
1996 : mUnion.DestroyEventHandlerNonNull();
1997 : tryNext = true;
1998 : return true;
1999 : }
2000 : }
2001 : return true;
2002 : }
2003 :
2004 : inline bool
2005 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2006 : {
2007 : tryNext = false;
2008 : { // scope for memberSlot
2009 : int32_t& memberSlot = RawSetAsLong();
2010 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
2011 : return false;
2012 : }
2013 : }
2014 : return true;
2015 : }
2016 :
2017 : private:
2018 : inline RootedCallback<OwningNonNull<binding_detail::FastEventHandlerNonNull>>&
2019 : RawSetAsEventHandlerNonNull(JSContext* cx)
2020 : {
2021 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2022 : mUnion.mType = mUnion.eEventHandlerNonNull;
2023 : return mUnion.mValue.mEventHandlerNonNull.SetValue(cx);
2024 : }
2025 :
2026 : inline int32_t&
2027 : RawSetAsLong()
2028 : {
2029 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2030 : mUnion.mType = mUnion.eLong;
2031 : return mUnion.mValue.mLong.SetValue();
2032 : }
2033 : };
2034 :
2035 : class EventInitOrLongArgument
2036 : {
2037 : EventInitOrLong& mUnion;
2038 :
2039 : EventInitOrLongArgument(const EventInitOrLongArgument&) = delete;
2040 : EventInitOrLongArgument& operator=(const EventInitOrLongArgument&) = delete;
2041 : public:
2042 : explicit inline EventInitOrLongArgument(const EventInitOrLong& aUnion)
2043 : : mUnion(const_cast<EventInitOrLong&>(aUnion))
2044 : {
2045 : }
2046 :
2047 : inline bool
2048 : TrySetToEventInit(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2049 : {
2050 : tryNext = false;
2051 : { // scope for memberSlot
2052 : binding_detail::FastEventInit& memberSlot = RawSetAsEventInit();
2053 : if (!IsConvertibleToDictionary(value)) {
2054 : mUnion.DestroyEventInit();
2055 : tryNext = true;
2056 : return true;
2057 : }
2058 : if (!memberSlot.Init(cx, value, "Member of EventInitOrLong", passedToJSImpl)) {
2059 : return false;
2060 : }
2061 : }
2062 : return true;
2063 : }
2064 :
2065 : inline bool
2066 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2067 : {
2068 : tryNext = false;
2069 : { // scope for memberSlot
2070 : int32_t& memberSlot = RawSetAsLong();
2071 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
2072 : return false;
2073 : }
2074 : }
2075 : return true;
2076 : }
2077 :
2078 : private:
2079 : inline binding_detail::FastEventInit&
2080 : RawSetAsEventInit()
2081 : {
2082 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2083 : mUnion.mType = mUnion.eEventInit;
2084 : return mUnion.mValue.mEventInit.SetValue();
2085 : }
2086 :
2087 : inline int32_t&
2088 : RawSetAsLong()
2089 : {
2090 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2091 : mUnion.mType = mUnion.eLong;
2092 : return mUnion.mValue.mLong.SetValue();
2093 : }
2094 : };
2095 :
2096 : class EventInitOrStringSequenceArgument
2097 : {
2098 : EventInitOrStringSequence& mUnion;
2099 :
2100 : EventInitOrStringSequenceArgument(const EventInitOrStringSequenceArgument&) = delete;
2101 : EventInitOrStringSequenceArgument& operator=(const EventInitOrStringSequenceArgument&) = delete;
2102 : public:
2103 : explicit inline EventInitOrStringSequenceArgument(const EventInitOrStringSequence& aUnion)
2104 : : mUnion(const_cast<EventInitOrStringSequence&>(aUnion))
2105 : {
2106 : }
2107 :
2108 : inline bool
2109 : TrySetToEventInit(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2110 : {
2111 : tryNext = false;
2112 : { // scope for memberSlot
2113 : binding_detail::FastEventInit& memberSlot = RawSetAsEventInit();
2114 : if (!IsConvertibleToDictionary(value)) {
2115 : mUnion.DestroyEventInit();
2116 : tryNext = true;
2117 : return true;
2118 : }
2119 : if (!memberSlot.Init(cx, value, "Member of EventInitOrStringSequence", passedToJSImpl)) {
2120 : return false;
2121 : }
2122 : }
2123 : return true;
2124 : }
2125 :
2126 : inline bool
2127 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2128 : {
2129 : tryNext = false;
2130 : { // scope for memberSlot
2131 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
2132 : JS::ForOfIterator iter(cx);
2133 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
2134 : return false;
2135 : }
2136 : if (!iter.valueIsIterable()) {
2137 : mUnion.DestroyStringSequence();
2138 : tryNext = true;
2139 : return true;
2140 : }
2141 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
2142 : JS::Rooted<JS::Value> temp(cx);
2143 : while (true) {
2144 : bool done;
2145 : if (!iter.next(&temp, &done)) {
2146 : return false;
2147 : }
2148 : if (done) {
2149 : break;
2150 : }
2151 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
2152 : if (!slotPtr) {
2153 : JS_ReportOutOfMemory(cx);
2154 : return false;
2155 : }
2156 : nsString& slot = *slotPtr;
2157 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
2158 : return false;
2159 : }
2160 : }
2161 : }
2162 : return true;
2163 : }
2164 :
2165 : private:
2166 : inline binding_detail::FastEventInit&
2167 : RawSetAsEventInit()
2168 : {
2169 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2170 : mUnion.mType = mUnion.eEventInit;
2171 : return mUnion.mValue.mEventInit.SetValue();
2172 : }
2173 :
2174 : inline binding_detail::AutoSequence<nsString>&
2175 : RawSetAsStringSequence()
2176 : {
2177 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2178 : mUnion.mType = mUnion.eStringSequence;
2179 : return mUnion.mValue.mStringSequence.SetValue();
2180 : }
2181 : };
2182 :
2183 : class EventListenerOptionsOrBooleanArgument
2184 : {
2185 : EventListenerOptionsOrBoolean& mUnion;
2186 :
2187 : EventListenerOptionsOrBooleanArgument(const EventListenerOptionsOrBooleanArgument&) = delete;
2188 : EventListenerOptionsOrBooleanArgument& operator=(const EventListenerOptionsOrBooleanArgument&) = delete;
2189 : public:
2190 15 : explicit inline EventListenerOptionsOrBooleanArgument(const EventListenerOptionsOrBoolean& aUnion)
2191 15 : : mUnion(const_cast<EventListenerOptionsOrBoolean&>(aUnion))
2192 : {
2193 15 : }
2194 :
2195 : inline bool
2196 7 : TrySetToEventListenerOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2197 : {
2198 7 : tryNext = false;
2199 : { // scope for memberSlot
2200 7 : binding_detail::FastEventListenerOptions& memberSlot = RawSetAsEventListenerOptions();
2201 7 : if (!IsConvertibleToDictionary(value)) {
2202 7 : mUnion.DestroyEventListenerOptions();
2203 7 : tryNext = true;
2204 7 : return true;
2205 : }
2206 0 : if (!memberSlot.Init(cx, value, "Member of EventListenerOptionsOrBoolean", passedToJSImpl)) {
2207 0 : return false;
2208 : }
2209 : }
2210 0 : return true;
2211 : }
2212 :
2213 : inline bool
2214 7 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2215 : {
2216 7 : tryNext = false;
2217 : { // scope for memberSlot
2218 7 : bool& memberSlot = RawSetAsBoolean();
2219 7 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
2220 0 : return false;
2221 : }
2222 : }
2223 7 : return true;
2224 : }
2225 :
2226 : private:
2227 : inline binding_detail::FastEventListenerOptions&
2228 7 : RawSetAsEventListenerOptions()
2229 : {
2230 7 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2231 7 : mUnion.mType = mUnion.eEventListenerOptions;
2232 7 : return mUnion.mValue.mEventListenerOptions.SetValue();
2233 : }
2234 :
2235 : inline bool&
2236 7 : RawSetAsBoolean()
2237 : {
2238 7 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2239 7 : mUnion.mType = mUnion.eBoolean;
2240 7 : return mUnion.mValue.mBoolean.SetValue();
2241 : }
2242 : };
2243 :
2244 : class EventOrStringArgument
2245 : {
2246 : EventOrString& mUnion;
2247 :
2248 : EventOrStringArgument(const EventOrStringArgument&) = delete;
2249 : EventOrStringArgument& operator=(const EventOrStringArgument&) = delete;
2250 : public:
2251 : explicit inline EventOrStringArgument(const EventOrString& aUnion)
2252 : : mUnion(const_cast<EventOrString&>(aUnion))
2253 : {
2254 : }
2255 :
2256 : inline bool
2257 : TrySetToEvent(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2258 : {
2259 : tryNext = false;
2260 : { // scope for memberSlot
2261 : NonNull<mozilla::dom::Event>& memberSlot = RawSetAsEvent();
2262 : {
2263 : nsresult rv = UnwrapObject<prototypes::id::Event, mozilla::dom::Event>(value, memberSlot);
2264 : if (NS_FAILED(rv)) {
2265 : mUnion.DestroyEvent();
2266 : tryNext = true;
2267 : return true;
2268 : }
2269 : }
2270 : }
2271 : return true;
2272 : }
2273 :
2274 : inline bool
2275 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2276 : {
2277 : tryNext = false;
2278 : { // scope for memberSlot
2279 : binding_detail::FakeString& memberSlot = RawSetAsString();
2280 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
2281 : return false;
2282 : }
2283 : }
2284 : return true;
2285 : }
2286 :
2287 : inline void
2288 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
2289 : {
2290 : RawSetAsString().Rebind(aData, aLength);
2291 : }
2292 :
2293 : private:
2294 : inline NonNull<mozilla::dom::Event>&
2295 : RawSetAsEvent()
2296 : {
2297 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2298 : mUnion.mType = mUnion.eEvent;
2299 : return mUnion.mValue.mEvent.SetValue();
2300 : }
2301 :
2302 : inline binding_detail::FakeString&
2303 : RawSetAsString()
2304 : {
2305 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2306 : mUnion.mType = mUnion.eString;
2307 : return mUnion.mValue.mString.SetValue();
2308 : }
2309 : };
2310 :
2311 : class ExternalOrWindowProxyArgument
2312 : {
2313 : ExternalOrWindowProxy& mUnion;
2314 : Maybe<RefPtr<nsPIDOMWindowOuter>> mWindowProxyHolder;
2315 :
2316 : ExternalOrWindowProxyArgument(const ExternalOrWindowProxyArgument&) = delete;
2317 : ExternalOrWindowProxyArgument& operator=(const ExternalOrWindowProxyArgument&) = delete;
2318 : public:
2319 : explicit inline ExternalOrWindowProxyArgument(const ExternalOrWindowProxy& aUnion)
2320 : : mUnion(const_cast<ExternalOrWindowProxy&>(aUnion))
2321 : {
2322 : }
2323 :
2324 : inline bool
2325 : TrySetToExternal(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2326 : {
2327 : tryNext = false;
2328 : { // scope for memberSlot
2329 : NonNull<mozilla::dom::External>& memberSlot = RawSetAsExternal();
2330 : {
2331 : nsresult rv = UnwrapObject<prototypes::id::External, mozilla::dom::External>(value, memberSlot);
2332 : if (NS_FAILED(rv)) {
2333 : mUnion.DestroyExternal();
2334 : tryNext = true;
2335 : return true;
2336 : }
2337 : }
2338 : }
2339 : return true;
2340 : }
2341 :
2342 : inline bool
2343 : TrySetToWindowProxy(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2344 : {
2345 : tryNext = false;
2346 : { // scope for memberSlot
2347 : nsPIDOMWindowOuter*& memberSlot = RawSetAsWindowProxy();
2348 : mWindowProxyHolder.emplace();
2349 : JS::Rooted<JSObject*> source(cx, &value.toObject());
2350 : if (NS_FAILED(UnwrapArg<nsPIDOMWindowOuter>(cx, source, getter_AddRefs(mWindowProxyHolder.ref())))) {
2351 : mWindowProxyHolder.reset();
2352 : mUnion.DestroyWindowProxy();
2353 : tryNext = true;
2354 : return true;
2355 : }
2356 : MOZ_ASSERT(mWindowProxyHolder.ref());
2357 : memberSlot = mWindowProxyHolder.ref();
2358 : }
2359 : return true;
2360 : }
2361 :
2362 : private:
2363 : inline NonNull<mozilla::dom::External>&
2364 : RawSetAsExternal()
2365 : {
2366 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2367 : mUnion.mType = mUnion.eExternal;
2368 : return mUnion.mValue.mExternal.SetValue();
2369 : }
2370 :
2371 : inline nsPIDOMWindowOuter*&
2372 : RawSetAsWindowProxy()
2373 : {
2374 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2375 : mUnion.mType = mUnion.eWindowProxy;
2376 : return mUnion.mValue.mWindowProxy.SetValue();
2377 : }
2378 : };
2379 :
2380 : class FileOrDirectoryArgument
2381 : {
2382 : FileOrDirectory& mUnion;
2383 :
2384 : FileOrDirectoryArgument(const FileOrDirectoryArgument&) = delete;
2385 : FileOrDirectoryArgument& operator=(const FileOrDirectoryArgument&) = delete;
2386 : public:
2387 : explicit inline FileOrDirectoryArgument(const FileOrDirectory& aUnion)
2388 : : mUnion(const_cast<FileOrDirectory&>(aUnion))
2389 : {
2390 : }
2391 :
2392 : inline bool
2393 : TrySetToFile(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2394 : {
2395 : tryNext = false;
2396 : { // scope for memberSlot
2397 : NonNull<mozilla::dom::File>& memberSlot = RawSetAsFile();
2398 : {
2399 : nsresult rv = UnwrapObject<prototypes::id::File, mozilla::dom::File>(value, memberSlot);
2400 : if (NS_FAILED(rv)) {
2401 : mUnion.DestroyFile();
2402 : tryNext = true;
2403 : return true;
2404 : }
2405 : }
2406 : }
2407 : return true;
2408 : }
2409 :
2410 : inline bool
2411 : TrySetToDirectory(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2412 : {
2413 : tryNext = false;
2414 : { // scope for memberSlot
2415 : NonNull<mozilla::dom::Directory>& memberSlot = RawSetAsDirectory();
2416 : {
2417 : nsresult rv = UnwrapObject<prototypes::id::Directory, mozilla::dom::Directory>(value, memberSlot);
2418 : if (NS_FAILED(rv)) {
2419 : mUnion.DestroyDirectory();
2420 : tryNext = true;
2421 : return true;
2422 : }
2423 : }
2424 : }
2425 : return true;
2426 : }
2427 :
2428 : private:
2429 : inline NonNull<mozilla::dom::File>&
2430 : RawSetAsFile()
2431 : {
2432 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2433 : mUnion.mType = mUnion.eFile;
2434 : return mUnion.mValue.mFile.SetValue();
2435 : }
2436 :
2437 : inline NonNull<mozilla::dom::Directory>&
2438 : RawSetAsDirectory()
2439 : {
2440 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2441 : mUnion.mType = mUnion.eDirectory;
2442 : return mUnion.mValue.mDirectory.SetValue();
2443 : }
2444 : };
2445 :
2446 : class Float32ArrayOrUnrestrictedFloatSequenceArgument
2447 : {
2448 : Float32ArrayOrUnrestrictedFloatSequence& mUnion;
2449 :
2450 : Float32ArrayOrUnrestrictedFloatSequenceArgument(const Float32ArrayOrUnrestrictedFloatSequenceArgument&) = delete;
2451 : Float32ArrayOrUnrestrictedFloatSequenceArgument& operator=(const Float32ArrayOrUnrestrictedFloatSequenceArgument&) = delete;
2452 : public:
2453 0 : explicit inline Float32ArrayOrUnrestrictedFloatSequenceArgument(const Float32ArrayOrUnrestrictedFloatSequence& aUnion)
2454 0 : : mUnion(const_cast<Float32ArrayOrUnrestrictedFloatSequence&>(aUnion))
2455 : {
2456 0 : }
2457 :
2458 : inline bool
2459 0 : TrySetToFloat32Array(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2460 : {
2461 0 : tryNext = false;
2462 : { // scope for memberSlot
2463 0 : RootedTypedArray<Float32Array>& memberSlot = RawSetAsFloat32Array(cx);
2464 0 : if (!memberSlot.Init(&value.toObject())) {
2465 0 : mUnion.DestroyFloat32Array();
2466 0 : tryNext = true;
2467 0 : return true;
2468 : }
2469 : }
2470 0 : return true;
2471 : }
2472 :
2473 : inline bool
2474 0 : TrySetToUnrestrictedFloatSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2475 : {
2476 0 : tryNext = false;
2477 : { // scope for memberSlot
2478 0 : binding_detail::AutoSequence<float>& memberSlot = RawSetAsUnrestrictedFloatSequence();
2479 0 : JS::ForOfIterator iter(cx);
2480 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
2481 0 : return false;
2482 : }
2483 0 : if (!iter.valueIsIterable()) {
2484 0 : mUnion.DestroyUnrestrictedFloatSequence();
2485 0 : tryNext = true;
2486 0 : return true;
2487 : }
2488 0 : binding_detail::AutoSequence<float> &arr = memberSlot;
2489 0 : JS::Rooted<JS::Value> temp(cx);
2490 : while (true) {
2491 : bool done;
2492 0 : if (!iter.next(&temp, &done)) {
2493 0 : return false;
2494 : }
2495 0 : if (done) {
2496 0 : break;
2497 : }
2498 0 : float* slotPtr = arr.AppendElement(mozilla::fallible);
2499 0 : if (!slotPtr) {
2500 0 : JS_ReportOutOfMemory(cx);
2501 0 : return false;
2502 : }
2503 0 : float& slot = *slotPtr;
2504 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp, &slot)) {
2505 0 : return false;
2506 : }
2507 0 : }
2508 : }
2509 0 : return true;
2510 : }
2511 :
2512 : private:
2513 : inline RootedTypedArray<Float32Array>&
2514 0 : RawSetAsFloat32Array(JSContext* cx)
2515 : {
2516 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2517 0 : mUnion.mType = mUnion.eFloat32Array;
2518 0 : return mUnion.mValue.mFloat32Array.SetValue(cx);
2519 : }
2520 :
2521 : inline binding_detail::AutoSequence<float>&
2522 0 : RawSetAsUnrestrictedFloatSequence()
2523 : {
2524 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2525 0 : mUnion.mType = mUnion.eUnrestrictedFloatSequence;
2526 0 : return mUnion.mValue.mUnrestrictedFloatSequence.SetValue();
2527 : }
2528 : };
2529 :
2530 : class FloatOrStringArgument
2531 : {
2532 : FloatOrString& mUnion;
2533 :
2534 : FloatOrStringArgument(const FloatOrStringArgument&) = delete;
2535 : FloatOrStringArgument& operator=(const FloatOrStringArgument&) = delete;
2536 : public:
2537 : explicit inline FloatOrStringArgument(const FloatOrString& aUnion)
2538 : : mUnion(const_cast<FloatOrString&>(aUnion))
2539 : {
2540 : }
2541 :
2542 : inline bool
2543 : TrySetToFloat(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2544 : {
2545 : tryNext = false;
2546 : { // scope for memberSlot
2547 : float& memberSlot = RawSetAsFloat();
2548 : if (!ValueToPrimitive<float, eDefault>(cx, value, &memberSlot)) {
2549 : return false;
2550 : } else if (!mozilla::IsFinite(memberSlot)) {
2551 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of FloatOrString");
2552 : return false;
2553 : }
2554 : }
2555 : return true;
2556 : }
2557 :
2558 : inline bool
2559 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2560 : {
2561 : tryNext = false;
2562 : { // scope for memberSlot
2563 : binding_detail::FakeString& memberSlot = RawSetAsString();
2564 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
2565 : return false;
2566 : }
2567 : }
2568 : return true;
2569 : }
2570 :
2571 : inline void
2572 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
2573 : {
2574 : RawSetAsString().Rebind(aData, aLength);
2575 : }
2576 :
2577 : private:
2578 : inline float&
2579 : RawSetAsFloat()
2580 : {
2581 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2582 : mUnion.mType = mUnion.eFloat;
2583 : return mUnion.mValue.mFloat.SetValue();
2584 : }
2585 :
2586 : inline binding_detail::FakeString&
2587 : RawSetAsString()
2588 : {
2589 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2590 : mUnion.mType = mUnion.eString;
2591 : return mUnion.mValue.mString.SetValue();
2592 : }
2593 : };
2594 :
2595 : class HTMLCanvasElementOrOffscreenCanvasArgument
2596 : {
2597 : HTMLCanvasElementOrOffscreenCanvas& mUnion;
2598 :
2599 : HTMLCanvasElementOrOffscreenCanvasArgument(const HTMLCanvasElementOrOffscreenCanvasArgument&) = delete;
2600 : HTMLCanvasElementOrOffscreenCanvasArgument& operator=(const HTMLCanvasElementOrOffscreenCanvasArgument&) = delete;
2601 : public:
2602 : explicit inline HTMLCanvasElementOrOffscreenCanvasArgument(const HTMLCanvasElementOrOffscreenCanvas& aUnion)
2603 : : mUnion(const_cast<HTMLCanvasElementOrOffscreenCanvas&>(aUnion))
2604 : {
2605 : }
2606 :
2607 : inline bool
2608 : TrySetToHTMLCanvasElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2609 : {
2610 : tryNext = false;
2611 : { // scope for memberSlot
2612 : NonNull<mozilla::dom::HTMLCanvasElement>& memberSlot = RawSetAsHTMLCanvasElement();
2613 : {
2614 : nsresult rv = UnwrapObject<prototypes::id::HTMLCanvasElement, mozilla::dom::HTMLCanvasElement>(value, memberSlot);
2615 : if (NS_FAILED(rv)) {
2616 : mUnion.DestroyHTMLCanvasElement();
2617 : tryNext = true;
2618 : return true;
2619 : }
2620 : }
2621 : }
2622 : return true;
2623 : }
2624 :
2625 : inline bool
2626 : TrySetToOffscreenCanvas(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2627 : {
2628 : tryNext = false;
2629 : { // scope for memberSlot
2630 : NonNull<mozilla::dom::OffscreenCanvas>& memberSlot = RawSetAsOffscreenCanvas();
2631 : {
2632 : nsresult rv = UnwrapObject<prototypes::id::OffscreenCanvas, mozilla::dom::OffscreenCanvas>(value, memberSlot);
2633 : if (NS_FAILED(rv)) {
2634 : mUnion.DestroyOffscreenCanvas();
2635 : tryNext = true;
2636 : return true;
2637 : }
2638 : }
2639 : }
2640 : return true;
2641 : }
2642 :
2643 : private:
2644 : inline NonNull<mozilla::dom::HTMLCanvasElement>&
2645 : RawSetAsHTMLCanvasElement()
2646 : {
2647 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2648 : mUnion.mType = mUnion.eHTMLCanvasElement;
2649 : return mUnion.mValue.mHTMLCanvasElement.SetValue();
2650 : }
2651 :
2652 : inline NonNull<mozilla::dom::OffscreenCanvas>&
2653 : RawSetAsOffscreenCanvas()
2654 : {
2655 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2656 : mUnion.mType = mUnion.eOffscreenCanvas;
2657 : return mUnion.mValue.mOffscreenCanvas.SetValue();
2658 : }
2659 : };
2660 :
2661 : class HTMLElementOrLongArgument
2662 : {
2663 : HTMLElementOrLong& mUnion;
2664 :
2665 : HTMLElementOrLongArgument(const HTMLElementOrLongArgument&) = delete;
2666 : HTMLElementOrLongArgument& operator=(const HTMLElementOrLongArgument&) = delete;
2667 : public:
2668 0 : explicit inline HTMLElementOrLongArgument(const HTMLElementOrLong& aUnion)
2669 0 : : mUnion(const_cast<HTMLElementOrLong&>(aUnion))
2670 : {
2671 0 : }
2672 :
2673 : inline bool
2674 0 : TrySetToHTMLElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2675 : {
2676 0 : tryNext = false;
2677 : { // scope for memberSlot
2678 0 : NonNull<nsGenericHTMLElement>& memberSlot = RawSetAsHTMLElement();
2679 : {
2680 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLElement, nsGenericHTMLElement>(value, memberSlot);
2681 0 : if (NS_FAILED(rv)) {
2682 0 : mUnion.DestroyHTMLElement();
2683 0 : tryNext = true;
2684 0 : return true;
2685 : }
2686 : }
2687 : }
2688 0 : return true;
2689 : }
2690 :
2691 : inline bool
2692 0 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2693 : {
2694 0 : tryNext = false;
2695 : { // scope for memberSlot
2696 0 : int32_t& memberSlot = RawSetAsLong();
2697 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
2698 0 : return false;
2699 : }
2700 : }
2701 0 : return true;
2702 : }
2703 :
2704 : private:
2705 : inline NonNull<nsGenericHTMLElement>&
2706 0 : RawSetAsHTMLElement()
2707 : {
2708 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2709 0 : mUnion.mType = mUnion.eHTMLElement;
2710 0 : return mUnion.mValue.mHTMLElement.SetValue();
2711 : }
2712 :
2713 : inline int32_t&
2714 0 : RawSetAsLong()
2715 : {
2716 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2717 0 : mUnion.mType = mUnion.eLong;
2718 0 : return mUnion.mValue.mLong.SetValue();
2719 : }
2720 : };
2721 :
2722 : class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument
2723 : {
2724 : HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap& mUnion;
2725 :
2726 : HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument(const HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument&) = delete;
2727 : HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument& operator=(const HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument&) = delete;
2728 : public:
2729 0 : explicit inline HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapArgument(const HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap& aUnion)
2730 0 : : mUnion(const_cast<HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap&>(aUnion))
2731 : {
2732 0 : }
2733 :
2734 : inline bool
2735 0 : TrySetToHTMLImageElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2736 : {
2737 0 : tryNext = false;
2738 : { // scope for memberSlot
2739 0 : NonNull<mozilla::dom::HTMLImageElement>& memberSlot = RawSetAsHTMLImageElement();
2740 : {
2741 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLImageElement, mozilla::dom::HTMLImageElement>(value, memberSlot);
2742 0 : if (NS_FAILED(rv)) {
2743 0 : mUnion.DestroyHTMLImageElement();
2744 0 : tryNext = true;
2745 0 : return true;
2746 : }
2747 : }
2748 : }
2749 0 : return true;
2750 : }
2751 :
2752 : inline bool
2753 0 : TrySetToHTMLCanvasElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2754 : {
2755 0 : tryNext = false;
2756 : { // scope for memberSlot
2757 0 : NonNull<mozilla::dom::HTMLCanvasElement>& memberSlot = RawSetAsHTMLCanvasElement();
2758 : {
2759 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLCanvasElement, mozilla::dom::HTMLCanvasElement>(value, memberSlot);
2760 0 : if (NS_FAILED(rv)) {
2761 0 : mUnion.DestroyHTMLCanvasElement();
2762 0 : tryNext = true;
2763 0 : return true;
2764 : }
2765 : }
2766 : }
2767 0 : return true;
2768 : }
2769 :
2770 : inline bool
2771 0 : TrySetToHTMLVideoElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2772 : {
2773 0 : tryNext = false;
2774 : { // scope for memberSlot
2775 0 : NonNull<mozilla::dom::HTMLVideoElement>& memberSlot = RawSetAsHTMLVideoElement();
2776 : {
2777 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLVideoElement, mozilla::dom::HTMLVideoElement>(value, memberSlot);
2778 0 : if (NS_FAILED(rv)) {
2779 0 : mUnion.DestroyHTMLVideoElement();
2780 0 : tryNext = true;
2781 0 : return true;
2782 : }
2783 : }
2784 : }
2785 0 : return true;
2786 : }
2787 :
2788 : inline bool
2789 0 : TrySetToImageBitmap(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2790 : {
2791 0 : tryNext = false;
2792 : { // scope for memberSlot
2793 0 : NonNull<mozilla::dom::ImageBitmap>& memberSlot = RawSetAsImageBitmap();
2794 : {
2795 0 : nsresult rv = UnwrapObject<prototypes::id::ImageBitmap, mozilla::dom::ImageBitmap>(value, memberSlot);
2796 0 : if (NS_FAILED(rv)) {
2797 0 : mUnion.DestroyImageBitmap();
2798 0 : tryNext = true;
2799 0 : return true;
2800 : }
2801 : }
2802 : }
2803 0 : return true;
2804 : }
2805 :
2806 : private:
2807 : inline NonNull<mozilla::dom::HTMLImageElement>&
2808 0 : RawSetAsHTMLImageElement()
2809 : {
2810 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2811 0 : mUnion.mType = mUnion.eHTMLImageElement;
2812 0 : return mUnion.mValue.mHTMLImageElement.SetValue();
2813 : }
2814 :
2815 : inline NonNull<mozilla::dom::HTMLCanvasElement>&
2816 0 : RawSetAsHTMLCanvasElement()
2817 : {
2818 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2819 0 : mUnion.mType = mUnion.eHTMLCanvasElement;
2820 0 : return mUnion.mValue.mHTMLCanvasElement.SetValue();
2821 : }
2822 :
2823 : inline NonNull<mozilla::dom::HTMLVideoElement>&
2824 0 : RawSetAsHTMLVideoElement()
2825 : {
2826 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2827 0 : mUnion.mType = mUnion.eHTMLVideoElement;
2828 0 : return mUnion.mValue.mHTMLVideoElement.SetValue();
2829 : }
2830 :
2831 : inline NonNull<mozilla::dom::ImageBitmap>&
2832 0 : RawSetAsImageBitmap()
2833 : {
2834 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
2835 0 : mUnion.mType = mUnion.eImageBitmap;
2836 0 : return mUnion.mValue.mImageBitmap.SetValue();
2837 : }
2838 : };
2839 :
2840 : class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument
2841 : {
2842 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& mUnion;
2843 :
2844 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument(const HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument&) = delete;
2845 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument& operator=(const HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument&) = delete;
2846 : public:
2847 0 : explicit inline HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument(const HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& aUnion)
2848 0 : : mUnion(const_cast<HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer&>(aUnion))
2849 : {
2850 0 : }
2851 :
2852 : inline bool
2853 0 : TrySetToHTMLImageElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2854 : {
2855 0 : tryNext = false;
2856 : { // scope for memberSlot
2857 0 : NonNull<mozilla::dom::HTMLImageElement>& memberSlot = RawSetAsHTMLImageElement();
2858 : {
2859 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLImageElement, mozilla::dom::HTMLImageElement>(value, memberSlot);
2860 0 : if (NS_FAILED(rv)) {
2861 0 : mUnion.DestroyHTMLImageElement();
2862 0 : tryNext = true;
2863 0 : return true;
2864 : }
2865 : }
2866 : }
2867 0 : return true;
2868 : }
2869 :
2870 : inline bool
2871 0 : TrySetToHTMLVideoElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2872 : {
2873 0 : tryNext = false;
2874 : { // scope for memberSlot
2875 0 : NonNull<mozilla::dom::HTMLVideoElement>& memberSlot = RawSetAsHTMLVideoElement();
2876 : {
2877 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLVideoElement, mozilla::dom::HTMLVideoElement>(value, memberSlot);
2878 0 : if (NS_FAILED(rv)) {
2879 0 : mUnion.DestroyHTMLVideoElement();
2880 0 : tryNext = true;
2881 0 : return true;
2882 : }
2883 : }
2884 : }
2885 0 : return true;
2886 : }
2887 :
2888 : inline bool
2889 0 : TrySetToHTMLCanvasElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2890 : {
2891 0 : tryNext = false;
2892 : { // scope for memberSlot
2893 0 : NonNull<mozilla::dom::HTMLCanvasElement>& memberSlot = RawSetAsHTMLCanvasElement();
2894 : {
2895 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLCanvasElement, mozilla::dom::HTMLCanvasElement>(value, memberSlot);
2896 0 : if (NS_FAILED(rv)) {
2897 0 : mUnion.DestroyHTMLCanvasElement();
2898 0 : tryNext = true;
2899 0 : return true;
2900 : }
2901 : }
2902 : }
2903 0 : return true;
2904 : }
2905 :
2906 : inline bool
2907 0 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2908 : {
2909 0 : tryNext = false;
2910 : { // scope for memberSlot
2911 0 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
2912 : {
2913 0 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
2914 0 : if (NS_FAILED(rv)) {
2915 0 : mUnion.DestroyBlob();
2916 0 : tryNext = true;
2917 0 : return true;
2918 : }
2919 : }
2920 : }
2921 0 : return true;
2922 : }
2923 :
2924 : inline bool
2925 0 : TrySetToImageData(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2926 : {
2927 0 : tryNext = false;
2928 : { // scope for memberSlot
2929 0 : NonNull<mozilla::dom::ImageData>& memberSlot = RawSetAsImageData();
2930 : {
2931 0 : nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(value, memberSlot);
2932 0 : if (NS_FAILED(rv)) {
2933 0 : mUnion.DestroyImageData();
2934 0 : tryNext = true;
2935 0 : return true;
2936 : }
2937 : }
2938 : }
2939 0 : return true;
2940 : }
2941 :
2942 : inline bool
2943 0 : TrySetToCanvasRenderingContext2D(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2944 : {
2945 0 : tryNext = false;
2946 : { // scope for memberSlot
2947 0 : NonNull<mozilla::dom::CanvasRenderingContext2D>& memberSlot = RawSetAsCanvasRenderingContext2D();
2948 : {
2949 0 : nsresult rv = UnwrapObject<prototypes::id::CanvasRenderingContext2D, mozilla::dom::CanvasRenderingContext2D>(value, memberSlot);
2950 0 : if (NS_FAILED(rv)) {
2951 0 : mUnion.DestroyCanvasRenderingContext2D();
2952 0 : tryNext = true;
2953 0 : return true;
2954 : }
2955 : }
2956 : }
2957 0 : return true;
2958 : }
2959 :
2960 : inline bool
2961 0 : TrySetToImageBitmap(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2962 : {
2963 0 : tryNext = false;
2964 : { // scope for memberSlot
2965 0 : NonNull<mozilla::dom::ImageBitmap>& memberSlot = RawSetAsImageBitmap();
2966 : {
2967 0 : nsresult rv = UnwrapObject<prototypes::id::ImageBitmap, mozilla::dom::ImageBitmap>(value, memberSlot);
2968 0 : if (NS_FAILED(rv)) {
2969 0 : mUnion.DestroyImageBitmap();
2970 0 : tryNext = true;
2971 0 : return true;
2972 : }
2973 : }
2974 : }
2975 0 : return true;
2976 : }
2977 :
2978 : inline bool
2979 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2980 : {
2981 0 : tryNext = false;
2982 : { // scope for memberSlot
2983 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
2984 0 : if (!memberSlot.Init(&value.toObject())) {
2985 0 : mUnion.DestroyArrayBufferView();
2986 0 : tryNext = true;
2987 0 : return true;
2988 : }
2989 : }
2990 0 : return true;
2991 : }
2992 :
2993 : inline bool
2994 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
2995 : {
2996 0 : tryNext = false;
2997 : { // scope for memberSlot
2998 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
2999 0 : if (!memberSlot.Init(&value.toObject())) {
3000 0 : mUnion.DestroyArrayBuffer();
3001 0 : tryNext = true;
3002 0 : return true;
3003 : }
3004 : }
3005 0 : return true;
3006 : }
3007 :
3008 : private:
3009 : inline NonNull<mozilla::dom::HTMLImageElement>&
3010 0 : RawSetAsHTMLImageElement()
3011 : {
3012 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3013 0 : mUnion.mType = mUnion.eHTMLImageElement;
3014 0 : return mUnion.mValue.mHTMLImageElement.SetValue();
3015 : }
3016 :
3017 : inline NonNull<mozilla::dom::HTMLVideoElement>&
3018 0 : RawSetAsHTMLVideoElement()
3019 : {
3020 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3021 0 : mUnion.mType = mUnion.eHTMLVideoElement;
3022 0 : return mUnion.mValue.mHTMLVideoElement.SetValue();
3023 : }
3024 :
3025 : inline NonNull<mozilla::dom::HTMLCanvasElement>&
3026 0 : RawSetAsHTMLCanvasElement()
3027 : {
3028 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3029 0 : mUnion.mType = mUnion.eHTMLCanvasElement;
3030 0 : return mUnion.mValue.mHTMLCanvasElement.SetValue();
3031 : }
3032 :
3033 : inline NonNull<mozilla::dom::Blob>&
3034 0 : RawSetAsBlob()
3035 : {
3036 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3037 0 : mUnion.mType = mUnion.eBlob;
3038 0 : return mUnion.mValue.mBlob.SetValue();
3039 : }
3040 :
3041 : inline NonNull<mozilla::dom::ImageData>&
3042 0 : RawSetAsImageData()
3043 : {
3044 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3045 0 : mUnion.mType = mUnion.eImageData;
3046 0 : return mUnion.mValue.mImageData.SetValue();
3047 : }
3048 :
3049 : inline NonNull<mozilla::dom::CanvasRenderingContext2D>&
3050 0 : RawSetAsCanvasRenderingContext2D()
3051 : {
3052 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3053 0 : mUnion.mType = mUnion.eCanvasRenderingContext2D;
3054 0 : return mUnion.mValue.mCanvasRenderingContext2D.SetValue();
3055 : }
3056 :
3057 : inline NonNull<mozilla::dom::ImageBitmap>&
3058 0 : RawSetAsImageBitmap()
3059 : {
3060 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3061 0 : mUnion.mType = mUnion.eImageBitmap;
3062 0 : return mUnion.mValue.mImageBitmap.SetValue();
3063 : }
3064 :
3065 : inline RootedTypedArray<ArrayBufferView>&
3066 0 : RawSetAsArrayBufferView(JSContext* cx)
3067 : {
3068 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3069 0 : mUnion.mType = mUnion.eArrayBufferView;
3070 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
3071 : }
3072 :
3073 : inline RootedTypedArray<ArrayBuffer>&
3074 0 : RawSetAsArrayBuffer(JSContext* cx)
3075 : {
3076 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3077 0 : mUnion.mType = mUnion.eArrayBuffer;
3078 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
3079 : }
3080 : };
3081 :
3082 : class HTMLOptionElementOrHTMLOptGroupElementArgument
3083 : {
3084 : HTMLOptionElementOrHTMLOptGroupElement& mUnion;
3085 :
3086 : HTMLOptionElementOrHTMLOptGroupElementArgument(const HTMLOptionElementOrHTMLOptGroupElementArgument&) = delete;
3087 : HTMLOptionElementOrHTMLOptGroupElementArgument& operator=(const HTMLOptionElementOrHTMLOptGroupElementArgument&) = delete;
3088 : public:
3089 0 : explicit inline HTMLOptionElementOrHTMLOptGroupElementArgument(const HTMLOptionElementOrHTMLOptGroupElement& aUnion)
3090 0 : : mUnion(const_cast<HTMLOptionElementOrHTMLOptGroupElement&>(aUnion))
3091 : {
3092 0 : }
3093 :
3094 : inline bool
3095 0 : TrySetToHTMLOptionElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3096 : {
3097 0 : tryNext = false;
3098 : { // scope for memberSlot
3099 0 : NonNull<mozilla::dom::HTMLOptionElement>& memberSlot = RawSetAsHTMLOptionElement();
3100 : {
3101 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLOptionElement, mozilla::dom::HTMLOptionElement>(value, memberSlot);
3102 0 : if (NS_FAILED(rv)) {
3103 0 : mUnion.DestroyHTMLOptionElement();
3104 0 : tryNext = true;
3105 0 : return true;
3106 : }
3107 : }
3108 : }
3109 0 : return true;
3110 : }
3111 :
3112 : inline bool
3113 0 : TrySetToHTMLOptGroupElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3114 : {
3115 0 : tryNext = false;
3116 : { // scope for memberSlot
3117 0 : NonNull<mozilla::dom::HTMLOptGroupElement>& memberSlot = RawSetAsHTMLOptGroupElement();
3118 : {
3119 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLOptGroupElement, mozilla::dom::HTMLOptGroupElement>(value, memberSlot);
3120 0 : if (NS_FAILED(rv)) {
3121 0 : mUnion.DestroyHTMLOptGroupElement();
3122 0 : tryNext = true;
3123 0 : return true;
3124 : }
3125 : }
3126 : }
3127 0 : return true;
3128 : }
3129 :
3130 : private:
3131 : inline NonNull<mozilla::dom::HTMLOptionElement>&
3132 0 : RawSetAsHTMLOptionElement()
3133 : {
3134 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3135 0 : mUnion.mType = mUnion.eHTMLOptionElement;
3136 0 : return mUnion.mValue.mHTMLOptionElement.SetValue();
3137 : }
3138 :
3139 : inline NonNull<mozilla::dom::HTMLOptGroupElement>&
3140 0 : RawSetAsHTMLOptGroupElement()
3141 : {
3142 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3143 0 : mUnion.mType = mUnion.eHTMLOptGroupElement;
3144 0 : return mUnion.mValue.mHTMLOptGroupElement.SetValue();
3145 : }
3146 : };
3147 :
3148 : class HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument
3149 : {
3150 : HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& mUnion;
3151 :
3152 : HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument(const HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument&) = delete;
3153 : HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument& operator=(const HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument&) = delete;
3154 : public:
3155 0 : explicit inline HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument(const HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aUnion)
3156 0 : : mUnion(const_cast<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord&>(aUnion))
3157 : {
3158 0 : }
3159 :
3160 : inline bool
3161 0 : TrySetToHeaders(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3162 : {
3163 0 : tryNext = false;
3164 : { // scope for memberSlot
3165 0 : NonNull<mozilla::dom::Headers>& memberSlot = RawSetAsHeaders();
3166 : {
3167 0 : nsresult rv = UnwrapObject<prototypes::id::Headers, mozilla::dom::Headers>(value, memberSlot);
3168 0 : if (NS_FAILED(rv)) {
3169 0 : mUnion.DestroyHeaders();
3170 0 : tryNext = true;
3171 0 : return true;
3172 : }
3173 : }
3174 : }
3175 0 : return true;
3176 : }
3177 :
3178 : inline bool
3179 0 : TrySetToByteStringSequenceSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3180 : {
3181 0 : tryNext = false;
3182 : { // scope for memberSlot
3183 0 : binding_detail::AutoSequence<Sequence<nsCString>>& memberSlot = RawSetAsByteStringSequenceSequence();
3184 0 : JS::ForOfIterator iter(cx);
3185 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3186 0 : return false;
3187 : }
3188 0 : if (!iter.valueIsIterable()) {
3189 0 : mUnion.DestroyByteStringSequenceSequence();
3190 0 : tryNext = true;
3191 0 : return true;
3192 : }
3193 0 : binding_detail::AutoSequence<Sequence<nsCString>> &arr = memberSlot;
3194 0 : JS::Rooted<JS::Value> temp(cx);
3195 : while (true) {
3196 : bool done;
3197 0 : if (!iter.next(&temp, &done)) {
3198 0 : return false;
3199 : }
3200 0 : if (done) {
3201 0 : break;
3202 : }
3203 0 : Sequence<nsCString>* slotPtr = arr.AppendElement(mozilla::fallible);
3204 0 : if (!slotPtr) {
3205 0 : JS_ReportOutOfMemory(cx);
3206 0 : return false;
3207 : }
3208 0 : Sequence<nsCString>& slot = *slotPtr;
3209 0 : if (temp.isObject()) {
3210 0 : JS::ForOfIterator iter1(cx);
3211 0 : if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
3212 0 : return false;
3213 : }
3214 0 : if (!iter1.valueIsIterable()) {
3215 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord");
3216 0 : return false;
3217 : }
3218 0 : Sequence<nsCString> &arr1 = slot;
3219 0 : JS::Rooted<JS::Value> temp1(cx);
3220 : while (true) {
3221 : bool done1;
3222 0 : if (!iter1.next(&temp1, &done1)) {
3223 0 : return false;
3224 : }
3225 0 : if (done1) {
3226 0 : break;
3227 : }
3228 0 : nsCString* slotPtr1 = arr1.AppendElement(mozilla::fallible);
3229 0 : if (!slotPtr1) {
3230 0 : JS_ReportOutOfMemory(cx);
3231 0 : return false;
3232 : }
3233 0 : nsCString& slot1 = *slotPtr1;
3234 0 : if (!ConvertJSValueToByteString(cx, temp1, false, slot1)) {
3235 0 : return false;
3236 : }
3237 0 : }
3238 : } else {
3239 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord");
3240 0 : return false;
3241 : }
3242 0 : }
3243 : }
3244 0 : return true;
3245 : }
3246 :
3247 : inline bool
3248 0 : TrySetToByteStringByteStringRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3249 : {
3250 0 : tryNext = false;
3251 : { // scope for memberSlot
3252 0 : Record<nsCString, nsCString>& memberSlot = RawSetAsByteStringByteStringRecord();
3253 0 : auto& recordEntries = memberSlot.Entries();
3254 :
3255 0 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
3256 0 : JS::AutoIdVector ids(cx);
3257 0 : if (!js::GetPropertyKeys(cx, recordObj,
3258 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
3259 0 : return false;
3260 : }
3261 0 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
3262 0 : JS_ReportOutOfMemory(cx);
3263 0 : return false;
3264 : }
3265 0 : JS::Rooted<JS::Value> propNameValue(cx);
3266 0 : JS::Rooted<JS::Value> temp(cx);
3267 0 : JS::Rooted<jsid> curId(cx);
3268 0 : JS::Rooted<JS::Value> idVal(cx);
3269 : // Use a hashset to keep track of ids seen, to avoid
3270 : // introducing nasty O(N^2) behavior scanning for them all the
3271 : // time. Ideally we'd use a data structure with O(1) lookup
3272 : // _and_ ordering for the MozMap, but we don't have one lying
3273 : // around.
3274 0 : nsTHashtable<nsCStringHashKey> idsSeen;
3275 0 : for (size_t i = 0; i < ids.length(); ++i) {
3276 0 : curId = ids[i];
3277 :
3278 0 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
3279 0 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
3280 : &desc)) {
3281 0 : return false;
3282 : }
3283 :
3284 0 : if (!desc.object() /* == undefined in spec terms */ ||
3285 0 : !desc.enumerable()) {
3286 0 : continue;
3287 : }
3288 :
3289 0 : idVal = js::IdToValue(curId);
3290 0 : nsCString propName;
3291 : // This will just throw if idVal is a Symbol, like the spec says
3292 : // to do.
3293 0 : if (!ConvertJSValueToByteString(cx, idVal, propName)) {
3294 0 : return false;
3295 : }
3296 :
3297 0 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
3298 0 : return false;
3299 : }
3300 :
3301 : Record<nsCString, nsCString>::EntryType* entry;
3302 0 : if (!idsSeen.EnsureInserted(propName)) {
3303 : // Find the existing entry.
3304 0 : auto idx = recordEntries.IndexOf(propName);
3305 0 : MOZ_ASSERT(idx != recordEntries.NoIndex,
3306 : "Why is it not found?");
3307 : // Now blow it away to make it look like it was just added
3308 : // to the array, because it's not obvious that it's
3309 : // safe to write to its already-initialized mValue via our
3310 : // normal codegen conversions. For example, the value
3311 : // could be a union and this would change its type, but
3312 : // codegen assumes we won't do that.
3313 0 : entry = recordEntries.ReconstructElementAt(idx);
3314 : } else {
3315 : // Safe to do an infallible append here, because we did a
3316 : // SetCapacity above to the right capacity.
3317 0 : entry = recordEntries.AppendElement();
3318 : }
3319 0 : entry->mKey = propName;
3320 0 : nsCString& slot = entry->mValue;
3321 0 : if (!ConvertJSValueToByteString(cx, temp, false, slot)) {
3322 0 : return false;
3323 : }
3324 : }
3325 : }
3326 0 : return true;
3327 : }
3328 :
3329 : private:
3330 : inline NonNull<mozilla::dom::Headers>&
3331 0 : RawSetAsHeaders()
3332 : {
3333 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3334 0 : mUnion.mType = mUnion.eHeaders;
3335 0 : return mUnion.mValue.mHeaders.SetValue();
3336 : }
3337 :
3338 : inline binding_detail::AutoSequence<Sequence<nsCString>>&
3339 0 : RawSetAsByteStringSequenceSequence()
3340 : {
3341 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3342 0 : mUnion.mType = mUnion.eByteStringSequenceSequence;
3343 0 : return mUnion.mValue.mByteStringSequenceSequence.SetValue();
3344 : }
3345 :
3346 : inline Record<nsCString, nsCString>&
3347 0 : RawSetAsByteStringByteStringRecord()
3348 : {
3349 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3350 0 : mUnion.mType = mUnion.eByteStringByteStringRecord;
3351 0 : return mUnion.mValue.mByteStringByteStringRecord.SetValue();
3352 : }
3353 : };
3354 :
3355 : class IDBObjectStoreOrIDBIndexArgument
3356 : {
3357 : IDBObjectStoreOrIDBIndex& mUnion;
3358 :
3359 : IDBObjectStoreOrIDBIndexArgument(const IDBObjectStoreOrIDBIndexArgument&) = delete;
3360 : IDBObjectStoreOrIDBIndexArgument& operator=(const IDBObjectStoreOrIDBIndexArgument&) = delete;
3361 : public:
3362 : explicit inline IDBObjectStoreOrIDBIndexArgument(const IDBObjectStoreOrIDBIndex& aUnion)
3363 : : mUnion(const_cast<IDBObjectStoreOrIDBIndex&>(aUnion))
3364 : {
3365 : }
3366 :
3367 : inline bool
3368 : TrySetToIDBObjectStore(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3369 : {
3370 : tryNext = false;
3371 : { // scope for memberSlot
3372 : NonNull<mozilla::dom::IDBObjectStore>& memberSlot = RawSetAsIDBObjectStore();
3373 : {
3374 : nsresult rv = UnwrapObject<prototypes::id::IDBObjectStore, mozilla::dom::IDBObjectStore>(value, memberSlot);
3375 : if (NS_FAILED(rv)) {
3376 : mUnion.DestroyIDBObjectStore();
3377 : tryNext = true;
3378 : return true;
3379 : }
3380 : }
3381 : }
3382 : return true;
3383 : }
3384 :
3385 : inline bool
3386 : TrySetToIDBIndex(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3387 : {
3388 : tryNext = false;
3389 : { // scope for memberSlot
3390 : NonNull<mozilla::dom::IDBIndex>& memberSlot = RawSetAsIDBIndex();
3391 : {
3392 : nsresult rv = UnwrapObject<prototypes::id::IDBIndex, mozilla::dom::IDBIndex>(value, memberSlot);
3393 : if (NS_FAILED(rv)) {
3394 : mUnion.DestroyIDBIndex();
3395 : tryNext = true;
3396 : return true;
3397 : }
3398 : }
3399 : }
3400 : return true;
3401 : }
3402 :
3403 : private:
3404 : inline NonNull<mozilla::dom::IDBObjectStore>&
3405 : RawSetAsIDBObjectStore()
3406 : {
3407 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3408 : mUnion.mType = mUnion.eIDBObjectStore;
3409 : return mUnion.mValue.mIDBObjectStore.SetValue();
3410 : }
3411 :
3412 : inline NonNull<mozilla::dom::IDBIndex>&
3413 : RawSetAsIDBIndex()
3414 : {
3415 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3416 : mUnion.mType = mUnion.eIDBIndex;
3417 : return mUnion.mValue.mIDBIndex.SetValue();
3418 : }
3419 : };
3420 :
3421 : class IDBObjectStoreOrIDBIndexOrIDBCursorArgument
3422 : {
3423 : IDBObjectStoreOrIDBIndexOrIDBCursor& mUnion;
3424 :
3425 : IDBObjectStoreOrIDBIndexOrIDBCursorArgument(const IDBObjectStoreOrIDBIndexOrIDBCursorArgument&) = delete;
3426 : IDBObjectStoreOrIDBIndexOrIDBCursorArgument& operator=(const IDBObjectStoreOrIDBIndexOrIDBCursorArgument&) = delete;
3427 : public:
3428 : explicit inline IDBObjectStoreOrIDBIndexOrIDBCursorArgument(const IDBObjectStoreOrIDBIndexOrIDBCursor& aUnion)
3429 : : mUnion(const_cast<IDBObjectStoreOrIDBIndexOrIDBCursor&>(aUnion))
3430 : {
3431 : }
3432 :
3433 : inline bool
3434 : TrySetToIDBObjectStore(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3435 : {
3436 : tryNext = false;
3437 : { // scope for memberSlot
3438 : NonNull<mozilla::dom::IDBObjectStore>& memberSlot = RawSetAsIDBObjectStore();
3439 : {
3440 : nsresult rv = UnwrapObject<prototypes::id::IDBObjectStore, mozilla::dom::IDBObjectStore>(value, memberSlot);
3441 : if (NS_FAILED(rv)) {
3442 : mUnion.DestroyIDBObjectStore();
3443 : tryNext = true;
3444 : return true;
3445 : }
3446 : }
3447 : }
3448 : return true;
3449 : }
3450 :
3451 : inline bool
3452 : TrySetToIDBIndex(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3453 : {
3454 : tryNext = false;
3455 : { // scope for memberSlot
3456 : NonNull<mozilla::dom::IDBIndex>& memberSlot = RawSetAsIDBIndex();
3457 : {
3458 : nsresult rv = UnwrapObject<prototypes::id::IDBIndex, mozilla::dom::IDBIndex>(value, memberSlot);
3459 : if (NS_FAILED(rv)) {
3460 : mUnion.DestroyIDBIndex();
3461 : tryNext = true;
3462 : return true;
3463 : }
3464 : }
3465 : }
3466 : return true;
3467 : }
3468 :
3469 : inline bool
3470 : TrySetToIDBCursor(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3471 : {
3472 : tryNext = false;
3473 : { // scope for memberSlot
3474 : NonNull<mozilla::dom::IDBCursor>& memberSlot = RawSetAsIDBCursor();
3475 : {
3476 : nsresult rv = UnwrapObject<prototypes::id::IDBCursor, mozilla::dom::IDBCursor>(value, memberSlot);
3477 : if (NS_FAILED(rv)) {
3478 : mUnion.DestroyIDBCursor();
3479 : tryNext = true;
3480 : return true;
3481 : }
3482 : }
3483 : }
3484 : return true;
3485 : }
3486 :
3487 : private:
3488 : inline NonNull<mozilla::dom::IDBObjectStore>&
3489 : RawSetAsIDBObjectStore()
3490 : {
3491 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3492 : mUnion.mType = mUnion.eIDBObjectStore;
3493 : return mUnion.mValue.mIDBObjectStore.SetValue();
3494 : }
3495 :
3496 : inline NonNull<mozilla::dom::IDBIndex>&
3497 : RawSetAsIDBIndex()
3498 : {
3499 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3500 : mUnion.mType = mUnion.eIDBIndex;
3501 : return mUnion.mValue.mIDBIndex.SetValue();
3502 : }
3503 :
3504 : inline NonNull<mozilla::dom::IDBCursor>&
3505 : RawSetAsIDBCursor()
3506 : {
3507 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3508 : mUnion.mType = mUnion.eIDBCursor;
3509 : return mUnion.mValue.mIDBCursor.SetValue();
3510 : }
3511 : };
3512 :
3513 : class ImageDataOrNullSequenceOrLongArgument
3514 : {
3515 : ImageDataOrNullSequenceOrLong& mUnion;
3516 :
3517 : ImageDataOrNullSequenceOrLongArgument(const ImageDataOrNullSequenceOrLongArgument&) = delete;
3518 : ImageDataOrNullSequenceOrLongArgument& operator=(const ImageDataOrNullSequenceOrLongArgument&) = delete;
3519 : public:
3520 : explicit inline ImageDataOrNullSequenceOrLongArgument(const ImageDataOrNullSequenceOrLong& aUnion)
3521 : : mUnion(const_cast<ImageDataOrNullSequenceOrLong&>(aUnion))
3522 : {
3523 : }
3524 :
3525 : inline bool
3526 : TrySetToImageDataOrNullSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3527 : {
3528 : tryNext = false;
3529 : { // scope for memberSlot
3530 : binding_detail::AutoSequence<RefPtr<mozilla::dom::ImageData>>& memberSlot = RawSetAsImageDataOrNullSequence();
3531 : JS::ForOfIterator iter(cx);
3532 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3533 : return false;
3534 : }
3535 : if (!iter.valueIsIterable()) {
3536 : mUnion.DestroyImageDataOrNullSequence();
3537 : tryNext = true;
3538 : return true;
3539 : }
3540 : binding_detail::AutoSequence<RefPtr<mozilla::dom::ImageData>> &arr = memberSlot;
3541 : JS::Rooted<JS::Value> temp(cx);
3542 : while (true) {
3543 : bool done;
3544 : if (!iter.next(&temp, &done)) {
3545 : return false;
3546 : }
3547 : if (done) {
3548 : break;
3549 : }
3550 : RefPtr<mozilla::dom::ImageData>* slotPtr = arr.AppendElement(mozilla::fallible);
3551 : if (!slotPtr) {
3552 : JS_ReportOutOfMemory(cx);
3553 : return false;
3554 : }
3555 : RefPtr<mozilla::dom::ImageData>& slot = *slotPtr;
3556 : if (temp.isObject()) {
3557 : static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
3558 : nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp, slot);
3559 : if (NS_FAILED(rv)) {
3560 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of member of ImageDataOrNullSequenceOrLong", "ImageData");
3561 : return false;
3562 : }
3563 : }
3564 : } else if (temp.isNullOrUndefined()) {
3565 : slot = nullptr;
3566 : } else {
3567 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ImageDataOrNullSequenceOrLong");
3568 : return false;
3569 : }
3570 : }
3571 : }
3572 : return true;
3573 : }
3574 :
3575 : inline bool
3576 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3577 : {
3578 : tryNext = false;
3579 : { // scope for memberSlot
3580 : int32_t& memberSlot = RawSetAsLong();
3581 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
3582 : return false;
3583 : }
3584 : }
3585 : return true;
3586 : }
3587 :
3588 : private:
3589 : inline binding_detail::AutoSequence<RefPtr<mozilla::dom::ImageData>>&
3590 : RawSetAsImageDataOrNullSequence()
3591 : {
3592 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3593 : mUnion.mType = mUnion.eImageDataOrNullSequence;
3594 : return mUnion.mValue.mImageDataOrNullSequence.SetValue();
3595 : }
3596 :
3597 : inline int32_t&
3598 : RawSetAsLong()
3599 : {
3600 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3601 : mUnion.mType = mUnion.eLong;
3602 : return mUnion.mValue.mLong.SetValue();
3603 : }
3604 : };
3605 :
3606 : class ImageDataOrNullSequenceSequenceOrLongArgument
3607 : {
3608 : ImageDataOrNullSequenceSequenceOrLong& mUnion;
3609 :
3610 : ImageDataOrNullSequenceSequenceOrLongArgument(const ImageDataOrNullSequenceSequenceOrLongArgument&) = delete;
3611 : ImageDataOrNullSequenceSequenceOrLongArgument& operator=(const ImageDataOrNullSequenceSequenceOrLongArgument&) = delete;
3612 : public:
3613 : explicit inline ImageDataOrNullSequenceSequenceOrLongArgument(const ImageDataOrNullSequenceSequenceOrLong& aUnion)
3614 : : mUnion(const_cast<ImageDataOrNullSequenceSequenceOrLong&>(aUnion))
3615 : {
3616 : }
3617 :
3618 : inline bool
3619 : TrySetToImageDataOrNullSequenceSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3620 : {
3621 : tryNext = false;
3622 : { // scope for memberSlot
3623 : binding_detail::AutoSequence<Sequence<RefPtr<mozilla::dom::ImageData>>>& memberSlot = RawSetAsImageDataOrNullSequenceSequence();
3624 : JS::ForOfIterator iter(cx);
3625 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3626 : return false;
3627 : }
3628 : if (!iter.valueIsIterable()) {
3629 : mUnion.DestroyImageDataOrNullSequenceSequence();
3630 : tryNext = true;
3631 : return true;
3632 : }
3633 : binding_detail::AutoSequence<Sequence<RefPtr<mozilla::dom::ImageData>>> &arr = memberSlot;
3634 : JS::Rooted<JS::Value> temp(cx);
3635 : while (true) {
3636 : bool done;
3637 : if (!iter.next(&temp, &done)) {
3638 : return false;
3639 : }
3640 : if (done) {
3641 : break;
3642 : }
3643 : Sequence<RefPtr<mozilla::dom::ImageData>>* slotPtr = arr.AppendElement(mozilla::fallible);
3644 : if (!slotPtr) {
3645 : JS_ReportOutOfMemory(cx);
3646 : return false;
3647 : }
3648 : Sequence<RefPtr<mozilla::dom::ImageData>>& slot = *slotPtr;
3649 : if (temp.isObject()) {
3650 : JS::ForOfIterator iter1(cx);
3651 : if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
3652 : return false;
3653 : }
3654 : if (!iter1.valueIsIterable()) {
3655 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataOrNullSequenceSequenceOrLong");
3656 : return false;
3657 : }
3658 : Sequence<RefPtr<mozilla::dom::ImageData>> &arr1 = slot;
3659 : JS::Rooted<JS::Value> temp1(cx);
3660 : while (true) {
3661 : bool done1;
3662 : if (!iter1.next(&temp1, &done1)) {
3663 : return false;
3664 : }
3665 : if (done1) {
3666 : break;
3667 : }
3668 : RefPtr<mozilla::dom::ImageData>* slotPtr1 = arr1.AppendElement(mozilla::fallible);
3669 : if (!slotPtr1) {
3670 : JS_ReportOutOfMemory(cx);
3671 : return false;
3672 : }
3673 : RefPtr<mozilla::dom::ImageData>& slot1 = *slotPtr1;
3674 : if (temp1.isObject()) {
3675 : static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
3676 : nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp1, slot1);
3677 : if (NS_FAILED(rv)) {
3678 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of element of member of ImageDataOrNullSequenceSequenceOrLong", "ImageData");
3679 : return false;
3680 : }
3681 : }
3682 : } else if (temp1.isNullOrUndefined()) {
3683 : slot1 = nullptr;
3684 : } else {
3685 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of element of member of ImageDataOrNullSequenceSequenceOrLong");
3686 : return false;
3687 : }
3688 : }
3689 : } else {
3690 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataOrNullSequenceSequenceOrLong");
3691 : return false;
3692 : }
3693 : }
3694 : }
3695 : return true;
3696 : }
3697 :
3698 : inline bool
3699 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3700 : {
3701 : tryNext = false;
3702 : { // scope for memberSlot
3703 : int32_t& memberSlot = RawSetAsLong();
3704 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
3705 : return false;
3706 : }
3707 : }
3708 : return true;
3709 : }
3710 :
3711 : private:
3712 : inline binding_detail::AutoSequence<Sequence<RefPtr<mozilla::dom::ImageData>>>&
3713 : RawSetAsImageDataOrNullSequenceSequence()
3714 : {
3715 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3716 : mUnion.mType = mUnion.eImageDataOrNullSequenceSequence;
3717 : return mUnion.mValue.mImageDataOrNullSequenceSequence.SetValue();
3718 : }
3719 :
3720 : inline int32_t&
3721 : RawSetAsLong()
3722 : {
3723 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3724 : mUnion.mType = mUnion.eLong;
3725 : return mUnion.mValue.mLong.SetValue();
3726 : }
3727 : };
3728 :
3729 : class ImageDataSequenceOrLongArgument
3730 : {
3731 : ImageDataSequenceOrLong& mUnion;
3732 :
3733 : ImageDataSequenceOrLongArgument(const ImageDataSequenceOrLongArgument&) = delete;
3734 : ImageDataSequenceOrLongArgument& operator=(const ImageDataSequenceOrLongArgument&) = delete;
3735 : public:
3736 : explicit inline ImageDataSequenceOrLongArgument(const ImageDataSequenceOrLong& aUnion)
3737 : : mUnion(const_cast<ImageDataSequenceOrLong&>(aUnion))
3738 : {
3739 : }
3740 :
3741 : inline bool
3742 : TrySetToImageDataSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3743 : {
3744 : tryNext = false;
3745 : { // scope for memberSlot
3746 : binding_detail::AutoSequence<OwningNonNull<mozilla::dom::ImageData>>& memberSlot = RawSetAsImageDataSequence();
3747 : JS::ForOfIterator iter(cx);
3748 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3749 : return false;
3750 : }
3751 : if (!iter.valueIsIterable()) {
3752 : mUnion.DestroyImageDataSequence();
3753 : tryNext = true;
3754 : return true;
3755 : }
3756 : binding_detail::AutoSequence<OwningNonNull<mozilla::dom::ImageData>> &arr = memberSlot;
3757 : JS::Rooted<JS::Value> temp(cx);
3758 : while (true) {
3759 : bool done;
3760 : if (!iter.next(&temp, &done)) {
3761 : return false;
3762 : }
3763 : if (done) {
3764 : break;
3765 : }
3766 : OwningNonNull<mozilla::dom::ImageData>* slotPtr = arr.AppendElement(mozilla::fallible);
3767 : if (!slotPtr) {
3768 : JS_ReportOutOfMemory(cx);
3769 : return false;
3770 : }
3771 : OwningNonNull<mozilla::dom::ImageData>& slot = *slotPtr;
3772 : if (temp.isObject()) {
3773 : static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
3774 : nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp, slot);
3775 : if (NS_FAILED(rv)) {
3776 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of member of ImageDataSequenceOrLong", "ImageData");
3777 : return false;
3778 : }
3779 : }
3780 : } else {
3781 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ImageDataSequenceOrLong");
3782 : return false;
3783 : }
3784 : }
3785 : }
3786 : return true;
3787 : }
3788 :
3789 : inline bool
3790 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3791 : {
3792 : tryNext = false;
3793 : { // scope for memberSlot
3794 : int32_t& memberSlot = RawSetAsLong();
3795 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
3796 : return false;
3797 : }
3798 : }
3799 : return true;
3800 : }
3801 :
3802 : private:
3803 : inline binding_detail::AutoSequence<OwningNonNull<mozilla::dom::ImageData>>&
3804 : RawSetAsImageDataSequence()
3805 : {
3806 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3807 : mUnion.mType = mUnion.eImageDataSequence;
3808 : return mUnion.mValue.mImageDataSequence.SetValue();
3809 : }
3810 :
3811 : inline int32_t&
3812 : RawSetAsLong()
3813 : {
3814 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3815 : mUnion.mType = mUnion.eLong;
3816 : return mUnion.mValue.mLong.SetValue();
3817 : }
3818 : };
3819 :
3820 : class ImageDataSequenceSequenceOrLongArgument
3821 : {
3822 : ImageDataSequenceSequenceOrLong& mUnion;
3823 :
3824 : ImageDataSequenceSequenceOrLongArgument(const ImageDataSequenceSequenceOrLongArgument&) = delete;
3825 : ImageDataSequenceSequenceOrLongArgument& operator=(const ImageDataSequenceSequenceOrLongArgument&) = delete;
3826 : public:
3827 : explicit inline ImageDataSequenceSequenceOrLongArgument(const ImageDataSequenceSequenceOrLong& aUnion)
3828 : : mUnion(const_cast<ImageDataSequenceSequenceOrLong&>(aUnion))
3829 : {
3830 : }
3831 :
3832 : inline bool
3833 : TrySetToImageDataSequenceSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3834 : {
3835 : tryNext = false;
3836 : { // scope for memberSlot
3837 : binding_detail::AutoSequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>>& memberSlot = RawSetAsImageDataSequenceSequence();
3838 : JS::ForOfIterator iter(cx);
3839 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3840 : return false;
3841 : }
3842 : if (!iter.valueIsIterable()) {
3843 : mUnion.DestroyImageDataSequenceSequence();
3844 : tryNext = true;
3845 : return true;
3846 : }
3847 : binding_detail::AutoSequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>> &arr = memberSlot;
3848 : JS::Rooted<JS::Value> temp(cx);
3849 : while (true) {
3850 : bool done;
3851 : if (!iter.next(&temp, &done)) {
3852 : return false;
3853 : }
3854 : if (done) {
3855 : break;
3856 : }
3857 : Sequence<OwningNonNull<mozilla::dom::ImageData>>* slotPtr = arr.AppendElement(mozilla::fallible);
3858 : if (!slotPtr) {
3859 : JS_ReportOutOfMemory(cx);
3860 : return false;
3861 : }
3862 : Sequence<OwningNonNull<mozilla::dom::ImageData>>& slot = *slotPtr;
3863 : if (temp.isObject()) {
3864 : JS::ForOfIterator iter1(cx);
3865 : if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
3866 : return false;
3867 : }
3868 : if (!iter1.valueIsIterable()) {
3869 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataSequenceSequenceOrLong");
3870 : return false;
3871 : }
3872 : Sequence<OwningNonNull<mozilla::dom::ImageData>> &arr1 = slot;
3873 : JS::Rooted<JS::Value> temp1(cx);
3874 : while (true) {
3875 : bool done1;
3876 : if (!iter1.next(&temp1, &done1)) {
3877 : return false;
3878 : }
3879 : if (done1) {
3880 : break;
3881 : }
3882 : OwningNonNull<mozilla::dom::ImageData>* slotPtr1 = arr1.AppendElement(mozilla::fallible);
3883 : if (!slotPtr1) {
3884 : JS_ReportOutOfMemory(cx);
3885 : return false;
3886 : }
3887 : OwningNonNull<mozilla::dom::ImageData>& slot1 = *slotPtr1;
3888 : if (temp1.isObject()) {
3889 : static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
3890 : nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp1, slot1);
3891 : if (NS_FAILED(rv)) {
3892 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of element of member of ImageDataSequenceSequenceOrLong", "ImageData");
3893 : return false;
3894 : }
3895 : }
3896 : } else {
3897 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of element of member of ImageDataSequenceSequenceOrLong");
3898 : return false;
3899 : }
3900 : }
3901 : } else {
3902 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataSequenceSequenceOrLong");
3903 : return false;
3904 : }
3905 : }
3906 : }
3907 : return true;
3908 : }
3909 :
3910 : inline bool
3911 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3912 : {
3913 : tryNext = false;
3914 : { // scope for memberSlot
3915 : int32_t& memberSlot = RawSetAsLong();
3916 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
3917 : return false;
3918 : }
3919 : }
3920 : return true;
3921 : }
3922 :
3923 : private:
3924 : inline binding_detail::AutoSequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>>&
3925 : RawSetAsImageDataSequenceSequence()
3926 : {
3927 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3928 : mUnion.mType = mUnion.eImageDataSequenceSequence;
3929 : return mUnion.mValue.mImageDataSequenceSequence.SetValue();
3930 : }
3931 :
3932 : inline int32_t&
3933 : RawSetAsLong()
3934 : {
3935 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
3936 : mUnion.mType = mUnion.eLong;
3937 : return mUnion.mValue.mLong.SetValue();
3938 : }
3939 : };
3940 :
3941 : class Int32ArrayOrLongSequenceArgument
3942 : {
3943 : Int32ArrayOrLongSequence& mUnion;
3944 :
3945 : Int32ArrayOrLongSequenceArgument(const Int32ArrayOrLongSequenceArgument&) = delete;
3946 : Int32ArrayOrLongSequenceArgument& operator=(const Int32ArrayOrLongSequenceArgument&) = delete;
3947 : public:
3948 0 : explicit inline Int32ArrayOrLongSequenceArgument(const Int32ArrayOrLongSequence& aUnion)
3949 0 : : mUnion(const_cast<Int32ArrayOrLongSequence&>(aUnion))
3950 : {
3951 0 : }
3952 :
3953 : inline bool
3954 0 : TrySetToInt32Array(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3955 : {
3956 0 : tryNext = false;
3957 : { // scope for memberSlot
3958 0 : RootedTypedArray<Int32Array>& memberSlot = RawSetAsInt32Array(cx);
3959 0 : if (!memberSlot.Init(&value.toObject())) {
3960 0 : mUnion.DestroyInt32Array();
3961 0 : tryNext = true;
3962 0 : return true;
3963 : }
3964 : }
3965 0 : return true;
3966 : }
3967 :
3968 : inline bool
3969 0 : TrySetToLongSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
3970 : {
3971 0 : tryNext = false;
3972 : { // scope for memberSlot
3973 0 : binding_detail::AutoSequence<int32_t>& memberSlot = RawSetAsLongSequence();
3974 0 : JS::ForOfIterator iter(cx);
3975 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
3976 0 : return false;
3977 : }
3978 0 : if (!iter.valueIsIterable()) {
3979 0 : mUnion.DestroyLongSequence();
3980 0 : tryNext = true;
3981 0 : return true;
3982 : }
3983 0 : binding_detail::AutoSequence<int32_t> &arr = memberSlot;
3984 0 : JS::Rooted<JS::Value> temp(cx);
3985 : while (true) {
3986 : bool done;
3987 0 : if (!iter.next(&temp, &done)) {
3988 0 : return false;
3989 : }
3990 0 : if (done) {
3991 0 : break;
3992 : }
3993 0 : int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
3994 0 : if (!slotPtr) {
3995 0 : JS_ReportOutOfMemory(cx);
3996 0 : return false;
3997 : }
3998 0 : int32_t& slot = *slotPtr;
3999 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
4000 0 : return false;
4001 : }
4002 0 : }
4003 : }
4004 0 : return true;
4005 : }
4006 :
4007 : private:
4008 : inline RootedTypedArray<Int32Array>&
4009 0 : RawSetAsInt32Array(JSContext* cx)
4010 : {
4011 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4012 0 : mUnion.mType = mUnion.eInt32Array;
4013 0 : return mUnion.mValue.mInt32Array.SetValue(cx);
4014 : }
4015 :
4016 : inline binding_detail::AutoSequence<int32_t>&
4017 0 : RawSetAsLongSequence()
4018 : {
4019 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4020 0 : mUnion.mType = mUnion.eLongSequence;
4021 0 : return mUnion.mValue.mLongSequence.SetValue();
4022 : }
4023 : };
4024 :
4025 : class LocationOrTestInterfaceJSArgument
4026 : {
4027 : LocationOrTestInterfaceJS& mUnion;
4028 :
4029 : LocationOrTestInterfaceJSArgument(const LocationOrTestInterfaceJSArgument&) = delete;
4030 : LocationOrTestInterfaceJSArgument& operator=(const LocationOrTestInterfaceJSArgument&) = delete;
4031 : public:
4032 : explicit inline LocationOrTestInterfaceJSArgument(const LocationOrTestInterfaceJS& aUnion)
4033 : : mUnion(const_cast<LocationOrTestInterfaceJS&>(aUnion))
4034 : {
4035 : }
4036 :
4037 : inline bool
4038 : TrySetToLocation(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4039 : {
4040 : tryNext = false;
4041 : { // scope for memberSlot
4042 : NonNull<mozilla::dom::Location>& memberSlot = RawSetAsLocation();
4043 : {
4044 : nsresult rv = UnwrapObject<prototypes::id::Location, mozilla::dom::Location>(value, memberSlot);
4045 : if (NS_FAILED(rv)) {
4046 : mUnion.DestroyLocation();
4047 : tryNext = true;
4048 : return true;
4049 : }
4050 : }
4051 : }
4052 : return true;
4053 : }
4054 :
4055 : inline bool
4056 : TrySetToTestInterfaceJS(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4057 : {
4058 : tryNext = false;
4059 : { // scope for memberSlot
4060 : NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
4061 : {
4062 : nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot);
4063 : if (NS_FAILED(rv)) {
4064 : mUnion.DestroyTestInterfaceJS();
4065 : tryNext = true;
4066 : return true;
4067 : }
4068 : }
4069 : }
4070 : return true;
4071 : }
4072 :
4073 : private:
4074 : inline NonNull<mozilla::dom::Location>&
4075 : RawSetAsLocation()
4076 : {
4077 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4078 : mUnion.mType = mUnion.eLocation;
4079 : return mUnion.mValue.mLocation.SetValue();
4080 : }
4081 :
4082 : inline NonNull<mozilla::dom::TestInterfaceJS>&
4083 : RawSetAsTestInterfaceJS()
4084 : {
4085 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4086 : mUnion.mType = mUnion.eTestInterfaceJS;
4087 : return mUnion.mValue.mTestInterfaceJS.SetValue();
4088 : }
4089 : };
4090 :
4091 : class LongOrBooleanArgument
4092 : {
4093 : LongOrBoolean& mUnion;
4094 :
4095 : LongOrBooleanArgument(const LongOrBooleanArgument&) = delete;
4096 : LongOrBooleanArgument& operator=(const LongOrBooleanArgument&) = delete;
4097 : public:
4098 : explicit inline LongOrBooleanArgument(const LongOrBoolean& aUnion)
4099 : : mUnion(const_cast<LongOrBoolean&>(aUnion))
4100 : {
4101 : }
4102 :
4103 : inline bool
4104 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4105 : {
4106 : tryNext = false;
4107 : { // scope for memberSlot
4108 : int32_t& memberSlot = RawSetAsLong();
4109 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4110 : return false;
4111 : }
4112 : }
4113 : return true;
4114 : }
4115 :
4116 : inline bool
4117 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4118 : {
4119 : tryNext = false;
4120 : { // scope for memberSlot
4121 : bool& memberSlot = RawSetAsBoolean();
4122 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
4123 : return false;
4124 : }
4125 : }
4126 : return true;
4127 : }
4128 :
4129 : private:
4130 : inline int32_t&
4131 : RawSetAsLong()
4132 : {
4133 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4134 : mUnion.mType = mUnion.eLong;
4135 : return mUnion.mValue.mLong.SetValue();
4136 : }
4137 :
4138 : inline bool&
4139 : RawSetAsBoolean()
4140 : {
4141 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4142 : mUnion.mType = mUnion.eBoolean;
4143 : return mUnion.mValue.mBoolean.SetValue();
4144 : }
4145 : };
4146 :
4147 : class LongOrConstrainLongRangeArgument
4148 : {
4149 : LongOrConstrainLongRange& mUnion;
4150 :
4151 : LongOrConstrainLongRangeArgument(const LongOrConstrainLongRangeArgument&) = delete;
4152 : LongOrConstrainLongRangeArgument& operator=(const LongOrConstrainLongRangeArgument&) = delete;
4153 : public:
4154 : explicit inline LongOrConstrainLongRangeArgument(const LongOrConstrainLongRange& aUnion)
4155 : : mUnion(const_cast<LongOrConstrainLongRange&>(aUnion))
4156 : {
4157 : }
4158 :
4159 : inline bool
4160 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4161 : {
4162 : tryNext = false;
4163 : { // scope for memberSlot
4164 : int32_t& memberSlot = RawSetAsLong();
4165 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4166 : return false;
4167 : }
4168 : }
4169 : return true;
4170 : }
4171 :
4172 : inline bool
4173 : TrySetToConstrainLongRange(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4174 : {
4175 : tryNext = false;
4176 : { // scope for memberSlot
4177 : binding_detail::FastConstrainLongRange& memberSlot = RawSetAsConstrainLongRange();
4178 : if (!IsConvertibleToDictionary(value)) {
4179 : mUnion.DestroyConstrainLongRange();
4180 : tryNext = true;
4181 : return true;
4182 : }
4183 : if (!memberSlot.Init(cx, value, "Member of LongOrConstrainLongRange", passedToJSImpl)) {
4184 : return false;
4185 : }
4186 : }
4187 : return true;
4188 : }
4189 :
4190 : private:
4191 : inline int32_t&
4192 : RawSetAsLong()
4193 : {
4194 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4195 : mUnion.mType = mUnion.eLong;
4196 : return mUnion.mValue.mLong.SetValue();
4197 : }
4198 :
4199 : inline binding_detail::FastConstrainLongRange&
4200 : RawSetAsConstrainLongRange()
4201 : {
4202 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4203 : mUnion.mType = mUnion.eConstrainLongRange;
4204 : return mUnion.mValue.mConstrainLongRange.SetValue();
4205 : }
4206 : };
4207 :
4208 : class LongOrStringAnyRecordArgument
4209 : {
4210 : LongOrStringAnyRecord& mUnion;
4211 : Maybe<RecordRooter<nsString, JS::Value>> mStringAnyRecordHolder;
4212 :
4213 : LongOrStringAnyRecordArgument(const LongOrStringAnyRecordArgument&) = delete;
4214 : LongOrStringAnyRecordArgument& operator=(const LongOrStringAnyRecordArgument&) = delete;
4215 : public:
4216 : explicit inline LongOrStringAnyRecordArgument(const LongOrStringAnyRecord& aUnion)
4217 : : mUnion(const_cast<LongOrStringAnyRecord&>(aUnion))
4218 : {
4219 : }
4220 :
4221 : inline bool
4222 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4223 : {
4224 : tryNext = false;
4225 : { // scope for memberSlot
4226 : int32_t& memberSlot = RawSetAsLong();
4227 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4228 : return false;
4229 : }
4230 : }
4231 : return true;
4232 : }
4233 :
4234 : inline bool
4235 : TrySetToStringAnyRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4236 : {
4237 : tryNext = false;
4238 : { // scope for memberSlot
4239 : Record<nsString, JS::Value>& memberSlot = RawSetAsStringAnyRecord();
4240 : mStringAnyRecordHolder.emplace(cx, &memberSlot);
4241 : auto& recordEntries = memberSlot.Entries();
4242 :
4243 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
4244 : JS::AutoIdVector ids(cx);
4245 : if (!js::GetPropertyKeys(cx, recordObj,
4246 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
4247 : return false;
4248 : }
4249 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
4250 : JS_ReportOutOfMemory(cx);
4251 : return false;
4252 : }
4253 : JS::Rooted<JS::Value> propNameValue(cx);
4254 : JS::Rooted<JS::Value> temp(cx);
4255 : JS::Rooted<jsid> curId(cx);
4256 : JS::Rooted<JS::Value> idVal(cx);
4257 : // Use a hashset to keep track of ids seen, to avoid
4258 : // introducing nasty O(N^2) behavior scanning for them all the
4259 : // time. Ideally we'd use a data structure with O(1) lookup
4260 : // _and_ ordering for the MozMap, but we don't have one lying
4261 : // around.
4262 : nsTHashtable<nsStringHashKey> idsSeen;
4263 : for (size_t i = 0; i < ids.length(); ++i) {
4264 : curId = ids[i];
4265 :
4266 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
4267 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
4268 : &desc)) {
4269 : return false;
4270 : }
4271 :
4272 : if (!desc.object() /* == undefined in spec terms */ ||
4273 : !desc.enumerable()) {
4274 : continue;
4275 : }
4276 :
4277 : idVal = js::IdToValue(curId);
4278 : nsString propName;
4279 : // This will just throw if idVal is a Symbol, like the spec says
4280 : // to do.
4281 : if (!ConvertJSValueToString(cx, idVal, propName)) {
4282 : return false;
4283 : }
4284 :
4285 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
4286 : return false;
4287 : }
4288 :
4289 : Record<nsString, JS::Value>::EntryType* entry;
4290 : if (!idsSeen.EnsureInserted(propName)) {
4291 : // Find the existing entry.
4292 : auto idx = recordEntries.IndexOf(propName);
4293 : MOZ_ASSERT(idx != recordEntries.NoIndex,
4294 : "Why is it not found?");
4295 : // Now blow it away to make it look like it was just added
4296 : // to the array, because it's not obvious that it's
4297 : // safe to write to its already-initialized mValue via our
4298 : // normal codegen conversions. For example, the value
4299 : // could be a union and this would change its type, but
4300 : // codegen assumes we won't do that.
4301 : entry = recordEntries.ReconstructElementAt(idx);
4302 : } else {
4303 : // Safe to do an infallible append here, because we did a
4304 : // SetCapacity above to the right capacity.
4305 : entry = recordEntries.AppendElement();
4306 : }
4307 : entry->mKey = propName;
4308 : JS::Value& slot = entry->mValue;
4309 : #ifdef __clang__
4310 : #pragma clang diagnostic push
4311 : #pragma clang diagnostic ignored "-Wunreachable-code"
4312 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
4313 : #endif // __clang__
4314 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
4315 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "value in member of LongOrStringAnyRecord");
4316 : return false;
4317 : }
4318 : #ifdef __clang__
4319 : #pragma clang diagnostic pop
4320 : #endif // __clang__
4321 : slot = temp;
4322 : }
4323 : }
4324 : return true;
4325 : }
4326 :
4327 : private:
4328 : inline int32_t&
4329 : RawSetAsLong()
4330 : {
4331 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4332 : mUnion.mType = mUnion.eLong;
4333 : return mUnion.mValue.mLong.SetValue();
4334 : }
4335 :
4336 : inline Record<nsString, JS::Value>&
4337 : RawSetAsStringAnyRecord()
4338 : {
4339 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4340 : mUnion.mType = mUnion.eStringAnyRecord;
4341 : return mUnion.mValue.mStringAnyRecord.SetValue();
4342 : }
4343 : };
4344 :
4345 : class LongSequenceOrLongArgument
4346 : {
4347 : LongSequenceOrLong& mUnion;
4348 :
4349 : LongSequenceOrLongArgument(const LongSequenceOrLongArgument&) = delete;
4350 : LongSequenceOrLongArgument& operator=(const LongSequenceOrLongArgument&) = delete;
4351 : public:
4352 : explicit inline LongSequenceOrLongArgument(const LongSequenceOrLong& aUnion)
4353 : : mUnion(const_cast<LongSequenceOrLong&>(aUnion))
4354 : {
4355 : }
4356 :
4357 : inline bool
4358 : TrySetToLongSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4359 : {
4360 : tryNext = false;
4361 : { // scope for memberSlot
4362 : binding_detail::AutoSequence<int32_t>& memberSlot = RawSetAsLongSequence();
4363 : JS::ForOfIterator iter(cx);
4364 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
4365 : return false;
4366 : }
4367 : if (!iter.valueIsIterable()) {
4368 : mUnion.DestroyLongSequence();
4369 : tryNext = true;
4370 : return true;
4371 : }
4372 : binding_detail::AutoSequence<int32_t> &arr = memberSlot;
4373 : JS::Rooted<JS::Value> temp(cx);
4374 : while (true) {
4375 : bool done;
4376 : if (!iter.next(&temp, &done)) {
4377 : return false;
4378 : }
4379 : if (done) {
4380 : break;
4381 : }
4382 : int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
4383 : if (!slotPtr) {
4384 : JS_ReportOutOfMemory(cx);
4385 : return false;
4386 : }
4387 : int32_t& slot = *slotPtr;
4388 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
4389 : return false;
4390 : }
4391 : }
4392 : }
4393 : return true;
4394 : }
4395 :
4396 : inline bool
4397 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4398 : {
4399 : tryNext = false;
4400 : { // scope for memberSlot
4401 : int32_t& memberSlot = RawSetAsLong();
4402 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4403 : return false;
4404 : }
4405 : }
4406 : return true;
4407 : }
4408 :
4409 : private:
4410 : inline binding_detail::AutoSequence<int32_t>&
4411 : RawSetAsLongSequence()
4412 : {
4413 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4414 : mUnion.mType = mUnion.eLongSequence;
4415 : return mUnion.mValue.mLongSequence.SetValue();
4416 : }
4417 :
4418 : inline int32_t&
4419 : RawSetAsLong()
4420 : {
4421 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4422 : mUnion.mType = mUnion.eLong;
4423 : return mUnion.mValue.mLong.SetValue();
4424 : }
4425 : };
4426 :
4427 : class LongSequenceOrNullOrLongArgument
4428 : {
4429 : LongSequenceOrNullOrLong& mUnion;
4430 :
4431 : LongSequenceOrNullOrLongArgument(const LongSequenceOrNullOrLongArgument&) = delete;
4432 : LongSequenceOrNullOrLongArgument& operator=(const LongSequenceOrNullOrLongArgument&) = delete;
4433 : public:
4434 : explicit inline LongSequenceOrNullOrLongArgument(const LongSequenceOrNullOrLong& aUnion)
4435 : : mUnion(const_cast<LongSequenceOrNullOrLong&>(aUnion))
4436 : {
4437 : }
4438 :
4439 : inline bool
4440 : SetNull()
4441 : {
4442 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4443 : mUnion.mType = mUnion.eNull;
4444 : return true;
4445 : }
4446 :
4447 : inline bool
4448 : TrySetToLongSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4449 : {
4450 : tryNext = false;
4451 : { // scope for memberSlot
4452 : binding_detail::AutoSequence<int32_t>& memberSlot = RawSetAsLongSequence();
4453 : JS::ForOfIterator iter(cx);
4454 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
4455 : return false;
4456 : }
4457 : if (!iter.valueIsIterable()) {
4458 : mUnion.DestroyLongSequence();
4459 : tryNext = true;
4460 : return true;
4461 : }
4462 : binding_detail::AutoSequence<int32_t> &arr = memberSlot;
4463 : JS::Rooted<JS::Value> temp(cx);
4464 : while (true) {
4465 : bool done;
4466 : if (!iter.next(&temp, &done)) {
4467 : return false;
4468 : }
4469 : if (done) {
4470 : break;
4471 : }
4472 : int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
4473 : if (!slotPtr) {
4474 : JS_ReportOutOfMemory(cx);
4475 : return false;
4476 : }
4477 : int32_t& slot = *slotPtr;
4478 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
4479 : return false;
4480 : }
4481 : }
4482 : }
4483 : return true;
4484 : }
4485 :
4486 : inline bool
4487 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4488 : {
4489 : tryNext = false;
4490 : { // scope for memberSlot
4491 : int32_t& memberSlot = RawSetAsLong();
4492 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4493 : return false;
4494 : }
4495 : }
4496 : return true;
4497 : }
4498 :
4499 : private:
4500 : inline binding_detail::AutoSequence<int32_t>&
4501 : RawSetAsLongSequence()
4502 : {
4503 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4504 : mUnion.mType = mUnion.eLongSequence;
4505 : return mUnion.mValue.mLongSequence.SetValue();
4506 : }
4507 :
4508 : inline int32_t&
4509 : RawSetAsLong()
4510 : {
4511 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4512 : mUnion.mType = mUnion.eLong;
4513 : return mUnion.mValue.mLong.SetValue();
4514 : }
4515 : };
4516 :
4517 : class NodeOrHTMLCollectionArgument
4518 : {
4519 : NodeOrHTMLCollection& mUnion;
4520 :
4521 : NodeOrHTMLCollectionArgument(const NodeOrHTMLCollectionArgument&) = delete;
4522 : NodeOrHTMLCollectionArgument& operator=(const NodeOrHTMLCollectionArgument&) = delete;
4523 : public:
4524 : explicit inline NodeOrHTMLCollectionArgument(const NodeOrHTMLCollection& aUnion)
4525 : : mUnion(const_cast<NodeOrHTMLCollection&>(aUnion))
4526 : {
4527 : }
4528 :
4529 : inline bool
4530 : TrySetToNode(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4531 : {
4532 : tryNext = false;
4533 : { // scope for memberSlot
4534 : NonNull<nsINode>& memberSlot = RawSetAsNode();
4535 : {
4536 : nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(value, memberSlot);
4537 : if (NS_FAILED(rv)) {
4538 : mUnion.DestroyNode();
4539 : tryNext = true;
4540 : return true;
4541 : }
4542 : }
4543 : }
4544 : return true;
4545 : }
4546 :
4547 : inline bool
4548 : TrySetToHTMLCollection(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4549 : {
4550 : tryNext = false;
4551 : { // scope for memberSlot
4552 : NonNull<nsIHTMLCollection>& memberSlot = RawSetAsHTMLCollection();
4553 : {
4554 : nsresult rv = UnwrapObject<prototypes::id::HTMLCollection, nsIHTMLCollection>(value, memberSlot);
4555 : if (NS_FAILED(rv)) {
4556 : mUnion.DestroyHTMLCollection();
4557 : tryNext = true;
4558 : return true;
4559 : }
4560 : }
4561 : }
4562 : return true;
4563 : }
4564 :
4565 : private:
4566 : inline NonNull<nsINode>&
4567 : RawSetAsNode()
4568 : {
4569 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4570 : mUnion.mType = mUnion.eNode;
4571 : return mUnion.mValue.mNode.SetValue();
4572 : }
4573 :
4574 : inline NonNull<nsIHTMLCollection>&
4575 : RawSetAsHTMLCollection()
4576 : {
4577 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4578 : mUnion.mType = mUnion.eHTMLCollection;
4579 : return mUnion.mValue.mHTMLCollection.SetValue();
4580 : }
4581 : };
4582 :
4583 : class NodeOrLongOrBooleanArgument
4584 : {
4585 : NodeOrLongOrBoolean& mUnion;
4586 :
4587 : NodeOrLongOrBooleanArgument(const NodeOrLongOrBooleanArgument&) = delete;
4588 : NodeOrLongOrBooleanArgument& operator=(const NodeOrLongOrBooleanArgument&) = delete;
4589 : public:
4590 : explicit inline NodeOrLongOrBooleanArgument(const NodeOrLongOrBoolean& aUnion)
4591 : : mUnion(const_cast<NodeOrLongOrBoolean&>(aUnion))
4592 : {
4593 : }
4594 :
4595 : inline bool
4596 : TrySetToNode(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4597 : {
4598 : tryNext = false;
4599 : { // scope for memberSlot
4600 : NonNull<nsINode>& memberSlot = RawSetAsNode();
4601 : {
4602 : nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(value, memberSlot);
4603 : if (NS_FAILED(rv)) {
4604 : mUnion.DestroyNode();
4605 : tryNext = true;
4606 : return true;
4607 : }
4608 : }
4609 : }
4610 : return true;
4611 : }
4612 :
4613 : inline bool
4614 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4615 : {
4616 : tryNext = false;
4617 : { // scope for memberSlot
4618 : int32_t& memberSlot = RawSetAsLong();
4619 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4620 : return false;
4621 : }
4622 : }
4623 : return true;
4624 : }
4625 :
4626 : inline bool
4627 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4628 : {
4629 : tryNext = false;
4630 : { // scope for memberSlot
4631 : bool& memberSlot = RawSetAsBoolean();
4632 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
4633 : return false;
4634 : }
4635 : }
4636 : return true;
4637 : }
4638 :
4639 : private:
4640 : inline NonNull<nsINode>&
4641 : RawSetAsNode()
4642 : {
4643 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4644 : mUnion.mType = mUnion.eNode;
4645 : return mUnion.mValue.mNode.SetValue();
4646 : }
4647 :
4648 : inline int32_t&
4649 : RawSetAsLong()
4650 : {
4651 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4652 : mUnion.mType = mUnion.eLong;
4653 : return mUnion.mValue.mLong.SetValue();
4654 : }
4655 :
4656 : inline bool&
4657 : RawSetAsBoolean()
4658 : {
4659 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4660 : mUnion.mType = mUnion.eBoolean;
4661 : return mUnion.mValue.mBoolean.SetValue();
4662 : }
4663 : };
4664 :
4665 : class NodeOrStringArgument
4666 : {
4667 : NodeOrString& mUnion;
4668 :
4669 : NodeOrStringArgument(const NodeOrStringArgument&) = delete;
4670 : NodeOrStringArgument& operator=(const NodeOrStringArgument&) = delete;
4671 : public:
4672 : explicit inline NodeOrStringArgument(const NodeOrString& aUnion)
4673 : : mUnion(const_cast<NodeOrString&>(aUnion))
4674 : {
4675 : }
4676 :
4677 : inline bool
4678 : TrySetToNode(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4679 : {
4680 : tryNext = false;
4681 : { // scope for memberSlot
4682 : NonNull<nsINode>& memberSlot = RawSetAsNode();
4683 : {
4684 : nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(value, memberSlot);
4685 : if (NS_FAILED(rv)) {
4686 : mUnion.DestroyNode();
4687 : tryNext = true;
4688 : return true;
4689 : }
4690 : }
4691 : }
4692 : return true;
4693 : }
4694 :
4695 : inline bool
4696 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4697 : {
4698 : tryNext = false;
4699 : { // scope for memberSlot
4700 : binding_detail::FakeString& memberSlot = RawSetAsString();
4701 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
4702 : return false;
4703 : }
4704 : }
4705 : return true;
4706 : }
4707 :
4708 : inline void
4709 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
4710 : {
4711 : RawSetAsString().Rebind(aData, aLength);
4712 : }
4713 :
4714 : private:
4715 : inline NonNull<nsINode>&
4716 : RawSetAsNode()
4717 : {
4718 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4719 : mUnion.mType = mUnion.eNode;
4720 : return mUnion.mValue.mNode.SetValue();
4721 : }
4722 :
4723 : inline binding_detail::FakeString&
4724 : RawSetAsString()
4725 : {
4726 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4727 : mUnion.mType = mUnion.eString;
4728 : return mUnion.mValue.mString.SetValue();
4729 : }
4730 : };
4731 :
4732 : class ObjectOrBooleanArgument
4733 : {
4734 : ObjectOrBoolean& mUnion;
4735 :
4736 : ObjectOrBooleanArgument(const ObjectOrBooleanArgument&) = delete;
4737 : ObjectOrBooleanArgument& operator=(const ObjectOrBooleanArgument&) = delete;
4738 : public:
4739 : explicit inline ObjectOrBooleanArgument(const ObjectOrBoolean& aUnion)
4740 : : mUnion(const_cast<ObjectOrBoolean&>(aUnion))
4741 : {
4742 : }
4743 :
4744 : inline bool
4745 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
4746 : {
4747 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4748 : mUnion.mValue.mObject.SetValue(cx, obj);
4749 : mUnion.mType = mUnion.eObject;
4750 : if (passedToJSImpl && !CallerSubsumes(obj)) {
4751 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
4752 : return false;
4753 : }
4754 : return true;
4755 : }
4756 :
4757 : inline bool
4758 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4759 : {
4760 : tryNext = false;
4761 : { // scope for memberSlot
4762 : bool& memberSlot = RawSetAsBoolean();
4763 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
4764 : return false;
4765 : }
4766 : }
4767 : return true;
4768 : }
4769 :
4770 : private:
4771 : inline bool&
4772 : RawSetAsBoolean()
4773 : {
4774 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4775 : mUnion.mType = mUnion.eBoolean;
4776 : return mUnion.mValue.mBoolean.SetValue();
4777 : }
4778 : };
4779 :
4780 : class ObjectOrLongArgument
4781 : {
4782 : ObjectOrLong& mUnion;
4783 :
4784 : ObjectOrLongArgument(const ObjectOrLongArgument&) = delete;
4785 : ObjectOrLongArgument& operator=(const ObjectOrLongArgument&) = delete;
4786 : public:
4787 : explicit inline ObjectOrLongArgument(const ObjectOrLong& aUnion)
4788 : : mUnion(const_cast<ObjectOrLong&>(aUnion))
4789 : {
4790 : }
4791 :
4792 : inline bool
4793 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
4794 : {
4795 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4796 : mUnion.mValue.mObject.SetValue(cx, obj);
4797 : mUnion.mType = mUnion.eObject;
4798 : if (passedToJSImpl && !CallerSubsumes(obj)) {
4799 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
4800 : return false;
4801 : }
4802 : return true;
4803 : }
4804 :
4805 : inline bool
4806 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4807 : {
4808 : tryNext = false;
4809 : { // scope for memberSlot
4810 : int32_t& memberSlot = RawSetAsLong();
4811 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4812 : return false;
4813 : }
4814 : }
4815 : return true;
4816 : }
4817 :
4818 : private:
4819 : inline int32_t&
4820 : RawSetAsLong()
4821 : {
4822 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4823 : mUnion.mType = mUnion.eLong;
4824 : return mUnion.mValue.mLong.SetValue();
4825 : }
4826 : };
4827 :
4828 : class ObjectOrLongOrBooleanArgument
4829 : {
4830 : ObjectOrLongOrBoolean& mUnion;
4831 :
4832 : ObjectOrLongOrBooleanArgument(const ObjectOrLongOrBooleanArgument&) = delete;
4833 : ObjectOrLongOrBooleanArgument& operator=(const ObjectOrLongOrBooleanArgument&) = delete;
4834 : public:
4835 : explicit inline ObjectOrLongOrBooleanArgument(const ObjectOrLongOrBoolean& aUnion)
4836 : : mUnion(const_cast<ObjectOrLongOrBoolean&>(aUnion))
4837 : {
4838 : }
4839 :
4840 : inline bool
4841 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
4842 : {
4843 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4844 : mUnion.mValue.mObject.SetValue(cx, obj);
4845 : mUnion.mType = mUnion.eObject;
4846 : if (passedToJSImpl && !CallerSubsumes(obj)) {
4847 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
4848 : return false;
4849 : }
4850 : return true;
4851 : }
4852 :
4853 : inline bool
4854 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4855 : {
4856 : tryNext = false;
4857 : { // scope for memberSlot
4858 : int32_t& memberSlot = RawSetAsLong();
4859 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4860 : return false;
4861 : }
4862 : }
4863 : return true;
4864 : }
4865 :
4866 : inline bool
4867 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4868 : {
4869 : tryNext = false;
4870 : { // scope for memberSlot
4871 : bool& memberSlot = RawSetAsBoolean();
4872 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
4873 : return false;
4874 : }
4875 : }
4876 : return true;
4877 : }
4878 :
4879 : private:
4880 : inline int32_t&
4881 : RawSetAsLong()
4882 : {
4883 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4884 : mUnion.mType = mUnion.eLong;
4885 : return mUnion.mValue.mLong.SetValue();
4886 : }
4887 :
4888 : inline bool&
4889 : RawSetAsBoolean()
4890 : {
4891 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4892 : mUnion.mType = mUnion.eBoolean;
4893 : return mUnion.mValue.mBoolean.SetValue();
4894 : }
4895 : };
4896 :
4897 : class ObjectOrLongOrNullArgument
4898 : {
4899 : ObjectOrLongOrNull& mUnion;
4900 :
4901 : ObjectOrLongOrNullArgument(const ObjectOrLongOrNullArgument&) = delete;
4902 : ObjectOrLongOrNullArgument& operator=(const ObjectOrLongOrNullArgument&) = delete;
4903 : public:
4904 : explicit inline ObjectOrLongOrNullArgument(const ObjectOrLongOrNull& aUnion)
4905 : : mUnion(const_cast<ObjectOrLongOrNull&>(aUnion))
4906 : {
4907 : }
4908 :
4909 : inline bool
4910 : SetNull()
4911 : {
4912 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4913 : mUnion.mType = mUnion.eNull;
4914 : return true;
4915 : }
4916 :
4917 : inline bool
4918 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
4919 : {
4920 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4921 : mUnion.mValue.mObject.SetValue(cx, obj);
4922 : mUnion.mType = mUnion.eObject;
4923 : if (passedToJSImpl && !CallerSubsumes(obj)) {
4924 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
4925 : return false;
4926 : }
4927 : return true;
4928 : }
4929 :
4930 : inline bool
4931 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4932 : {
4933 : tryNext = false;
4934 : { // scope for memberSlot
4935 : int32_t& memberSlot = RawSetAsLong();
4936 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4937 : return false;
4938 : }
4939 : }
4940 : return true;
4941 : }
4942 :
4943 : private:
4944 : inline int32_t&
4945 : RawSetAsLong()
4946 : {
4947 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4948 : mUnion.mType = mUnion.eLong;
4949 : return mUnion.mValue.mLong.SetValue();
4950 : }
4951 : };
4952 :
4953 : class ObjectOrNullOrLongArgument
4954 : {
4955 : ObjectOrNullOrLong& mUnion;
4956 :
4957 : ObjectOrNullOrLongArgument(const ObjectOrNullOrLongArgument&) = delete;
4958 : ObjectOrNullOrLongArgument& operator=(const ObjectOrNullOrLongArgument&) = delete;
4959 : public:
4960 : explicit inline ObjectOrNullOrLongArgument(const ObjectOrNullOrLong& aUnion)
4961 : : mUnion(const_cast<ObjectOrNullOrLong&>(aUnion))
4962 : {
4963 : }
4964 :
4965 : inline bool
4966 : SetNull()
4967 : {
4968 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4969 : mUnion.mType = mUnion.eNull;
4970 : return true;
4971 : }
4972 :
4973 : inline bool
4974 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
4975 : {
4976 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
4977 : mUnion.mValue.mObject.SetValue(cx, obj);
4978 : mUnion.mType = mUnion.eObject;
4979 : if (passedToJSImpl && !CallerSubsumes(obj)) {
4980 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
4981 : return false;
4982 : }
4983 : return true;
4984 : }
4985 :
4986 : inline bool
4987 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
4988 : {
4989 : tryNext = false;
4990 : { // scope for memberSlot
4991 : int32_t& memberSlot = RawSetAsLong();
4992 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
4993 : return false;
4994 : }
4995 : }
4996 : return true;
4997 : }
4998 :
4999 : private:
5000 : inline int32_t&
5001 : RawSetAsLong()
5002 : {
5003 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5004 : mUnion.mType = mUnion.eLong;
5005 : return mUnion.mValue.mLong.SetValue();
5006 : }
5007 : };
5008 :
5009 : class ObjectOrStringArgument
5010 : {
5011 : ObjectOrString& mUnion;
5012 :
5013 : ObjectOrStringArgument(const ObjectOrStringArgument&) = delete;
5014 : ObjectOrStringArgument& operator=(const ObjectOrStringArgument&) = delete;
5015 : public:
5016 0 : explicit inline ObjectOrStringArgument(const ObjectOrString& aUnion)
5017 0 : : mUnion(const_cast<ObjectOrString&>(aUnion))
5018 : {
5019 0 : }
5020 :
5021 : inline bool
5022 0 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
5023 : {
5024 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5025 0 : mUnion.mValue.mObject.SetValue(cx, obj);
5026 0 : mUnion.mType = mUnion.eObject;
5027 0 : if (passedToJSImpl && !CallerSubsumes(obj)) {
5028 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
5029 0 : return false;
5030 : }
5031 0 : return true;
5032 : }
5033 :
5034 : inline bool
5035 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5036 : {
5037 0 : tryNext = false;
5038 : { // scope for memberSlot
5039 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
5040 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5041 0 : return false;
5042 : }
5043 : }
5044 0 : return true;
5045 : }
5046 :
5047 : inline void
5048 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5049 : {
5050 : RawSetAsString().Rebind(aData, aLength);
5051 : }
5052 :
5053 : private:
5054 : inline binding_detail::FakeString&
5055 0 : RawSetAsString()
5056 : {
5057 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5058 0 : mUnion.mType = mUnion.eString;
5059 0 : return mUnion.mValue.mString.SetValue();
5060 : }
5061 : };
5062 :
5063 : class ObjectOrStringOrBooleanArgument
5064 : {
5065 : ObjectOrStringOrBoolean& mUnion;
5066 :
5067 : ObjectOrStringOrBooleanArgument(const ObjectOrStringOrBooleanArgument&) = delete;
5068 : ObjectOrStringOrBooleanArgument& operator=(const ObjectOrStringOrBooleanArgument&) = delete;
5069 : public:
5070 : explicit inline ObjectOrStringOrBooleanArgument(const ObjectOrStringOrBoolean& aUnion)
5071 : : mUnion(const_cast<ObjectOrStringOrBoolean&>(aUnion))
5072 : {
5073 : }
5074 :
5075 : inline bool
5076 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
5077 : {
5078 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5079 : mUnion.mValue.mObject.SetValue(cx, obj);
5080 : mUnion.mType = mUnion.eObject;
5081 : if (passedToJSImpl && !CallerSubsumes(obj)) {
5082 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
5083 : return false;
5084 : }
5085 : return true;
5086 : }
5087 :
5088 : inline bool
5089 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5090 : {
5091 : tryNext = false;
5092 : { // scope for memberSlot
5093 : binding_detail::FakeString& memberSlot = RawSetAsString();
5094 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5095 : return false;
5096 : }
5097 : }
5098 : return true;
5099 : }
5100 :
5101 : inline void
5102 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5103 : {
5104 : RawSetAsString().Rebind(aData, aLength);
5105 : }
5106 :
5107 : inline bool
5108 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5109 : {
5110 : tryNext = false;
5111 : { // scope for memberSlot
5112 : bool& memberSlot = RawSetAsBoolean();
5113 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
5114 : return false;
5115 : }
5116 : }
5117 : return true;
5118 : }
5119 :
5120 : private:
5121 : inline binding_detail::FakeString&
5122 : RawSetAsString()
5123 : {
5124 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5125 : mUnion.mType = mUnion.eString;
5126 : return mUnion.mValue.mString.SetValue();
5127 : }
5128 :
5129 : inline bool&
5130 : RawSetAsBoolean()
5131 : {
5132 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5133 : mUnion.mType = mUnion.eBoolean;
5134 : return mUnion.mValue.mBoolean.SetValue();
5135 : }
5136 : };
5137 :
5138 : class ObjectOrStringOrLongArgument
5139 : {
5140 : ObjectOrStringOrLong& mUnion;
5141 :
5142 : ObjectOrStringOrLongArgument(const ObjectOrStringOrLongArgument&) = delete;
5143 : ObjectOrStringOrLongArgument& operator=(const ObjectOrStringOrLongArgument&) = delete;
5144 : public:
5145 : explicit inline ObjectOrStringOrLongArgument(const ObjectOrStringOrLong& aUnion)
5146 : : mUnion(const_cast<ObjectOrStringOrLong&>(aUnion))
5147 : {
5148 : }
5149 :
5150 : inline bool
5151 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
5152 : {
5153 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5154 : mUnion.mValue.mObject.SetValue(cx, obj);
5155 : mUnion.mType = mUnion.eObject;
5156 : if (passedToJSImpl && !CallerSubsumes(obj)) {
5157 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
5158 : return false;
5159 : }
5160 : return true;
5161 : }
5162 :
5163 : inline bool
5164 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5165 : {
5166 : tryNext = false;
5167 : { // scope for memberSlot
5168 : binding_detail::FakeString& memberSlot = RawSetAsString();
5169 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5170 : return false;
5171 : }
5172 : }
5173 : return true;
5174 : }
5175 :
5176 : inline void
5177 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5178 : {
5179 : RawSetAsString().Rebind(aData, aLength);
5180 : }
5181 :
5182 : inline bool
5183 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5184 : {
5185 : tryNext = false;
5186 : { // scope for memberSlot
5187 : int32_t& memberSlot = RawSetAsLong();
5188 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
5189 : return false;
5190 : }
5191 : }
5192 : return true;
5193 : }
5194 :
5195 : private:
5196 : inline binding_detail::FakeString&
5197 : RawSetAsString()
5198 : {
5199 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5200 : mUnion.mType = mUnion.eString;
5201 : return mUnion.mValue.mString.SetValue();
5202 : }
5203 :
5204 : inline int32_t&
5205 : RawSetAsLong()
5206 : {
5207 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5208 : mUnion.mType = mUnion.eLong;
5209 : return mUnion.mValue.mLong.SetValue();
5210 : }
5211 : };
5212 :
5213 : class ObjectOrStringOrLongOrBooleanArgument
5214 : {
5215 : ObjectOrStringOrLongOrBoolean& mUnion;
5216 :
5217 : ObjectOrStringOrLongOrBooleanArgument(const ObjectOrStringOrLongOrBooleanArgument&) = delete;
5218 : ObjectOrStringOrLongOrBooleanArgument& operator=(const ObjectOrStringOrLongOrBooleanArgument&) = delete;
5219 : public:
5220 : explicit inline ObjectOrStringOrLongOrBooleanArgument(const ObjectOrStringOrLongOrBoolean& aUnion)
5221 : : mUnion(const_cast<ObjectOrStringOrLongOrBoolean&>(aUnion))
5222 : {
5223 : }
5224 :
5225 : inline bool
5226 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
5227 : {
5228 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5229 : mUnion.mValue.mObject.SetValue(cx, obj);
5230 : mUnion.mType = mUnion.eObject;
5231 : if (passedToJSImpl && !CallerSubsumes(obj)) {
5232 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
5233 : return false;
5234 : }
5235 : return true;
5236 : }
5237 :
5238 : inline bool
5239 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5240 : {
5241 : tryNext = false;
5242 : { // scope for memberSlot
5243 : binding_detail::FakeString& memberSlot = RawSetAsString();
5244 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5245 : return false;
5246 : }
5247 : }
5248 : return true;
5249 : }
5250 :
5251 : inline void
5252 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5253 : {
5254 : RawSetAsString().Rebind(aData, aLength);
5255 : }
5256 :
5257 : inline bool
5258 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5259 : {
5260 : tryNext = false;
5261 : { // scope for memberSlot
5262 : int32_t& memberSlot = RawSetAsLong();
5263 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
5264 : return false;
5265 : }
5266 : }
5267 : return true;
5268 : }
5269 :
5270 : inline bool
5271 : TrySetToBoolean(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5272 : {
5273 : tryNext = false;
5274 : { // scope for memberSlot
5275 : bool& memberSlot = RawSetAsBoolean();
5276 : if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
5277 : return false;
5278 : }
5279 : }
5280 : return true;
5281 : }
5282 :
5283 : private:
5284 : inline binding_detail::FakeString&
5285 : RawSetAsString()
5286 : {
5287 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5288 : mUnion.mType = mUnion.eString;
5289 : return mUnion.mValue.mString.SetValue();
5290 : }
5291 :
5292 : inline int32_t&
5293 : RawSetAsLong()
5294 : {
5295 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5296 : mUnion.mType = mUnion.eLong;
5297 : return mUnion.mValue.mLong.SetValue();
5298 : }
5299 :
5300 : inline bool&
5301 : RawSetAsBoolean()
5302 : {
5303 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5304 : mUnion.mType = mUnion.eBoolean;
5305 : return mUnion.mValue.mBoolean.SetValue();
5306 : }
5307 : };
5308 :
5309 : class ObjectSequenceOrLongArgument
5310 : {
5311 : ObjectSequenceOrLong& mUnion;
5312 : Maybe<SequenceRooter<JSObject*>> mObjectSequenceHolder;
5313 :
5314 : ObjectSequenceOrLongArgument(const ObjectSequenceOrLongArgument&) = delete;
5315 : ObjectSequenceOrLongArgument& operator=(const ObjectSequenceOrLongArgument&) = delete;
5316 : public:
5317 : explicit inline ObjectSequenceOrLongArgument(const ObjectSequenceOrLong& aUnion)
5318 : : mUnion(const_cast<ObjectSequenceOrLong&>(aUnion))
5319 : {
5320 : }
5321 :
5322 : inline bool
5323 : TrySetToObjectSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5324 : {
5325 : tryNext = false;
5326 : { // scope for memberSlot
5327 : binding_detail::AutoSequence<JSObject*>& memberSlot = RawSetAsObjectSequence();
5328 : mObjectSequenceHolder.emplace(cx, &memberSlot);
5329 : JS::ForOfIterator iter(cx);
5330 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
5331 : return false;
5332 : }
5333 : if (!iter.valueIsIterable()) {
5334 : mObjectSequenceHolder.reset();
5335 : mUnion.DestroyObjectSequence();
5336 : tryNext = true;
5337 : return true;
5338 : }
5339 : binding_detail::AutoSequence<JSObject*> &arr = memberSlot;
5340 : JS::Rooted<JS::Value> temp(cx);
5341 : while (true) {
5342 : bool done;
5343 : if (!iter.next(&temp, &done)) {
5344 : return false;
5345 : }
5346 : if (done) {
5347 : break;
5348 : }
5349 : JSObject** slotPtr = arr.AppendElement(mozilla::fallible);
5350 : if (!slotPtr) {
5351 : JS_ReportOutOfMemory(cx);
5352 : return false;
5353 : }
5354 : JSObject*& slot = *slotPtr;
5355 : if (temp.isObject()) {
5356 : #ifdef __clang__
5357 : #pragma clang diagnostic push
5358 : #pragma clang diagnostic ignored "-Wunreachable-code"
5359 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
5360 : #endif // __clang__
5361 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
5362 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of member of ObjectSequenceOrLong");
5363 : return false;
5364 : }
5365 : #ifdef __clang__
5366 : #pragma clang diagnostic pop
5367 : #endif // __clang__
5368 : slot = &temp.toObject();
5369 : } else {
5370 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ObjectSequenceOrLong");
5371 : return false;
5372 : }
5373 : }
5374 : }
5375 : return true;
5376 : }
5377 :
5378 : inline bool
5379 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5380 : {
5381 : tryNext = false;
5382 : { // scope for memberSlot
5383 : int32_t& memberSlot = RawSetAsLong();
5384 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
5385 : return false;
5386 : }
5387 : }
5388 : return true;
5389 : }
5390 :
5391 : private:
5392 : inline binding_detail::AutoSequence<JSObject*>&
5393 : RawSetAsObjectSequence()
5394 : {
5395 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5396 : mUnion.mType = mUnion.eObjectSequence;
5397 : return mUnion.mValue.mObjectSequence.SetValue();
5398 : }
5399 :
5400 : inline int32_t&
5401 : RawSetAsLong()
5402 : {
5403 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5404 : mUnion.mType = mUnion.eLong;
5405 : return mUnion.mValue.mLong.SetValue();
5406 : }
5407 : };
5408 :
5409 : class RTCIceCandidateInitOrRTCIceCandidateArgument
5410 : {
5411 : RTCIceCandidateInitOrRTCIceCandidate& mUnion;
5412 :
5413 : RTCIceCandidateInitOrRTCIceCandidateArgument(const RTCIceCandidateInitOrRTCIceCandidateArgument&) = delete;
5414 : RTCIceCandidateInitOrRTCIceCandidateArgument& operator=(const RTCIceCandidateInitOrRTCIceCandidateArgument&) = delete;
5415 : public:
5416 0 : explicit inline RTCIceCandidateInitOrRTCIceCandidateArgument(const RTCIceCandidateInitOrRTCIceCandidate& aUnion)
5417 0 : : mUnion(const_cast<RTCIceCandidateInitOrRTCIceCandidate&>(aUnion))
5418 : {
5419 0 : }
5420 :
5421 : inline bool
5422 0 : TrySetToRTCIceCandidateInit(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5423 : {
5424 0 : tryNext = false;
5425 : { // scope for memberSlot
5426 0 : binding_detail::FastRTCIceCandidateInit& memberSlot = RawSetAsRTCIceCandidateInit();
5427 0 : if (!IsConvertibleToDictionary(value)) {
5428 0 : mUnion.DestroyRTCIceCandidateInit();
5429 0 : tryNext = true;
5430 0 : return true;
5431 : }
5432 0 : if (!memberSlot.Init(cx, value, "Member of RTCIceCandidateInitOrRTCIceCandidate", passedToJSImpl)) {
5433 0 : return false;
5434 : }
5435 : }
5436 0 : return true;
5437 : }
5438 :
5439 : inline bool
5440 0 : TrySetToRTCIceCandidate(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5441 : {
5442 0 : tryNext = false;
5443 : { // scope for memberSlot
5444 0 : NonNull<mozilla::dom::RTCIceCandidate>& memberSlot = RawSetAsRTCIceCandidate();
5445 : {
5446 0 : nsresult rv = UnwrapObject<prototypes::id::RTCIceCandidate, mozilla::dom::RTCIceCandidate>(value, memberSlot);
5447 0 : if (NS_FAILED(rv)) {
5448 0 : mUnion.DestroyRTCIceCandidate();
5449 0 : tryNext = true;
5450 0 : return true;
5451 : }
5452 : }
5453 : }
5454 0 : return true;
5455 : }
5456 :
5457 : private:
5458 : inline binding_detail::FastRTCIceCandidateInit&
5459 0 : RawSetAsRTCIceCandidateInit()
5460 : {
5461 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5462 0 : mUnion.mType = mUnion.eRTCIceCandidateInit;
5463 0 : return mUnion.mValue.mRTCIceCandidateInit.SetValue();
5464 : }
5465 :
5466 : inline NonNull<mozilla::dom::RTCIceCandidate>&
5467 0 : RawSetAsRTCIceCandidate()
5468 : {
5469 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5470 0 : mUnion.mType = mUnion.eRTCIceCandidate;
5471 0 : return mUnion.mValue.mRTCIceCandidate.SetValue();
5472 : }
5473 : };
5474 :
5475 : class RadioNodeListOrElementArgument
5476 : {
5477 : RadioNodeListOrElement& mUnion;
5478 :
5479 : RadioNodeListOrElementArgument(const RadioNodeListOrElementArgument&) = delete;
5480 : RadioNodeListOrElementArgument& operator=(const RadioNodeListOrElementArgument&) = delete;
5481 : public:
5482 : explicit inline RadioNodeListOrElementArgument(const RadioNodeListOrElement& aUnion)
5483 : : mUnion(const_cast<RadioNodeListOrElement&>(aUnion))
5484 : {
5485 : }
5486 :
5487 : inline bool
5488 : TrySetToRadioNodeList(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5489 : {
5490 : tryNext = false;
5491 : { // scope for memberSlot
5492 : NonNull<mozilla::dom::RadioNodeList>& memberSlot = RawSetAsRadioNodeList();
5493 : {
5494 : nsresult rv = UnwrapObject<prototypes::id::RadioNodeList, mozilla::dom::RadioNodeList>(value, memberSlot);
5495 : if (NS_FAILED(rv)) {
5496 : mUnion.DestroyRadioNodeList();
5497 : tryNext = true;
5498 : return true;
5499 : }
5500 : }
5501 : }
5502 : return true;
5503 : }
5504 :
5505 : inline bool
5506 : TrySetToElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5507 : {
5508 : tryNext = false;
5509 : { // scope for memberSlot
5510 : NonNull<mozilla::dom::Element>& memberSlot = RawSetAsElement();
5511 : {
5512 : nsresult rv = UnwrapObject<prototypes::id::Element, mozilla::dom::Element>(value, memberSlot);
5513 : if (NS_FAILED(rv)) {
5514 : mUnion.DestroyElement();
5515 : tryNext = true;
5516 : return true;
5517 : }
5518 : }
5519 : }
5520 : return true;
5521 : }
5522 :
5523 : private:
5524 : inline NonNull<mozilla::dom::RadioNodeList>&
5525 : RawSetAsRadioNodeList()
5526 : {
5527 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5528 : mUnion.mType = mUnion.eRadioNodeList;
5529 : return mUnion.mValue.mRadioNodeList.SetValue();
5530 : }
5531 :
5532 : inline NonNull<mozilla::dom::Element>&
5533 : RawSetAsElement()
5534 : {
5535 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5536 : mUnion.mType = mUnion.eElement;
5537 : return mUnion.mValue.mElement.SetValue();
5538 : }
5539 : };
5540 :
5541 : class RequestOrUSVStringArgument
5542 : {
5543 : RequestOrUSVString& mUnion;
5544 :
5545 : RequestOrUSVStringArgument(const RequestOrUSVStringArgument&) = delete;
5546 : RequestOrUSVStringArgument& operator=(const RequestOrUSVStringArgument&) = delete;
5547 : public:
5548 1 : explicit inline RequestOrUSVStringArgument(const RequestOrUSVString& aUnion)
5549 1 : : mUnion(const_cast<RequestOrUSVString&>(aUnion))
5550 : {
5551 1 : }
5552 :
5553 : inline bool
5554 0 : TrySetToRequest(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5555 : {
5556 0 : tryNext = false;
5557 : { // scope for memberSlot
5558 0 : NonNull<mozilla::dom::Request>& memberSlot = RawSetAsRequest();
5559 : {
5560 0 : nsresult rv = UnwrapObject<prototypes::id::Request, mozilla::dom::Request>(value, memberSlot);
5561 0 : if (NS_FAILED(rv)) {
5562 0 : mUnion.DestroyRequest();
5563 0 : tryNext = true;
5564 0 : return true;
5565 : }
5566 : }
5567 : }
5568 0 : return true;
5569 : }
5570 :
5571 : inline bool
5572 1 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5573 : {
5574 1 : tryNext = false;
5575 : { // scope for memberSlot
5576 1 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
5577 1 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5578 0 : return false;
5579 : }
5580 1 : NormalizeUSVString(memberSlot);
5581 : }
5582 1 : return true;
5583 : }
5584 :
5585 : inline void
5586 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5587 : {
5588 : RawSetAsUSVString().Rebind(aData, aLength);
5589 : }
5590 :
5591 : private:
5592 : inline NonNull<mozilla::dom::Request>&
5593 0 : RawSetAsRequest()
5594 : {
5595 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5596 0 : mUnion.mType = mUnion.eRequest;
5597 0 : return mUnion.mValue.mRequest.SetValue();
5598 : }
5599 :
5600 : inline binding_detail::FakeString&
5601 1 : RawSetAsUSVString()
5602 : {
5603 1 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5604 1 : mUnion.mType = mUnion.eUSVString;
5605 1 : return mUnion.mValue.mUSVString.SetValue();
5606 : }
5607 : };
5608 :
5609 : class StringLongRecordOrLongArgument
5610 : {
5611 : StringLongRecordOrLong& mUnion;
5612 :
5613 : StringLongRecordOrLongArgument(const StringLongRecordOrLongArgument&) = delete;
5614 : StringLongRecordOrLongArgument& operator=(const StringLongRecordOrLongArgument&) = delete;
5615 : public:
5616 : explicit inline StringLongRecordOrLongArgument(const StringLongRecordOrLong& aUnion)
5617 : : mUnion(const_cast<StringLongRecordOrLong&>(aUnion))
5618 : {
5619 : }
5620 :
5621 : inline bool
5622 : TrySetToStringLongRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5623 : {
5624 : tryNext = false;
5625 : { // scope for memberSlot
5626 : Record<nsString, int32_t>& memberSlot = RawSetAsStringLongRecord();
5627 : auto& recordEntries = memberSlot.Entries();
5628 :
5629 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
5630 : JS::AutoIdVector ids(cx);
5631 : if (!js::GetPropertyKeys(cx, recordObj,
5632 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
5633 : return false;
5634 : }
5635 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
5636 : JS_ReportOutOfMemory(cx);
5637 : return false;
5638 : }
5639 : JS::Rooted<JS::Value> propNameValue(cx);
5640 : JS::Rooted<JS::Value> temp(cx);
5641 : JS::Rooted<jsid> curId(cx);
5642 : JS::Rooted<JS::Value> idVal(cx);
5643 : // Use a hashset to keep track of ids seen, to avoid
5644 : // introducing nasty O(N^2) behavior scanning for them all the
5645 : // time. Ideally we'd use a data structure with O(1) lookup
5646 : // _and_ ordering for the MozMap, but we don't have one lying
5647 : // around.
5648 : nsTHashtable<nsStringHashKey> idsSeen;
5649 : for (size_t i = 0; i < ids.length(); ++i) {
5650 : curId = ids[i];
5651 :
5652 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
5653 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
5654 : &desc)) {
5655 : return false;
5656 : }
5657 :
5658 : if (!desc.object() /* == undefined in spec terms */ ||
5659 : !desc.enumerable()) {
5660 : continue;
5661 : }
5662 :
5663 : idVal = js::IdToValue(curId);
5664 : nsString propName;
5665 : // This will just throw if idVal is a Symbol, like the spec says
5666 : // to do.
5667 : if (!ConvertJSValueToString(cx, idVal, propName)) {
5668 : return false;
5669 : }
5670 :
5671 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
5672 : return false;
5673 : }
5674 :
5675 : Record<nsString, int32_t>::EntryType* entry;
5676 : if (!idsSeen.EnsureInserted(propName)) {
5677 : // Find the existing entry.
5678 : auto idx = recordEntries.IndexOf(propName);
5679 : MOZ_ASSERT(idx != recordEntries.NoIndex,
5680 : "Why is it not found?");
5681 : // Now blow it away to make it look like it was just added
5682 : // to the array, because it's not obvious that it's
5683 : // safe to write to its already-initialized mValue via our
5684 : // normal codegen conversions. For example, the value
5685 : // could be a union and this would change its type, but
5686 : // codegen assumes we won't do that.
5687 : entry = recordEntries.ReconstructElementAt(idx);
5688 : } else {
5689 : // Safe to do an infallible append here, because we did a
5690 : // SetCapacity above to the right capacity.
5691 : entry = recordEntries.AppendElement();
5692 : }
5693 : entry->mKey = propName;
5694 : int32_t& slot = entry->mValue;
5695 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
5696 : return false;
5697 : }
5698 : }
5699 : }
5700 : return true;
5701 : }
5702 :
5703 : inline bool
5704 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5705 : {
5706 : tryNext = false;
5707 : { // scope for memberSlot
5708 : int32_t& memberSlot = RawSetAsLong();
5709 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
5710 : return false;
5711 : }
5712 : }
5713 : return true;
5714 : }
5715 :
5716 : private:
5717 : inline Record<nsString, int32_t>&
5718 : RawSetAsStringLongRecord()
5719 : {
5720 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5721 : mUnion.mType = mUnion.eStringLongRecord;
5722 : return mUnion.mValue.mStringLongRecord.SetValue();
5723 : }
5724 :
5725 : inline int32_t&
5726 : RawSetAsLong()
5727 : {
5728 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5729 : mUnion.mType = mUnion.eLong;
5730 : return mUnion.mValue.mLong.SetValue();
5731 : }
5732 : };
5733 :
5734 : class StringObjectRecordOrLongArgument
5735 : {
5736 : StringObjectRecordOrLong& mUnion;
5737 : Maybe<RecordRooter<nsString, JSObject*>> mStringObjectRecordHolder;
5738 :
5739 : StringObjectRecordOrLongArgument(const StringObjectRecordOrLongArgument&) = delete;
5740 : StringObjectRecordOrLongArgument& operator=(const StringObjectRecordOrLongArgument&) = delete;
5741 : public:
5742 : explicit inline StringObjectRecordOrLongArgument(const StringObjectRecordOrLong& aUnion)
5743 : : mUnion(const_cast<StringObjectRecordOrLong&>(aUnion))
5744 : {
5745 : }
5746 :
5747 : inline bool
5748 : TrySetToStringObjectRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5749 : {
5750 : tryNext = false;
5751 : { // scope for memberSlot
5752 : Record<nsString, JSObject*>& memberSlot = RawSetAsStringObjectRecord();
5753 : mStringObjectRecordHolder.emplace(cx, &memberSlot);
5754 : auto& recordEntries = memberSlot.Entries();
5755 :
5756 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
5757 : JS::AutoIdVector ids(cx);
5758 : if (!js::GetPropertyKeys(cx, recordObj,
5759 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
5760 : return false;
5761 : }
5762 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
5763 : JS_ReportOutOfMemory(cx);
5764 : return false;
5765 : }
5766 : JS::Rooted<JS::Value> propNameValue(cx);
5767 : JS::Rooted<JS::Value> temp(cx);
5768 : JS::Rooted<jsid> curId(cx);
5769 : JS::Rooted<JS::Value> idVal(cx);
5770 : // Use a hashset to keep track of ids seen, to avoid
5771 : // introducing nasty O(N^2) behavior scanning for them all the
5772 : // time. Ideally we'd use a data structure with O(1) lookup
5773 : // _and_ ordering for the MozMap, but we don't have one lying
5774 : // around.
5775 : nsTHashtable<nsStringHashKey> idsSeen;
5776 : for (size_t i = 0; i < ids.length(); ++i) {
5777 : curId = ids[i];
5778 :
5779 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
5780 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
5781 : &desc)) {
5782 : return false;
5783 : }
5784 :
5785 : if (!desc.object() /* == undefined in spec terms */ ||
5786 : !desc.enumerable()) {
5787 : continue;
5788 : }
5789 :
5790 : idVal = js::IdToValue(curId);
5791 : nsString propName;
5792 : // This will just throw if idVal is a Symbol, like the spec says
5793 : // to do.
5794 : if (!ConvertJSValueToString(cx, idVal, propName)) {
5795 : return false;
5796 : }
5797 :
5798 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
5799 : return false;
5800 : }
5801 :
5802 : Record<nsString, JSObject*>::EntryType* entry;
5803 : if (!idsSeen.EnsureInserted(propName)) {
5804 : // Find the existing entry.
5805 : auto idx = recordEntries.IndexOf(propName);
5806 : MOZ_ASSERT(idx != recordEntries.NoIndex,
5807 : "Why is it not found?");
5808 : // Now blow it away to make it look like it was just added
5809 : // to the array, because it's not obvious that it's
5810 : // safe to write to its already-initialized mValue via our
5811 : // normal codegen conversions. For example, the value
5812 : // could be a union and this would change its type, but
5813 : // codegen assumes we won't do that.
5814 : entry = recordEntries.ReconstructElementAt(idx);
5815 : } else {
5816 : // Safe to do an infallible append here, because we did a
5817 : // SetCapacity above to the right capacity.
5818 : entry = recordEntries.AppendElement();
5819 : }
5820 : entry->mKey = propName;
5821 : JSObject*& slot = entry->mValue;
5822 : if (temp.isObject()) {
5823 : #ifdef __clang__
5824 : #pragma clang diagnostic push
5825 : #pragma clang diagnostic ignored "-Wunreachable-code"
5826 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
5827 : #endif // __clang__
5828 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
5829 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "value in member of StringObjectRecordOrLong");
5830 : return false;
5831 : }
5832 : #ifdef __clang__
5833 : #pragma clang diagnostic pop
5834 : #endif // __clang__
5835 : slot = &temp.toObject();
5836 : } else {
5837 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Value in member of StringObjectRecordOrLong");
5838 : return false;
5839 : }
5840 : }
5841 : }
5842 : return true;
5843 : }
5844 :
5845 : inline bool
5846 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5847 : {
5848 : tryNext = false;
5849 : { // scope for memberSlot
5850 : int32_t& memberSlot = RawSetAsLong();
5851 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
5852 : return false;
5853 : }
5854 : }
5855 : return true;
5856 : }
5857 :
5858 : private:
5859 : inline Record<nsString, JSObject*>&
5860 : RawSetAsStringObjectRecord()
5861 : {
5862 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5863 : mUnion.mType = mUnion.eStringObjectRecord;
5864 : return mUnion.mValue.mStringObjectRecord.SetValue();
5865 : }
5866 :
5867 : inline int32_t&
5868 : RawSetAsLong()
5869 : {
5870 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5871 : mUnion.mType = mUnion.eLong;
5872 : return mUnion.mValue.mLong.SetValue();
5873 : }
5874 : };
5875 :
5876 : class StringOrArrayBufferOrArrayBufferViewArgument
5877 : {
5878 : StringOrArrayBufferOrArrayBufferView& mUnion;
5879 :
5880 : StringOrArrayBufferOrArrayBufferViewArgument(const StringOrArrayBufferOrArrayBufferViewArgument&) = delete;
5881 : StringOrArrayBufferOrArrayBufferViewArgument& operator=(const StringOrArrayBufferOrArrayBufferViewArgument&) = delete;
5882 : public:
5883 0 : explicit inline StringOrArrayBufferOrArrayBufferViewArgument(const StringOrArrayBufferOrArrayBufferView& aUnion)
5884 0 : : mUnion(const_cast<StringOrArrayBufferOrArrayBufferView&>(aUnion))
5885 : {
5886 0 : }
5887 :
5888 : inline bool
5889 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5890 : {
5891 0 : tryNext = false;
5892 : { // scope for memberSlot
5893 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
5894 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5895 0 : return false;
5896 : }
5897 : }
5898 0 : return true;
5899 : }
5900 :
5901 : inline void
5902 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5903 : {
5904 : RawSetAsString().Rebind(aData, aLength);
5905 : }
5906 :
5907 : inline bool
5908 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5909 : {
5910 0 : tryNext = false;
5911 : { // scope for memberSlot
5912 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
5913 0 : if (!memberSlot.Init(&value.toObject())) {
5914 0 : mUnion.DestroyArrayBuffer();
5915 0 : tryNext = true;
5916 0 : return true;
5917 : }
5918 : }
5919 0 : return true;
5920 : }
5921 :
5922 : inline bool
5923 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5924 : {
5925 0 : tryNext = false;
5926 : { // scope for memberSlot
5927 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
5928 0 : if (!memberSlot.Init(&value.toObject())) {
5929 0 : mUnion.DestroyArrayBufferView();
5930 0 : tryNext = true;
5931 0 : return true;
5932 : }
5933 : }
5934 0 : return true;
5935 : }
5936 :
5937 : private:
5938 : inline binding_detail::FakeString&
5939 0 : RawSetAsString()
5940 : {
5941 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5942 0 : mUnion.mType = mUnion.eString;
5943 0 : return mUnion.mValue.mString.SetValue();
5944 : }
5945 :
5946 : inline RootedTypedArray<ArrayBuffer>&
5947 0 : RawSetAsArrayBuffer(JSContext* cx)
5948 : {
5949 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5950 0 : mUnion.mType = mUnion.eArrayBuffer;
5951 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
5952 : }
5953 :
5954 : inline RootedTypedArray<ArrayBufferView>&
5955 0 : RawSetAsArrayBufferView(JSContext* cx)
5956 : {
5957 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
5958 0 : mUnion.mType = mUnion.eArrayBufferView;
5959 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
5960 : }
5961 : };
5962 :
5963 : class StringOrArrayBufferOrArrayBufferViewOrBlobArgument
5964 : {
5965 : StringOrArrayBufferOrArrayBufferViewOrBlob& mUnion;
5966 :
5967 : StringOrArrayBufferOrArrayBufferViewOrBlobArgument(const StringOrArrayBufferOrArrayBufferViewOrBlobArgument&) = delete;
5968 : StringOrArrayBufferOrArrayBufferViewOrBlobArgument& operator=(const StringOrArrayBufferOrArrayBufferViewOrBlobArgument&) = delete;
5969 : public:
5970 0 : explicit inline StringOrArrayBufferOrArrayBufferViewOrBlobArgument(const StringOrArrayBufferOrArrayBufferViewOrBlob& aUnion)
5971 0 : : mUnion(const_cast<StringOrArrayBufferOrArrayBufferViewOrBlob&>(aUnion))
5972 : {
5973 0 : }
5974 :
5975 : inline bool
5976 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5977 : {
5978 0 : tryNext = false;
5979 : { // scope for memberSlot
5980 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
5981 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
5982 0 : return false;
5983 : }
5984 : }
5985 0 : return true;
5986 : }
5987 :
5988 : inline void
5989 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
5990 : {
5991 : RawSetAsString().Rebind(aData, aLength);
5992 : }
5993 :
5994 : inline bool
5995 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
5996 : {
5997 0 : tryNext = false;
5998 : { // scope for memberSlot
5999 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
6000 0 : if (!memberSlot.Init(&value.toObject())) {
6001 0 : mUnion.DestroyArrayBuffer();
6002 0 : tryNext = true;
6003 0 : return true;
6004 : }
6005 : }
6006 0 : return true;
6007 : }
6008 :
6009 : inline bool
6010 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6011 : {
6012 0 : tryNext = false;
6013 : { // scope for memberSlot
6014 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
6015 0 : if (!memberSlot.Init(&value.toObject())) {
6016 0 : mUnion.DestroyArrayBufferView();
6017 0 : tryNext = true;
6018 0 : return true;
6019 : }
6020 : }
6021 0 : return true;
6022 : }
6023 :
6024 : inline bool
6025 0 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6026 : {
6027 0 : tryNext = false;
6028 : { // scope for memberSlot
6029 0 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
6030 : {
6031 0 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
6032 0 : if (NS_FAILED(rv)) {
6033 0 : mUnion.DestroyBlob();
6034 0 : tryNext = true;
6035 0 : return true;
6036 : }
6037 : }
6038 : }
6039 0 : return true;
6040 : }
6041 :
6042 : private:
6043 : inline binding_detail::FakeString&
6044 0 : RawSetAsString()
6045 : {
6046 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6047 0 : mUnion.mType = mUnion.eString;
6048 0 : return mUnion.mValue.mString.SetValue();
6049 : }
6050 :
6051 : inline RootedTypedArray<ArrayBuffer>&
6052 0 : RawSetAsArrayBuffer(JSContext* cx)
6053 : {
6054 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6055 0 : mUnion.mType = mUnion.eArrayBuffer;
6056 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
6057 : }
6058 :
6059 : inline RootedTypedArray<ArrayBufferView>&
6060 0 : RawSetAsArrayBufferView(JSContext* cx)
6061 : {
6062 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6063 0 : mUnion.mType = mUnion.eArrayBufferView;
6064 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
6065 : }
6066 :
6067 : inline NonNull<mozilla::dom::Blob>&
6068 0 : RawSetAsBlob()
6069 : {
6070 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6071 0 : mUnion.mType = mUnion.eBlob;
6072 0 : return mUnion.mValue.mBlob.SetValue();
6073 : }
6074 : };
6075 :
6076 : class StringOrBlobOrArrayBufferOrArrayBufferViewArgument
6077 : {
6078 : StringOrBlobOrArrayBufferOrArrayBufferView& mUnion;
6079 :
6080 : StringOrBlobOrArrayBufferOrArrayBufferViewArgument(const StringOrBlobOrArrayBufferOrArrayBufferViewArgument&) = delete;
6081 : StringOrBlobOrArrayBufferOrArrayBufferViewArgument& operator=(const StringOrBlobOrArrayBufferOrArrayBufferViewArgument&) = delete;
6082 : public:
6083 0 : explicit inline StringOrBlobOrArrayBufferOrArrayBufferViewArgument(const StringOrBlobOrArrayBufferOrArrayBufferView& aUnion)
6084 0 : : mUnion(const_cast<StringOrBlobOrArrayBufferOrArrayBufferView&>(aUnion))
6085 : {
6086 0 : }
6087 :
6088 : inline bool
6089 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6090 : {
6091 0 : tryNext = false;
6092 : { // scope for memberSlot
6093 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
6094 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6095 0 : return false;
6096 : }
6097 : }
6098 0 : return true;
6099 : }
6100 :
6101 : inline void
6102 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6103 : {
6104 : RawSetAsString().Rebind(aData, aLength);
6105 : }
6106 :
6107 : inline bool
6108 0 : TrySetToBlob(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6109 : {
6110 0 : tryNext = false;
6111 : { // scope for memberSlot
6112 0 : NonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
6113 : {
6114 0 : nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
6115 0 : if (NS_FAILED(rv)) {
6116 0 : mUnion.DestroyBlob();
6117 0 : tryNext = true;
6118 0 : return true;
6119 : }
6120 : }
6121 : }
6122 0 : return true;
6123 : }
6124 :
6125 : inline bool
6126 0 : TrySetToArrayBuffer(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6127 : {
6128 0 : tryNext = false;
6129 : { // scope for memberSlot
6130 0 : RootedTypedArray<ArrayBuffer>& memberSlot = RawSetAsArrayBuffer(cx);
6131 0 : if (!memberSlot.Init(&value.toObject())) {
6132 0 : mUnion.DestroyArrayBuffer();
6133 0 : tryNext = true;
6134 0 : return true;
6135 : }
6136 : }
6137 0 : return true;
6138 : }
6139 :
6140 : inline bool
6141 0 : TrySetToArrayBufferView(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6142 : {
6143 0 : tryNext = false;
6144 : { // scope for memberSlot
6145 0 : RootedTypedArray<ArrayBufferView>& memberSlot = RawSetAsArrayBufferView(cx);
6146 0 : if (!memberSlot.Init(&value.toObject())) {
6147 0 : mUnion.DestroyArrayBufferView();
6148 0 : tryNext = true;
6149 0 : return true;
6150 : }
6151 : }
6152 0 : return true;
6153 : }
6154 :
6155 : private:
6156 : inline binding_detail::FakeString&
6157 0 : RawSetAsString()
6158 : {
6159 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6160 0 : mUnion.mType = mUnion.eString;
6161 0 : return mUnion.mValue.mString.SetValue();
6162 : }
6163 :
6164 : inline NonNull<mozilla::dom::Blob>&
6165 0 : RawSetAsBlob()
6166 : {
6167 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6168 0 : mUnion.mType = mUnion.eBlob;
6169 0 : return mUnion.mValue.mBlob.SetValue();
6170 : }
6171 :
6172 : inline RootedTypedArray<ArrayBuffer>&
6173 0 : RawSetAsArrayBuffer(JSContext* cx)
6174 : {
6175 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6176 0 : mUnion.mType = mUnion.eArrayBuffer;
6177 0 : return mUnion.mValue.mArrayBuffer.SetValue(cx);
6178 : }
6179 :
6180 : inline RootedTypedArray<ArrayBufferView>&
6181 0 : RawSetAsArrayBufferView(JSContext* cx)
6182 : {
6183 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6184 0 : mUnion.mType = mUnion.eArrayBufferView;
6185 0 : return mUnion.mValue.mArrayBufferView.SetValue(cx);
6186 : }
6187 : };
6188 :
6189 : class StringOrCanvasGradientOrCanvasPatternArgument
6190 : {
6191 : StringOrCanvasGradientOrCanvasPattern& mUnion;
6192 :
6193 : StringOrCanvasGradientOrCanvasPatternArgument(const StringOrCanvasGradientOrCanvasPatternArgument&) = delete;
6194 : StringOrCanvasGradientOrCanvasPatternArgument& operator=(const StringOrCanvasGradientOrCanvasPatternArgument&) = delete;
6195 : public:
6196 0 : explicit inline StringOrCanvasGradientOrCanvasPatternArgument(const StringOrCanvasGradientOrCanvasPattern& aUnion)
6197 0 : : mUnion(const_cast<StringOrCanvasGradientOrCanvasPattern&>(aUnion))
6198 : {
6199 0 : }
6200 :
6201 : inline bool
6202 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6203 : {
6204 0 : tryNext = false;
6205 : { // scope for memberSlot
6206 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
6207 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6208 0 : return false;
6209 : }
6210 : }
6211 0 : return true;
6212 : }
6213 :
6214 : inline void
6215 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6216 : {
6217 : RawSetAsString().Rebind(aData, aLength);
6218 : }
6219 :
6220 : inline bool
6221 0 : TrySetToCanvasGradient(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6222 : {
6223 0 : tryNext = false;
6224 : { // scope for memberSlot
6225 0 : NonNull<mozilla::dom::CanvasGradient>& memberSlot = RawSetAsCanvasGradient();
6226 : {
6227 0 : nsresult rv = UnwrapObject<prototypes::id::CanvasGradient, mozilla::dom::CanvasGradient>(value, memberSlot);
6228 0 : if (NS_FAILED(rv)) {
6229 0 : mUnion.DestroyCanvasGradient();
6230 0 : tryNext = true;
6231 0 : return true;
6232 : }
6233 : }
6234 : }
6235 0 : return true;
6236 : }
6237 :
6238 : inline bool
6239 0 : TrySetToCanvasPattern(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6240 : {
6241 0 : tryNext = false;
6242 : { // scope for memberSlot
6243 0 : NonNull<mozilla::dom::CanvasPattern>& memberSlot = RawSetAsCanvasPattern();
6244 : {
6245 0 : nsresult rv = UnwrapObject<prototypes::id::CanvasPattern, mozilla::dom::CanvasPattern>(value, memberSlot);
6246 0 : if (NS_FAILED(rv)) {
6247 0 : mUnion.DestroyCanvasPattern();
6248 0 : tryNext = true;
6249 0 : return true;
6250 : }
6251 : }
6252 : }
6253 0 : return true;
6254 : }
6255 :
6256 : private:
6257 : inline binding_detail::FakeString&
6258 0 : RawSetAsString()
6259 : {
6260 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6261 0 : mUnion.mType = mUnion.eString;
6262 0 : return mUnion.mValue.mString.SetValue();
6263 : }
6264 :
6265 : inline NonNull<mozilla::dom::CanvasGradient>&
6266 0 : RawSetAsCanvasGradient()
6267 : {
6268 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6269 0 : mUnion.mType = mUnion.eCanvasGradient;
6270 0 : return mUnion.mValue.mCanvasGradient.SetValue();
6271 : }
6272 :
6273 : inline NonNull<mozilla::dom::CanvasPattern>&
6274 0 : RawSetAsCanvasPattern()
6275 : {
6276 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6277 0 : mUnion.mType = mUnion.eCanvasPattern;
6278 0 : return mUnion.mValue.mCanvasPattern.SetValue();
6279 : }
6280 : };
6281 :
6282 : class StringOrInstallTriggerDataArgument
6283 : {
6284 : StringOrInstallTriggerData& mUnion;
6285 :
6286 : StringOrInstallTriggerDataArgument(const StringOrInstallTriggerDataArgument&) = delete;
6287 : StringOrInstallTriggerDataArgument& operator=(const StringOrInstallTriggerDataArgument&) = delete;
6288 : public:
6289 : explicit inline StringOrInstallTriggerDataArgument(const StringOrInstallTriggerData& aUnion)
6290 : : mUnion(const_cast<StringOrInstallTriggerData&>(aUnion))
6291 : {
6292 : }
6293 :
6294 : inline bool
6295 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6296 : {
6297 : tryNext = false;
6298 : { // scope for memberSlot
6299 : binding_detail::FakeString& memberSlot = RawSetAsString();
6300 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6301 : return false;
6302 : }
6303 : }
6304 : return true;
6305 : }
6306 :
6307 : inline void
6308 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6309 : {
6310 : RawSetAsString().Rebind(aData, aLength);
6311 : }
6312 :
6313 : inline bool
6314 : TrySetToInstallTriggerData(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6315 : {
6316 : tryNext = false;
6317 : { // scope for memberSlot
6318 : binding_detail::FastInstallTriggerData& memberSlot = RawSetAsInstallTriggerData();
6319 : if (!IsConvertibleToDictionary(value)) {
6320 : mUnion.DestroyInstallTriggerData();
6321 : tryNext = true;
6322 : return true;
6323 : }
6324 : if (!memberSlot.Init(cx, value, "Member of StringOrInstallTriggerData", passedToJSImpl)) {
6325 : return false;
6326 : }
6327 : }
6328 : return true;
6329 : }
6330 :
6331 : private:
6332 : inline binding_detail::FakeString&
6333 : RawSetAsString()
6334 : {
6335 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6336 : mUnion.mType = mUnion.eString;
6337 : return mUnion.mValue.mString.SetValue();
6338 : }
6339 :
6340 : inline binding_detail::FastInstallTriggerData&
6341 : RawSetAsInstallTriggerData()
6342 : {
6343 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6344 : mUnion.mType = mUnion.eInstallTriggerData;
6345 : return mUnion.mValue.mInstallTriggerData.SetValue();
6346 : }
6347 : };
6348 :
6349 : class StringOrLongArgument
6350 : {
6351 : StringOrLong& mUnion;
6352 :
6353 : StringOrLongArgument(const StringOrLongArgument&) = delete;
6354 : StringOrLongArgument& operator=(const StringOrLongArgument&) = delete;
6355 : public:
6356 : explicit inline StringOrLongArgument(const StringOrLong& aUnion)
6357 : : mUnion(const_cast<StringOrLong&>(aUnion))
6358 : {
6359 : }
6360 :
6361 : inline bool
6362 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6363 : {
6364 : tryNext = false;
6365 : { // scope for memberSlot
6366 : binding_detail::FakeString& memberSlot = RawSetAsString();
6367 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6368 : return false;
6369 : }
6370 : }
6371 : return true;
6372 : }
6373 :
6374 : inline void
6375 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6376 : {
6377 : RawSetAsString().Rebind(aData, aLength);
6378 : }
6379 :
6380 : inline bool
6381 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6382 : {
6383 : tryNext = false;
6384 : { // scope for memberSlot
6385 : int32_t& memberSlot = RawSetAsLong();
6386 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
6387 : return false;
6388 : }
6389 : }
6390 : return true;
6391 : }
6392 :
6393 : private:
6394 : inline binding_detail::FakeString&
6395 : RawSetAsString()
6396 : {
6397 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6398 : mUnion.mType = mUnion.eString;
6399 : return mUnion.mValue.mString.SetValue();
6400 : }
6401 :
6402 : inline int32_t&
6403 : RawSetAsLong()
6404 : {
6405 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6406 : mUnion.mType = mUnion.eLong;
6407 : return mUnion.mValue.mLong.SetValue();
6408 : }
6409 : };
6410 :
6411 : class StringOrMatchPatternArgument
6412 : {
6413 : StringOrMatchPattern& mUnion;
6414 :
6415 : StringOrMatchPatternArgument(const StringOrMatchPatternArgument&) = delete;
6416 : StringOrMatchPatternArgument& operator=(const StringOrMatchPatternArgument&) = delete;
6417 : public:
6418 : explicit inline StringOrMatchPatternArgument(const StringOrMatchPattern& aUnion)
6419 : : mUnion(const_cast<StringOrMatchPattern&>(aUnion))
6420 : {
6421 : }
6422 :
6423 : inline bool
6424 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6425 : {
6426 : tryNext = false;
6427 : { // scope for memberSlot
6428 : binding_detail::FakeString& memberSlot = RawSetAsString();
6429 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6430 : return false;
6431 : }
6432 : }
6433 : return true;
6434 : }
6435 :
6436 : inline void
6437 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6438 : {
6439 : RawSetAsString().Rebind(aData, aLength);
6440 : }
6441 :
6442 : inline bool
6443 : TrySetToMatchPattern(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6444 : {
6445 : tryNext = false;
6446 : { // scope for memberSlot
6447 : NonNull<mozilla::extensions::MatchPattern>& memberSlot = RawSetAsMatchPattern();
6448 : {
6449 : nsresult rv = UnwrapObject<prototypes::id::MatchPattern, mozilla::extensions::MatchPattern>(value, memberSlot);
6450 : if (NS_FAILED(rv)) {
6451 : mUnion.DestroyMatchPattern();
6452 : tryNext = true;
6453 : return true;
6454 : }
6455 : }
6456 : }
6457 : return true;
6458 : }
6459 :
6460 : private:
6461 : inline binding_detail::FakeString&
6462 : RawSetAsString()
6463 : {
6464 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6465 : mUnion.mType = mUnion.eString;
6466 : return mUnion.mValue.mString.SetValue();
6467 : }
6468 :
6469 : inline NonNull<mozilla::extensions::MatchPattern>&
6470 : RawSetAsMatchPattern()
6471 : {
6472 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6473 : mUnion.mType = mUnion.eMatchPattern;
6474 : return mUnion.mValue.mMatchPattern.SetValue();
6475 : }
6476 : };
6477 :
6478 : class StringOrObjectArgument
6479 : {
6480 : StringOrObject& mUnion;
6481 :
6482 : StringOrObjectArgument(const StringOrObjectArgument&) = delete;
6483 : StringOrObjectArgument& operator=(const StringOrObjectArgument&) = delete;
6484 : public:
6485 : explicit inline StringOrObjectArgument(const StringOrObject& aUnion)
6486 : : mUnion(const_cast<StringOrObject&>(aUnion))
6487 : {
6488 : }
6489 :
6490 : inline bool
6491 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6492 : {
6493 : tryNext = false;
6494 : { // scope for memberSlot
6495 : binding_detail::FakeString& memberSlot = RawSetAsString();
6496 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6497 : return false;
6498 : }
6499 : }
6500 : return true;
6501 : }
6502 :
6503 : inline void
6504 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6505 : {
6506 : RawSetAsString().Rebind(aData, aLength);
6507 : }
6508 :
6509 : inline bool
6510 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
6511 : {
6512 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6513 : mUnion.mValue.mObject.SetValue(cx, obj);
6514 : mUnion.mType = mUnion.eObject;
6515 : if (passedToJSImpl && !CallerSubsumes(obj)) {
6516 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
6517 : return false;
6518 : }
6519 : return true;
6520 : }
6521 :
6522 : private:
6523 : inline binding_detail::FakeString&
6524 : RawSetAsString()
6525 : {
6526 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6527 : mUnion.mType = mUnion.eString;
6528 : return mUnion.mValue.mString.SetValue();
6529 : }
6530 : };
6531 :
6532 : class StringOrStringSequenceArgument
6533 : {
6534 : StringOrStringSequence& mUnion;
6535 :
6536 : StringOrStringSequenceArgument(const StringOrStringSequenceArgument&) = delete;
6537 : StringOrStringSequenceArgument& operator=(const StringOrStringSequenceArgument&) = delete;
6538 : public:
6539 0 : explicit inline StringOrStringSequenceArgument(const StringOrStringSequence& aUnion)
6540 0 : : mUnion(const_cast<StringOrStringSequence&>(aUnion))
6541 : {
6542 0 : }
6543 :
6544 : inline bool
6545 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6546 : {
6547 0 : tryNext = false;
6548 : { // scope for memberSlot
6549 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
6550 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6551 0 : return false;
6552 : }
6553 : }
6554 0 : return true;
6555 : }
6556 :
6557 : inline void
6558 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6559 : {
6560 : RawSetAsString().Rebind(aData, aLength);
6561 : }
6562 :
6563 : inline bool
6564 0 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6565 : {
6566 0 : tryNext = false;
6567 : { // scope for memberSlot
6568 0 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
6569 0 : JS::ForOfIterator iter(cx);
6570 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
6571 0 : return false;
6572 : }
6573 0 : if (!iter.valueIsIterable()) {
6574 0 : mUnion.DestroyStringSequence();
6575 0 : tryNext = true;
6576 0 : return true;
6577 : }
6578 0 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
6579 0 : JS::Rooted<JS::Value> temp(cx);
6580 : while (true) {
6581 : bool done;
6582 0 : if (!iter.next(&temp, &done)) {
6583 0 : return false;
6584 : }
6585 0 : if (done) {
6586 0 : break;
6587 : }
6588 0 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
6589 0 : if (!slotPtr) {
6590 0 : JS_ReportOutOfMemory(cx);
6591 0 : return false;
6592 : }
6593 0 : nsString& slot = *slotPtr;
6594 0 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
6595 0 : return false;
6596 : }
6597 0 : }
6598 : }
6599 0 : return true;
6600 : }
6601 :
6602 : private:
6603 : inline binding_detail::FakeString&
6604 0 : RawSetAsString()
6605 : {
6606 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6607 0 : mUnion.mType = mUnion.eString;
6608 0 : return mUnion.mValue.mString.SetValue();
6609 : }
6610 :
6611 : inline binding_detail::AutoSequence<nsString>&
6612 0 : RawSetAsStringSequence()
6613 : {
6614 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6615 0 : mUnion.mType = mUnion.eStringSequence;
6616 0 : return mUnion.mValue.mStringSequence.SetValue();
6617 : }
6618 : };
6619 :
6620 : class StringOrStringSequenceOrConstrainDOMStringParametersArgument
6621 : {
6622 : StringOrStringSequenceOrConstrainDOMStringParameters& mUnion;
6623 :
6624 : StringOrStringSequenceOrConstrainDOMStringParametersArgument(const StringOrStringSequenceOrConstrainDOMStringParametersArgument&) = delete;
6625 : StringOrStringSequenceOrConstrainDOMStringParametersArgument& operator=(const StringOrStringSequenceOrConstrainDOMStringParametersArgument&) = delete;
6626 : public:
6627 : explicit inline StringOrStringSequenceOrConstrainDOMStringParametersArgument(const StringOrStringSequenceOrConstrainDOMStringParameters& aUnion)
6628 : : mUnion(const_cast<StringOrStringSequenceOrConstrainDOMStringParameters&>(aUnion))
6629 : {
6630 : }
6631 :
6632 : inline bool
6633 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6634 : {
6635 : tryNext = false;
6636 : { // scope for memberSlot
6637 : binding_detail::FakeString& memberSlot = RawSetAsString();
6638 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6639 : return false;
6640 : }
6641 : }
6642 : return true;
6643 : }
6644 :
6645 : inline void
6646 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6647 : {
6648 : RawSetAsString().Rebind(aData, aLength);
6649 : }
6650 :
6651 : inline bool
6652 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6653 : {
6654 : tryNext = false;
6655 : { // scope for memberSlot
6656 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
6657 : JS::ForOfIterator iter(cx);
6658 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
6659 : return false;
6660 : }
6661 : if (!iter.valueIsIterable()) {
6662 : mUnion.DestroyStringSequence();
6663 : tryNext = true;
6664 : return true;
6665 : }
6666 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
6667 : JS::Rooted<JS::Value> temp(cx);
6668 : while (true) {
6669 : bool done;
6670 : if (!iter.next(&temp, &done)) {
6671 : return false;
6672 : }
6673 : if (done) {
6674 : break;
6675 : }
6676 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
6677 : if (!slotPtr) {
6678 : JS_ReportOutOfMemory(cx);
6679 : return false;
6680 : }
6681 : nsString& slot = *slotPtr;
6682 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
6683 : return false;
6684 : }
6685 : }
6686 : }
6687 : return true;
6688 : }
6689 :
6690 : inline bool
6691 : TrySetToConstrainDOMStringParameters(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6692 : {
6693 : tryNext = false;
6694 : { // scope for memberSlot
6695 : binding_detail::FastConstrainDOMStringParameters& memberSlot = RawSetAsConstrainDOMStringParameters();
6696 : if (!IsConvertibleToDictionary(value)) {
6697 : mUnion.DestroyConstrainDOMStringParameters();
6698 : tryNext = true;
6699 : return true;
6700 : }
6701 : if (!memberSlot.Init(cx, value, "Member of StringOrStringSequenceOrConstrainDOMStringParameters", passedToJSImpl)) {
6702 : return false;
6703 : }
6704 : }
6705 : return true;
6706 : }
6707 :
6708 : private:
6709 : inline binding_detail::FakeString&
6710 : RawSetAsString()
6711 : {
6712 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6713 : mUnion.mType = mUnion.eString;
6714 : return mUnion.mValue.mString.SetValue();
6715 : }
6716 :
6717 : inline binding_detail::AutoSequence<nsString>&
6718 : RawSetAsStringSequence()
6719 : {
6720 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6721 : mUnion.mType = mUnion.eStringSequence;
6722 : return mUnion.mValue.mStringSequence.SetValue();
6723 : }
6724 :
6725 : inline binding_detail::FastConstrainDOMStringParameters&
6726 : RawSetAsConstrainDOMStringParameters()
6727 : {
6728 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6729 : mUnion.mType = mUnion.eConstrainDOMStringParameters;
6730 : return mUnion.mValue.mConstrainDOMStringParameters.SetValue();
6731 : }
6732 : };
6733 :
6734 : class StringOrTestInterfaceJSOrNullArgument
6735 : {
6736 : StringOrTestInterfaceJSOrNull& mUnion;
6737 :
6738 : StringOrTestInterfaceJSOrNullArgument(const StringOrTestInterfaceJSOrNullArgument&) = delete;
6739 : StringOrTestInterfaceJSOrNullArgument& operator=(const StringOrTestInterfaceJSOrNullArgument&) = delete;
6740 : public:
6741 : explicit inline StringOrTestInterfaceJSOrNullArgument(const StringOrTestInterfaceJSOrNull& aUnion)
6742 : : mUnion(const_cast<StringOrTestInterfaceJSOrNull&>(aUnion))
6743 : {
6744 : }
6745 :
6746 : inline bool
6747 : SetNull()
6748 : {
6749 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6750 : mUnion.mType = mUnion.eNull;
6751 : return true;
6752 : }
6753 :
6754 : inline bool
6755 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6756 : {
6757 : tryNext = false;
6758 : { // scope for memberSlot
6759 : binding_detail::FakeString& memberSlot = RawSetAsString();
6760 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6761 : return false;
6762 : }
6763 : }
6764 : return true;
6765 : }
6766 :
6767 : inline void
6768 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6769 : {
6770 : RawSetAsString().Rebind(aData, aLength);
6771 : }
6772 :
6773 : inline bool
6774 : TrySetToTestInterfaceJS(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6775 : {
6776 : tryNext = false;
6777 : { // scope for memberSlot
6778 : NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
6779 : {
6780 : nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot);
6781 : if (NS_FAILED(rv)) {
6782 : mUnion.DestroyTestInterfaceJS();
6783 : tryNext = true;
6784 : return true;
6785 : }
6786 : }
6787 : }
6788 : return true;
6789 : }
6790 :
6791 : private:
6792 : inline binding_detail::FakeString&
6793 : RawSetAsString()
6794 : {
6795 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6796 : mUnion.mType = mUnion.eString;
6797 : return mUnion.mValue.mString.SetValue();
6798 : }
6799 :
6800 : inline NonNull<mozilla::dom::TestInterfaceJS>&
6801 : RawSetAsTestInterfaceJS()
6802 : {
6803 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6804 : mUnion.mType = mUnion.eTestInterfaceJS;
6805 : return mUnion.mValue.mTestInterfaceJS.SetValue();
6806 : }
6807 : };
6808 :
6809 : class StringOrWorkerOptionsArgument
6810 : {
6811 : StringOrWorkerOptions& mUnion;
6812 :
6813 : StringOrWorkerOptionsArgument(const StringOrWorkerOptionsArgument&) = delete;
6814 : StringOrWorkerOptionsArgument& operator=(const StringOrWorkerOptionsArgument&) = delete;
6815 : public:
6816 0 : explicit inline StringOrWorkerOptionsArgument(const StringOrWorkerOptions& aUnion)
6817 0 : : mUnion(const_cast<StringOrWorkerOptions&>(aUnion))
6818 : {
6819 0 : }
6820 :
6821 : inline bool
6822 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6823 : {
6824 0 : tryNext = false;
6825 : { // scope for memberSlot
6826 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
6827 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
6828 0 : return false;
6829 : }
6830 : }
6831 0 : return true;
6832 : }
6833 :
6834 : inline void
6835 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
6836 : {
6837 : RawSetAsString().Rebind(aData, aLength);
6838 : }
6839 :
6840 : inline bool
6841 0 : TrySetToWorkerOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6842 : {
6843 0 : tryNext = false;
6844 : { // scope for memberSlot
6845 0 : binding_detail::FastWorkerOptions& memberSlot = RawSetAsWorkerOptions();
6846 0 : if (!IsConvertibleToDictionary(value)) {
6847 0 : mUnion.DestroyWorkerOptions();
6848 0 : tryNext = true;
6849 0 : return true;
6850 : }
6851 0 : if (!memberSlot.Init(cx, value, "Member of StringOrWorkerOptions", passedToJSImpl)) {
6852 0 : return false;
6853 : }
6854 : }
6855 0 : return true;
6856 : }
6857 :
6858 : private:
6859 : inline binding_detail::FakeString&
6860 0 : RawSetAsString()
6861 : {
6862 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6863 0 : mUnion.mType = mUnion.eString;
6864 0 : return mUnion.mValue.mString.SetValue();
6865 : }
6866 :
6867 : inline binding_detail::FastWorkerOptions&
6868 0 : RawSetAsWorkerOptions()
6869 : {
6870 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6871 0 : mUnion.mType = mUnion.eWorkerOptions;
6872 0 : return mUnion.mValue.mWorkerOptions.SetValue();
6873 : }
6874 : };
6875 :
6876 : class StringSequenceOrEventInitArgument
6877 : {
6878 : StringSequenceOrEventInit& mUnion;
6879 :
6880 : StringSequenceOrEventInitArgument(const StringSequenceOrEventInitArgument&) = delete;
6881 : StringSequenceOrEventInitArgument& operator=(const StringSequenceOrEventInitArgument&) = delete;
6882 : public:
6883 : explicit inline StringSequenceOrEventInitArgument(const StringSequenceOrEventInit& aUnion)
6884 : : mUnion(const_cast<StringSequenceOrEventInit&>(aUnion))
6885 : {
6886 : }
6887 :
6888 : inline bool
6889 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6890 : {
6891 : tryNext = false;
6892 : { // scope for memberSlot
6893 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
6894 : JS::ForOfIterator iter(cx);
6895 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
6896 : return false;
6897 : }
6898 : if (!iter.valueIsIterable()) {
6899 : mUnion.DestroyStringSequence();
6900 : tryNext = true;
6901 : return true;
6902 : }
6903 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
6904 : JS::Rooted<JS::Value> temp(cx);
6905 : while (true) {
6906 : bool done;
6907 : if (!iter.next(&temp, &done)) {
6908 : return false;
6909 : }
6910 : if (done) {
6911 : break;
6912 : }
6913 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
6914 : if (!slotPtr) {
6915 : JS_ReportOutOfMemory(cx);
6916 : return false;
6917 : }
6918 : nsString& slot = *slotPtr;
6919 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
6920 : return false;
6921 : }
6922 : }
6923 : }
6924 : return true;
6925 : }
6926 :
6927 : inline bool
6928 : TrySetToEventInit(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6929 : {
6930 : tryNext = false;
6931 : { // scope for memberSlot
6932 : binding_detail::FastEventInit& memberSlot = RawSetAsEventInit();
6933 : if (!IsConvertibleToDictionary(value)) {
6934 : mUnion.DestroyEventInit();
6935 : tryNext = true;
6936 : return true;
6937 : }
6938 : if (!memberSlot.Init(cx, value, "Member of StringSequenceOrEventInit", passedToJSImpl)) {
6939 : return false;
6940 : }
6941 : }
6942 : return true;
6943 : }
6944 :
6945 : private:
6946 : inline binding_detail::AutoSequence<nsString>&
6947 : RawSetAsStringSequence()
6948 : {
6949 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6950 : mUnion.mType = mUnion.eStringSequence;
6951 : return mUnion.mValue.mStringSequence.SetValue();
6952 : }
6953 :
6954 : inline binding_detail::FastEventInit&
6955 : RawSetAsEventInit()
6956 : {
6957 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
6958 : mUnion.mType = mUnion.eEventInit;
6959 : return mUnion.mValue.mEventInit.SetValue();
6960 : }
6961 : };
6962 :
6963 : class StringSequenceOrStringArgument
6964 : {
6965 : StringSequenceOrString& mUnion;
6966 :
6967 : StringSequenceOrStringArgument(const StringSequenceOrStringArgument&) = delete;
6968 : StringSequenceOrStringArgument& operator=(const StringSequenceOrStringArgument&) = delete;
6969 : public:
6970 0 : explicit inline StringSequenceOrStringArgument(const StringSequenceOrString& aUnion)
6971 0 : : mUnion(const_cast<StringSequenceOrString&>(aUnion))
6972 : {
6973 0 : }
6974 :
6975 : inline bool
6976 0 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
6977 : {
6978 0 : tryNext = false;
6979 : { // scope for memberSlot
6980 0 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
6981 0 : JS::ForOfIterator iter(cx);
6982 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
6983 0 : return false;
6984 : }
6985 0 : if (!iter.valueIsIterable()) {
6986 0 : mUnion.DestroyStringSequence();
6987 0 : tryNext = true;
6988 0 : return true;
6989 : }
6990 0 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
6991 0 : JS::Rooted<JS::Value> temp(cx);
6992 : while (true) {
6993 : bool done;
6994 0 : if (!iter.next(&temp, &done)) {
6995 0 : return false;
6996 : }
6997 0 : if (done) {
6998 0 : break;
6999 : }
7000 0 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
7001 0 : if (!slotPtr) {
7002 0 : JS_ReportOutOfMemory(cx);
7003 0 : return false;
7004 : }
7005 0 : nsString& slot = *slotPtr;
7006 0 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7007 0 : return false;
7008 : }
7009 0 : }
7010 : }
7011 0 : return true;
7012 : }
7013 :
7014 : inline bool
7015 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7016 : {
7017 0 : tryNext = false;
7018 : { // scope for memberSlot
7019 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
7020 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
7021 0 : return false;
7022 : }
7023 : }
7024 0 : return true;
7025 : }
7026 :
7027 : inline void
7028 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
7029 : {
7030 : RawSetAsString().Rebind(aData, aLength);
7031 : }
7032 :
7033 : private:
7034 : inline binding_detail::AutoSequence<nsString>&
7035 0 : RawSetAsStringSequence()
7036 : {
7037 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7038 0 : mUnion.mType = mUnion.eStringSequence;
7039 0 : return mUnion.mValue.mStringSequence.SetValue();
7040 : }
7041 :
7042 : inline binding_detail::FakeString&
7043 0 : RawSetAsString()
7044 : {
7045 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7046 0 : mUnion.mType = mUnion.eString;
7047 0 : return mUnion.mValue.mString.SetValue();
7048 : }
7049 : };
7050 :
7051 : class StringSequenceOrStringStringRecordArgument
7052 : {
7053 : StringSequenceOrStringStringRecord& mUnion;
7054 :
7055 : StringSequenceOrStringStringRecordArgument(const StringSequenceOrStringStringRecordArgument&) = delete;
7056 : StringSequenceOrStringStringRecordArgument& operator=(const StringSequenceOrStringStringRecordArgument&) = delete;
7057 : public:
7058 : explicit inline StringSequenceOrStringStringRecordArgument(const StringSequenceOrStringStringRecord& aUnion)
7059 : : mUnion(const_cast<StringSequenceOrStringStringRecord&>(aUnion))
7060 : {
7061 : }
7062 :
7063 : inline bool
7064 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7065 : {
7066 : tryNext = false;
7067 : { // scope for memberSlot
7068 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
7069 : JS::ForOfIterator iter(cx);
7070 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
7071 : return false;
7072 : }
7073 : if (!iter.valueIsIterable()) {
7074 : mUnion.DestroyStringSequence();
7075 : tryNext = true;
7076 : return true;
7077 : }
7078 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
7079 : JS::Rooted<JS::Value> temp(cx);
7080 : while (true) {
7081 : bool done;
7082 : if (!iter.next(&temp, &done)) {
7083 : return false;
7084 : }
7085 : if (done) {
7086 : break;
7087 : }
7088 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
7089 : if (!slotPtr) {
7090 : JS_ReportOutOfMemory(cx);
7091 : return false;
7092 : }
7093 : nsString& slot = *slotPtr;
7094 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7095 : return false;
7096 : }
7097 : }
7098 : }
7099 : return true;
7100 : }
7101 :
7102 : inline bool
7103 : TrySetToStringStringRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7104 : {
7105 : tryNext = false;
7106 : { // scope for memberSlot
7107 : Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
7108 : auto& recordEntries = memberSlot.Entries();
7109 :
7110 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
7111 : JS::AutoIdVector ids(cx);
7112 : if (!js::GetPropertyKeys(cx, recordObj,
7113 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
7114 : return false;
7115 : }
7116 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
7117 : JS_ReportOutOfMemory(cx);
7118 : return false;
7119 : }
7120 : JS::Rooted<JS::Value> propNameValue(cx);
7121 : JS::Rooted<JS::Value> temp(cx);
7122 : JS::Rooted<jsid> curId(cx);
7123 : JS::Rooted<JS::Value> idVal(cx);
7124 : // Use a hashset to keep track of ids seen, to avoid
7125 : // introducing nasty O(N^2) behavior scanning for them all the
7126 : // time. Ideally we'd use a data structure with O(1) lookup
7127 : // _and_ ordering for the MozMap, but we don't have one lying
7128 : // around.
7129 : nsTHashtable<nsStringHashKey> idsSeen;
7130 : for (size_t i = 0; i < ids.length(); ++i) {
7131 : curId = ids[i];
7132 :
7133 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
7134 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
7135 : &desc)) {
7136 : return false;
7137 : }
7138 :
7139 : if (!desc.object() /* == undefined in spec terms */ ||
7140 : !desc.enumerable()) {
7141 : continue;
7142 : }
7143 :
7144 : idVal = js::IdToValue(curId);
7145 : nsString propName;
7146 : // This will just throw if idVal is a Symbol, like the spec says
7147 : // to do.
7148 : if (!ConvertJSValueToString(cx, idVal, propName)) {
7149 : return false;
7150 : }
7151 :
7152 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
7153 : return false;
7154 : }
7155 :
7156 : Record<nsString, nsString>::EntryType* entry;
7157 : if (!idsSeen.EnsureInserted(propName)) {
7158 : // Find the existing entry.
7159 : auto idx = recordEntries.IndexOf(propName);
7160 : MOZ_ASSERT(idx != recordEntries.NoIndex,
7161 : "Why is it not found?");
7162 : // Now blow it away to make it look like it was just added
7163 : // to the array, because it's not obvious that it's
7164 : // safe to write to its already-initialized mValue via our
7165 : // normal codegen conversions. For example, the value
7166 : // could be a union and this would change its type, but
7167 : // codegen assumes we won't do that.
7168 : entry = recordEntries.ReconstructElementAt(idx);
7169 : } else {
7170 : // Safe to do an infallible append here, because we did a
7171 : // SetCapacity above to the right capacity.
7172 : entry = recordEntries.AppendElement();
7173 : }
7174 : entry->mKey = propName;
7175 : nsString& slot = entry->mValue;
7176 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7177 : return false;
7178 : }
7179 : }
7180 : }
7181 : return true;
7182 : }
7183 :
7184 : private:
7185 : inline binding_detail::AutoSequence<nsString>&
7186 : RawSetAsStringSequence()
7187 : {
7188 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7189 : mUnion.mType = mUnion.eStringSequence;
7190 : return mUnion.mValue.mStringSequence.SetValue();
7191 : }
7192 :
7193 : inline Record<nsString, nsString>&
7194 : RawSetAsStringStringRecord()
7195 : {
7196 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7197 : mUnion.mType = mUnion.eStringStringRecord;
7198 : return mUnion.mValue.mStringStringRecord.SetValue();
7199 : }
7200 : };
7201 :
7202 : class StringStringRecordOrStringArgument
7203 : {
7204 : StringStringRecordOrString& mUnion;
7205 :
7206 : StringStringRecordOrStringArgument(const StringStringRecordOrStringArgument&) = delete;
7207 : StringStringRecordOrStringArgument& operator=(const StringStringRecordOrStringArgument&) = delete;
7208 : public:
7209 : explicit inline StringStringRecordOrStringArgument(const StringStringRecordOrString& aUnion)
7210 : : mUnion(const_cast<StringStringRecordOrString&>(aUnion))
7211 : {
7212 : }
7213 :
7214 : inline bool
7215 : TrySetToStringStringRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7216 : {
7217 : tryNext = false;
7218 : { // scope for memberSlot
7219 : Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
7220 : auto& recordEntries = memberSlot.Entries();
7221 :
7222 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
7223 : JS::AutoIdVector ids(cx);
7224 : if (!js::GetPropertyKeys(cx, recordObj,
7225 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
7226 : return false;
7227 : }
7228 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
7229 : JS_ReportOutOfMemory(cx);
7230 : return false;
7231 : }
7232 : JS::Rooted<JS::Value> propNameValue(cx);
7233 : JS::Rooted<JS::Value> temp(cx);
7234 : JS::Rooted<jsid> curId(cx);
7235 : JS::Rooted<JS::Value> idVal(cx);
7236 : // Use a hashset to keep track of ids seen, to avoid
7237 : // introducing nasty O(N^2) behavior scanning for them all the
7238 : // time. Ideally we'd use a data structure with O(1) lookup
7239 : // _and_ ordering for the MozMap, but we don't have one lying
7240 : // around.
7241 : nsTHashtable<nsStringHashKey> idsSeen;
7242 : for (size_t i = 0; i < ids.length(); ++i) {
7243 : curId = ids[i];
7244 :
7245 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
7246 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
7247 : &desc)) {
7248 : return false;
7249 : }
7250 :
7251 : if (!desc.object() /* == undefined in spec terms */ ||
7252 : !desc.enumerable()) {
7253 : continue;
7254 : }
7255 :
7256 : idVal = js::IdToValue(curId);
7257 : nsString propName;
7258 : // This will just throw if idVal is a Symbol, like the spec says
7259 : // to do.
7260 : if (!ConvertJSValueToString(cx, idVal, propName)) {
7261 : return false;
7262 : }
7263 :
7264 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
7265 : return false;
7266 : }
7267 :
7268 : Record<nsString, nsString>::EntryType* entry;
7269 : if (!idsSeen.EnsureInserted(propName)) {
7270 : // Find the existing entry.
7271 : auto idx = recordEntries.IndexOf(propName);
7272 : MOZ_ASSERT(idx != recordEntries.NoIndex,
7273 : "Why is it not found?");
7274 : // Now blow it away to make it look like it was just added
7275 : // to the array, because it's not obvious that it's
7276 : // safe to write to its already-initialized mValue via our
7277 : // normal codegen conversions. For example, the value
7278 : // could be a union and this would change its type, but
7279 : // codegen assumes we won't do that.
7280 : entry = recordEntries.ReconstructElementAt(idx);
7281 : } else {
7282 : // Safe to do an infallible append here, because we did a
7283 : // SetCapacity above to the right capacity.
7284 : entry = recordEntries.AppendElement();
7285 : }
7286 : entry->mKey = propName;
7287 : nsString& slot = entry->mValue;
7288 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7289 : return false;
7290 : }
7291 : }
7292 : }
7293 : return true;
7294 : }
7295 :
7296 : inline bool
7297 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7298 : {
7299 : tryNext = false;
7300 : { // scope for memberSlot
7301 : binding_detail::FakeString& memberSlot = RawSetAsString();
7302 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
7303 : return false;
7304 : }
7305 : }
7306 : return true;
7307 : }
7308 :
7309 : inline void
7310 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
7311 : {
7312 : RawSetAsString().Rebind(aData, aLength);
7313 : }
7314 :
7315 : private:
7316 : inline Record<nsString, nsString>&
7317 : RawSetAsStringStringRecord()
7318 : {
7319 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7320 : mUnion.mType = mUnion.eStringStringRecord;
7321 : return mUnion.mValue.mStringStringRecord.SetValue();
7322 : }
7323 :
7324 : inline binding_detail::FakeString&
7325 : RawSetAsString()
7326 : {
7327 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7328 : mUnion.mType = mUnion.eString;
7329 : return mUnion.mValue.mString.SetValue();
7330 : }
7331 : };
7332 :
7333 : class StringStringRecordOrStringSequenceArgument
7334 : {
7335 : StringStringRecordOrStringSequence& mUnion;
7336 :
7337 : StringStringRecordOrStringSequenceArgument(const StringStringRecordOrStringSequenceArgument&) = delete;
7338 : StringStringRecordOrStringSequenceArgument& operator=(const StringStringRecordOrStringSequenceArgument&) = delete;
7339 : public:
7340 : explicit inline StringStringRecordOrStringSequenceArgument(const StringStringRecordOrStringSequence& aUnion)
7341 : : mUnion(const_cast<StringStringRecordOrStringSequence&>(aUnion))
7342 : {
7343 : }
7344 :
7345 : inline bool
7346 : TrySetToStringStringRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7347 : {
7348 : tryNext = false;
7349 : { // scope for memberSlot
7350 : Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
7351 : auto& recordEntries = memberSlot.Entries();
7352 :
7353 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
7354 : JS::AutoIdVector ids(cx);
7355 : if (!js::GetPropertyKeys(cx, recordObj,
7356 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
7357 : return false;
7358 : }
7359 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
7360 : JS_ReportOutOfMemory(cx);
7361 : return false;
7362 : }
7363 : JS::Rooted<JS::Value> propNameValue(cx);
7364 : JS::Rooted<JS::Value> temp(cx);
7365 : JS::Rooted<jsid> curId(cx);
7366 : JS::Rooted<JS::Value> idVal(cx);
7367 : // Use a hashset to keep track of ids seen, to avoid
7368 : // introducing nasty O(N^2) behavior scanning for them all the
7369 : // time. Ideally we'd use a data structure with O(1) lookup
7370 : // _and_ ordering for the MozMap, but we don't have one lying
7371 : // around.
7372 : nsTHashtable<nsStringHashKey> idsSeen;
7373 : for (size_t i = 0; i < ids.length(); ++i) {
7374 : curId = ids[i];
7375 :
7376 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
7377 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
7378 : &desc)) {
7379 : return false;
7380 : }
7381 :
7382 : if (!desc.object() /* == undefined in spec terms */ ||
7383 : !desc.enumerable()) {
7384 : continue;
7385 : }
7386 :
7387 : idVal = js::IdToValue(curId);
7388 : nsString propName;
7389 : // This will just throw if idVal is a Symbol, like the spec says
7390 : // to do.
7391 : if (!ConvertJSValueToString(cx, idVal, propName)) {
7392 : return false;
7393 : }
7394 :
7395 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
7396 : return false;
7397 : }
7398 :
7399 : Record<nsString, nsString>::EntryType* entry;
7400 : if (!idsSeen.EnsureInserted(propName)) {
7401 : // Find the existing entry.
7402 : auto idx = recordEntries.IndexOf(propName);
7403 : MOZ_ASSERT(idx != recordEntries.NoIndex,
7404 : "Why is it not found?");
7405 : // Now blow it away to make it look like it was just added
7406 : // to the array, because it's not obvious that it's
7407 : // safe to write to its already-initialized mValue via our
7408 : // normal codegen conversions. For example, the value
7409 : // could be a union and this would change its type, but
7410 : // codegen assumes we won't do that.
7411 : entry = recordEntries.ReconstructElementAt(idx);
7412 : } else {
7413 : // Safe to do an infallible append here, because we did a
7414 : // SetCapacity above to the right capacity.
7415 : entry = recordEntries.AppendElement();
7416 : }
7417 : entry->mKey = propName;
7418 : nsString& slot = entry->mValue;
7419 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7420 : return false;
7421 : }
7422 : }
7423 : }
7424 : return true;
7425 : }
7426 :
7427 : inline bool
7428 : TrySetToStringSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7429 : {
7430 : tryNext = false;
7431 : { // scope for memberSlot
7432 : binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
7433 : JS::ForOfIterator iter(cx);
7434 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
7435 : return false;
7436 : }
7437 : if (!iter.valueIsIterable()) {
7438 : mUnion.DestroyStringSequence();
7439 : tryNext = true;
7440 : return true;
7441 : }
7442 : binding_detail::AutoSequence<nsString> &arr = memberSlot;
7443 : JS::Rooted<JS::Value> temp(cx);
7444 : while (true) {
7445 : bool done;
7446 : if (!iter.next(&temp, &done)) {
7447 : return false;
7448 : }
7449 : if (done) {
7450 : break;
7451 : }
7452 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
7453 : if (!slotPtr) {
7454 : JS_ReportOutOfMemory(cx);
7455 : return false;
7456 : }
7457 : nsString& slot = *slotPtr;
7458 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
7459 : return false;
7460 : }
7461 : }
7462 : }
7463 : return true;
7464 : }
7465 :
7466 : private:
7467 : inline Record<nsString, nsString>&
7468 : RawSetAsStringStringRecord()
7469 : {
7470 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7471 : mUnion.mType = mUnion.eStringStringRecord;
7472 : return mUnion.mValue.mStringStringRecord.SetValue();
7473 : }
7474 :
7475 : inline binding_detail::AutoSequence<nsString>&
7476 : RawSetAsStringSequence()
7477 : {
7478 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7479 : mUnion.mType = mUnion.eStringSequence;
7480 : return mUnion.mValue.mStringSequence.SetValue();
7481 : }
7482 : };
7483 :
7484 : class SupportedTypeOrObjectArgument
7485 : {
7486 : SupportedTypeOrObject& mUnion;
7487 :
7488 : SupportedTypeOrObjectArgument(const SupportedTypeOrObjectArgument&) = delete;
7489 : SupportedTypeOrObjectArgument& operator=(const SupportedTypeOrObjectArgument&) = delete;
7490 : public:
7491 : explicit inline SupportedTypeOrObjectArgument(const SupportedTypeOrObject& aUnion)
7492 : : mUnion(const_cast<SupportedTypeOrObject&>(aUnion))
7493 : {
7494 : }
7495 :
7496 : inline bool
7497 : TrySetToSupportedType(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7498 : {
7499 : tryNext = false;
7500 : { // scope for memberSlot
7501 : SupportedType& memberSlot = RawSetAsSupportedType();
7502 : {
7503 : int index;
7504 : if (!FindEnumStringIndex<true>(cx, value, SupportedTypeValues::strings, "SupportedType", "Member of SupportedTypeOrObject", &index)) {
7505 : return false;
7506 : }
7507 : MOZ_ASSERT(index >= 0);
7508 : memberSlot = static_cast<SupportedType>(index);
7509 : }
7510 : }
7511 : return true;
7512 : }
7513 :
7514 : inline bool
7515 : SetToObject(JSContext* cx, JSObject* obj, bool passedToJSImpl = false)
7516 : {
7517 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7518 : mUnion.mValue.mObject.SetValue(cx, obj);
7519 : mUnion.mType = mUnion.eObject;
7520 : if (passedToJSImpl && !CallerSubsumes(obj)) {
7521 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
7522 : return false;
7523 : }
7524 : return true;
7525 : }
7526 :
7527 : private:
7528 : inline SupportedType&
7529 : RawSetAsSupportedType()
7530 : {
7531 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7532 : mUnion.mType = mUnion.eSupportedType;
7533 : return mUnion.mValue.mSupportedType.SetValue();
7534 : }
7535 : };
7536 :
7537 : class TestInterfaceJSOrLongArgument
7538 : {
7539 : TestInterfaceJSOrLong& mUnion;
7540 :
7541 : TestInterfaceJSOrLongArgument(const TestInterfaceJSOrLongArgument&) = delete;
7542 : TestInterfaceJSOrLongArgument& operator=(const TestInterfaceJSOrLongArgument&) = delete;
7543 : public:
7544 0 : explicit inline TestInterfaceJSOrLongArgument(const TestInterfaceJSOrLong& aUnion)
7545 0 : : mUnion(const_cast<TestInterfaceJSOrLong&>(aUnion))
7546 : {
7547 0 : }
7548 :
7549 : inline bool
7550 0 : TrySetToTestInterfaceJS(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7551 : {
7552 0 : tryNext = false;
7553 : { // scope for memberSlot
7554 0 : NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
7555 : {
7556 0 : nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot);
7557 0 : if (NS_FAILED(rv)) {
7558 0 : mUnion.DestroyTestInterfaceJS();
7559 0 : tryNext = true;
7560 0 : return true;
7561 : }
7562 : }
7563 : }
7564 0 : return true;
7565 : }
7566 :
7567 : inline bool
7568 0 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7569 : {
7570 0 : tryNext = false;
7571 : { // scope for memberSlot
7572 0 : int32_t& memberSlot = RawSetAsLong();
7573 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
7574 0 : return false;
7575 : }
7576 : }
7577 0 : return true;
7578 : }
7579 :
7580 : private:
7581 : inline NonNull<mozilla::dom::TestInterfaceJS>&
7582 0 : RawSetAsTestInterfaceJS()
7583 : {
7584 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7585 0 : mUnion.mType = mUnion.eTestInterfaceJS;
7586 0 : return mUnion.mValue.mTestInterfaceJS.SetValue();
7587 : }
7588 :
7589 : inline int32_t&
7590 0 : RawSetAsLong()
7591 : {
7592 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7593 0 : mUnion.mType = mUnion.eLong;
7594 0 : return mUnion.mValue.mLong.SetValue();
7595 : }
7596 : };
7597 :
7598 : class TestInterfaceJSOrNullOrStringArgument
7599 : {
7600 : TestInterfaceJSOrNullOrString& mUnion;
7601 :
7602 : TestInterfaceJSOrNullOrStringArgument(const TestInterfaceJSOrNullOrStringArgument&) = delete;
7603 : TestInterfaceJSOrNullOrStringArgument& operator=(const TestInterfaceJSOrNullOrStringArgument&) = delete;
7604 : public:
7605 0 : explicit inline TestInterfaceJSOrNullOrStringArgument(const TestInterfaceJSOrNullOrString& aUnion)
7606 0 : : mUnion(const_cast<TestInterfaceJSOrNullOrString&>(aUnion))
7607 : {
7608 0 : }
7609 :
7610 : inline bool
7611 0 : SetNull()
7612 : {
7613 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7614 0 : mUnion.mType = mUnion.eNull;
7615 0 : return true;
7616 : }
7617 :
7618 : inline bool
7619 0 : TrySetToTestInterfaceJS(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7620 : {
7621 0 : tryNext = false;
7622 : { // scope for memberSlot
7623 0 : NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
7624 : {
7625 0 : nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot);
7626 0 : if (NS_FAILED(rv)) {
7627 0 : mUnion.DestroyTestInterfaceJS();
7628 0 : tryNext = true;
7629 0 : return true;
7630 : }
7631 : }
7632 : }
7633 0 : return true;
7634 : }
7635 :
7636 : inline bool
7637 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7638 : {
7639 0 : tryNext = false;
7640 : { // scope for memberSlot
7641 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
7642 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
7643 0 : return false;
7644 : }
7645 : }
7646 0 : return true;
7647 : }
7648 :
7649 : inline void
7650 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
7651 : {
7652 : RawSetAsString().Rebind(aData, aLength);
7653 : }
7654 :
7655 : private:
7656 : inline NonNull<mozilla::dom::TestInterfaceJS>&
7657 0 : RawSetAsTestInterfaceJS()
7658 : {
7659 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7660 0 : mUnion.mType = mUnion.eTestInterfaceJS;
7661 0 : return mUnion.mValue.mTestInterfaceJS.SetValue();
7662 : }
7663 :
7664 : inline binding_detail::FakeString&
7665 0 : RawSetAsString()
7666 : {
7667 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7668 0 : mUnion.mType = mUnion.eString;
7669 0 : return mUnion.mValue.mString.SetValue();
7670 : }
7671 : };
7672 :
7673 : class TestInterfaceJSUnionableDictionaryOrLongArgument
7674 : {
7675 : TestInterfaceJSUnionableDictionaryOrLong& mUnion;
7676 :
7677 : TestInterfaceJSUnionableDictionaryOrLongArgument(const TestInterfaceJSUnionableDictionaryOrLongArgument&) = delete;
7678 : TestInterfaceJSUnionableDictionaryOrLongArgument& operator=(const TestInterfaceJSUnionableDictionaryOrLongArgument&) = delete;
7679 : public:
7680 0 : explicit inline TestInterfaceJSUnionableDictionaryOrLongArgument(const TestInterfaceJSUnionableDictionaryOrLong& aUnion)
7681 0 : : mUnion(const_cast<TestInterfaceJSUnionableDictionaryOrLong&>(aUnion))
7682 : {
7683 0 : }
7684 :
7685 : inline bool
7686 0 : TrySetToTestInterfaceJSUnionableDictionary(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7687 : {
7688 0 : tryNext = false;
7689 : { // scope for memberSlot
7690 0 : RootedDictionary<binding_detail::FastTestInterfaceJSUnionableDictionary>& memberSlot = RawSetAsTestInterfaceJSUnionableDictionary(cx);
7691 0 : if (!IsConvertibleToDictionary(value)) {
7692 0 : mUnion.DestroyTestInterfaceJSUnionableDictionary();
7693 0 : tryNext = true;
7694 0 : return true;
7695 : }
7696 0 : if (!memberSlot.Init(cx, value, "Member of TestInterfaceJSUnionableDictionaryOrLong", passedToJSImpl)) {
7697 0 : return false;
7698 : }
7699 : }
7700 0 : return true;
7701 : }
7702 :
7703 : inline bool
7704 0 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7705 : {
7706 0 : tryNext = false;
7707 : { // scope for memberSlot
7708 0 : int32_t& memberSlot = RawSetAsLong();
7709 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
7710 0 : return false;
7711 : }
7712 : }
7713 0 : return true;
7714 : }
7715 :
7716 : private:
7717 : inline RootedDictionary<binding_detail::FastTestInterfaceJSUnionableDictionary>&
7718 0 : RawSetAsTestInterfaceJSUnionableDictionary(JSContext* cx)
7719 : {
7720 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7721 0 : mUnion.mType = mUnion.eTestInterfaceJSUnionableDictionary;
7722 0 : return mUnion.mValue.mTestInterfaceJSUnionableDictionary.SetValue(cx);
7723 : }
7724 :
7725 : inline int32_t&
7726 0 : RawSetAsLong()
7727 : {
7728 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7729 0 : mUnion.mType = mUnion.eLong;
7730 0 : return mUnion.mValue.mLong.SetValue();
7731 : }
7732 : };
7733 :
7734 : class TextOrElementOrDocumentArgument
7735 : {
7736 : TextOrElementOrDocument& mUnion;
7737 :
7738 : TextOrElementOrDocumentArgument(const TextOrElementOrDocumentArgument&) = delete;
7739 : TextOrElementOrDocumentArgument& operator=(const TextOrElementOrDocumentArgument&) = delete;
7740 : public:
7741 0 : explicit inline TextOrElementOrDocumentArgument(const TextOrElementOrDocument& aUnion)
7742 0 : : mUnion(const_cast<TextOrElementOrDocument&>(aUnion))
7743 : {
7744 0 : }
7745 :
7746 : inline bool
7747 0 : TrySetToText(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7748 : {
7749 0 : tryNext = false;
7750 : { // scope for memberSlot
7751 0 : NonNull<mozilla::dom::Text>& memberSlot = RawSetAsText();
7752 : {
7753 0 : nsresult rv = UnwrapObject<prototypes::id::Text, mozilla::dom::Text>(value, memberSlot);
7754 0 : if (NS_FAILED(rv)) {
7755 0 : mUnion.DestroyText();
7756 0 : tryNext = true;
7757 0 : return true;
7758 : }
7759 : }
7760 : }
7761 0 : return true;
7762 : }
7763 :
7764 : inline bool
7765 0 : TrySetToElement(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7766 : {
7767 0 : tryNext = false;
7768 : { // scope for memberSlot
7769 0 : NonNull<mozilla::dom::Element>& memberSlot = RawSetAsElement();
7770 : {
7771 0 : nsresult rv = UnwrapObject<prototypes::id::Element, mozilla::dom::Element>(value, memberSlot);
7772 0 : if (NS_FAILED(rv)) {
7773 0 : mUnion.DestroyElement();
7774 0 : tryNext = true;
7775 0 : return true;
7776 : }
7777 : }
7778 : }
7779 0 : return true;
7780 : }
7781 :
7782 : inline bool
7783 0 : TrySetToDocument(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7784 : {
7785 0 : tryNext = false;
7786 : { // scope for memberSlot
7787 0 : NonNull<nsIDocument>& memberSlot = RawSetAsDocument();
7788 : {
7789 0 : nsresult rv = UnwrapObject<prototypes::id::Document, nsIDocument>(value, memberSlot);
7790 0 : if (NS_FAILED(rv)) {
7791 0 : mUnion.DestroyDocument();
7792 0 : tryNext = true;
7793 0 : return true;
7794 : }
7795 : }
7796 : }
7797 0 : return true;
7798 : }
7799 :
7800 : private:
7801 : inline NonNull<mozilla::dom::Text>&
7802 0 : RawSetAsText()
7803 : {
7804 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7805 0 : mUnion.mType = mUnion.eText;
7806 0 : return mUnion.mValue.mText.SetValue();
7807 : }
7808 :
7809 : inline NonNull<mozilla::dom::Element>&
7810 0 : RawSetAsElement()
7811 : {
7812 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7813 0 : mUnion.mType = mUnion.eElement;
7814 0 : return mUnion.mValue.mElement.SetValue();
7815 : }
7816 :
7817 : inline NonNull<nsIDocument>&
7818 0 : RawSetAsDocument()
7819 : {
7820 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7821 0 : mUnion.mType = mUnion.eDocument;
7822 0 : return mUnion.mValue.mDocument.SetValue();
7823 : }
7824 : };
7825 :
7826 : class USVStringOrLongArgument
7827 : {
7828 : USVStringOrLong& mUnion;
7829 :
7830 : USVStringOrLongArgument(const USVStringOrLongArgument&) = delete;
7831 : USVStringOrLongArgument& operator=(const USVStringOrLongArgument&) = delete;
7832 : public:
7833 : explicit inline USVStringOrLongArgument(const USVStringOrLong& aUnion)
7834 : : mUnion(const_cast<USVStringOrLong&>(aUnion))
7835 : {
7836 : }
7837 :
7838 : inline bool
7839 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7840 : {
7841 : tryNext = false;
7842 : { // scope for memberSlot
7843 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
7844 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
7845 : return false;
7846 : }
7847 : NormalizeUSVString(memberSlot);
7848 : }
7849 : return true;
7850 : }
7851 :
7852 : inline void
7853 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
7854 : {
7855 : RawSetAsUSVString().Rebind(aData, aLength);
7856 : }
7857 :
7858 : inline bool
7859 : TrySetToLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7860 : {
7861 : tryNext = false;
7862 : { // scope for memberSlot
7863 : int32_t& memberSlot = RawSetAsLong();
7864 : if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
7865 : return false;
7866 : }
7867 : }
7868 : return true;
7869 : }
7870 :
7871 : private:
7872 : inline binding_detail::FakeString&
7873 : RawSetAsUSVString()
7874 : {
7875 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7876 : mUnion.mType = mUnion.eUSVString;
7877 : return mUnion.mValue.mUSVString.SetValue();
7878 : }
7879 :
7880 : inline int32_t&
7881 : RawSetAsLong()
7882 : {
7883 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
7884 : mUnion.mType = mUnion.eLong;
7885 : return mUnion.mValue.mLong.SetValue();
7886 : }
7887 : };
7888 :
7889 : class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument
7890 : {
7891 : USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& mUnion;
7892 :
7893 : USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument(const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument&) = delete;
7894 : USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument& operator=(const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument&) = delete;
7895 : public:
7896 0 : explicit inline USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVStringArgument(const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& aUnion)
7897 0 : : mUnion(const_cast<USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString&>(aUnion))
7898 : {
7899 0 : }
7900 :
7901 : inline bool
7902 0 : TrySetToUSVStringSequenceSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7903 : {
7904 0 : tryNext = false;
7905 : { // scope for memberSlot
7906 0 : binding_detail::AutoSequence<Sequence<nsString>>& memberSlot = RawSetAsUSVStringSequenceSequence();
7907 0 : JS::ForOfIterator iter(cx);
7908 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
7909 0 : return false;
7910 : }
7911 0 : if (!iter.valueIsIterable()) {
7912 0 : mUnion.DestroyUSVStringSequenceSequence();
7913 0 : tryNext = true;
7914 0 : return true;
7915 : }
7916 0 : binding_detail::AutoSequence<Sequence<nsString>> &arr = memberSlot;
7917 0 : JS::Rooted<JS::Value> temp(cx);
7918 : while (true) {
7919 : bool done;
7920 0 : if (!iter.next(&temp, &done)) {
7921 0 : return false;
7922 : }
7923 0 : if (done) {
7924 0 : break;
7925 : }
7926 0 : Sequence<nsString>* slotPtr = arr.AppendElement(mozilla::fallible);
7927 0 : if (!slotPtr) {
7928 0 : JS_ReportOutOfMemory(cx);
7929 0 : return false;
7930 : }
7931 0 : Sequence<nsString>& slot = *slotPtr;
7932 0 : if (temp.isObject()) {
7933 0 : JS::ForOfIterator iter1(cx);
7934 0 : if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
7935 0 : return false;
7936 : }
7937 0 : if (!iter1.valueIsIterable()) {
7938 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString");
7939 0 : return false;
7940 : }
7941 0 : Sequence<nsString> &arr1 = slot;
7942 0 : JS::Rooted<JS::Value> temp1(cx);
7943 : while (true) {
7944 : bool done1;
7945 0 : if (!iter1.next(&temp1, &done1)) {
7946 0 : return false;
7947 : }
7948 0 : if (done1) {
7949 0 : break;
7950 : }
7951 0 : nsString* slotPtr1 = arr1.AppendElement(mozilla::fallible);
7952 0 : if (!slotPtr1) {
7953 0 : JS_ReportOutOfMemory(cx);
7954 0 : return false;
7955 : }
7956 0 : nsString& slot1 = *slotPtr1;
7957 0 : if (!ConvertJSValueToString(cx, temp1, eStringify, eStringify, slot1)) {
7958 0 : return false;
7959 : }
7960 0 : NormalizeUSVString(slot1);
7961 0 : }
7962 : } else {
7963 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString");
7964 0 : return false;
7965 : }
7966 0 : }
7967 : }
7968 0 : return true;
7969 : }
7970 :
7971 : inline bool
7972 0 : TrySetToUSVStringUSVStringRecord(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
7973 : {
7974 0 : tryNext = false;
7975 : { // scope for memberSlot
7976 0 : Record<nsString, nsString>& memberSlot = RawSetAsUSVStringUSVStringRecord();
7977 0 : auto& recordEntries = memberSlot.Entries();
7978 :
7979 0 : JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
7980 0 : JS::AutoIdVector ids(cx);
7981 0 : if (!js::GetPropertyKeys(cx, recordObj,
7982 : JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
7983 0 : return false;
7984 : }
7985 0 : if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
7986 0 : JS_ReportOutOfMemory(cx);
7987 0 : return false;
7988 : }
7989 0 : JS::Rooted<JS::Value> propNameValue(cx);
7990 0 : JS::Rooted<JS::Value> temp(cx);
7991 0 : JS::Rooted<jsid> curId(cx);
7992 0 : JS::Rooted<JS::Value> idVal(cx);
7993 : // Use a hashset to keep track of ids seen, to avoid
7994 : // introducing nasty O(N^2) behavior scanning for them all the
7995 : // time. Ideally we'd use a data structure with O(1) lookup
7996 : // _and_ ordering for the MozMap, but we don't have one lying
7997 : // around.
7998 0 : nsTHashtable<nsStringHashKey> idsSeen;
7999 0 : for (size_t i = 0; i < ids.length(); ++i) {
8000 0 : curId = ids[i];
8001 :
8002 0 : JS::Rooted<JS::PropertyDescriptor> desc(cx);
8003 0 : if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
8004 : &desc)) {
8005 0 : return false;
8006 : }
8007 :
8008 0 : if (!desc.object() /* == undefined in spec terms */ ||
8009 0 : !desc.enumerable()) {
8010 0 : continue;
8011 : }
8012 :
8013 0 : idVal = js::IdToValue(curId);
8014 0 : nsString propName;
8015 : // This will just throw if idVal is a Symbol, like the spec says
8016 : // to do.
8017 0 : if (!ConvertJSValueToUSVString(cx, idVal, propName)) {
8018 0 : return false;
8019 : }
8020 :
8021 0 : if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
8022 0 : return false;
8023 : }
8024 :
8025 : Record<nsString, nsString>::EntryType* entry;
8026 0 : if (!idsSeen.EnsureInserted(propName)) {
8027 : // Find the existing entry.
8028 0 : auto idx = recordEntries.IndexOf(propName);
8029 0 : MOZ_ASSERT(idx != recordEntries.NoIndex,
8030 : "Why is it not found?");
8031 : // Now blow it away to make it look like it was just added
8032 : // to the array, because it's not obvious that it's
8033 : // safe to write to its already-initialized mValue via our
8034 : // normal codegen conversions. For example, the value
8035 : // could be a union and this would change its type, but
8036 : // codegen assumes we won't do that.
8037 0 : entry = recordEntries.ReconstructElementAt(idx);
8038 : } else {
8039 : // Safe to do an infallible append here, because we did a
8040 : // SetCapacity above to the right capacity.
8041 0 : entry = recordEntries.AppendElement();
8042 : }
8043 0 : entry->mKey = propName;
8044 0 : nsString& slot = entry->mValue;
8045 0 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
8046 0 : return false;
8047 : }
8048 0 : NormalizeUSVString(slot);
8049 : }
8050 : }
8051 0 : return true;
8052 : }
8053 :
8054 : inline bool
8055 0 : TrySetToUSVString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8056 : {
8057 0 : tryNext = false;
8058 : { // scope for memberSlot
8059 0 : binding_detail::FakeString& memberSlot = RawSetAsUSVString();
8060 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
8061 0 : return false;
8062 : }
8063 0 : NormalizeUSVString(memberSlot);
8064 : }
8065 0 : return true;
8066 : }
8067 :
8068 : inline void
8069 0 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
8070 : {
8071 0 : RawSetAsUSVString().Rebind(aData, aLength);
8072 0 : }
8073 :
8074 : private:
8075 : inline binding_detail::AutoSequence<Sequence<nsString>>&
8076 0 : RawSetAsUSVStringSequenceSequence()
8077 : {
8078 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8079 0 : mUnion.mType = mUnion.eUSVStringSequenceSequence;
8080 0 : return mUnion.mValue.mUSVStringSequenceSequence.SetValue();
8081 : }
8082 :
8083 : inline Record<nsString, nsString>&
8084 0 : RawSetAsUSVStringUSVStringRecord()
8085 : {
8086 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8087 0 : mUnion.mType = mUnion.eUSVStringUSVStringRecord;
8088 0 : return mUnion.mValue.mUSVStringUSVStringRecord.SetValue();
8089 : }
8090 :
8091 : inline binding_detail::FakeString&
8092 0 : RawSetAsUSVString()
8093 : {
8094 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8095 0 : mUnion.mType = mUnion.eUSVString;
8096 0 : return mUnion.mValue.mUSVString.SetValue();
8097 : }
8098 : };
8099 :
8100 : class Uint32ArrayOrUnsignedLongSequenceArgument
8101 : {
8102 : Uint32ArrayOrUnsignedLongSequence& mUnion;
8103 :
8104 : Uint32ArrayOrUnsignedLongSequenceArgument(const Uint32ArrayOrUnsignedLongSequenceArgument&) = delete;
8105 : Uint32ArrayOrUnsignedLongSequenceArgument& operator=(const Uint32ArrayOrUnsignedLongSequenceArgument&) = delete;
8106 : public:
8107 0 : explicit inline Uint32ArrayOrUnsignedLongSequenceArgument(const Uint32ArrayOrUnsignedLongSequence& aUnion)
8108 0 : : mUnion(const_cast<Uint32ArrayOrUnsignedLongSequence&>(aUnion))
8109 : {
8110 0 : }
8111 :
8112 : inline bool
8113 0 : TrySetToUint32Array(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8114 : {
8115 0 : tryNext = false;
8116 : { // scope for memberSlot
8117 0 : RootedTypedArray<Uint32Array>& memberSlot = RawSetAsUint32Array(cx);
8118 0 : if (!memberSlot.Init(&value.toObject())) {
8119 0 : mUnion.DestroyUint32Array();
8120 0 : tryNext = true;
8121 0 : return true;
8122 : }
8123 : }
8124 0 : return true;
8125 : }
8126 :
8127 : inline bool
8128 0 : TrySetToUnsignedLongSequence(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8129 : {
8130 0 : tryNext = false;
8131 : { // scope for memberSlot
8132 0 : binding_detail::AutoSequence<uint32_t>& memberSlot = RawSetAsUnsignedLongSequence();
8133 0 : JS::ForOfIterator iter(cx);
8134 0 : if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
8135 0 : return false;
8136 : }
8137 0 : if (!iter.valueIsIterable()) {
8138 0 : mUnion.DestroyUnsignedLongSequence();
8139 0 : tryNext = true;
8140 0 : return true;
8141 : }
8142 0 : binding_detail::AutoSequence<uint32_t> &arr = memberSlot;
8143 0 : JS::Rooted<JS::Value> temp(cx);
8144 : while (true) {
8145 : bool done;
8146 0 : if (!iter.next(&temp, &done)) {
8147 0 : return false;
8148 : }
8149 0 : if (done) {
8150 0 : break;
8151 : }
8152 0 : uint32_t* slotPtr = arr.AppendElement(mozilla::fallible);
8153 0 : if (!slotPtr) {
8154 0 : JS_ReportOutOfMemory(cx);
8155 0 : return false;
8156 : }
8157 0 : uint32_t& slot = *slotPtr;
8158 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp, &slot)) {
8159 0 : return false;
8160 : }
8161 0 : }
8162 : }
8163 0 : return true;
8164 : }
8165 :
8166 : private:
8167 : inline RootedTypedArray<Uint32Array>&
8168 0 : RawSetAsUint32Array(JSContext* cx)
8169 : {
8170 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8171 0 : mUnion.mType = mUnion.eUint32Array;
8172 0 : return mUnion.mValue.mUint32Array.SetValue(cx);
8173 : }
8174 :
8175 : inline binding_detail::AutoSequence<uint32_t>&
8176 0 : RawSetAsUnsignedLongSequence()
8177 : {
8178 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8179 0 : mUnion.mType = mUnion.eUnsignedLongSequence;
8180 0 : return mUnion.mValue.mUnsignedLongSequence.SetValue();
8181 : }
8182 : };
8183 :
8184 : class UnrestrictedDoubleOrKeyframeAnimationOptionsArgument
8185 : {
8186 : UnrestrictedDoubleOrKeyframeAnimationOptions& mUnion;
8187 :
8188 : UnrestrictedDoubleOrKeyframeAnimationOptionsArgument(const UnrestrictedDoubleOrKeyframeAnimationOptionsArgument&) = delete;
8189 : UnrestrictedDoubleOrKeyframeAnimationOptionsArgument& operator=(const UnrestrictedDoubleOrKeyframeAnimationOptionsArgument&) = delete;
8190 : public:
8191 0 : explicit inline UnrestrictedDoubleOrKeyframeAnimationOptionsArgument(const UnrestrictedDoubleOrKeyframeAnimationOptions& aUnion)
8192 0 : : mUnion(const_cast<UnrestrictedDoubleOrKeyframeAnimationOptions&>(aUnion))
8193 : {
8194 0 : }
8195 :
8196 : inline bool
8197 0 : TrySetToUnrestrictedDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8198 : {
8199 0 : tryNext = false;
8200 : { // scope for memberSlot
8201 0 : double& memberSlot = RawSetAsUnrestrictedDouble();
8202 0 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
8203 0 : return false;
8204 : }
8205 : }
8206 0 : return true;
8207 : }
8208 :
8209 : inline bool
8210 0 : TrySetToKeyframeAnimationOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8211 : {
8212 0 : tryNext = false;
8213 : { // scope for memberSlot
8214 0 : binding_detail::FastKeyframeAnimationOptions& memberSlot = RawSetAsKeyframeAnimationOptions();
8215 0 : if (!IsConvertibleToDictionary(value)) {
8216 0 : mUnion.DestroyKeyframeAnimationOptions();
8217 0 : tryNext = true;
8218 0 : return true;
8219 : }
8220 0 : if (!memberSlot.Init(cx, value, "Member of UnrestrictedDoubleOrKeyframeAnimationOptions", passedToJSImpl)) {
8221 0 : return false;
8222 : }
8223 : }
8224 0 : return true;
8225 : }
8226 :
8227 : private:
8228 : inline double&
8229 0 : RawSetAsUnrestrictedDouble()
8230 : {
8231 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8232 0 : mUnion.mType = mUnion.eUnrestrictedDouble;
8233 0 : return mUnion.mValue.mUnrestrictedDouble.SetValue();
8234 : }
8235 :
8236 : inline binding_detail::FastKeyframeAnimationOptions&
8237 0 : RawSetAsKeyframeAnimationOptions()
8238 : {
8239 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8240 0 : mUnion.mType = mUnion.eKeyframeAnimationOptions;
8241 0 : return mUnion.mValue.mKeyframeAnimationOptions.SetValue();
8242 : }
8243 : };
8244 :
8245 : class UnrestrictedDoubleOrKeyframeEffectOptionsArgument
8246 : {
8247 : UnrestrictedDoubleOrKeyframeEffectOptions& mUnion;
8248 :
8249 : UnrestrictedDoubleOrKeyframeEffectOptionsArgument(const UnrestrictedDoubleOrKeyframeEffectOptionsArgument&) = delete;
8250 : UnrestrictedDoubleOrKeyframeEffectOptionsArgument& operator=(const UnrestrictedDoubleOrKeyframeEffectOptionsArgument&) = delete;
8251 : public:
8252 0 : explicit inline UnrestrictedDoubleOrKeyframeEffectOptionsArgument(const UnrestrictedDoubleOrKeyframeEffectOptions& aUnion)
8253 0 : : mUnion(const_cast<UnrestrictedDoubleOrKeyframeEffectOptions&>(aUnion))
8254 : {
8255 0 : }
8256 :
8257 : inline bool
8258 0 : TrySetToUnrestrictedDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8259 : {
8260 0 : tryNext = false;
8261 : { // scope for memberSlot
8262 0 : double& memberSlot = RawSetAsUnrestrictedDouble();
8263 0 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
8264 0 : return false;
8265 : }
8266 : }
8267 0 : return true;
8268 : }
8269 :
8270 : inline bool
8271 0 : TrySetToKeyframeEffectOptions(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8272 : {
8273 0 : tryNext = false;
8274 : { // scope for memberSlot
8275 0 : binding_detail::FastKeyframeEffectOptions& memberSlot = RawSetAsKeyframeEffectOptions();
8276 0 : if (!IsConvertibleToDictionary(value)) {
8277 0 : mUnion.DestroyKeyframeEffectOptions();
8278 0 : tryNext = true;
8279 0 : return true;
8280 : }
8281 0 : if (!memberSlot.Init(cx, value, "Member of UnrestrictedDoubleOrKeyframeEffectOptions", passedToJSImpl)) {
8282 0 : return false;
8283 : }
8284 : }
8285 0 : return true;
8286 : }
8287 :
8288 : private:
8289 : inline double&
8290 0 : RawSetAsUnrestrictedDouble()
8291 : {
8292 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8293 0 : mUnion.mType = mUnion.eUnrestrictedDouble;
8294 0 : return mUnion.mValue.mUnrestrictedDouble.SetValue();
8295 : }
8296 :
8297 : inline binding_detail::FastKeyframeEffectOptions&
8298 0 : RawSetAsKeyframeEffectOptions()
8299 : {
8300 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8301 0 : mUnion.mType = mUnion.eKeyframeEffectOptions;
8302 0 : return mUnion.mValue.mKeyframeEffectOptions.SetValue();
8303 : }
8304 : };
8305 :
8306 : class UnrestrictedDoubleOrStringArgument
8307 : {
8308 : UnrestrictedDoubleOrString& mUnion;
8309 :
8310 : UnrestrictedDoubleOrStringArgument(const UnrestrictedDoubleOrStringArgument&) = delete;
8311 : UnrestrictedDoubleOrStringArgument& operator=(const UnrestrictedDoubleOrStringArgument&) = delete;
8312 : public:
8313 0 : explicit inline UnrestrictedDoubleOrStringArgument(const UnrestrictedDoubleOrString& aUnion)
8314 0 : : mUnion(const_cast<UnrestrictedDoubleOrString&>(aUnion))
8315 : {
8316 0 : }
8317 :
8318 : inline bool
8319 0 : TrySetToUnrestrictedDouble(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8320 : {
8321 0 : tryNext = false;
8322 : { // scope for memberSlot
8323 0 : double& memberSlot = RawSetAsUnrestrictedDouble();
8324 0 : if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
8325 0 : return false;
8326 : }
8327 : }
8328 0 : return true;
8329 : }
8330 :
8331 : inline bool
8332 0 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8333 : {
8334 0 : tryNext = false;
8335 : { // scope for memberSlot
8336 0 : binding_detail::FakeString& memberSlot = RawSetAsString();
8337 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
8338 0 : return false;
8339 : }
8340 : }
8341 0 : return true;
8342 : }
8343 :
8344 : inline void
8345 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
8346 : {
8347 : RawSetAsString().Rebind(aData, aLength);
8348 : }
8349 :
8350 : private:
8351 : inline double&
8352 0 : RawSetAsUnrestrictedDouble()
8353 : {
8354 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8355 0 : mUnion.mType = mUnion.eUnrestrictedDouble;
8356 0 : return mUnion.mValue.mUnrestrictedDouble.SetValue();
8357 : }
8358 :
8359 : inline binding_detail::FakeString&
8360 0 : RawSetAsString()
8361 : {
8362 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8363 0 : mUnion.mType = mUnion.eString;
8364 0 : return mUnion.mValue.mString.SetValue();
8365 : }
8366 : };
8367 :
8368 : class UnrestrictedFloatOrStringArgument
8369 : {
8370 : UnrestrictedFloatOrString& mUnion;
8371 :
8372 : UnrestrictedFloatOrStringArgument(const UnrestrictedFloatOrStringArgument&) = delete;
8373 : UnrestrictedFloatOrStringArgument& operator=(const UnrestrictedFloatOrStringArgument&) = delete;
8374 : public:
8375 : explicit inline UnrestrictedFloatOrStringArgument(const UnrestrictedFloatOrString& aUnion)
8376 : : mUnion(const_cast<UnrestrictedFloatOrString&>(aUnion))
8377 : {
8378 : }
8379 :
8380 : inline bool
8381 : TrySetToUnrestrictedFloat(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8382 : {
8383 : tryNext = false;
8384 : { // scope for memberSlot
8385 : float& memberSlot = RawSetAsUnrestrictedFloat();
8386 : if (!ValueToPrimitive<float, eDefault>(cx, value, &memberSlot)) {
8387 : return false;
8388 : }
8389 : }
8390 : return true;
8391 : }
8392 :
8393 : inline bool
8394 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8395 : {
8396 : tryNext = false;
8397 : { // scope for memberSlot
8398 : binding_detail::FakeString& memberSlot = RawSetAsString();
8399 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
8400 : return false;
8401 : }
8402 : }
8403 : return true;
8404 : }
8405 :
8406 : inline void
8407 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
8408 : {
8409 : RawSetAsString().Rebind(aData, aLength);
8410 : }
8411 :
8412 : private:
8413 : inline float&
8414 : RawSetAsUnrestrictedFloat()
8415 : {
8416 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8417 : mUnion.mType = mUnion.eUnrestrictedFloat;
8418 : return mUnion.mValue.mUnrestrictedFloat.SetValue();
8419 : }
8420 :
8421 : inline binding_detail::FakeString&
8422 : RawSetAsString()
8423 : {
8424 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8425 : mUnion.mType = mUnion.eString;
8426 : return mUnion.mValue.mString.SetValue();
8427 : }
8428 : };
8429 :
8430 : class UnsignedLongLongOrStringArgument
8431 : {
8432 : UnsignedLongLongOrString& mUnion;
8433 :
8434 : UnsignedLongLongOrStringArgument(const UnsignedLongLongOrStringArgument&) = delete;
8435 : UnsignedLongLongOrStringArgument& operator=(const UnsignedLongLongOrStringArgument&) = delete;
8436 : public:
8437 : explicit inline UnsignedLongLongOrStringArgument(const UnsignedLongLongOrString& aUnion)
8438 : : mUnion(const_cast<UnsignedLongLongOrString&>(aUnion))
8439 : {
8440 : }
8441 :
8442 : inline bool
8443 : TrySetToUnsignedLongLong(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8444 : {
8445 : tryNext = false;
8446 : { // scope for memberSlot
8447 : uint64_t& memberSlot = RawSetAsUnsignedLongLong();
8448 : if (!ValueToPrimitive<uint64_t, eDefault>(cx, value, &memberSlot)) {
8449 : return false;
8450 : }
8451 : }
8452 : return true;
8453 : }
8454 :
8455 : inline bool
8456 : TrySetToString(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8457 : {
8458 : tryNext = false;
8459 : { // scope for memberSlot
8460 : binding_detail::FakeString& memberSlot = RawSetAsString();
8461 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
8462 : return false;
8463 : }
8464 : }
8465 : return true;
8466 : }
8467 :
8468 : inline void
8469 : SetStringData(const nsDependentString::char_type* aData, nsDependentString::size_type aLength)
8470 : {
8471 : RawSetAsString().Rebind(aData, aLength);
8472 : }
8473 :
8474 : private:
8475 : inline uint64_t&
8476 : RawSetAsUnsignedLongLong()
8477 : {
8478 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8479 : mUnion.mType = mUnion.eUnsignedLongLong;
8480 : return mUnion.mValue.mUnsignedLongLong.SetValue();
8481 : }
8482 :
8483 : inline binding_detail::FakeString&
8484 : RawSetAsString()
8485 : {
8486 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8487 : mUnion.mType = mUnion.eString;
8488 : return mUnion.mValue.mString.SetValue();
8489 : }
8490 : };
8491 :
8492 : class VideoTrackOrAudioTrackOrTextTrackArgument
8493 : {
8494 : VideoTrackOrAudioTrackOrTextTrack& mUnion;
8495 :
8496 : VideoTrackOrAudioTrackOrTextTrackArgument(const VideoTrackOrAudioTrackOrTextTrackArgument&) = delete;
8497 : VideoTrackOrAudioTrackOrTextTrackArgument& operator=(const VideoTrackOrAudioTrackOrTextTrackArgument&) = delete;
8498 : public:
8499 : explicit inline VideoTrackOrAudioTrackOrTextTrackArgument(const VideoTrackOrAudioTrackOrTextTrack& aUnion)
8500 : : mUnion(const_cast<VideoTrackOrAudioTrackOrTextTrack&>(aUnion))
8501 : {
8502 : }
8503 :
8504 : inline bool
8505 : TrySetToVideoTrack(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8506 : {
8507 : tryNext = false;
8508 : { // scope for memberSlot
8509 : NonNull<mozilla::dom::VideoTrack>& memberSlot = RawSetAsVideoTrack();
8510 : {
8511 : nsresult rv = UnwrapObject<prototypes::id::VideoTrack, mozilla::dom::VideoTrack>(value, memberSlot);
8512 : if (NS_FAILED(rv)) {
8513 : mUnion.DestroyVideoTrack();
8514 : tryNext = true;
8515 : return true;
8516 : }
8517 : }
8518 : }
8519 : return true;
8520 : }
8521 :
8522 : inline bool
8523 : TrySetToAudioTrack(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8524 : {
8525 : tryNext = false;
8526 : { // scope for memberSlot
8527 : NonNull<mozilla::dom::AudioTrack>& memberSlot = RawSetAsAudioTrack();
8528 : {
8529 : nsresult rv = UnwrapObject<prototypes::id::AudioTrack, mozilla::dom::AudioTrack>(value, memberSlot);
8530 : if (NS_FAILED(rv)) {
8531 : mUnion.DestroyAudioTrack();
8532 : tryNext = true;
8533 : return true;
8534 : }
8535 : }
8536 : }
8537 : return true;
8538 : }
8539 :
8540 : inline bool
8541 : TrySetToTextTrack(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8542 : {
8543 : tryNext = false;
8544 : { // scope for memberSlot
8545 : NonNull<mozilla::dom::TextTrack>& memberSlot = RawSetAsTextTrack();
8546 : {
8547 : nsresult rv = UnwrapObject<prototypes::id::TextTrack, mozilla::dom::TextTrack>(value, memberSlot);
8548 : if (NS_FAILED(rv)) {
8549 : mUnion.DestroyTextTrack();
8550 : tryNext = true;
8551 : return true;
8552 : }
8553 : }
8554 : }
8555 : return true;
8556 : }
8557 :
8558 : private:
8559 : inline NonNull<mozilla::dom::VideoTrack>&
8560 : RawSetAsVideoTrack()
8561 : {
8562 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8563 : mUnion.mType = mUnion.eVideoTrack;
8564 : return mUnion.mValue.mVideoTrack.SetValue();
8565 : }
8566 :
8567 : inline NonNull<mozilla::dom::AudioTrack>&
8568 : RawSetAsAudioTrack()
8569 : {
8570 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8571 : mUnion.mType = mUnion.eAudioTrack;
8572 : return mUnion.mValue.mAudioTrack.SetValue();
8573 : }
8574 :
8575 : inline NonNull<mozilla::dom::TextTrack>&
8576 : RawSetAsTextTrack()
8577 : {
8578 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8579 : mUnion.mType = mUnion.eTextTrack;
8580 : return mUnion.mValue.mTextTrack.SetValue();
8581 : }
8582 : };
8583 :
8584 0 : class WindowProxyOrMessagePortOrServiceWorkerArgument
8585 : {
8586 : WindowProxyOrMessagePortOrServiceWorker& mUnion;
8587 : Maybe<RefPtr<nsPIDOMWindowOuter>> mWindowProxyHolder;
8588 :
8589 : WindowProxyOrMessagePortOrServiceWorkerArgument(const WindowProxyOrMessagePortOrServiceWorkerArgument&) = delete;
8590 : WindowProxyOrMessagePortOrServiceWorkerArgument& operator=(const WindowProxyOrMessagePortOrServiceWorkerArgument&) = delete;
8591 : public:
8592 0 : explicit inline WindowProxyOrMessagePortOrServiceWorkerArgument(const WindowProxyOrMessagePortOrServiceWorker& aUnion)
8593 0 : : mUnion(const_cast<WindowProxyOrMessagePortOrServiceWorker&>(aUnion))
8594 : {
8595 0 : }
8596 :
8597 : inline bool
8598 0 : TrySetToWindowProxy(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8599 : {
8600 0 : tryNext = false;
8601 : { // scope for memberSlot
8602 0 : nsPIDOMWindowOuter*& memberSlot = RawSetAsWindowProxy();
8603 0 : mWindowProxyHolder.emplace();
8604 0 : JS::Rooted<JSObject*> source(cx, &value.toObject());
8605 0 : if (NS_FAILED(UnwrapArg<nsPIDOMWindowOuter>(cx, source, getter_AddRefs(mWindowProxyHolder.ref())))) {
8606 0 : mWindowProxyHolder.reset();
8607 0 : mUnion.DestroyWindowProxy();
8608 0 : tryNext = true;
8609 0 : return true;
8610 : }
8611 0 : MOZ_ASSERT(mWindowProxyHolder.ref());
8612 0 : memberSlot = mWindowProxyHolder.ref();
8613 : }
8614 0 : return true;
8615 : }
8616 :
8617 : inline bool
8618 0 : TrySetToMessagePort(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8619 : {
8620 0 : tryNext = false;
8621 : { // scope for memberSlot
8622 0 : NonNull<mozilla::dom::MessagePort>& memberSlot = RawSetAsMessagePort();
8623 : {
8624 0 : nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(value, memberSlot);
8625 0 : if (NS_FAILED(rv)) {
8626 0 : mUnion.DestroyMessagePort();
8627 0 : tryNext = true;
8628 0 : return true;
8629 : }
8630 : }
8631 : }
8632 0 : return true;
8633 : }
8634 :
8635 : inline bool
8636 0 : TrySetToServiceWorker(JSContext* cx, JS::MutableHandle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false)
8637 : {
8638 0 : tryNext = false;
8639 : { // scope for memberSlot
8640 0 : NonNull<mozilla::dom::workers::ServiceWorker>& memberSlot = RawSetAsServiceWorker();
8641 : {
8642 0 : nsresult rv = UnwrapObject<prototypes::id::ServiceWorker, mozilla::dom::workers::ServiceWorker>(value, memberSlot);
8643 0 : if (NS_FAILED(rv)) {
8644 0 : mUnion.DestroyServiceWorker();
8645 0 : tryNext = true;
8646 0 : return true;
8647 : }
8648 : }
8649 : }
8650 0 : return true;
8651 : }
8652 :
8653 : private:
8654 : inline nsPIDOMWindowOuter*&
8655 0 : RawSetAsWindowProxy()
8656 : {
8657 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8658 0 : mUnion.mType = mUnion.eWindowProxy;
8659 0 : return mUnion.mValue.mWindowProxy.SetValue();
8660 : }
8661 :
8662 : inline NonNull<mozilla::dom::MessagePort>&
8663 0 : RawSetAsMessagePort()
8664 : {
8665 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8666 0 : mUnion.mType = mUnion.eMessagePort;
8667 0 : return mUnion.mValue.mMessagePort.SetValue();
8668 : }
8669 :
8670 : inline NonNull<mozilla::dom::workers::ServiceWorker>&
8671 0 : RawSetAsServiceWorker()
8672 : {
8673 0 : MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
8674 0 : mUnion.mType = mUnion.eServiceWorker;
8675 0 : return mUnion.mValue.mServiceWorker.SetValue();
8676 : }
8677 : };
8678 :
8679 :
8680 : } // namespace dom
8681 : } // namespace mozilla
8682 :
8683 :
8684 : #endif // mozilla_dom_UnionConversions_h
|