Coverage Report

Created: 2018-09-25 14:53

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