Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/XMLHttpRequestBinding.h
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM XMLHttpRequest.webidl BY Codegen.py - DO NOT EDIT */
2
3
#ifndef mozilla_dom_XMLHttpRequestBinding_h
4
#define mozilla_dom_XMLHttpRequestBinding_h
5
6
#include "GeckoProfiler.h"
7
#include "js/RootingAPI.h"
8
#include "jsfriendapi.h"
9
#include "jspubtd.h"
10
#include "mozilla/ErrorResult.h"
11
#include "mozilla/dom/BindingDeclarations.h"
12
#include "mozilla/dom/FakeString.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/PrototypeList.h"
15
#include "mozilla/dom/TypedArray.h"
16
#include "mozilla/dom/UnionMember.h"
17
18
class nsIDocument;
19
20
namespace mozilla {
21
namespace dom {
22
23
class Blob;
24
class FormData;
25
struct MozXMLHttpRequestParametersAtoms;
26
struct NativePropertyHooks;
27
class OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString;
28
class ProtoAndIfaceCache;
29
class URLSearchParams;
30
class XMLHttpRequest;
31
struct XMLHttpRequestAtoms;
32
33
} // namespace dom
34
} // namespace mozilla
35
36
namespace mozilla {
37
namespace dom {
38
39
enum class XMLHttpRequestResponseType : uint8_t {
40
  _empty,
41
  Arraybuffer,
42
  Blob,
43
  Document,
44
  Json,
45
  Text,
46
  Moz_chunked_arraybuffer,
47
  EndGuard_
48
};
49
50
namespace XMLHttpRequestResponseTypeValues {
51
extern const EnumEntry strings[8];
52
} // namespace XMLHttpRequestResponseTypeValues
53
54
bool
55
ToJSValue(JSContext* aCx, XMLHttpRequestResponseType aArgument, JS::MutableHandle<JS::Value> aValue);
56
57
58
void
59
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion, const char* aName, uint32_t aFlags = 0);
60
61
62
void
63
ImplCycleCollectionUnlink(OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion);
64
65
66
class DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString
67
{
68
  friend class DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument;
69
  enum Type
70
  {
71
    eUninitialized,
72
    eDocument,
73
    eBlob,
74
    eArrayBufferView,
75
    eArrayBuffer,
76
    eFormData,
77
    eURLSearchParams,
78
    eUSVString
79
  };
80
81
  union Value
82
  {
83
    UnionMember<NonNull<nsIDocument> > mDocument;
84
    UnionMember<NonNull<mozilla::dom::Blob> > mBlob;
85
    UnionMember<RootedSpiderMonkeyInterface<ArrayBufferView> > mArrayBufferView;
86
    UnionMember<RootedSpiderMonkeyInterface<ArrayBuffer> > mArrayBuffer;
87
    UnionMember<NonNull<mozilla::dom::FormData> > mFormData;
88
    UnionMember<NonNull<mozilla::dom::URLSearchParams> > mURLSearchParams;
89
    UnionMember<binding_detail::FakeString > mUSVString;
90
91
  };
92
93
  Type mType;
94
  Value mValue;
95
96
  DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString(const DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString&) = delete;
97
  DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& operator=(const DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString&) = delete;
98
public:
99
  explicit inline DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString()
100
    : mType(eUninitialized)
101
0
  {
102
0
  }
103
104
  inline ~DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString()
105
0
  {
106
0
    Uninit();
107
0
  }
108
109
  inline NonNull<nsIDocument>&
110
  RawSetAsDocument()
111
0
  {
112
0
    if (mType == eDocument) {
113
0
      return mValue.mDocument.Value();
114
0
    }
115
0
    MOZ_ASSERT(mType == eUninitialized);
116
0
    mType = eDocument;
117
0
    return mValue.mDocument.SetValue();
118
0
  }
119
120
  inline NonNull<nsIDocument>&
121
  SetAsDocument()
122
0
  {
123
0
    if (mType == eDocument) {
124
0
      return mValue.mDocument.Value();
125
0
    }
126
0
    Uninit();
127
0
    mType = eDocument;
128
0
    return mValue.mDocument.SetValue();
129
0
  }
130
131
  inline bool
132
  IsDocument() const
133
0
  {
134
0
    return mType == eDocument;
135
0
  }
136
137
  inline NonNull<nsIDocument>&
138
  GetAsDocument()
139
0
  {
140
0
    MOZ_ASSERT(IsDocument(), "Wrong type!");
141
0
    return mValue.mDocument.Value();
142
0
  }
143
144
  inline nsIDocument&
145
  GetAsDocument() const
146
0
  {
147
0
    MOZ_ASSERT(IsDocument(), "Wrong type!");
148
0
    return mValue.mDocument.Value();
149
0
  }
150
151
  inline NonNull<mozilla::dom::Blob>&
152
  RawSetAsBlob()
153
0
  {
154
0
    if (mType == eBlob) {
155
0
      return mValue.mBlob.Value();
156
0
    }
157
0
    MOZ_ASSERT(mType == eUninitialized);
158
0
    mType = eBlob;
159
0
    return mValue.mBlob.SetValue();
160
0
  }
161
162
  inline NonNull<mozilla::dom::Blob>&
163
  SetAsBlob()
164
0
  {
165
0
    if (mType == eBlob) {
166
0
      return mValue.mBlob.Value();
167
0
    }
168
0
    Uninit();
169
0
    mType = eBlob;
170
0
    return mValue.mBlob.SetValue();
171
0
  }
172
173
  inline bool
174
  IsBlob() const
175
0
  {
176
0
    return mType == eBlob;
177
0
  }
178
179
  inline NonNull<mozilla::dom::Blob>&
180
  GetAsBlob()
181
0
  {
182
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
183
0
    return mValue.mBlob.Value();
184
0
  }
185
186
  inline mozilla::dom::Blob&
187
  GetAsBlob() const
188
0
  {
189
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
190
0
    return mValue.mBlob.Value();
191
0
  }
192
193
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
194
  RawSetAsArrayBufferView(JSContext* cx)
195
0
  {
196
0
    if (mType == eArrayBufferView) {
197
0
      return mValue.mArrayBufferView.Value();
198
0
    }
199
0
    MOZ_ASSERT(mType == eUninitialized);
200
0
    mType = eArrayBufferView;
201
0
    return mValue.mArrayBufferView.SetValue(cx);
202
0
  }
203
204
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
205
  SetAsArrayBufferView(JSContext* cx)
206
0
  {
207
0
    if (mType == eArrayBufferView) {
208
0
      return mValue.mArrayBufferView.Value();
209
0
    }
210
0
    Uninit();
211
0
    mType = eArrayBufferView;
212
0
    return mValue.mArrayBufferView.SetValue(cx);
213
0
  }
214
215
  inline bool
216
  IsArrayBufferView() const
217
0
  {
218
0
    return mType == eArrayBufferView;
219
0
  }
220
221
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
222
  GetAsArrayBufferView()
223
0
  {
224
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
225
0
    return mValue.mArrayBufferView.Value();
226
0
  }
227
228
  inline ArrayBufferView const &
229
  GetAsArrayBufferView() const
230
0
  {
231
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
232
0
    return mValue.mArrayBufferView.Value();
233
0
  }
234
235
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
236
  RawSetAsArrayBuffer(JSContext* cx)
237
0
  {
238
0
    if (mType == eArrayBuffer) {
239
0
      return mValue.mArrayBuffer.Value();
240
0
    }
241
0
    MOZ_ASSERT(mType == eUninitialized);
242
0
    mType = eArrayBuffer;
243
0
    return mValue.mArrayBuffer.SetValue(cx);
244
0
  }
245
246
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
247
  SetAsArrayBuffer(JSContext* cx)
248
0
  {
249
0
    if (mType == eArrayBuffer) {
250
0
      return mValue.mArrayBuffer.Value();
251
0
    }
252
0
    Uninit();
253
0
    mType = eArrayBuffer;
254
0
    return mValue.mArrayBuffer.SetValue(cx);
255
0
  }
256
257
  inline bool
258
  IsArrayBuffer() const
259
0
  {
260
0
    return mType == eArrayBuffer;
261
0
  }
262
263
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
264
  GetAsArrayBuffer()
265
0
  {
266
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
267
0
    return mValue.mArrayBuffer.Value();
268
0
  }
269
270
  inline ArrayBuffer const &
271
  GetAsArrayBuffer() const
272
0
  {
273
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
274
0
    return mValue.mArrayBuffer.Value();
275
0
  }
276
277
  inline NonNull<mozilla::dom::FormData>&
278
  RawSetAsFormData()
279
0
  {
280
0
    if (mType == eFormData) {
281
0
      return mValue.mFormData.Value();
282
0
    }
283
0
    MOZ_ASSERT(mType == eUninitialized);
284
0
    mType = eFormData;
285
0
    return mValue.mFormData.SetValue();
286
0
  }
287
288
  inline NonNull<mozilla::dom::FormData>&
289
  SetAsFormData()
290
0
  {
291
0
    if (mType == eFormData) {
292
0
      return mValue.mFormData.Value();
293
0
    }
294
0
    Uninit();
295
0
    mType = eFormData;
296
0
    return mValue.mFormData.SetValue();
297
0
  }
298
299
  inline bool
300
  IsFormData() const
301
0
  {
302
0
    return mType == eFormData;
303
0
  }
304
305
  inline NonNull<mozilla::dom::FormData>&
306
  GetAsFormData()
307
0
  {
308
0
    MOZ_ASSERT(IsFormData(), "Wrong type!");
309
0
    return mValue.mFormData.Value();
310
0
  }
311
312
  inline mozilla::dom::FormData&
313
  GetAsFormData() const
314
0
  {
315
0
    MOZ_ASSERT(IsFormData(), "Wrong type!");
316
0
    return mValue.mFormData.Value();
317
0
  }
318
319
  inline NonNull<mozilla::dom::URLSearchParams>&
320
  RawSetAsURLSearchParams()
321
0
  {
322
0
    if (mType == eURLSearchParams) {
323
0
      return mValue.mURLSearchParams.Value();
324
0
    }
325
0
    MOZ_ASSERT(mType == eUninitialized);
326
0
    mType = eURLSearchParams;
327
0
    return mValue.mURLSearchParams.SetValue();
328
0
  }
329
330
  inline NonNull<mozilla::dom::URLSearchParams>&
331
  SetAsURLSearchParams()
332
0
  {
333
0
    if (mType == eURLSearchParams) {
334
0
      return mValue.mURLSearchParams.Value();
335
0
    }
336
0
    Uninit();
337
0
    mType = eURLSearchParams;
338
0
    return mValue.mURLSearchParams.SetValue();
339
0
  }
340
341
  inline bool
342
  IsURLSearchParams() const
343
0
  {
344
0
    return mType == eURLSearchParams;
345
0
  }
346
347
  inline NonNull<mozilla::dom::URLSearchParams>&
348
  GetAsURLSearchParams()
349
0
  {
350
0
    MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
351
0
    return mValue.mURLSearchParams.Value();
352
0
  }
353
354
  inline mozilla::dom::URLSearchParams&
355
  GetAsURLSearchParams() const
356
0
  {
357
0
    MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
358
0
    return mValue.mURLSearchParams.Value();
359
0
  }
360
361
  inline binding_detail::FakeString&
362
  RawSetAsUSVString()
363
0
  {
364
0
    if (mType == eUSVString) {
365
0
      return mValue.mUSVString.Value();
366
0
    }
367
0
    MOZ_ASSERT(mType == eUninitialized);
368
0
    mType = eUSVString;
369
0
    return mValue.mUSVString.SetValue();
370
0
  }
371
372
  inline binding_detail::FakeString&
373
  SetAsUSVString()
374
0
  {
375
0
    if (mType == eUSVString) {
376
0
      return mValue.mUSVString.Value();
377
0
    }
378
0
    Uninit();
379
0
    mType = eUSVString;
380
0
    return mValue.mUSVString.SetValue();
381
0
  }
382
383
  inline bool
384
  IsUSVString() const
385
0
  {
386
0
    return mType == eUSVString;
387
0
  }
388
389
  inline binding_detail::FakeString&
390
  GetAsUSVString()
391
0
  {
392
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
393
0
    return mValue.mUSVString.Value();
394
0
  }
395
396
  inline const nsAString&
397
  GetAsUSVString() const
398
0
  {
399
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
400
0
    return mValue.mUSVString.Value();
401
0
  }
402
403
  inline void
404
  Uninit()
405
  {
406
    switch (mType) {
407
      case eUninitialized: {
408
        break;
409
      }
410
      case eDocument: {
411
        DestroyDocument();
412
        break;
413
      }
414
      case eBlob: {
415
        DestroyBlob();
416
        break;
417
      }
418
      case eArrayBufferView: {
419
        DestroyArrayBufferView();
420
        break;
421
      }
422
      case eArrayBuffer: {
423
        DestroyArrayBuffer();
424
        break;
425
      }
426
      case eFormData: {
427
        DestroyFormData();
428
        break;
429
      }
430
      case eURLSearchParams: {
431
        DestroyURLSearchParams();
432
        break;
433
      }
434
      case eUSVString: {
435
        DestroyUSVString();
436
        break;
437
      }
438
    }
439
  }
440
441
  bool
442
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
443
444
private:
445
  inline void
446
  DestroyDocument()
447
0
  {
448
0
    MOZ_ASSERT(IsDocument(), "Wrong type!");
449
0
    mValue.mDocument.Destroy();
450
0
    mType = eUninitialized;
451
0
  }
452
453
  inline void
454
  DestroyBlob()
455
0
  {
456
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
457
0
    mValue.mBlob.Destroy();
458
0
    mType = eUninitialized;
459
0
  }
460
461
  inline void
462
  DestroyArrayBufferView()
463
0
  {
464
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
465
0
    mValue.mArrayBufferView.Destroy();
466
0
    mType = eUninitialized;
467
0
  }
468
469
  inline void
470
  DestroyArrayBuffer()
471
0
  {
472
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
473
0
    mValue.mArrayBuffer.Destroy();
474
0
    mType = eUninitialized;
475
0
  }
476
477
  inline void
478
  DestroyFormData()
479
0
  {
480
0
    MOZ_ASSERT(IsFormData(), "Wrong type!");
481
0
    mValue.mFormData.Destroy();
482
0
    mType = eUninitialized;
483
0
  }
484
485
  inline void
486
  DestroyURLSearchParams()
487
0
  {
488
0
    MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
489
0
    mValue.mURLSearchParams.Destroy();
490
0
    mType = eUninitialized;
491
0
  }
492
493
  inline void
494
  DestroyUSVString()
495
0
  {
496
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
497
0
    mValue.mUSVString.Destroy();
498
0
    mType = eUninitialized;
499
0
  }
500
};
501
502
503
class OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString : public AllOwningUnionBase
504
{
505
  friend void ImplCycleCollectionUnlink(OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion);
506
  enum Type
507
  {
508
    eUninitialized,
509
    eDocument,
510
    eBlob,
511
    eArrayBufferView,
512
    eArrayBuffer,
513
    eFormData,
514
    eURLSearchParams,
515
    eUSVString
516
  };
517
518
  union Value
519
  {
520
    UnionMember<OwningNonNull<nsIDocument> > mDocument;
521
    UnionMember<OwningNonNull<mozilla::dom::Blob> > mBlob;
522
    UnionMember<ArrayBufferView > mArrayBufferView;
523
    UnionMember<ArrayBuffer > mArrayBuffer;
524
    UnionMember<OwningNonNull<mozilla::dom::FormData> > mFormData;
525
    UnionMember<OwningNonNull<mozilla::dom::URLSearchParams> > mURLSearchParams;
526
    UnionMember<nsString > mUSVString;
527
528
  };
529
530
  Type mType;
531
  Value mValue;
532
533
  OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString(const OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString&) = delete;
534
  OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& operator=(const OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString&) = delete;
535
public:
536
  explicit inline OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString()
537
    : mType(eUninitialized)
538
0
  {
539
0
  }
540
541
  inline ~OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString()
542
0
  {
543
0
    Uninit();
544
0
  }
545
546
  OwningNonNull<nsIDocument>&
547
  RawSetAsDocument();
548
549
  OwningNonNull<nsIDocument>&
550
  SetAsDocument();
551
552
  bool
553
  TrySetToDocument(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
554
555
  inline bool
556
  IsDocument() const
557
0
  {
558
0
    return mType == eDocument;
559
0
  }
560
561
  inline OwningNonNull<nsIDocument>&
562
  GetAsDocument()
563
0
  {
564
0
    MOZ_ASSERT(IsDocument(), "Wrong type!");
565
0
    return mValue.mDocument.Value();
566
0
  }
567
568
  inline OwningNonNull<nsIDocument> const &
569
  GetAsDocument() const
570
0
  {
571
0
    MOZ_ASSERT(IsDocument(), "Wrong type!");
572
0
    return mValue.mDocument.Value();
573
0
  }
574
575
  OwningNonNull<mozilla::dom::Blob>&
576
  RawSetAsBlob();
577
578
  OwningNonNull<mozilla::dom::Blob>&
579
  SetAsBlob();
580
581
  bool
582
  TrySetToBlob(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
583
584
  inline bool
585
  IsBlob() const
586
0
  {
587
0
    return mType == eBlob;
588
0
  }
589
590
  inline OwningNonNull<mozilla::dom::Blob>&
591
  GetAsBlob()
592
0
  {
593
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
594
0
    return mValue.mBlob.Value();
595
0
  }
596
597
  inline OwningNonNull<mozilla::dom::Blob> const &
598
  GetAsBlob() const
599
0
  {
600
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
601
0
    return mValue.mBlob.Value();
602
0
  }
603
604
  ArrayBufferView&
605
  RawSetAsArrayBufferView();
606
607
  ArrayBufferView&
608
  SetAsArrayBufferView();
609
610
  bool
611
  TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
612
613
  inline bool
614
  IsArrayBufferView() const
615
0
  {
616
0
    return mType == eArrayBufferView;
617
0
  }
618
619
  inline ArrayBufferView&
620
  GetAsArrayBufferView()
621
0
  {
622
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
623
0
    return mValue.mArrayBufferView.Value();
624
0
  }
625
626
  inline ArrayBufferView const &
627
  GetAsArrayBufferView() const
628
0
  {
629
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
630
0
    return mValue.mArrayBufferView.Value();
631
0
  }
632
633
  ArrayBuffer&
634
  RawSetAsArrayBuffer();
635
636
  ArrayBuffer&
637
  SetAsArrayBuffer();
638
639
  bool
640
  TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
641
642
  inline bool
643
  IsArrayBuffer() const
644
0
  {
645
0
    return mType == eArrayBuffer;
646
0
  }
647
648
  inline ArrayBuffer&
649
  GetAsArrayBuffer()
650
0
  {
651
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
652
0
    return mValue.mArrayBuffer.Value();
653
0
  }
654
655
  inline ArrayBuffer const &
656
  GetAsArrayBuffer() const
657
0
  {
658
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
659
0
    return mValue.mArrayBuffer.Value();
660
0
  }
661
662
  OwningNonNull<mozilla::dom::FormData>&
663
  RawSetAsFormData();
664
665
  OwningNonNull<mozilla::dom::FormData>&
666
  SetAsFormData();
667
668
  bool
669
  TrySetToFormData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
670
671
  inline bool
672
  IsFormData() const
673
0
  {
674
0
    return mType == eFormData;
675
0
  }
676
677
  inline OwningNonNull<mozilla::dom::FormData>&
678
  GetAsFormData()
679
0
  {
680
0
    MOZ_ASSERT(IsFormData(), "Wrong type!");
681
0
    return mValue.mFormData.Value();
682
0
  }
683
684
  inline OwningNonNull<mozilla::dom::FormData> const &
685
  GetAsFormData() const
686
0
  {
687
0
    MOZ_ASSERT(IsFormData(), "Wrong type!");
688
0
    return mValue.mFormData.Value();
689
0
  }
690
691
  OwningNonNull<mozilla::dom::URLSearchParams>&
692
  RawSetAsURLSearchParams();
693
694
  OwningNonNull<mozilla::dom::URLSearchParams>&
695
  SetAsURLSearchParams();
696
697
  bool
698
  TrySetToURLSearchParams(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
699
700
  inline bool
701
  IsURLSearchParams() const
702
0
  {
703
0
    return mType == eURLSearchParams;
704
0
  }
705
706
  inline OwningNonNull<mozilla::dom::URLSearchParams>&
707
  GetAsURLSearchParams()
708
0
  {
709
0
    MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
710
0
    return mValue.mURLSearchParams.Value();
711
0
  }
712
713
  inline OwningNonNull<mozilla::dom::URLSearchParams> const &
714
  GetAsURLSearchParams() const
715
0
  {
716
0
    MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
717
0
    return mValue.mURLSearchParams.Value();
718
0
  }
719
720
  nsString&
721
  RawSetAsUSVString();
722
723
  nsString&
724
  SetAsUSVString();
725
726
  bool
727
  TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
728
729
  inline void
730
  SetStringData(const nsString::char_type* aData, nsString::size_type aLength)
731
0
  {
732
0
    RawSetAsUSVString().Assign(aData, aLength);
733
0
  }
734
735
  inline bool
736
  IsUSVString() const
737
0
  {
738
0
    return mType == eUSVString;
739
0
  }
740
741
  inline nsString&
742
  GetAsUSVString()
743
0
  {
744
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
745
0
    return mValue.mUSVString.Value();
746
0
  }
747
748
  inline nsString const &
749
  GetAsUSVString() const
750
0
  {
751
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
752
0
    return mValue.mUSVString.Value();
753
0
  }
754
755
  void
756
  Uninit();
757
758
  bool
759
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
760
761
  void
762
  TraceUnion(JSTracer* trc);
763
764
private:
765
  void
766
  DestroyDocument();
767
768
  void
769
  DestroyBlob();
770
771
  void
772
  DestroyArrayBufferView();
773
774
  void
775
  DestroyArrayBuffer();
776
777
  void
778
  DestroyFormData();
779
780
  void
781
  DestroyURLSearchParams();
782
783
  void
784
  DestroyUSVString();
785
};
786
787
788
struct MozXMLHttpRequestParameters : public DictionaryBase
789
{
790
  MOZ_INIT_OUTSIDE_CTOR bool mMozAnon;
791
  MOZ_INIT_OUTSIDE_CTOR bool mMozSystem;
792
793
  MozXMLHttpRequestParameters();
794
795
  explicit inline MozXMLHttpRequestParameters(const FastDictionaryInitializer& )
796
0
  {
797
0
    // Do nothing here; this is used by our "Fast" subclass
798
0
  }
799
800
  explicit inline MozXMLHttpRequestParameters(const MozXMLHttpRequestParameters& aOther)
801
0
  {
802
0
    *this = aOther;
803
0
  }
804
805
  bool
806
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
807
808
  bool
809
  Init(const nsAString& aJSON);
810
811
  bool
812
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
813
814
  bool
815
  ToJSON(nsAString& aJSON) const;
816
817
  void
818
  TraceDictionary(JSTracer* trc);
819
820
  MozXMLHttpRequestParameters&
821
  operator=(const MozXMLHttpRequestParameters& aOther);
822
823
private:
824
  static bool
825
  InitIds(JSContext* cx, MozXMLHttpRequestParametersAtoms* atomsCache);
826
};
827
828
namespace binding_detail {
829
struct FastMozXMLHttpRequestParameters : public MozXMLHttpRequestParameters
830
{
831
  inline FastMozXMLHttpRequestParameters()
832
    : MozXMLHttpRequestParameters(FastDictionaryInitializer())
833
0
  {
834
0
    // Doesn't matter what int we pass to the parent constructor
835
0
  }
836
};
837
} // namespace binding_detail
838
839
840
namespace XMLHttpRequest_Binding {
841
842
  typedef mozilla::dom::XMLHttpRequest NativeType;
843
844
  static const uint16_t UNSENT = 0;
845
  static const uint16_t OPENED = 1;
846
  static const uint16_t HEADERS_RECEIVED = 2;
847
  static const uint16_t LOADING = 3;
848
  static const uint16_t DONE = 4;
849
  bool
850
  ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
851
852
  const JSClass*
853
  GetJSClass();
854
855
  bool
856
  Wrap(JSContext* aCx, mozilla::dom::XMLHttpRequest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
857
858
  template <class T>
859
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
860
0
  {
861
0
    JS::Rooted<JSObject*> reflector(aCx);
862
0
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
863
0
  }
864
865
  // We declare this as an array so that retrieving a pointer to this
866
  // binding's property hooks only requires compile/link-time resolvable
867
  // address arithmetic.  Declaring it as a pointer instead would require
868
  // doing a run-time load to fetch a pointer to this binding's property
869
  // hooks.  And then structures which embedded a pointer to this structure
870
  // would require a run-time load for proper initialization, which would
871
  // then induce static constructors.  Lots of static constructors.
872
  extern const NativePropertyHooks sNativePropertyHooks[];
873
874
  void
875
  ClearCachedResponseTextValue(mozilla::dom::XMLHttpRequest* aObject);
876
877
  void
878
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
879
880
  inline JS::Handle<JSObject*> GetProtoObjectHandle(JSContext* aCx)
881
0
  {
882
0
    /* Get the interface prototype object for this class.  This will create the
883
0
       object as needed. */
884
0
    return GetPerInterfaceObjectHandle(aCx, prototypes::id::XMLHttpRequest,
885
0
                                       &CreateInterfaceObjects,
886
0
                                       /* aDefineOnGlobal = */ true);
887
0
888
0
  }
889
890
  inline JS::Handle<JSObject*> GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true)
891
0
  {
892
0
    /* Get the interface object for this class.  This will create the object as
893
0
       needed. */
894
0
895
0
    return GetPerInterfaceObjectHandle(aCx, constructors::id::XMLHttpRequest,
896
0
                                       &CreateInterfaceObjects,
897
0
                                       aDefineOnGlobal);
898
0
  }
899
900
  JSObject*
901
  GetConstructorObject(JSContext* aCx);
902
903
} // namespace XMLHttpRequest_Binding
904
905
906
907
} // namespace dom
908
} // namespace mozilla
909
910
#endif // mozilla_dom_XMLHttpRequestBinding_h