Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ResponseBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Response.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "ResponseBinding.h"
5
#include "WrapperFactory.h"
6
#include "jsapi.h"
7
#include "jsfriendapi.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/Blob.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/DOMPrefs.h"
13
#include "mozilla/dom/FormData.h"
14
#include "mozilla/dom/Headers.h"
15
#include "mozilla/dom/NonRefcountedDOMObject.h"
16
#include "mozilla/dom/Nullable.h"
17
#include "mozilla/dom/PrimitiveConversions.h"
18
#include "mozilla/dom/Promise.h"
19
#include "mozilla/dom/ReadableStream.h"
20
#include "mozilla/dom/Response.h"
21
#include "mozilla/dom/ScriptSettings.h"
22
#include "mozilla/dom/ToJSValue.h"
23
#include "mozilla/dom/URLSearchParams.h"
24
#include "mozilla/dom/UnionConversions.h"
25
#include "mozilla/dom/XrayExpandoClass.h"
26
#include "nsContentUtils.h"
27
28
namespace mozilla {
29
namespace dom {
30
31
namespace binding_detail {}; // Just to make sure it's known as a namespace
32
using namespace mozilla::dom::binding_detail;
33
34
35
namespace ResponseTypeValues {
36
extern const EnumEntry strings[7] = {
37
  {"basic", 5},
38
  {"cors", 4},
39
  {"default", 7},
40
  {"error", 5},
41
  {"opaque", 6},
42
  {"opaqueredirect", 14},
43
  { nullptr, 0 }
44
};
45
} // namespace ResponseTypeValues
46
47
bool
48
ToJSValue(JSContext* aCx, ResponseType aArgument, JS::MutableHandle<JS::Value> aValue)
49
0
{
50
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ResponseTypeValues::strings));
51
0
  JSString* resultStr =
52
0
    JS_NewStringCopyN(aCx, ResponseTypeValues::strings[uint32_t(aArgument)].value,
53
0
                      ResponseTypeValues::strings[uint32_t(aArgument)].length);
54
0
  if (!resultStr) {
55
0
    return false;
56
0
  }
57
0
  aValue.setString(resultStr);
58
0
  return true;
59
0
}
60
61
62
void
63
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString& aUnion, const char* aName, uint32_t aFlags)
64
0
{
65
0
  if (aUnion.IsBlob()) {
66
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsBlob(), "mBlob", aFlags);
67
0
  } else if (aUnion.IsFormData()) {
68
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsFormData(), "mFormData", aFlags);
69
0
  } else if (aUnion.IsURLSearchParams()) {
70
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsURLSearchParams(), "mURLSearchParams", aFlags);
71
0
  }
72
0
}
73
74
75
void
76
ImplCycleCollectionUnlink(OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString& aUnion)
77
0
{
78
0
  aUnion.Uninit();
79
0
}
80
81
82
bool
83
BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
84
0
{
85
0
  switch (mType) {
86
0
    case eUninitialized: {
87
0
      return false;
88
0
      break;
89
0
    }
90
0
    case eBlob: {
91
0
      if (!GetOrCreateDOMReflector(cx, mValue.mBlob.Value(), rval)) {
92
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
93
0
        return false;
94
0
      }
95
0
      return true;
96
0
      break;
97
0
    }
98
0
    case eArrayBufferView: {
99
0
      rval.setObject(*mValue.mArrayBufferView.Value().Obj());
100
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
101
0
        return false;
102
0
      }
103
0
      return true;
104
0
      break;
105
0
    }
106
0
    case eArrayBuffer: {
107
0
      rval.setObject(*mValue.mArrayBuffer.Value().Obj());
108
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
109
0
        return false;
110
0
      }
111
0
      return true;
112
0
      break;
113
0
    }
114
0
    case eFormData: {
115
0
      if (!GetOrCreateDOMReflector(cx, mValue.mFormData.Value(), rval)) {
116
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
117
0
        return false;
118
0
      }
119
0
      return true;
120
0
      break;
121
0
    }
122
0
    case eURLSearchParams: {
123
0
      if (!GetOrCreateDOMReflector(cx, mValue.mURLSearchParams.Value(), rval)) {
124
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
125
0
        return false;
126
0
      }
127
0
      return true;
128
0
      break;
129
0
    }
130
0
    case eReadableStream: {
131
0
      rval.setObject(*mValue.mReadableStream.Value().Obj());
132
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
133
0
        return false;
134
0
      }
135
0
      return true;
136
0
      break;
137
0
    }
138
0
    case eUSVString: {
139
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
140
0
        return false;
141
0
      }
142
0
      return true;
143
0
      break;
144
0
    }
145
0
    default: {
146
0
      return false;
147
0
      break;
148
0
    }
149
0
  }
150
0
151
0
  return false;
152
0
}
153
154
155
OwningNonNull<mozilla::dom::Blob>&
156
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsBlob()
157
0
{
158
0
  if (mType == eBlob) {
159
0
    return mValue.mBlob.Value();
160
0
  }
161
0
  MOZ_ASSERT(mType == eUninitialized);
162
0
  mType = eBlob;
163
0
  return mValue.mBlob.SetValue();
164
0
}
165
166
OwningNonNull<mozilla::dom::Blob>&
167
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsBlob()
168
0
{
169
0
  if (mType == eBlob) {
170
0
    return mValue.mBlob.Value();
171
0
  }
172
0
  Uninit();
173
0
  mType = eBlob;
174
0
  return mValue.mBlob.SetValue();
175
0
}
176
177
bool
178
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToBlob(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
179
0
{
180
0
  tryNext = false;
181
0
  { // scope for memberSlot
182
0
    OwningNonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
183
0
    static_assert(IsRefcounted<mozilla::dom::Blob>::value, "We can only store refcounted classes.");{
184
0
      nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
185
0
      if (NS_FAILED(rv)) {
186
0
        DestroyBlob();
187
0
        tryNext = true;
188
0
        return true;
189
0
      }
190
0
    }
191
0
  }
192
0
  return true;
193
0
}
194
195
void
196
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyBlob()
197
0
{
198
0
  MOZ_ASSERT(IsBlob(), "Wrong type!");
199
0
  mValue.mBlob.Destroy();
200
0
  mType = eUninitialized;
201
0
}
202
203
204
205
206
ArrayBufferView&
207
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsArrayBufferView()
208
0
{
209
0
  if (mType == eArrayBufferView) {
210
0
    return mValue.mArrayBufferView.Value();
211
0
  }
212
0
  MOZ_ASSERT(mType == eUninitialized);
213
0
  mType = eArrayBufferView;
214
0
  return mValue.mArrayBufferView.SetValue();
215
0
}
216
217
ArrayBufferView&
218
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsArrayBufferView()
219
0
{
220
0
  if (mType == eArrayBufferView) {
221
0
    return mValue.mArrayBufferView.Value();
222
0
  }
223
0
  Uninit();
224
0
  mType = eArrayBufferView;
225
0
  return mValue.mArrayBufferView.SetValue();
226
0
}
227
228
bool
229
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
230
0
{
231
0
  tryNext = false;
232
0
  { // scope for memberSlot
233
0
    ArrayBufferView& memberSlot = RawSetAsArrayBufferView();
234
0
    if (!memberSlot.Init(&value.toObject())) {
235
0
      DestroyArrayBufferView();
236
0
      tryNext = true;
237
0
      return true;
238
0
    }
239
0
  }
240
0
  return true;
241
0
}
242
243
void
244
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyArrayBufferView()
245
0
{
246
0
  MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
247
0
  mValue.mArrayBufferView.Destroy();
248
0
  mType = eUninitialized;
249
0
}
250
251
252
253
254
ArrayBuffer&
255
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsArrayBuffer()
256
0
{
257
0
  if (mType == eArrayBuffer) {
258
0
    return mValue.mArrayBuffer.Value();
259
0
  }
260
0
  MOZ_ASSERT(mType == eUninitialized);
261
0
  mType = eArrayBuffer;
262
0
  return mValue.mArrayBuffer.SetValue();
263
0
}
264
265
ArrayBuffer&
266
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsArrayBuffer()
267
0
{
268
0
  if (mType == eArrayBuffer) {
269
0
    return mValue.mArrayBuffer.Value();
270
0
  }
271
0
  Uninit();
272
0
  mType = eArrayBuffer;
273
0
  return mValue.mArrayBuffer.SetValue();
274
0
}
275
276
bool
277
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
278
0
{
279
0
  tryNext = false;
280
0
  { // scope for memberSlot
281
0
    ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
282
0
    if (!memberSlot.Init(&value.toObject())) {
283
0
      DestroyArrayBuffer();
284
0
      tryNext = true;
285
0
      return true;
286
0
    }
287
0
  }
288
0
  return true;
289
0
}
290
291
void
292
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyArrayBuffer()
293
0
{
294
0
  MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
295
0
  mValue.mArrayBuffer.Destroy();
296
0
  mType = eUninitialized;
297
0
}
298
299
300
301
302
OwningNonNull<mozilla::dom::FormData>&
303
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsFormData()
304
0
{
305
0
  if (mType == eFormData) {
306
0
    return mValue.mFormData.Value();
307
0
  }
308
0
  MOZ_ASSERT(mType == eUninitialized);
309
0
  mType = eFormData;
310
0
  return mValue.mFormData.SetValue();
311
0
}
312
313
OwningNonNull<mozilla::dom::FormData>&
314
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsFormData()
315
0
{
316
0
  if (mType == eFormData) {
317
0
    return mValue.mFormData.Value();
318
0
  }
319
0
  Uninit();
320
0
  mType = eFormData;
321
0
  return mValue.mFormData.SetValue();
322
0
}
323
324
bool
325
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToFormData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
326
0
{
327
0
  tryNext = false;
328
0
  { // scope for memberSlot
329
0
    OwningNonNull<mozilla::dom::FormData>& memberSlot = RawSetAsFormData();
330
0
    static_assert(IsRefcounted<mozilla::dom::FormData>::value, "We can only store refcounted classes.");{
331
0
      nsresult rv = UnwrapObject<prototypes::id::FormData, mozilla::dom::FormData>(value, memberSlot);
332
0
      if (NS_FAILED(rv)) {
333
0
        DestroyFormData();
334
0
        tryNext = true;
335
0
        return true;
336
0
      }
337
0
    }
338
0
  }
339
0
  return true;
340
0
}
341
342
void
343
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyFormData()
344
0
{
345
0
  MOZ_ASSERT(IsFormData(), "Wrong type!");
346
0
  mValue.mFormData.Destroy();
347
0
  mType = eUninitialized;
348
0
}
349
350
351
352
353
OwningNonNull<mozilla::dom::URLSearchParams>&
354
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsURLSearchParams()
355
0
{
356
0
  if (mType == eURLSearchParams) {
357
0
    return mValue.mURLSearchParams.Value();
358
0
  }
359
0
  MOZ_ASSERT(mType == eUninitialized);
360
0
  mType = eURLSearchParams;
361
0
  return mValue.mURLSearchParams.SetValue();
362
0
}
363
364
OwningNonNull<mozilla::dom::URLSearchParams>&
365
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsURLSearchParams()
366
0
{
367
0
  if (mType == eURLSearchParams) {
368
0
    return mValue.mURLSearchParams.Value();
369
0
  }
370
0
  Uninit();
371
0
  mType = eURLSearchParams;
372
0
  return mValue.mURLSearchParams.SetValue();
373
0
}
374
375
bool
376
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToURLSearchParams(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
377
0
{
378
0
  tryNext = false;
379
0
  { // scope for memberSlot
380
0
    OwningNonNull<mozilla::dom::URLSearchParams>& memberSlot = RawSetAsURLSearchParams();
381
0
    static_assert(IsRefcounted<mozilla::dom::URLSearchParams>::value, "We can only store refcounted classes.");{
382
0
      nsresult rv = UnwrapObject<prototypes::id::URLSearchParams, mozilla::dom::URLSearchParams>(value, memberSlot);
383
0
      if (NS_FAILED(rv)) {
384
0
        DestroyURLSearchParams();
385
0
        tryNext = true;
386
0
        return true;
387
0
      }
388
0
    }
389
0
  }
390
0
  return true;
391
0
}
392
393
void
394
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyURLSearchParams()
395
0
{
396
0
  MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
397
0
  mValue.mURLSearchParams.Destroy();
398
0
  mType = eUninitialized;
399
0
}
400
401
402
403
404
ReadableStream&
405
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsReadableStream()
406
0
{
407
0
  if (mType == eReadableStream) {
408
0
    return mValue.mReadableStream.Value();
409
0
  }
410
0
  MOZ_ASSERT(mType == eUninitialized);
411
0
  mType = eReadableStream;
412
0
  return mValue.mReadableStream.SetValue();
413
0
}
414
415
ReadableStream&
416
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsReadableStream()
417
0
{
418
0
  if (mType == eReadableStream) {
419
0
    return mValue.mReadableStream.Value();
420
0
  }
421
0
  Uninit();
422
0
  mType = eReadableStream;
423
0
  return mValue.mReadableStream.SetValue();
424
0
}
425
426
bool
427
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToReadableStream(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
428
0
{
429
0
  tryNext = false;
430
0
  { // scope for memberSlot
431
0
    ReadableStream& memberSlot = RawSetAsReadableStream();
432
0
    if (!memberSlot.Init(&value.toObject())) {
433
0
      DestroyReadableStream();
434
0
      tryNext = true;
435
0
      return true;
436
0
    }
437
0
  }
438
0
  return true;
439
0
}
440
441
void
442
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyReadableStream()
443
0
{
444
0
  MOZ_ASSERT(IsReadableStream(), "Wrong type!");
445
0
  mValue.mReadableStream.Destroy();
446
0
  mType = eUninitialized;
447
0
}
448
449
450
451
452
nsString&
453
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::RawSetAsUSVString()
454
0
{
455
0
  if (mType == eUSVString) {
456
0
    return mValue.mUSVString.Value();
457
0
  }
458
0
  MOZ_ASSERT(mType == eUninitialized);
459
0
  mType = eUSVString;
460
0
  return mValue.mUSVString.SetValue();
461
0
}
462
463
nsString&
464
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::SetAsUSVString()
465
0
{
466
0
  if (mType == eUSVString) {
467
0
    return mValue.mUSVString.Value();
468
0
  }
469
0
  Uninit();
470
0
  mType = eUSVString;
471
0
  return mValue.mUSVString.SetValue();
472
0
}
473
474
bool
475
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
476
0
{
477
0
  tryNext = false;
478
0
  { // scope for memberSlot
479
0
    nsString& memberSlot = RawSetAsUSVString();
480
0
    if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
481
0
      return false;
482
0
    }
483
0
    NormalizeUSVString(memberSlot);
484
0
  }
485
0
  return true;
486
0
}
487
488
489
void
490
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::DestroyUSVString()
491
0
{
492
0
  MOZ_ASSERT(IsUSVString(), "Wrong type!");
493
0
  mValue.mUSVString.Destroy();
494
0
  mType = eUninitialized;
495
0
}
496
497
498
499
500
void
501
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::Uninit()
502
{
503
  switch (mType) {
504
    case eUninitialized: {
505
      break;
506
    }
507
    case eBlob: {
508
      DestroyBlob();
509
      break;
510
    }
511
    case eArrayBufferView: {
512
      DestroyArrayBufferView();
513
      break;
514
    }
515
    case eArrayBuffer: {
516
      DestroyArrayBuffer();
517
      break;
518
    }
519
    case eFormData: {
520
      DestroyFormData();
521
      break;
522
    }
523
    case eURLSearchParams: {
524
      DestroyURLSearchParams();
525
      break;
526
    }
527
    case eReadableStream: {
528
      DestroyReadableStream();
529
      break;
530
    }
531
    case eUSVString: {
532
      DestroyUSVString();
533
      break;
534
    }
535
  }
536
}
537
538
bool
539
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
540
0
{
541
0
  switch (mType) {
542
0
    case eUninitialized: {
543
0
      return false;
544
0
      break;
545
0
    }
546
0
    case eBlob: {
547
0
      if (!GetOrCreateDOMReflector(cx, mValue.mBlob.Value(), rval)) {
548
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
549
0
        return false;
550
0
      }
551
0
      return true;
552
0
      break;
553
0
    }
554
0
    case eArrayBufferView: {
555
0
      rval.setObject(*mValue.mArrayBufferView.Value().Obj());
556
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
557
0
        return false;
558
0
      }
559
0
      return true;
560
0
      break;
561
0
    }
562
0
    case eArrayBuffer: {
563
0
      rval.setObject(*mValue.mArrayBuffer.Value().Obj());
564
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
565
0
        return false;
566
0
      }
567
0
      return true;
568
0
      break;
569
0
    }
570
0
    case eFormData: {
571
0
      if (!GetOrCreateDOMReflector(cx, mValue.mFormData.Value(), rval)) {
572
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
573
0
        return false;
574
0
      }
575
0
      return true;
576
0
      break;
577
0
    }
578
0
    case eURLSearchParams: {
579
0
      if (!GetOrCreateDOMReflector(cx, mValue.mURLSearchParams.Value(), rval)) {
580
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
581
0
        return false;
582
0
      }
583
0
      return true;
584
0
      break;
585
0
    }
586
0
    case eReadableStream: {
587
0
      rval.setObject(*mValue.mReadableStream.Value().Obj());
588
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
589
0
        return false;
590
0
      }
591
0
      return true;
592
0
      break;
593
0
    }
594
0
    case eUSVString: {
595
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
596
0
        return false;
597
0
      }
598
0
      return true;
599
0
      break;
600
0
    }
601
0
    default: {
602
0
      return false;
603
0
      break;
604
0
    }
605
0
  }
606
0
607
0
  return false;
608
0
}
609
610
void
611
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString::TraceUnion(JSTracer* trc)
612
{
613
  switch (mType) {
614
    case eArrayBufferView: {
615
      mValue.mArrayBufferView.Value().TraceSelf(trc);
616
      break;
617
    }
618
    case eArrayBuffer: {
619
      mValue.mArrayBuffer.Value().TraceSelf(trc);
620
      break;
621
    }
622
    case eReadableStream: {
623
      mValue.mReadableStream.Value().TraceSelf(trc);
624
      break;
625
    }
626
    default: {
627
      break;
628
    }
629
  }
630
}
631
632
633
634
ResponseInit::ResponseInit()
635
0
{
636
0
  // Safe to pass a null context if we pass a null value
637
0
  Init(nullptr, JS::NullHandleValue);
638
0
}
639
640
641
bool
642
ResponseInit::InitIds(JSContext* cx, ResponseInitAtoms* atomsCache)
643
0
{
644
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
645
0
646
0
  // Initialize these in reverse order so that any failure leaves the first one
647
0
  // uninitialized.
648
0
  if (!atomsCache->statusText_id.init(cx, "statusText") ||
649
0
      !atomsCache->status_id.init(cx, "status") ||
650
0
      !atomsCache->headers_id.init(cx, "headers")) {
651
0
    return false;
652
0
  }
653
0
  return true;
654
0
}
655
656
bool
657
ResponseInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
658
0
{
659
0
  // Passing a null JSContext is OK only if we're initing from null,
660
0
  // Since in that case we will not have to do any property gets
661
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
662
0
  // checkers by static analysis tools
663
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
664
0
  ResponseInitAtoms* atomsCache = nullptr;
665
0
  if (cx) {
666
0
    atomsCache = GetAtomCache<ResponseInitAtoms>(cx);
667
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
668
0
      return false;
669
0
    }
670
0
  }
671
0
672
0
  if (!IsConvertibleToDictionary(val)) {
673
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
674
0
  }
675
0
676
0
  bool isNull = val.isNullOrUndefined();
677
0
  // We only need these if !isNull, in which case we have |cx|.
678
0
  Maybe<JS::Rooted<JSObject *> > object;
679
0
  Maybe<JS::Rooted<JS::Value> > temp;
680
0
  if (!isNull) {
681
0
    MOZ_ASSERT(cx);
682
0
    object.emplace(cx, &val.toObject());
683
0
    temp.emplace(cx);
684
0
  }
685
0
  if (!isNull) {
686
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->headers_id, temp.ptr())) {
687
0
      return false;
688
0
    }
689
0
  }
690
0
  if (!isNull && !temp->isUndefined()) {
691
0
    mHeaders.Construct();
692
0
    {
693
0
      bool done = false, failed = false, tryNext;
694
0
      if (temp.ref().isObject()) {
695
0
        done = (failed = !(mHeaders.Value()).TrySetToHeaders(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
696
0
697
0
        if (!done) {
698
0
          done = (failed = !(mHeaders.Value()).TrySetToByteStringSequenceSequence(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
699
0
        }
700
0
        if (!done) {
701
0
          done = (failed = !(mHeaders.Value()).TrySetToByteStringByteStringRecord(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
702
0
        }
703
0
      }
704
0
      if (failed) {
705
0
        return false;
706
0
      }
707
0
      if (!done) {
708
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'headers' member of ResponseInit", "Headers, ByteStringSequenceSequence, ByteStringByteStringRecord");
709
0
        return false;
710
0
      }
711
0
    }
712
0
    mIsAnyMemberPresent = true;
713
0
  }
714
0
715
0
  if (!isNull) {
716
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->status_id, temp.ptr())) {
717
0
      return false;
718
0
    }
719
0
  }
720
0
  if (!isNull && !temp->isUndefined()) {
721
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &mStatus)) {
722
0
      return false;
723
0
    }
724
0
  } else {
725
0
    mStatus = 200;
726
0
  }
727
0
  mIsAnyMemberPresent = true;
728
0
729
0
  if (!isNull) {
730
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->statusText_id, temp.ptr())) {
731
0
      return false;
732
0
    }
733
0
  }
734
0
  if (!isNull && !temp->isUndefined()) {
735
0
    if (!ConvertJSValueToByteString(cx, temp.ref(), false, mStatusText)) {
736
0
      return false;
737
0
    }
738
0
  } else {
739
0
    static const char data[] = { 'O', 'K', 0 };
740
0
    mStatusText.Rebind(data, ArrayLength(data) - 1);
741
0
  }
742
0
  mIsAnyMemberPresent = true;
743
0
  return true;
744
0
}
745
746
bool
747
ResponseInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
748
0
{
749
0
  ResponseInitAtoms* atomsCache = GetAtomCache<ResponseInitAtoms>(cx);
750
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
751
0
    return false;
752
0
  }
753
0
754
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
755
0
  if (!obj) {
756
0
    return false;
757
0
  }
758
0
  rval.set(JS::ObjectValue(*obj));
759
0
760
0
  if (mHeaders.WasPassed()) {
761
0
    do {
762
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
763
0
      JS::Rooted<JS::Value> temp(cx);
764
0
      OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord const & currentValue = mHeaders.InternalValue();
765
0
      if (!currentValue.ToJSVal(cx, obj, &temp)) {
766
0
        return false;
767
0
      }
768
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->headers_id, temp, JSPROP_ENUMERATE)) {
769
0
        return false;
770
0
      }
771
0
      break;
772
0
    } while(false);
773
0
  }
774
0
775
0
  do {
776
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
777
0
    JS::Rooted<JS::Value> temp(cx);
778
0
    uint16_t const & currentValue = mStatus;
779
0
    temp.setInt32(int32_t(currentValue));
780
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->status_id, temp, JSPROP_ENUMERATE)) {
781
0
      return false;
782
0
    }
783
0
    break;
784
0
  } while(false);
785
0
786
0
  do {
787
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
788
0
    JS::Rooted<JS::Value> temp(cx);
789
0
    nsCString const & currentValue = mStatusText;
790
0
    if (!NonVoidByteStringToJsval(cx, currentValue, &temp)) {
791
0
      return false;
792
0
    }
793
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->statusText_id, temp, JSPROP_ENUMERATE)) {
794
0
      return false;
795
0
    }
796
0
    break;
797
0
  } while(false);
798
0
799
0
  return true;
800
0
}
801
802
void
803
ResponseInit::TraceDictionary(JSTracer* trc)
804
0
{
805
0
}
806
807
808
809
namespace binding_detail {
810
} // namespace binding_detail
811
812
813
namespace Response_Binding {
814
815
static bool
816
error(JSContext* cx, unsigned argc, JS::Value* vp)
817
0
{
818
0
  AUTO_PROFILER_LABEL_FAST("Response.error", DOM, cx);
819
0
820
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
821
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
822
0
823
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
824
0
  if (global.Failed()) {
825
0
    return false;
826
0
  }
827
0
828
0
  auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Error(global)));
829
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
830
0
  static_assert(!IsPointer<decltype(result)>::value,
831
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
832
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
833
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
834
0
    return false;
835
0
  }
836
0
  return true;
837
0
}
838
839
static bool
840
redirect(JSContext* cx, unsigned argc, JS::Value* vp)
841
0
{
842
0
  AUTO_PROFILER_LABEL_FAST("Response.redirect", DOM, cx);
843
0
844
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
845
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
846
0
847
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
848
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Response.redirect");
849
0
  }
850
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
851
0
  if (global.Failed()) {
852
0
    return false;
853
0
  }
854
0
855
0
  binding_detail::FakeString arg0;
856
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
857
0
    return false;
858
0
  }
859
0
  NormalizeUSVString(arg0);
860
0
  uint16_t arg1;
861
0
  if (args.hasDefined(1)) {
862
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
863
0
      return false;
864
0
    }
865
0
  } else {
866
0
    arg1 = 302;
867
0
  }
868
0
  FastErrorResult rv;
869
0
  auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Redirect(global, Constify(arg0), arg1, rv)));
870
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
871
0
    return false;
872
0
  }
873
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
874
0
  static_assert(!IsPointer<decltype(result)>::value,
875
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
876
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
877
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
878
0
    return false;
879
0
  }
880
0
  return true;
881
0
}
882
883
MOZ_CAN_RUN_SCRIPT static bool
884
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
885
0
{
886
0
  AUTO_PROFILER_LABEL_FAST("get Response.type", DOM, cx);
887
0
888
0
  ResponseType result(self->Type());
889
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
890
0
  if (!ToJSValue(cx, result, args.rval())) {
891
0
    return false;
892
0
  }
893
0
  return true;
894
0
}
895
896
static const JSJitInfo type_getterinfo = {
897
  { (JSJitGetterOp)get_type },
898
  { prototypes::id::Response },
899
  { PrototypeTraits<prototypes::id::Response>::Depth },
900
  JSJitInfo::Getter,
901
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
902
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
903
  false,  /* isInfallible. False in setters. */
904
  false,  /* isMovable.  Not relevant for setters. */
905
  false, /* isEliminatable.  Not relevant for setters. */
906
  false, /* isAlwaysInSlot.  Only relevant for getters. */
907
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
908
  false,  /* isTypedMethod.  Only relevant for methods. */
909
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
910
};
911
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
912
static_assert(0 < 1, "There is no slot for us");
913
914
MOZ_CAN_RUN_SCRIPT static bool
915
get_url(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
916
0
{
917
0
  AUTO_PROFILER_LABEL_FAST("get Response.url", DOM, cx);
918
0
919
0
  DOMString result;
920
0
  self->GetUrl(result);
921
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
922
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
923
0
    return false;
924
0
  }
925
0
  return true;
926
0
}
927
928
static const JSJitInfo url_getterinfo = {
929
  { (JSJitGetterOp)get_url },
930
  { prototypes::id::Response },
931
  { PrototypeTraits<prototypes::id::Response>::Depth },
932
  JSJitInfo::Getter,
933
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
934
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
935
  false,  /* isInfallible. False in setters. */
936
  false,  /* isMovable.  Not relevant for setters. */
937
  false, /* isEliminatable.  Not relevant for setters. */
938
  false, /* isAlwaysInSlot.  Only relevant for getters. */
939
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
940
  false,  /* isTypedMethod.  Only relevant for methods. */
941
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
942
};
943
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
944
static_assert(0 < 1, "There is no slot for us");
945
946
MOZ_CAN_RUN_SCRIPT static bool
947
get_redirected(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
948
0
{
949
0
  AUTO_PROFILER_LABEL_FAST("get Response.redirected", DOM, cx);
950
0
951
0
  bool result(self->Redirected());
952
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
953
0
  args.rval().setBoolean(result);
954
0
  return true;
955
0
}
956
957
static const JSJitInfo redirected_getterinfo = {
958
  { (JSJitGetterOp)get_redirected },
959
  { prototypes::id::Response },
960
  { PrototypeTraits<prototypes::id::Response>::Depth },
961
  JSJitInfo::Getter,
962
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
963
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
964
  true,  /* isInfallible. False in setters. */
965
  false,  /* isMovable.  Not relevant for setters. */
966
  false, /* isEliminatable.  Not relevant for setters. */
967
  false, /* isAlwaysInSlot.  Only relevant for getters. */
968
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
969
  false,  /* isTypedMethod.  Only relevant for methods. */
970
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
971
};
972
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
973
static_assert(0 < 1, "There is no slot for us");
974
975
MOZ_CAN_RUN_SCRIPT static bool
976
get_status(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
977
0
{
978
0
  AUTO_PROFILER_LABEL_FAST("get Response.status", DOM, cx);
979
0
980
0
  uint16_t result(self->Status());
981
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
982
0
  args.rval().setInt32(int32_t(result));
983
0
  return true;
984
0
}
985
986
static const JSJitInfo status_getterinfo = {
987
  { (JSJitGetterOp)get_status },
988
  { prototypes::id::Response },
989
  { PrototypeTraits<prototypes::id::Response>::Depth },
990
  JSJitInfo::Getter,
991
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
992
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
993
  true,  /* isInfallible. False in setters. */
994
  false,  /* isMovable.  Not relevant for setters. */
995
  false, /* isEliminatable.  Not relevant for setters. */
996
  false, /* isAlwaysInSlot.  Only relevant for getters. */
997
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
998
  false,  /* isTypedMethod.  Only relevant for methods. */
999
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1000
};
1001
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1002
static_assert(0 < 1, "There is no slot for us");
1003
1004
MOZ_CAN_RUN_SCRIPT static bool
1005
get_ok(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
1006
0
{
1007
0
  AUTO_PROFILER_LABEL_FAST("get Response.ok", DOM, cx);
1008
0
1009
0
  bool result(self->Ok());
1010
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1011
0
  args.rval().setBoolean(result);
1012
0
  return true;
1013
0
}
1014
1015
static const JSJitInfo ok_getterinfo = {
1016
  { (JSJitGetterOp)get_ok },
1017
  { prototypes::id::Response },
1018
  { PrototypeTraits<prototypes::id::Response>::Depth },
1019
  JSJitInfo::Getter,
1020
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1021
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1022
  true,  /* isInfallible. False in setters. */
1023
  false,  /* isMovable.  Not relevant for setters. */
1024
  false, /* isEliminatable.  Not relevant for setters. */
1025
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1026
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1027
  false,  /* isTypedMethod.  Only relevant for methods. */
1028
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1029
};
1030
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1031
static_assert(0 < 1, "There is no slot for us");
1032
1033
MOZ_CAN_RUN_SCRIPT static bool
1034
get_statusText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
1035
0
{
1036
0
  AUTO_PROFILER_LABEL_FAST("get Response.statusText", DOM, cx);
1037
0
1038
0
  nsCString result;
1039
0
  self->GetStatusText(result);
1040
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1041
0
  if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
1042
0
    return false;
1043
0
  }
1044
0
  return true;
1045
0
}
1046
1047
static const JSJitInfo statusText_getterinfo = {
1048
  { (JSJitGetterOp)get_statusText },
1049
  { prototypes::id::Response },
1050
  { PrototypeTraits<prototypes::id::Response>::Depth },
1051
  JSJitInfo::Getter,
1052
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1053
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1054
  false,  /* isInfallible. False in setters. */
1055
  false,  /* isMovable.  Not relevant for setters. */
1056
  false, /* isEliminatable.  Not relevant for setters. */
1057
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1058
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1059
  false,  /* isTypedMethod.  Only relevant for methods. */
1060
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1061
};
1062
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1063
static_assert(0 < 1, "There is no slot for us");
1064
1065
MOZ_CAN_RUN_SCRIPT static bool
1066
get_headers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
1067
0
{
1068
0
  AUTO_PROFILER_LABEL_FAST("get Response.headers", DOM, cx);
1069
0
1070
0
  auto result(StrongOrRawPtr<mozilla::dom::Headers>(self->Headers_()));
1071
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1072
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1073
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1074
0
    return false;
1075
0
  }
1076
0
  return true;
1077
0
}
1078
1079
static const JSJitInfo headers_getterinfo = {
1080
  { (JSJitGetterOp)get_headers },
1081
  { prototypes::id::Response },
1082
  { PrototypeTraits<prototypes::id::Response>::Depth },
1083
  JSJitInfo::Getter,
1084
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
1085
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1086
  false,  /* isInfallible. False in setters. */
1087
  true,  /* isMovable.  Not relevant for setters. */
1088
  true, /* isEliminatable.  Not relevant for setters. */
1089
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1090
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1091
  false,  /* isTypedMethod.  Only relevant for methods. */
1092
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1093
};
1094
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1095
static_assert(0 < 1, "There is no slot for us");
1096
1097
MOZ_CAN_RUN_SCRIPT static bool
1098
clone(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1099
0
{
1100
0
  AUTO_PROFILER_LABEL_FAST("Response.clone", DOM, cx);
1101
0
1102
0
  FastErrorResult rv;
1103
0
  auto result(StrongOrRawPtr<mozilla::dom::Response>(self->Clone(cx, rv)));
1104
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1105
0
    return false;
1106
0
  }
1107
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1108
0
  static_assert(!IsPointer<decltype(result)>::value,
1109
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1110
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1111
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1112
0
    return false;
1113
0
  }
1114
0
  return true;
1115
0
}
1116
1117
static const JSJitInfo clone_methodinfo = {
1118
  { (JSJitGetterOp)clone },
1119
  { prototypes::id::Response },
1120
  { PrototypeTraits<prototypes::id::Response>::Depth },
1121
  JSJitInfo::Method,
1122
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1123
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1124
  false,  /* isInfallible. False in setters. */
1125
  false,  /* isMovable.  Not relevant for setters. */
1126
  false, /* isEliminatable.  Not relevant for setters. */
1127
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1128
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1129
  false,  /* isTypedMethod.  Only relevant for methods. */
1130
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1131
};
1132
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1133
static_assert(0 < 1, "There is no slot for us");
1134
1135
MOZ_CAN_RUN_SCRIPT static bool
1136
cloneUnfiltered(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1137
0
{
1138
0
  AUTO_PROFILER_LABEL_FAST("Response.cloneUnfiltered", DOM, cx);
1139
0
1140
0
  FastErrorResult rv;
1141
0
  auto result(StrongOrRawPtr<mozilla::dom::Response>(self->CloneUnfiltered(cx, rv)));
1142
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1143
0
    return false;
1144
0
  }
1145
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1146
0
  static_assert(!IsPointer<decltype(result)>::value,
1147
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1148
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1149
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1150
0
    return false;
1151
0
  }
1152
0
  return true;
1153
0
}
1154
1155
static const JSJitInfo cloneUnfiltered_methodinfo = {
1156
  { (JSJitGetterOp)cloneUnfiltered },
1157
  { prototypes::id::Response },
1158
  { PrototypeTraits<prototypes::id::Response>::Depth },
1159
  JSJitInfo::Method,
1160
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1161
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1162
  false,  /* isInfallible. False in setters. */
1163
  false,  /* isMovable.  Not relevant for setters. */
1164
  false, /* isEliminatable.  Not relevant for setters. */
1165
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1166
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1167
  false,  /* isTypedMethod.  Only relevant for methods. */
1168
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1169
};
1170
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1171
static_assert(0 < 1, "There is no slot for us");
1172
1173
MOZ_CAN_RUN_SCRIPT static bool
1174
get_body(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
1175
0
{
1176
0
  AUTO_PROFILER_LABEL_FAST("get Response.body", DOM, cx);
1177
0
1178
0
  FastErrorResult rv;
1179
0
  JS::Rooted<JSObject*> result(cx);
1180
0
  self->GetBody(cx, &result, rv);
1181
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1182
0
    return false;
1183
0
  }
1184
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1185
0
  if (result) {
1186
0
                JS::ExposeObjectToActiveJS(result);
1187
0
              }
1188
0
              args.rval().setObjectOrNull(result);
1189
0
  if (!MaybeWrapNonDOMObjectOrNullValue(cx, args.rval())) {
1190
0
    return false;
1191
0
  }
1192
0
  return true;
1193
0
}
1194
1195
static const JSJitInfo body_getterinfo = {
1196
  { (JSJitGetterOp)get_body },
1197
  { prototypes::id::Response },
1198
  { PrototypeTraits<prototypes::id::Response>::Depth },
1199
  JSJitInfo::Getter,
1200
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1201
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1202
  false,  /* isInfallible. False in setters. */
1203
  false,  /* isMovable.  Not relevant for setters. */
1204
  false, /* isEliminatable.  Not relevant for setters. */
1205
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1206
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1207
  false,  /* isTypedMethod.  Only relevant for methods. */
1208
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1209
};
1210
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1211
static_assert(0 < 1, "There is no slot for us");
1212
1213
MOZ_CAN_RUN_SCRIPT static bool
1214
get_bodyUsed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
1215
0
{
1216
0
  AUTO_PROFILER_LABEL_FAST("get Response.bodyUsed", DOM, cx);
1217
0
1218
0
  bool result(self->BodyUsed());
1219
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1220
0
  args.rval().setBoolean(result);
1221
0
  return true;
1222
0
}
1223
1224
static const JSJitInfo bodyUsed_getterinfo = {
1225
  { (JSJitGetterOp)get_bodyUsed },
1226
  { prototypes::id::Response },
1227
  { PrototypeTraits<prototypes::id::Response>::Depth },
1228
  JSJitInfo::Getter,
1229
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1230
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1231
  true,  /* isInfallible. False in setters. */
1232
  false,  /* isMovable.  Not relevant for setters. */
1233
  false, /* isEliminatable.  Not relevant for setters. */
1234
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1235
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1236
  false,  /* isTypedMethod.  Only relevant for methods. */
1237
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1238
};
1239
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1240
static_assert(0 < 1, "There is no slot for us");
1241
1242
MOZ_CAN_RUN_SCRIPT static bool
1243
arrayBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1244
0
{
1245
0
  AUTO_PROFILER_LABEL_FAST("Response.arrayBuffer", DOM, cx);
1246
0
1247
0
  FastErrorResult rv;
1248
0
  auto result(StrongOrRawPtr<Promise>(self->ArrayBuffer(cx, rv)));
1249
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1250
0
    return false;
1251
0
  }
1252
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1253
0
  if (!ToJSValue(cx, result, args.rval())) {
1254
0
    return false;
1255
0
  }
1256
0
  return true;
1257
0
}
1258
1259
MOZ_CAN_RUN_SCRIPT static bool
1260
arrayBuffer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1261
0
{
1262
0
  bool ok = arrayBuffer(cx, obj, self, args);
1263
0
  if (ok) {
1264
0
    return true;
1265
0
  }
1266
0
  return ConvertExceptionToPromise(cx, args.rval());
1267
0
}
1268
1269
static const JSJitInfo arrayBuffer_methodinfo = {
1270
  { (JSJitGetterOp)arrayBuffer_promiseWrapper },
1271
  { prototypes::id::Response },
1272
  { PrototypeTraits<prototypes::id::Response>::Depth },
1273
  JSJitInfo::Method,
1274
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1275
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1276
  false,  /* isInfallible. False in setters. */
1277
  false,  /* isMovable.  Not relevant for setters. */
1278
  false, /* isEliminatable.  Not relevant for setters. */
1279
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1280
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1281
  false,  /* isTypedMethod.  Only relevant for methods. */
1282
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1283
};
1284
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1285
static_assert(0 < 1, "There is no slot for us");
1286
1287
MOZ_CAN_RUN_SCRIPT static bool
1288
blob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1289
0
{
1290
0
  AUTO_PROFILER_LABEL_FAST("Response.blob", DOM, cx);
1291
0
1292
0
  FastErrorResult rv;
1293
0
  auto result(StrongOrRawPtr<Promise>(self->Blob(cx, rv)));
1294
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1295
0
    return false;
1296
0
  }
1297
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1298
0
  if (!ToJSValue(cx, result, args.rval())) {
1299
0
    return false;
1300
0
  }
1301
0
  return true;
1302
0
}
1303
1304
MOZ_CAN_RUN_SCRIPT static bool
1305
blob_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1306
0
{
1307
0
  bool ok = blob(cx, obj, self, args);
1308
0
  if (ok) {
1309
0
    return true;
1310
0
  }
1311
0
  return ConvertExceptionToPromise(cx, args.rval());
1312
0
}
1313
1314
static const JSJitInfo blob_methodinfo = {
1315
  { (JSJitGetterOp)blob_promiseWrapper },
1316
  { prototypes::id::Response },
1317
  { PrototypeTraits<prototypes::id::Response>::Depth },
1318
  JSJitInfo::Method,
1319
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1320
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1321
  false,  /* isInfallible. False in setters. */
1322
  false,  /* isMovable.  Not relevant for setters. */
1323
  false, /* isEliminatable.  Not relevant for setters. */
1324
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1325
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1326
  false,  /* isTypedMethod.  Only relevant for methods. */
1327
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1328
};
1329
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1330
static_assert(0 < 1, "There is no slot for us");
1331
1332
MOZ_CAN_RUN_SCRIPT static bool
1333
formData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1334
0
{
1335
0
  AUTO_PROFILER_LABEL_FAST("Response.formData", DOM, cx);
1336
0
1337
0
  FastErrorResult rv;
1338
0
  auto result(StrongOrRawPtr<Promise>(self->FormData(cx, rv)));
1339
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1340
0
    return false;
1341
0
  }
1342
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1343
0
  if (!ToJSValue(cx, result, args.rval())) {
1344
0
    return false;
1345
0
  }
1346
0
  return true;
1347
0
}
1348
1349
MOZ_CAN_RUN_SCRIPT static bool
1350
formData_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1351
0
{
1352
0
  bool ok = formData(cx, obj, self, args);
1353
0
  if (ok) {
1354
0
    return true;
1355
0
  }
1356
0
  return ConvertExceptionToPromise(cx, args.rval());
1357
0
}
1358
1359
static const JSJitInfo formData_methodinfo = {
1360
  { (JSJitGetterOp)formData_promiseWrapper },
1361
  { prototypes::id::Response },
1362
  { PrototypeTraits<prototypes::id::Response>::Depth },
1363
  JSJitInfo::Method,
1364
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1365
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1366
  false,  /* isInfallible. False in setters. */
1367
  false,  /* isMovable.  Not relevant for setters. */
1368
  false, /* isEliminatable.  Not relevant for setters. */
1369
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1370
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1371
  false,  /* isTypedMethod.  Only relevant for methods. */
1372
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1373
};
1374
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1375
static_assert(0 < 1, "There is no slot for us");
1376
1377
MOZ_CAN_RUN_SCRIPT static bool
1378
json(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1379
0
{
1380
0
  AUTO_PROFILER_LABEL_FAST("Response.json", DOM, cx);
1381
0
1382
0
  FastErrorResult rv;
1383
0
  auto result(StrongOrRawPtr<Promise>(self->Json(cx, rv)));
1384
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1385
0
    return false;
1386
0
  }
1387
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1388
0
  if (!ToJSValue(cx, result, args.rval())) {
1389
0
    return false;
1390
0
  }
1391
0
  return true;
1392
0
}
1393
1394
MOZ_CAN_RUN_SCRIPT static bool
1395
json_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1396
0
{
1397
0
  bool ok = json(cx, obj, self, args);
1398
0
  if (ok) {
1399
0
    return true;
1400
0
  }
1401
0
  return ConvertExceptionToPromise(cx, args.rval());
1402
0
}
1403
1404
static const JSJitInfo json_methodinfo = {
1405
  { (JSJitGetterOp)json_promiseWrapper },
1406
  { prototypes::id::Response },
1407
  { PrototypeTraits<prototypes::id::Response>::Depth },
1408
  JSJitInfo::Method,
1409
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1410
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1411
  false,  /* isInfallible. False in setters. */
1412
  false,  /* isMovable.  Not relevant for setters. */
1413
  false, /* isEliminatable.  Not relevant for setters. */
1414
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1415
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1416
  false,  /* isTypedMethod.  Only relevant for methods. */
1417
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1418
};
1419
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1420
static_assert(0 < 1, "There is no slot for us");
1421
1422
MOZ_CAN_RUN_SCRIPT static bool
1423
text(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1424
0
{
1425
0
  AUTO_PROFILER_LABEL_FAST("Response.text", DOM, cx);
1426
0
1427
0
  FastErrorResult rv;
1428
0
  auto result(StrongOrRawPtr<Promise>(self->Text(cx, rv)));
1429
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1430
0
    return false;
1431
0
  }
1432
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1433
0
  if (!ToJSValue(cx, result, args.rval())) {
1434
0
    return false;
1435
0
  }
1436
0
  return true;
1437
0
}
1438
1439
MOZ_CAN_RUN_SCRIPT static bool
1440
text_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
1441
0
{
1442
0
  bool ok = text(cx, obj, self, args);
1443
0
  if (ok) {
1444
0
    return true;
1445
0
  }
1446
0
  return ConvertExceptionToPromise(cx, args.rval());
1447
0
}
1448
1449
static const JSJitInfo text_methodinfo = {
1450
  { (JSJitGetterOp)text_promiseWrapper },
1451
  { prototypes::id::Response },
1452
  { PrototypeTraits<prototypes::id::Response>::Depth },
1453
  JSJitInfo::Method,
1454
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1455
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1456
  false,  /* isInfallible. False in setters. */
1457
  false,  /* isMovable.  Not relevant for setters. */
1458
  false, /* isEliminatable.  Not relevant for setters. */
1459
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1460
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1461
  false,  /* isTypedMethod.  Only relevant for methods. */
1462
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1463
};
1464
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1465
static_assert(0 < 1, "There is no slot for us");
1466
1467
static bool
1468
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1469
0
{
1470
0
  mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
1471
0
  // We don't want to preserve if we don't have a wrapper, and we
1472
0
  // obviously can't preserve if we're not initialized.
1473
0
  if (self && self->GetWrapperPreserveColor()) {
1474
0
    PreserveWrapper(self);
1475
0
  }
1476
0
  return true;
1477
0
}
1478
1479
static void
1480
_finalize(js::FreeOp* fop, JSObject* obj)
1481
0
{
1482
0
  mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
1483
0
  if (self) {
1484
0
    ClearWrapper(self, self, obj);
1485
0
    AddForDeferredFinalization<mozilla::dom::Response>(self);
1486
0
  }
1487
0
}
1488
1489
static size_t
1490
_objectMoved(JSObject* obj, JSObject* old)
1491
0
{
1492
0
  mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
1493
0
  if (self) {
1494
0
    UpdateWrapper(self, self, obj, old);
1495
0
  }
1496
0
1497
0
  return 0;
1498
0
}
1499
1500
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1501
#if defined(__clang__)
1502
#pragma clang diagnostic push
1503
#pragma clang diagnostic ignored "-Wmissing-braces"
1504
#endif
1505
static const JSFunctionSpec sStaticMethods_specs[] = {
1506
  JS_FNSPEC("error", error, nullptr, 0, JSPROP_ENUMERATE, nullptr),
1507
  JS_FNSPEC("redirect", redirect, nullptr, 1, JSPROP_ENUMERATE, nullptr),
1508
  JS_FS_END
1509
};
1510
#if defined(__clang__)
1511
#pragma clang diagnostic pop
1512
#endif
1513
1514
1515
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
1516
  { nullptr, &sStaticMethods_specs[0] },
1517
  { nullptr, nullptr }
1518
};
1519
1520
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1521
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1522
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1523
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1524
1525
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1526
#if defined(__clang__)
1527
#pragma clang diagnostic push
1528
#pragma clang diagnostic ignored "-Wmissing-braces"
1529
#endif
1530
static const JSFunctionSpec sMethods_specs[] = {
1531
  JS_FNSPEC("clone", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&clone_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1532
  JS_FNSPEC("arrayBuffer", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&arrayBuffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1533
  JS_FNSPEC("blob", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&blob_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1534
  JS_FNSPEC("formData", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&formData_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1535
  JS_FNSPEC("json", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&json_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1536
  JS_FNSPEC("text", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&text_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1537
  JS_FS_END
1538
};
1539
#if defined(__clang__)
1540
#pragma clang diagnostic pop
1541
#endif
1542
1543
1544
static const Prefable<const JSFunctionSpec> sMethods[] = {
1545
  { nullptr, &sMethods_specs[0] },
1546
  { nullptr, nullptr }
1547
};
1548
1549
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1550
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1551
static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1552
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1553
1554
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1555
#if defined(__clang__)
1556
#pragma clang diagnostic push
1557
#pragma clang diagnostic ignored "-Wmissing-braces"
1558
#endif
1559
static const JSFunctionSpec sChromeMethods_specs[] = {
1560
  JS_FNSPEC("cloneUnfiltered", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&cloneUnfiltered_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1561
  JS_FS_END
1562
};
1563
#if defined(__clang__)
1564
#pragma clang diagnostic pop
1565
#endif
1566
1567
1568
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
1569
  { nullptr, &sChromeMethods_specs[0] },
1570
  { nullptr, nullptr }
1571
};
1572
1573
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1574
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1575
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1576
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1577
1578
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1579
#if defined(__clang__)
1580
#pragma clang diagnostic push
1581
#pragma clang diagnostic ignored "-Wmissing-braces"
1582
#endif
1583
static const JSPropertySpec sAttributes_specs[] = {
1584
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
1585
  { "url", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &url_getterinfo, nullptr, nullptr },
1586
  { "redirected", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &redirected_getterinfo, nullptr, nullptr },
1587
  { "status", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &status_getterinfo, nullptr, nullptr },
1588
  { "ok", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ok_getterinfo, nullptr, nullptr },
1589
  { "statusText", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &statusText_getterinfo, nullptr, nullptr },
1590
  { "headers", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &headers_getterinfo, nullptr, nullptr },
1591
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
1592
  { "body", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &body_getterinfo, nullptr, nullptr },
1593
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
1594
  { "bodyUsed", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &bodyUsed_getterinfo, nullptr, nullptr },
1595
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1596
};
1597
#if defined(__clang__)
1598
#pragma clang diagnostic pop
1599
#endif
1600
1601
// Can't be const because the pref-enabled boolean needs to be writable
1602
static PrefableDisablers sAttributes_disablers8 = {
1603
  true, false, 0, &mozilla::dom::DOMPrefs::dom_streams_enabled
1604
};
1605
1606
static const Prefable<const JSPropertySpec> sAttributes[] = {
1607
  { nullptr, &sAttributes_specs[0] },
1608
  { &sAttributes_disablers8, &sAttributes_specs[8] },
1609
  { nullptr, &sAttributes_specs[10] },
1610
  { nullptr, nullptr }
1611
};
1612
1613
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1614
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1615
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1616
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1617
1618
1619
static uint16_t sNativeProperties_sortedPropertyIndices[17];
1620
static PropertyInfo sNativeProperties_propertyInfos[17];
1621
1622
static const NativePropertiesN<3> sNativeProperties = {
1623
  true,  0 /* sStaticMethods */,
1624
  false, 0,
1625
  true,  1 /* sMethods */,
1626
  true,  2 /* sAttributes */,
1627
  false, 0,
1628
  false, 0,
1629
  false, 0,
1630
  -1,
1631
  17,
1632
  sNativeProperties_sortedPropertyIndices,
1633
  {
1634
    { sStaticMethods, &sNativeProperties_propertyInfos[0] },
1635
    { sMethods, &sNativeProperties_propertyInfos[2] },
1636
    { sAttributes, &sNativeProperties_propertyInfos[8] }
1637
  }
1638
};
1639
static_assert(17 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1640
    "We have a property info count that is oversized");
1641
1642
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
1643
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
1644
1645
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
1646
  false, 0,
1647
  false, 0,
1648
  true,  0 /* sChromeMethods */,
1649
  false, 0,
1650
  false, 0,
1651
  false, 0,
1652
  false, 0,
1653
  -1,
1654
  1,
1655
  sChromeOnlyNativeProperties_sortedPropertyIndices,
1656
  {
1657
    { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
1658
  }
1659
};
1660
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1661
    "We have a property info count that is oversized");
1662
1663
static bool
1664
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1665
0
{
1666
0
  AUTO_PROFILER_LABEL_FAST("Response constructor", DOM, cx);
1667
0
1668
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1669
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1670
0
  if (!args.isConstructing()) {
1671
0
    // XXXbz wish I could get the name from the callee instead of
1672
0
    // Adding more relocations
1673
0
    return ThrowConstructorWithoutNew(cx, "Response");
1674
0
  }
1675
0
1676
0
  JS::Rooted<JSObject*> desiredProto(cx);
1677
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1678
0
    return false;
1679
0
  }
1680
0
1681
0
  GlobalObject global(cx, obj);
1682
0
  if (global.Failed()) {
1683
0
    return false;
1684
0
  }
1685
0
1686
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1687
0
  Optional<Nullable<BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString >> arg0;
1688
0
  Maybe<BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVStringArgument> arg0_holder;
1689
0
  if (args.hasDefined(0)) {
1690
0
    arg0.Construct();
1691
0
    if (args[0].isNullOrUndefined()) {
1692
0
      arg0.Value().SetNull();
1693
0
    } else {
1694
0
      arg0_holder.emplace(arg0.Value().SetValue());
1695
0
      {
1696
0
        bool done = false, failed = false, tryNext;
1697
0
        if (args[0].isObject()) {
1698
0
          done = (failed = !arg0_holder.ref().TrySetToBlob(cx, args[0], tryNext, false)) || !tryNext ||
1699
0
                 (failed = !arg0_holder.ref().TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext ||
1700
0
                 (failed = !arg0_holder.ref().TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext ||
1701
0
                 (failed = !arg0_holder.ref().TrySetToFormData(cx, args[0], tryNext, false)) || !tryNext ||
1702
0
                 (failed = !arg0_holder.ref().TrySetToURLSearchParams(cx, args[0], tryNext, false)) || !tryNext ||
1703
0
                 (failed = !arg0_holder.ref().TrySetToReadableStream(cx, args[0], tryNext, false)) || !tryNext;
1704
0
1705
0
        }
1706
0
        if (!done) {
1707
0
          do {
1708
0
            done = (failed = !arg0_holder.ref().TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
1709
0
            break;
1710
0
          } while (false);
1711
0
        }
1712
0
        if (failed) {
1713
0
          return false;
1714
0
        }
1715
0
        if (!done) {
1716
0
          ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Response.constructor", "Blob, ArrayBufferView, ArrayBuffer, FormData, URLSearchParams, ReadableStream");
1717
0
          return false;
1718
0
        }
1719
0
      }
1720
0
    }
1721
0
  }
1722
0
  binding_detail::FastResponseInit arg1;
1723
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Response.constructor", false)) {
1724
0
    return false;
1725
0
  }
1726
0
  Maybe<JSAutoRealm> ar;
1727
0
  if (objIsXray) {
1728
0
    obj = js::CheckedUnwrap(obj);
1729
0
    if (!obj) {
1730
0
      return false;
1731
0
    }
1732
0
    ar.emplace(cx, obj);
1733
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1734
0
      return false;
1735
0
    }
1736
0
    if (arg0.WasPassed()) {
1737
0
      if (arg0.Value().Value().IsArrayBufferView()) {
1738
0
        if (!arg0.Value().Value().GetAsArrayBufferView().WrapIntoNewCompartment(cx)) {
1739
0
          return false;
1740
0
        }
1741
0
      }
1742
0
      else if (arg0.Value().Value().IsArrayBuffer()) {
1743
0
        if (!arg0.Value().Value().GetAsArrayBuffer().WrapIntoNewCompartment(cx)) {
1744
0
          return false;
1745
0
        }
1746
0
      }
1747
0
      else if (arg0.Value().Value().IsReadableStream()) {
1748
0
        if (!arg0.Value().Value().GetAsReadableStream().WrapIntoNewCompartment(cx)) {
1749
0
          return false;
1750
0
        }
1751
0
      }
1752
0
    }
1753
0
  }
1754
0
  FastErrorResult rv;
1755
0
  auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Constructor(global, Constify(arg0), Constify(arg1), rv)));
1756
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1757
0
    return false;
1758
0
  }
1759
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1760
0
  static_assert(!IsPointer<decltype(result)>::value,
1761
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1762
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1763
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1764
0
    return false;
1765
0
  }
1766
0
  return true;
1767
0
}
1768
1769
static const js::ClassOps sInterfaceObjectClassOps = {
1770
    nullptr,               /* addProperty */
1771
    nullptr,               /* delProperty */
1772
    nullptr,               /* enumerate */
1773
    nullptr,               /* newEnumerate */
1774
    nullptr,               /* resolve */
1775
    nullptr,               /* mayResolve */
1776
    nullptr,               /* finalize */
1777
    _constructor, /* call */
1778
    nullptr,               /* hasInstance */
1779
    _constructor, /* construct */
1780
    nullptr,               /* trace */
1781
};
1782
1783
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1784
  {
1785
    "Function",
1786
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1787
    &sInterfaceObjectClassOps,
1788
    JS_NULL_CLASS_SPEC,
1789
    JS_NULL_CLASS_EXT,
1790
    &sInterfaceObjectClassObjectOps
1791
  },
1792
  eInterface,
1793
  true,
1794
  prototypes::id::Response,
1795
  PrototypeTraits<prototypes::id::Response>::Depth,
1796
  sNativePropertyHooks,
1797
  "function Response() {\n    [native code]\n}",
1798
  JS::GetRealmFunctionPrototype
1799
};
1800
1801
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1802
  {
1803
    "ResponsePrototype",
1804
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1805
    JS_NULL_CLASS_OPS,
1806
    JS_NULL_CLASS_SPEC,
1807
    JS_NULL_CLASS_EXT,
1808
    JS_NULL_OBJECT_OPS
1809
  },
1810
  eInterfacePrototype,
1811
  false,
1812
  prototypes::id::Response,
1813
  PrototypeTraits<prototypes::id::Response>::Depth,
1814
  sNativePropertyHooks,
1815
  "[object ResponsePrototype]",
1816
  JS::GetRealmObjectPrototype
1817
};
1818
1819
static const js::ClassOps sClassOps = {
1820
  _addProperty, /* addProperty */
1821
  nullptr,               /* delProperty */
1822
  nullptr,               /* enumerate */
1823
  nullptr, /* newEnumerate */
1824
  nullptr, /* resolve */
1825
  nullptr, /* mayResolve */
1826
  _finalize, /* finalize */
1827
  nullptr, /* call */
1828
  nullptr,               /* hasInstance */
1829
  nullptr,               /* construct */
1830
  nullptr, /* trace */
1831
};
1832
1833
static const js::ClassExtension sClassExtension = {
1834
  nullptr, /* weakmapKeyDelegateOp */
1835
  _objectMoved /* objectMovedOp */
1836
};
1837
1838
static const DOMJSClass sClass = {
1839
  { "Response",
1840
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1841
    &sClassOps,
1842
    JS_NULL_CLASS_SPEC,
1843
    &sClassExtension,
1844
    JS_NULL_OBJECT_OPS
1845
  },
1846
  { prototypes::id::Response, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1847
  IsBaseOf<nsISupports, mozilla::dom::Response >::value,
1848
  sNativePropertyHooks,
1849
  FindAssociatedGlobalForNative<mozilla::dom::Response>::Get,
1850
  GetProtoObjectHandle,
1851
  GetCCParticipant<mozilla::dom::Response>::Get()
1852
};
1853
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1854
              "Must have the right minimal number of reserved slots.");
1855
static_assert(1 >= 1,
1856
              "Must have enough reserved slots.");
1857
1858
const JSClass*
1859
GetJSClass()
1860
0
{
1861
0
  return sClass.ToJSClass();
1862
0
}
1863
1864
bool
1865
Wrap(JSContext* aCx, mozilla::dom::Response* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1866
0
{
1867
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Response>::value,
1868
0
                "Shouldn't have wrappercached things that are not refcounted.");
1869
0
  MOZ_ASSERT(static_cast<mozilla::dom::Response*>(aObject) ==
1870
0
             reinterpret_cast<mozilla::dom::Response*>(aObject),
1871
0
             "Multiple inheritance for mozilla::dom::Response is broken.");
1872
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1873
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1874
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1875
0
             "You should probably not be using Wrap() directly; use "
1876
0
             "GetOrCreateDOMReflector instead");
1877
0
1878
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1879
0
             "nsISupports must be on our primary inheritance chain");
1880
0
1881
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1882
0
  if (!global) {
1883
0
    return false;
1884
0
  }
1885
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1886
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1887
0
1888
0
  // That might have ended up wrapping us already, due to the wonders
1889
0
  // of XBL.  Check for that, and bail out as needed.
1890
0
  aReflector.set(aCache->GetWrapper());
1891
0
  if (aReflector) {
1892
#ifdef DEBUG
1893
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1894
#endif // DEBUG
1895
    return true;
1896
0
  }
1897
0
1898
0
  JSAutoRealm ar(aCx, global);
1899
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1900
0
  if (!canonicalProto) {
1901
0
    return false;
1902
0
  }
1903
0
  JS::Rooted<JSObject*> proto(aCx);
1904
0
  if (aGivenProto) {
1905
0
    proto = aGivenProto;
1906
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1907
0
    // coming in, we changed compartments to that of "parent" so may need
1908
0
    // to wrap the proto here.
1909
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1910
0
      if (!JS_WrapObject(aCx, &proto)) {
1911
0
        return false;
1912
0
      }
1913
0
    }
1914
0
  } else {
1915
0
    proto = canonicalProto;
1916
0
  }
1917
0
1918
0
  BindingJSObjectCreator<mozilla::dom::Response> creator(aCx);
1919
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1920
0
  if (!aReflector) {
1921
0
    return false;
1922
0
  }
1923
0
1924
0
  aCache->SetWrapper(aReflector);
1925
0
  creator.InitializationSucceeded();
1926
0
1927
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1928
0
             aCache->GetWrapperPreserveColor() == aReflector);
1929
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1930
0
  // otherwise we won't be able to properly recreate it later, since
1931
0
  // we won't know what proto to use.  Note that we don't check
1932
0
  // aGivenProto here, since it's entirely possible (and even
1933
0
  // somewhat common) to have a non-null aGivenProto which is the
1934
0
  // same as canonicalProto.
1935
0
  if (proto != canonicalProto) {
1936
0
    PreserveWrapper(aObject);
1937
0
  }
1938
0
1939
0
  return true;
1940
0
}
1941
1942
const NativePropertyHooks sNativePropertyHooks[] = { {
1943
  nullptr,
1944
  nullptr,
1945
  nullptr,
1946
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1947
  prototypes::id::Response,
1948
  constructors::id::Response,
1949
  nullptr,
1950
  &DefaultXrayExpandoObjectClass
1951
} };
1952
1953
void
1954
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1955
0
{
1956
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1957
0
  if (!parentProto) {
1958
0
    return;
1959
0
  }
1960
0
1961
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1962
0
  if (!constructorProto) {
1963
0
    return;
1964
0
  }
1965
0
1966
0
  static bool sIdsInited = false;
1967
0
  if (!sIdsInited && NS_IsMainThread()) {
1968
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1969
0
      return;
1970
0
    }
1971
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1972
0
      return;
1973
0
    }
1974
0
    sIdsInited = true;
1975
0
  }
1976
0
1977
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Response);
1978
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Response);
1979
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1980
0
                              &sPrototypeClass.mBase, protoCache,
1981
0
                              nullptr,
1982
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1983
0
                              interfaceCache,
1984
0
                              sNativeProperties.Upcast(),
1985
0
                              sChromeOnlyNativeProperties.Upcast(),
1986
0
                              "Response", aDefineOnGlobal,
1987
0
                              nullptr,
1988
0
                              false);
1989
0
}
1990
1991
JSObject*
1992
GetConstructorObject(JSContext* aCx)
1993
0
{
1994
0
  return GetConstructorObjectHandle(aCx);
1995
0
}
1996
1997
} // namespace Response_Binding
1998
1999
2000
2001
} // namespace dom
2002
} // namespace mozilla