Coverage Report

Created: 2018-09-25 14:53

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