Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/XMLHttpRequestBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM XMLHttpRequest.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "ChromeUtilsBinding.h"
5
#include "EventHandlerBinding.h"
6
#include "WrapperFactory.h"
7
#include "XMLHttpRequestBinding.h"
8
#include "XMLHttpRequestEventTargetBinding.h"
9
#include "XrayWrapper.h"
10
#include "jsapi.h"
11
#include "mozilla/OwningNonNull.h"
12
#include "mozilla/dom/BindingUtils.h"
13
#include "mozilla/dom/Blob.h"
14
#include "mozilla/dom/DOMJSClass.h"
15
#include "mozilla/dom/FormData.h"
16
#include "mozilla/dom/NonRefcountedDOMObject.h"
17
#include "mozilla/dom/Nullable.h"
18
#include "mozilla/dom/PrimitiveConversions.h"
19
#include "mozilla/dom/ScriptSettings.h"
20
#include "mozilla/dom/SimpleGlobalObject.h"
21
#include "mozilla/dom/URLSearchParams.h"
22
#include "mozilla/dom/UnionConversions.h"
23
#include "mozilla/dom/XMLHttpRequest.h"
24
#include "mozilla/dom/XMLHttpRequestUpload.h"
25
#include "mozilla/dom/XrayExpandoClass.h"
26
#include "nsContentUtils.h"
27
#include "nsIChannel.h"
28
#include "nsIDocument.h"
29
#include "nsIInputStream.h"
30
#include "nsISupports.h"
31
#include "nsThreadUtils.h"
32
#include "xpcjsid.h"
33
34
namespace mozilla {
35
namespace dom {
36
37
namespace binding_detail {}; // Just to make sure it's known as a namespace
38
using namespace mozilla::dom::binding_detail;
39
40
41
namespace XMLHttpRequestResponseTypeValues {
42
extern const EnumEntry strings[8] = {
43
  {"", 0},
44
  {"arraybuffer", 11},
45
  {"blob", 4},
46
  {"document", 8},
47
  {"json", 4},
48
  {"text", 4},
49
  {"moz-chunked-arraybuffer", 23},
50
  { nullptr, 0 }
51
};
52
} // namespace XMLHttpRequestResponseTypeValues
53
54
bool
55
ToJSValue(JSContext* aCx, XMLHttpRequestResponseType aArgument, JS::MutableHandle<JS::Value> aValue)
56
0
{
57
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(XMLHttpRequestResponseTypeValues::strings));
58
0
  JSString* resultStr =
59
0
    JS_NewStringCopyN(aCx, XMLHttpRequestResponseTypeValues::strings[uint32_t(aArgument)].value,
60
0
                      XMLHttpRequestResponseTypeValues::strings[uint32_t(aArgument)].length);
61
0
  if (!resultStr) {
62
0
    return false;
63
0
  }
64
0
  aValue.setString(resultStr);
65
0
  return true;
66
0
}
67
68
69
void
70
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion, const char* aName, uint32_t aFlags)
71
0
{
72
0
  if (aUnion.IsDocument()) {
73
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsDocument(), "mDocument", aFlags);
74
0
  } else if (aUnion.IsBlob()) {
75
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsBlob(), "mBlob", aFlags);
76
0
  } else if (aUnion.IsFormData()) {
77
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsFormData(), "mFormData", aFlags);
78
0
  } else if (aUnion.IsURLSearchParams()) {
79
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsURLSearchParams(), "mURLSearchParams", aFlags);
80
0
  }
81
0
}
82
83
84
void
85
ImplCycleCollectionUnlink(OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString& aUnion)
86
0
{
87
0
  aUnion.Uninit();
88
0
}
89
90
91
bool
92
DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
93
0
{
94
0
  switch (mType) {
95
0
    case eUninitialized: {
96
0
      return false;
97
0
      break;
98
0
    }
99
0
    case eDocument: {
100
0
      if (!GetOrCreateDOMReflector(cx, mValue.mDocument.Value(), rval)) {
101
0
        MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing");
102
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
103
0
        return false;
104
0
      }
105
0
      return true;
106
0
      break;
107
0
    }
108
0
    case eBlob: {
109
0
      if (!GetOrCreateDOMReflector(cx, mValue.mBlob.Value(), rval)) {
110
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
111
0
        return false;
112
0
      }
113
0
      return true;
114
0
      break;
115
0
    }
116
0
    case eArrayBufferView: {
117
0
      rval.setObject(*mValue.mArrayBufferView.Value().Obj());
118
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
119
0
        return false;
120
0
      }
121
0
      return true;
122
0
      break;
123
0
    }
124
0
    case eArrayBuffer: {
125
0
      rval.setObject(*mValue.mArrayBuffer.Value().Obj());
126
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
127
0
        return false;
128
0
      }
129
0
      return true;
130
0
      break;
131
0
    }
132
0
    case eFormData: {
133
0
      if (!GetOrCreateDOMReflector(cx, mValue.mFormData.Value(), rval)) {
134
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
135
0
        return false;
136
0
      }
137
0
      return true;
138
0
      break;
139
0
    }
140
0
    case eURLSearchParams: {
141
0
      if (!GetOrCreateDOMReflector(cx, mValue.mURLSearchParams.Value(), rval)) {
142
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
143
0
        return false;
144
0
      }
145
0
      return true;
146
0
      break;
147
0
    }
148
0
    case eUSVString: {
149
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
150
0
        return false;
151
0
      }
152
0
      return true;
153
0
      break;
154
0
    }
155
0
    default: {
156
0
      return false;
157
0
      break;
158
0
    }
159
0
  }
160
0
161
0
  return false;
162
0
}
163
164
165
OwningNonNull<nsIDocument>&
166
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsDocument()
167
0
{
168
0
  if (mType == eDocument) {
169
0
    return mValue.mDocument.Value();
170
0
  }
171
0
  MOZ_ASSERT(mType == eUninitialized);
172
0
  mType = eDocument;
173
0
  return mValue.mDocument.SetValue();
174
0
}
175
176
OwningNonNull<nsIDocument>&
177
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsDocument()
178
0
{
179
0
  if (mType == eDocument) {
180
0
    return mValue.mDocument.Value();
181
0
  }
182
0
  Uninit();
183
0
  mType = eDocument;
184
0
  return mValue.mDocument.SetValue();
185
0
}
186
187
bool
188
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToDocument(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
189
0
{
190
0
  tryNext = false;
191
0
  { // scope for memberSlot
192
0
    OwningNonNull<nsIDocument>& memberSlot = RawSetAsDocument();
193
0
    static_assert(IsRefcounted<nsIDocument>::value, "We can only store refcounted classes.");{
194
0
      nsresult rv = UnwrapObject<prototypes::id::Document, nsIDocument>(value, memberSlot);
195
0
      if (NS_FAILED(rv)) {
196
0
        DestroyDocument();
197
0
        tryNext = true;
198
0
        return true;
199
0
      }
200
0
    }
201
0
  }
202
0
  return true;
203
0
}
204
205
void
206
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyDocument()
207
0
{
208
0
  MOZ_ASSERT(IsDocument(), "Wrong type!");
209
0
  mValue.mDocument.Destroy();
210
0
  mType = eUninitialized;
211
0
}
212
213
214
215
216
OwningNonNull<mozilla::dom::Blob>&
217
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsBlob()
218
0
{
219
0
  if (mType == eBlob) {
220
0
    return mValue.mBlob.Value();
221
0
  }
222
0
  MOZ_ASSERT(mType == eUninitialized);
223
0
  mType = eBlob;
224
0
  return mValue.mBlob.SetValue();
225
0
}
226
227
OwningNonNull<mozilla::dom::Blob>&
228
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsBlob()
229
0
{
230
0
  if (mType == eBlob) {
231
0
    return mValue.mBlob.Value();
232
0
  }
233
0
  Uninit();
234
0
  mType = eBlob;
235
0
  return mValue.mBlob.SetValue();
236
0
}
237
238
bool
239
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToBlob(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
240
0
{
241
0
  tryNext = false;
242
0
  { // scope for memberSlot
243
0
    OwningNonNull<mozilla::dom::Blob>& memberSlot = RawSetAsBlob();
244
0
    static_assert(IsRefcounted<mozilla::dom::Blob>::value, "We can only store refcounted classes.");{
245
0
      nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(value, memberSlot);
246
0
      if (NS_FAILED(rv)) {
247
0
        DestroyBlob();
248
0
        tryNext = true;
249
0
        return true;
250
0
      }
251
0
    }
252
0
  }
253
0
  return true;
254
0
}
255
256
void
257
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyBlob()
258
0
{
259
0
  MOZ_ASSERT(IsBlob(), "Wrong type!");
260
0
  mValue.mBlob.Destroy();
261
0
  mType = eUninitialized;
262
0
}
263
264
265
266
267
ArrayBufferView&
268
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsArrayBufferView()
269
0
{
270
0
  if (mType == eArrayBufferView) {
271
0
    return mValue.mArrayBufferView.Value();
272
0
  }
273
0
  MOZ_ASSERT(mType == eUninitialized);
274
0
  mType = eArrayBufferView;
275
0
  return mValue.mArrayBufferView.SetValue();
276
0
}
277
278
ArrayBufferView&
279
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsArrayBufferView()
280
0
{
281
0
  if (mType == eArrayBufferView) {
282
0
    return mValue.mArrayBufferView.Value();
283
0
  }
284
0
  Uninit();
285
0
  mType = eArrayBufferView;
286
0
  return mValue.mArrayBufferView.SetValue();
287
0
}
288
289
bool
290
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
291
0
{
292
0
  tryNext = false;
293
0
  { // scope for memberSlot
294
0
    ArrayBufferView& memberSlot = RawSetAsArrayBufferView();
295
0
    if (!memberSlot.Init(&value.toObject())) {
296
0
      DestroyArrayBufferView();
297
0
      tryNext = true;
298
0
      return true;
299
0
    }
300
0
  }
301
0
  return true;
302
0
}
303
304
void
305
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyArrayBufferView()
306
0
{
307
0
  MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
308
0
  mValue.mArrayBufferView.Destroy();
309
0
  mType = eUninitialized;
310
0
}
311
312
313
314
315
ArrayBuffer&
316
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsArrayBuffer()
317
0
{
318
0
  if (mType == eArrayBuffer) {
319
0
    return mValue.mArrayBuffer.Value();
320
0
  }
321
0
  MOZ_ASSERT(mType == eUninitialized);
322
0
  mType = eArrayBuffer;
323
0
  return mValue.mArrayBuffer.SetValue();
324
0
}
325
326
ArrayBuffer&
327
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsArrayBuffer()
328
0
{
329
0
  if (mType == eArrayBuffer) {
330
0
    return mValue.mArrayBuffer.Value();
331
0
  }
332
0
  Uninit();
333
0
  mType = eArrayBuffer;
334
0
  return mValue.mArrayBuffer.SetValue();
335
0
}
336
337
bool
338
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
339
0
{
340
0
  tryNext = false;
341
0
  { // scope for memberSlot
342
0
    ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
343
0
    if (!memberSlot.Init(&value.toObject())) {
344
0
      DestroyArrayBuffer();
345
0
      tryNext = true;
346
0
      return true;
347
0
    }
348
0
  }
349
0
  return true;
350
0
}
351
352
void
353
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyArrayBuffer()
354
0
{
355
0
  MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
356
0
  mValue.mArrayBuffer.Destroy();
357
0
  mType = eUninitialized;
358
0
}
359
360
361
362
363
OwningNonNull<mozilla::dom::FormData>&
364
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsFormData()
365
0
{
366
0
  if (mType == eFormData) {
367
0
    return mValue.mFormData.Value();
368
0
  }
369
0
  MOZ_ASSERT(mType == eUninitialized);
370
0
  mType = eFormData;
371
0
  return mValue.mFormData.SetValue();
372
0
}
373
374
OwningNonNull<mozilla::dom::FormData>&
375
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsFormData()
376
0
{
377
0
  if (mType == eFormData) {
378
0
    return mValue.mFormData.Value();
379
0
  }
380
0
  Uninit();
381
0
  mType = eFormData;
382
0
  return mValue.mFormData.SetValue();
383
0
}
384
385
bool
386
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToFormData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
387
0
{
388
0
  tryNext = false;
389
0
  { // scope for memberSlot
390
0
    OwningNonNull<mozilla::dom::FormData>& memberSlot = RawSetAsFormData();
391
0
    static_assert(IsRefcounted<mozilla::dom::FormData>::value, "We can only store refcounted classes.");{
392
0
      nsresult rv = UnwrapObject<prototypes::id::FormData, mozilla::dom::FormData>(value, memberSlot);
393
0
      if (NS_FAILED(rv)) {
394
0
        DestroyFormData();
395
0
        tryNext = true;
396
0
        return true;
397
0
      }
398
0
    }
399
0
  }
400
0
  return true;
401
0
}
402
403
void
404
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyFormData()
405
0
{
406
0
  MOZ_ASSERT(IsFormData(), "Wrong type!");
407
0
  mValue.mFormData.Destroy();
408
0
  mType = eUninitialized;
409
0
}
410
411
412
413
414
OwningNonNull<mozilla::dom::URLSearchParams>&
415
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsURLSearchParams()
416
0
{
417
0
  if (mType == eURLSearchParams) {
418
0
    return mValue.mURLSearchParams.Value();
419
0
  }
420
0
  MOZ_ASSERT(mType == eUninitialized);
421
0
  mType = eURLSearchParams;
422
0
  return mValue.mURLSearchParams.SetValue();
423
0
}
424
425
OwningNonNull<mozilla::dom::URLSearchParams>&
426
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsURLSearchParams()
427
0
{
428
0
  if (mType == eURLSearchParams) {
429
0
    return mValue.mURLSearchParams.Value();
430
0
  }
431
0
  Uninit();
432
0
  mType = eURLSearchParams;
433
0
  return mValue.mURLSearchParams.SetValue();
434
0
}
435
436
bool
437
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToURLSearchParams(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
438
0
{
439
0
  tryNext = false;
440
0
  { // scope for memberSlot
441
0
    OwningNonNull<mozilla::dom::URLSearchParams>& memberSlot = RawSetAsURLSearchParams();
442
0
    static_assert(IsRefcounted<mozilla::dom::URLSearchParams>::value, "We can only store refcounted classes.");{
443
0
      nsresult rv = UnwrapObject<prototypes::id::URLSearchParams, mozilla::dom::URLSearchParams>(value, memberSlot);
444
0
      if (NS_FAILED(rv)) {
445
0
        DestroyURLSearchParams();
446
0
        tryNext = true;
447
0
        return true;
448
0
      }
449
0
    }
450
0
  }
451
0
  return true;
452
0
}
453
454
void
455
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyURLSearchParams()
456
0
{
457
0
  MOZ_ASSERT(IsURLSearchParams(), "Wrong type!");
458
0
  mValue.mURLSearchParams.Destroy();
459
0
  mType = eUninitialized;
460
0
}
461
462
463
464
465
nsString&
466
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::RawSetAsUSVString()
467
0
{
468
0
  if (mType == eUSVString) {
469
0
    return mValue.mUSVString.Value();
470
0
  }
471
0
  MOZ_ASSERT(mType == eUninitialized);
472
0
  mType = eUSVString;
473
0
  return mValue.mUSVString.SetValue();
474
0
}
475
476
nsString&
477
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::SetAsUSVString()
478
0
{
479
0
  if (mType == eUSVString) {
480
0
    return mValue.mUSVString.Value();
481
0
  }
482
0
  Uninit();
483
0
  mType = eUSVString;
484
0
  return mValue.mUSVString.SetValue();
485
0
}
486
487
bool
488
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
489
0
{
490
0
  tryNext = false;
491
0
  { // scope for memberSlot
492
0
    nsString& memberSlot = RawSetAsUSVString();
493
0
    if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
494
0
      return false;
495
0
    }
496
0
    NormalizeUSVString(memberSlot);
497
0
  }
498
0
  return true;
499
0
}
500
501
502
void
503
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::DestroyUSVString()
504
0
{
505
0
  MOZ_ASSERT(IsUSVString(), "Wrong type!");
506
0
  mValue.mUSVString.Destroy();
507
0
  mType = eUninitialized;
508
0
}
509
510
511
512
513
void
514
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::Uninit()
515
{
516
  switch (mType) {
517
    case eUninitialized: {
518
      break;
519
    }
520
    case eDocument: {
521
      DestroyDocument();
522
      break;
523
    }
524
    case eBlob: {
525
      DestroyBlob();
526
      break;
527
    }
528
    case eArrayBufferView: {
529
      DestroyArrayBufferView();
530
      break;
531
    }
532
    case eArrayBuffer: {
533
      DestroyArrayBuffer();
534
      break;
535
    }
536
    case eFormData: {
537
      DestroyFormData();
538
      break;
539
    }
540
    case eURLSearchParams: {
541
      DestroyURLSearchParams();
542
      break;
543
    }
544
    case eUSVString: {
545
      DestroyUSVString();
546
      break;
547
    }
548
  }
549
}
550
551
bool
552
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
553
0
{
554
0
  switch (mType) {
555
0
    case eUninitialized: {
556
0
      return false;
557
0
      break;
558
0
    }
559
0
    case eDocument: {
560
0
      if (!GetOrCreateDOMReflector(cx, mValue.mDocument.Value(), rval)) {
561
0
        MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing");
562
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
563
0
        return false;
564
0
      }
565
0
      return true;
566
0
      break;
567
0
    }
568
0
    case eBlob: {
569
0
      if (!GetOrCreateDOMReflector(cx, mValue.mBlob.Value(), rval)) {
570
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
571
0
        return false;
572
0
      }
573
0
      return true;
574
0
      break;
575
0
    }
576
0
    case eArrayBufferView: {
577
0
      rval.setObject(*mValue.mArrayBufferView.Value().Obj());
578
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
579
0
        return false;
580
0
      }
581
0
      return true;
582
0
      break;
583
0
    }
584
0
    case eArrayBuffer: {
585
0
      rval.setObject(*mValue.mArrayBuffer.Value().Obj());
586
0
      if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
587
0
        return false;
588
0
      }
589
0
      return true;
590
0
      break;
591
0
    }
592
0
    case eFormData: {
593
0
      if (!GetOrCreateDOMReflector(cx, mValue.mFormData.Value(), rval)) {
594
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
595
0
        return false;
596
0
      }
597
0
      return true;
598
0
      break;
599
0
    }
600
0
    case eURLSearchParams: {
601
0
      if (!GetOrCreateDOMReflector(cx, mValue.mURLSearchParams.Value(), rval)) {
602
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
603
0
        return false;
604
0
      }
605
0
      return true;
606
0
      break;
607
0
    }
608
0
    case eUSVString: {
609
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
610
0
        return false;
611
0
      }
612
0
      return true;
613
0
      break;
614
0
    }
615
0
    default: {
616
0
      return false;
617
0
      break;
618
0
    }
619
0
  }
620
0
621
0
  return false;
622
0
}
623
624
void
625
OwningDocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString::TraceUnion(JSTracer* trc)
626
{
627
  switch (mType) {
628
    case eArrayBufferView: {
629
      mValue.mArrayBufferView.Value().TraceSelf(trc);
630
      break;
631
    }
632
    case eArrayBuffer: {
633
      mValue.mArrayBuffer.Value().TraceSelf(trc);
634
      break;
635
    }
636
    default: {
637
      break;
638
    }
639
  }
640
}
641
642
643
644
MozXMLHttpRequestParameters::MozXMLHttpRequestParameters()
645
0
{
646
0
  // Safe to pass a null context if we pass a null value
647
0
  Init(nullptr, JS::NullHandleValue);
648
0
}
649
650
651
652
bool
653
MozXMLHttpRequestParameters::InitIds(JSContext* cx, MozXMLHttpRequestParametersAtoms* atomsCache)
654
0
{
655
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
656
0
657
0
  // Initialize these in reverse order so that any failure leaves the first one
658
0
  // uninitialized.
659
0
  if (!atomsCache->mozSystem_id.init(cx, "mozSystem") ||
660
0
      !atomsCache->mozAnon_id.init(cx, "mozAnon")) {
661
0
    return false;
662
0
  }
663
0
  return true;
664
0
}
665
666
bool
667
MozXMLHttpRequestParameters::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
668
0
{
669
0
  // Passing a null JSContext is OK only if we're initing from null,
670
0
  // Since in that case we will not have to do any property gets
671
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
672
0
  // checkers by static analysis tools
673
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
674
0
  MozXMLHttpRequestParametersAtoms* atomsCache = nullptr;
675
0
  if (cx) {
676
0
    atomsCache = GetAtomCache<MozXMLHttpRequestParametersAtoms>(cx);
677
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
678
0
      return false;
679
0
    }
680
0
  }
681
0
682
0
  if (!IsConvertibleToDictionary(val)) {
683
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
684
0
  }
685
0
686
0
  bool isNull = val.isNullOrUndefined();
687
0
  // We only need these if !isNull, in which case we have |cx|.
688
0
  Maybe<JS::Rooted<JSObject *> > object;
689
0
  Maybe<JS::Rooted<JS::Value> > temp;
690
0
  if (!isNull) {
691
0
    MOZ_ASSERT(cx);
692
0
    object.emplace(cx, &val.toObject());
693
0
    temp.emplace(cx);
694
0
  }
695
0
  if (!isNull) {
696
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->mozAnon_id, temp.ptr())) {
697
0
      return false;
698
0
    }
699
0
  }
700
0
  if (!isNull && !temp->isUndefined()) {
701
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mMozAnon)) {
702
0
      return false;
703
0
    }
704
0
  } else {
705
0
    mMozAnon = false;
706
0
  }
707
0
  mIsAnyMemberPresent = true;
708
0
709
0
  if (!isNull) {
710
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->mozSystem_id, temp.ptr())) {
711
0
      return false;
712
0
    }
713
0
  }
714
0
  if (!isNull && !temp->isUndefined()) {
715
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mMozSystem)) {
716
0
      return false;
717
0
    }
718
0
  } else {
719
0
    mMozSystem = false;
720
0
  }
721
0
  mIsAnyMemberPresent = true;
722
0
  return true;
723
0
}
724
725
bool
726
MozXMLHttpRequestParameters::Init(const nsAString& aJSON)
727
0
{
728
0
  AutoJSAPI jsapi;
729
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
730
0
  if (!cleanGlobal) {
731
0
    return false;
732
0
  }
733
0
  if (!jsapi.Init(cleanGlobal)) {
734
0
    return false;
735
0
  }
736
0
  JSContext* cx = jsapi.cx();
737
0
  JS::Rooted<JS::Value> json(cx);
738
0
  bool ok = ParseJSON(cx, aJSON, &json);
739
0
  NS_ENSURE_TRUE(ok, false);
740
0
  return Init(cx, json);
741
0
}
742
743
bool
744
MozXMLHttpRequestParameters::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
745
0
{
746
0
  MozXMLHttpRequestParametersAtoms* atomsCache = GetAtomCache<MozXMLHttpRequestParametersAtoms>(cx);
747
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
748
0
    return false;
749
0
  }
750
0
751
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
752
0
  if (!obj) {
753
0
    return false;
754
0
  }
755
0
  rval.set(JS::ObjectValue(*obj));
756
0
757
0
  do {
758
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
759
0
    JS::Rooted<JS::Value> temp(cx);
760
0
    bool const & currentValue = mMozAnon;
761
0
    temp.setBoolean(currentValue);
762
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->mozAnon_id, temp, JSPROP_ENUMERATE)) {
763
0
      return false;
764
0
    }
765
0
    break;
766
0
  } while(false);
767
0
768
0
  do {
769
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
770
0
    JS::Rooted<JS::Value> temp(cx);
771
0
    bool const & currentValue = mMozSystem;
772
0
    temp.setBoolean(currentValue);
773
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->mozSystem_id, temp, JSPROP_ENUMERATE)) {
774
0
      return false;
775
0
    }
776
0
    break;
777
0
  } while(false);
778
0
779
0
  return true;
780
0
}
781
782
bool
783
MozXMLHttpRequestParameters::ToJSON(nsAString& aJSON) const
784
0
{
785
0
  AutoJSAPI jsapi;
786
0
  jsapi.Init();
787
0
  JSContext *cx = jsapi.cx();
788
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
789
0
  // because we'll only be creating objects, in ways that have no
790
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
791
0
  // which likewise guarantees no side-effects for the sorts of
792
0
  // things we will pass it.
793
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
794
0
  JS::Rooted<JS::Value> val(cx);
795
0
  if (!ToObjectInternal(cx, &val)) {
796
0
    return false;
797
0
  }
798
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
799
0
  return StringifyToJSON(cx, obj, aJSON);
800
0
}
801
802
void
803
MozXMLHttpRequestParameters::TraceDictionary(JSTracer* trc)
804
0
{
805
0
}
806
807
MozXMLHttpRequestParameters&
808
MozXMLHttpRequestParameters::operator=(const MozXMLHttpRequestParameters& aOther)
809
0
{
810
0
  DictionaryBase::operator=(aOther);
811
0
  mMozAnon = aOther.mMozAnon;
812
0
  mMozSystem = aOther.mMozSystem;
813
0
  return *this;
814
0
}
815
816
namespace binding_detail {
817
} // namespace binding_detail
818
819
820
namespace XMLHttpRequest_Binding {
821
822
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<XMLHttpRequestEventTarget_Binding::NativeType>::value,
823
              "Can't inherit from an interface with a different ownership model.");
824
825
MOZ_CAN_RUN_SCRIPT static bool
826
get_onreadystatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
827
0
{
828
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.onreadystatechange", DOM, cx);
829
0
830
0
  RefPtr<EventHandlerNonNull> result(self->GetOnreadystatechange());
831
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
832
0
  if (result) {
833
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
834
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
835
0
      return false;
836
0
    }
837
0
    return true;
838
0
  } else {
839
0
    args.rval().setNull();
840
0
    return true;
841
0
  }
842
0
}
843
844
MOZ_CAN_RUN_SCRIPT static bool
845
set_onreadystatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitSetterCallArgs args)
846
0
{
847
0
  AUTO_PROFILER_LABEL_FAST("set XMLHttpRequest.onreadystatechange", DOM, cx);
848
0
849
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
850
0
  if (args[0].isObject()) {
851
0
    { // scope for tempRoot and tempGlobalRoot if needed
852
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
853
0
    }
854
0
  } else {
855
0
    arg0 = nullptr;
856
0
  }
857
0
  self->SetOnreadystatechange(Constify(arg0));
858
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
859
0
860
0
  return true;
861
0
}
862
863
static const JSJitInfo onreadystatechange_getterinfo = {
864
  { (JSJitGetterOp)get_onreadystatechange },
865
  { prototypes::id::XMLHttpRequest },
866
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
867
  JSJitInfo::Getter,
868
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
869
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
870
  false,  /* isInfallible. False in setters. */
871
  false,  /* isMovable.  Not relevant for setters. */
872
  false, /* isEliminatable.  Not relevant for setters. */
873
  false, /* isAlwaysInSlot.  Only relevant for getters. */
874
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
875
  false,  /* isTypedMethod.  Only relevant for methods. */
876
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
877
};
878
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
879
static_assert(0 < 2, "There is no slot for us");
880
static const JSJitInfo onreadystatechange_setterinfo = {
881
  { (JSJitGetterOp)set_onreadystatechange },
882
  { prototypes::id::XMLHttpRequest },
883
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
884
  JSJitInfo::Setter,
885
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
886
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
887
  false,  /* isInfallible. False in setters. */
888
  false,  /* isMovable.  Not relevant for setters. */
889
  false, /* isEliminatable.  Not relevant for setters. */
890
  false, /* isAlwaysInSlot.  Only relevant for getters. */
891
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
892
  false,  /* isTypedMethod.  Only relevant for methods. */
893
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
894
};
895
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
896
static_assert(0 < 2, "There is no slot for us");
897
898
MOZ_CAN_RUN_SCRIPT static bool
899
get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
900
0
{
901
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.readyState", DOM, cx);
902
0
903
0
  uint16_t result(self->ReadyState());
904
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
905
0
  args.rval().setInt32(int32_t(result));
906
0
  return true;
907
0
}
908
909
static const JSJitInfo readyState_getterinfo = {
910
  { (JSJitGetterOp)get_readyState },
911
  { prototypes::id::XMLHttpRequest },
912
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
913
  JSJitInfo::Getter,
914
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
915
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
916
  true,  /* isInfallible. False in setters. */
917
  false,  /* isMovable.  Not relevant for setters. */
918
  false, /* isEliminatable.  Not relevant for setters. */
919
  false, /* isAlwaysInSlot.  Only relevant for getters. */
920
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
921
  false,  /* isTypedMethod.  Only relevant for methods. */
922
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
923
};
924
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
925
static_assert(0 < 2, "There is no slot for us");
926
927
MOZ_CAN_RUN_SCRIPT static bool
928
open(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
929
0
{
930
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.open", DOM, cx);
931
0
932
0
  unsigned argcount = std::min(args.length(), 5u);
933
0
  switch (argcount) {
934
0
    case 2: {
935
0
      nsCString arg0;
936
0
      if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
937
0
        return false;
938
0
      }
939
0
      binding_detail::FakeString arg1;
940
0
      if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
941
0
        return false;
942
0
      }
943
0
      NormalizeUSVString(arg1);
944
0
      FastErrorResult rv;
945
0
      self->Open(Constify(arg0), Constify(arg1), rv);
946
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
947
0
        return false;
948
0
      }
949
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
950
0
      args.rval().setUndefined();
951
0
      return true;
952
0
      break;
953
0
    }
954
0
    case 3: {
955
0
      MOZ_FALLTHROUGH;
956
0
    }
957
0
    case 4: {
958
0
      MOZ_FALLTHROUGH;
959
0
    }
960
0
    case 5: {
961
0
      nsCString arg0;
962
0
      if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
963
0
        return false;
964
0
      }
965
0
      binding_detail::FakeString arg1;
966
0
      if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
967
0
        return false;
968
0
      }
969
0
      NormalizeUSVString(arg1);
970
0
      bool arg2;
971
0
      if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
972
0
        return false;
973
0
      }
974
0
      binding_detail::FakeString arg3;
975
0
      if (args.hasDefined(3)) {
976
0
        if (!ConvertJSValueToString(cx, args[3], eNull, eNull, arg3)) {
977
0
          return false;
978
0
        }
979
0
        NormalizeUSVString(arg3);
980
0
      } else {
981
0
        arg3.SetIsVoid(true);
982
0
      }
983
0
      binding_detail::FakeString arg4;
984
0
      if (args.hasDefined(4)) {
985
0
        if (!ConvertJSValueToString(cx, args[4], eNull, eNull, arg4)) {
986
0
          return false;
987
0
        }
988
0
        NormalizeUSVString(arg4);
989
0
      } else {
990
0
        arg4.SetIsVoid(true);
991
0
      }
992
0
      FastErrorResult rv;
993
0
      self->Open(Constify(arg0), Constify(arg1), arg2, Constify(arg3), Constify(arg4), rv);
994
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
995
0
        return false;
996
0
      }
997
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
998
0
      args.rval().setUndefined();
999
0
      return true;
1000
0
      break;
1001
0
    }
1002
0
    default: {
1003
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.open");
1004
0
      break;
1005
0
    }
1006
0
  }
1007
0
  MOZ_CRASH("We have an always-returning default case");
1008
0
  return false;
1009
0
}
1010
1011
static const JSJitInfo open_methodinfo = {
1012
  { (JSJitGetterOp)open },
1013
  { prototypes::id::XMLHttpRequest },
1014
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1015
  JSJitInfo::Method,
1016
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1017
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1018
  false,  /* isInfallible. False in setters. */
1019
  false,  /* isMovable.  Not relevant for setters. */
1020
  false, /* isEliminatable.  Not relevant for setters. */
1021
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1022
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1023
  false,  /* isTypedMethod.  Only relevant for methods. */
1024
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1025
};
1026
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1027
static_assert(0 < 2, "There is no slot for us");
1028
1029
MOZ_CAN_RUN_SCRIPT static bool
1030
setRequestHeader(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1031
0
{
1032
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.setRequestHeader", DOM, cx);
1033
0
1034
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
1035
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.setRequestHeader");
1036
0
  }
1037
0
  nsCString arg0;
1038
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
1039
0
    return false;
1040
0
  }
1041
0
  nsCString arg1;
1042
0
  if (!ConvertJSValueToByteString(cx, args[1], false, arg1)) {
1043
0
    return false;
1044
0
  }
1045
0
  FastErrorResult rv;
1046
0
  self->SetRequestHeader(Constify(arg0), Constify(arg1), rv);
1047
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1048
0
    return false;
1049
0
  }
1050
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1051
0
  args.rval().setUndefined();
1052
0
  return true;
1053
0
}
1054
1055
static const JSJitInfo setRequestHeader_methodinfo = {
1056
  { (JSJitGetterOp)setRequestHeader },
1057
  { prototypes::id::XMLHttpRequest },
1058
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1059
  JSJitInfo::Method,
1060
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1061
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1062
  false,  /* isInfallible. False in setters. */
1063
  false,  /* isMovable.  Not relevant for setters. */
1064
  false, /* isEliminatable.  Not relevant for setters. */
1065
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1066
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1067
  false,  /* isTypedMethod.  Only relevant for methods. */
1068
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1069
};
1070
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1071
static_assert(0 < 2, "There is no slot for us");
1072
1073
MOZ_CAN_RUN_SCRIPT static bool
1074
get_timeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1075
0
{
1076
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.timeout", DOM, cx);
1077
0
1078
0
  uint32_t result(self->Timeout());
1079
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1080
0
  args.rval().setNumber(result);
1081
0
  return true;
1082
0
}
1083
1084
MOZ_CAN_RUN_SCRIPT static bool
1085
set_timeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitSetterCallArgs args)
1086
0
{
1087
0
  AUTO_PROFILER_LABEL_FAST("set XMLHttpRequest.timeout", DOM, cx);
1088
0
1089
0
  uint32_t arg0;
1090
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
1091
0
    return false;
1092
0
  }
1093
0
  FastErrorResult rv;
1094
0
  self->SetTimeout(arg0, rv);
1095
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1096
0
    return false;
1097
0
  }
1098
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1099
0
1100
0
  return true;
1101
0
}
1102
1103
static const JSJitInfo timeout_getterinfo = {
1104
  { (JSJitGetterOp)get_timeout },
1105
  { prototypes::id::XMLHttpRequest },
1106
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1107
  JSJitInfo::Getter,
1108
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1109
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
1110
  true,  /* isInfallible. False in setters. */
1111
  false,  /* isMovable.  Not relevant for setters. */
1112
  false, /* isEliminatable.  Not relevant for setters. */
1113
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1114
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1115
  false,  /* isTypedMethod.  Only relevant for methods. */
1116
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1117
};
1118
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1119
static_assert(0 < 2, "There is no slot for us");
1120
static const JSJitInfo timeout_setterinfo = {
1121
  { (JSJitGetterOp)set_timeout },
1122
  { prototypes::id::XMLHttpRequest },
1123
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1124
  JSJitInfo::Setter,
1125
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1126
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1127
  false,  /* isInfallible. False in setters. */
1128
  false,  /* isMovable.  Not relevant for setters. */
1129
  false, /* isEliminatable.  Not relevant for setters. */
1130
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1131
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1132
  false,  /* isTypedMethod.  Only relevant for methods. */
1133
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1134
};
1135
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1136
static_assert(0 < 2, "There is no slot for us");
1137
1138
MOZ_CAN_RUN_SCRIPT static bool
1139
get_withCredentials(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1140
0
{
1141
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.withCredentials", DOM, cx);
1142
0
1143
0
  bool result(self->WithCredentials());
1144
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1145
0
  args.rval().setBoolean(result);
1146
0
  return true;
1147
0
}
1148
1149
MOZ_CAN_RUN_SCRIPT static bool
1150
set_withCredentials(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitSetterCallArgs args)
1151
0
{
1152
0
  AUTO_PROFILER_LABEL_FAST("set XMLHttpRequest.withCredentials", DOM, cx);
1153
0
1154
0
  bool arg0;
1155
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
1156
0
    return false;
1157
0
  }
1158
0
  FastErrorResult rv;
1159
0
  self->SetWithCredentials(arg0, rv);
1160
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1161
0
    return false;
1162
0
  }
1163
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1164
0
1165
0
  return true;
1166
0
}
1167
1168
static const JSJitInfo withCredentials_getterinfo = {
1169
  { (JSJitGetterOp)get_withCredentials },
1170
  { prototypes::id::XMLHttpRequest },
1171
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1172
  JSJitInfo::Getter,
1173
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1174
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1175
  true,  /* isInfallible. False in setters. */
1176
  false,  /* isMovable.  Not relevant for setters. */
1177
  false, /* isEliminatable.  Not relevant for setters. */
1178
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1179
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1180
  false,  /* isTypedMethod.  Only relevant for methods. */
1181
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1182
};
1183
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1184
static_assert(0 < 2, "There is no slot for us");
1185
static const JSJitInfo withCredentials_setterinfo = {
1186
  { (JSJitGetterOp)set_withCredentials },
1187
  { prototypes::id::XMLHttpRequest },
1188
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1189
  JSJitInfo::Setter,
1190
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1191
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1192
  false,  /* isInfallible. False in setters. */
1193
  false,  /* isMovable.  Not relevant for setters. */
1194
  false, /* isEliminatable.  Not relevant for setters. */
1195
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1196
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1197
  false,  /* isTypedMethod.  Only relevant for methods. */
1198
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1199
};
1200
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1201
static_assert(0 < 2, "There is no slot for us");
1202
1203
MOZ_CAN_RUN_SCRIPT static bool
1204
get_upload(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1205
0
{
1206
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.upload", DOM, cx);
1207
0
1208
0
  FastErrorResult rv;
1209
0
  auto result(StrongOrRawPtr<mozilla::dom::XMLHttpRequestUpload>(self->GetUpload(rv)));
1210
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1211
0
    return false;
1212
0
  }
1213
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1214
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1215
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1216
0
    return false;
1217
0
  }
1218
0
  return true;
1219
0
}
1220
1221
static const JSJitInfo upload_getterinfo = {
1222
  { (JSJitGetterOp)get_upload },
1223
  { prototypes::id::XMLHttpRequest },
1224
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1225
  JSJitInfo::Getter,
1226
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1227
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1228
  false,  /* isInfallible. False in setters. */
1229
  false,  /* isMovable.  Not relevant for setters. */
1230
  false, /* isEliminatable.  Not relevant for setters. */
1231
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1232
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1233
  false,  /* isTypedMethod.  Only relevant for methods. */
1234
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1235
};
1236
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1237
static_assert(0 < 2, "There is no slot for us");
1238
1239
MOZ_CAN_RUN_SCRIPT static bool
1240
send(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1241
0
{
1242
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.send", DOM, cx);
1243
0
1244
0
  Nullable<DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString > arg0;
1245
0
  Maybe<DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument> arg0_holder;
1246
0
  if (!(args.hasDefined(0)) || args[0].isNullOrUndefined()) {
1247
0
    arg0.SetNull();
1248
0
  } else {
1249
0
    arg0_holder.emplace(arg0.SetValue());
1250
0
    {
1251
0
      bool done = false, failed = false, tryNext;
1252
0
      if (args[0].isObject()) {
1253
0
        done = (failed = !arg0_holder.ref().TrySetToDocument(cx, args[0], tryNext, false)) || !tryNext ||
1254
0
               (failed = !arg0_holder.ref().TrySetToBlob(cx, args[0], tryNext, false)) || !tryNext ||
1255
0
               (failed = !arg0_holder.ref().TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext ||
1256
0
               (failed = !arg0_holder.ref().TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext ||
1257
0
               (failed = !arg0_holder.ref().TrySetToFormData(cx, args[0], tryNext, false)) || !tryNext ||
1258
0
               (failed = !arg0_holder.ref().TrySetToURLSearchParams(cx, args[0], tryNext, false)) || !tryNext;
1259
0
1260
0
      }
1261
0
      if (!done) {
1262
0
        do {
1263
0
          done = (failed = !arg0_holder.ref().TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
1264
0
          break;
1265
0
        } while (false);
1266
0
      }
1267
0
      if (failed) {
1268
0
        return false;
1269
0
      }
1270
0
      if (!done) {
1271
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of XMLHttpRequest.send", "Document, Blob, ArrayBufferView, ArrayBuffer, FormData, URLSearchParams");
1272
0
        return false;
1273
0
      }
1274
0
    }
1275
0
  }
1276
0
  FastErrorResult rv;
1277
0
  self->Send(cx, Constify(arg0), rv);
1278
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1279
0
    return false;
1280
0
  }
1281
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1282
0
  args.rval().setUndefined();
1283
0
  return true;
1284
0
}
1285
1286
static const JSJitInfo send_methodinfo = {
1287
  { (JSJitGetterOp)send },
1288
  { prototypes::id::XMLHttpRequest },
1289
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1290
  JSJitInfo::Method,
1291
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1292
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1293
  false,  /* isInfallible. False in setters. */
1294
  false,  /* isMovable.  Not relevant for setters. */
1295
  false, /* isEliminatable.  Not relevant for setters. */
1296
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1297
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1298
  false,  /* isTypedMethod.  Only relevant for methods. */
1299
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1300
};
1301
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1302
static_assert(0 < 2, "There is no slot for us");
1303
1304
MOZ_CAN_RUN_SCRIPT static bool
1305
abort(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1306
0
{
1307
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.abort", DOM, cx);
1308
0
1309
0
  FastErrorResult rv;
1310
0
  self->Abort(rv);
1311
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1312
0
    return false;
1313
0
  }
1314
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1315
0
  args.rval().setUndefined();
1316
0
  return true;
1317
0
}
1318
1319
static const JSJitInfo abort_methodinfo = {
1320
  { (JSJitGetterOp)abort },
1321
  { prototypes::id::XMLHttpRequest },
1322
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1323
  JSJitInfo::Method,
1324
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1325
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1326
  false,  /* isInfallible. False in setters. */
1327
  false,  /* isMovable.  Not relevant for setters. */
1328
  false, /* isEliminatable.  Not relevant for setters. */
1329
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1330
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1331
  false,  /* isTypedMethod.  Only relevant for methods. */
1332
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1333
};
1334
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1335
static_assert(0 < 2, "There is no slot for us");
1336
1337
MOZ_CAN_RUN_SCRIPT static bool
1338
get_responseURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1339
0
{
1340
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.responseURL", DOM, cx);
1341
0
1342
0
  DOMString result;
1343
0
  self->GetResponseURL(result);
1344
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1345
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
1346
0
    return false;
1347
0
  }
1348
0
  return true;
1349
0
}
1350
1351
static const JSJitInfo responseURL_getterinfo = {
1352
  { (JSJitGetterOp)get_responseURL },
1353
  { prototypes::id::XMLHttpRequest },
1354
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1355
  JSJitInfo::Getter,
1356
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1357
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1358
  false,  /* isInfallible. False in setters. */
1359
  false,  /* isMovable.  Not relevant for setters. */
1360
  false, /* isEliminatable.  Not relevant for setters. */
1361
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1362
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1363
  false,  /* isTypedMethod.  Only relevant for methods. */
1364
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1365
};
1366
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1367
static_assert(0 < 2, "There is no slot for us");
1368
1369
MOZ_CAN_RUN_SCRIPT static bool
1370
get_status(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1371
0
{
1372
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.status", DOM, cx);
1373
0
1374
0
  FastErrorResult rv;
1375
0
  uint16_t result(self->GetStatus(rv));
1376
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1377
0
    return false;
1378
0
  }
1379
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1380
0
  args.rval().setInt32(int32_t(result));
1381
0
  return true;
1382
0
}
1383
1384
static const JSJitInfo status_getterinfo = {
1385
  { (JSJitGetterOp)get_status },
1386
  { prototypes::id::XMLHttpRequest },
1387
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1388
  JSJitInfo::Getter,
1389
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1390
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
1391
  false,  /* isInfallible. False in setters. */
1392
  false,  /* isMovable.  Not relevant for setters. */
1393
  false, /* isEliminatable.  Not relevant for setters. */
1394
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1395
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1396
  false,  /* isTypedMethod.  Only relevant for methods. */
1397
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1398
};
1399
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1400
static_assert(0 < 2, "There is no slot for us");
1401
1402
MOZ_CAN_RUN_SCRIPT static bool
1403
get_statusText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1404
0
{
1405
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.statusText", DOM, cx);
1406
0
1407
0
  FastErrorResult rv;
1408
0
  nsCString result;
1409
0
  self->GetStatusText(result, rv);
1410
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1411
0
    return false;
1412
0
  }
1413
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1414
0
  if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
1415
0
    return false;
1416
0
  }
1417
0
  return true;
1418
0
}
1419
1420
static const JSJitInfo statusText_getterinfo = {
1421
  { (JSJitGetterOp)get_statusText },
1422
  { prototypes::id::XMLHttpRequest },
1423
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1424
  JSJitInfo::Getter,
1425
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1426
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1427
  false,  /* isInfallible. False in setters. */
1428
  false,  /* isMovable.  Not relevant for setters. */
1429
  false, /* isEliminatable.  Not relevant for setters. */
1430
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1431
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1432
  false,  /* isTypedMethod.  Only relevant for methods. */
1433
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1434
};
1435
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1436
static_assert(0 < 2, "There is no slot for us");
1437
1438
MOZ_CAN_RUN_SCRIPT static bool
1439
getResponseHeader(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1440
0
{
1441
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.getResponseHeader", DOM, cx);
1442
0
1443
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1444
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.getResponseHeader");
1445
0
  }
1446
0
  nsCString arg0;
1447
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
1448
0
    return false;
1449
0
  }
1450
0
  FastErrorResult rv;
1451
0
  nsCString result;
1452
0
  self->GetResponseHeader(Constify(arg0), result, rv);
1453
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1454
0
    return false;
1455
0
  }
1456
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1457
0
  if (!ByteStringToJsval(cx, result, args.rval())) {
1458
0
    return false;
1459
0
  }
1460
0
  return true;
1461
0
}
1462
1463
static const JSJitInfo getResponseHeader_methodinfo = {
1464
  { (JSJitGetterOp)getResponseHeader },
1465
  { prototypes::id::XMLHttpRequest },
1466
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1467
  JSJitInfo::Method,
1468
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1469
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1470
  false,  /* isInfallible. False in setters. */
1471
  false,  /* isMovable.  Not relevant for setters. */
1472
  false, /* isEliminatable.  Not relevant for setters. */
1473
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1474
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1475
  false,  /* isTypedMethod.  Only relevant for methods. */
1476
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1477
};
1478
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1479
static_assert(0 < 2, "There is no slot for us");
1480
1481
MOZ_CAN_RUN_SCRIPT static bool
1482
getAllResponseHeaders(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1483
0
{
1484
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.getAllResponseHeaders", DOM, cx);
1485
0
1486
0
  FastErrorResult rv;
1487
0
  nsCString result;
1488
0
  self->GetAllResponseHeaders(result, rv);
1489
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1490
0
    return false;
1491
0
  }
1492
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1493
0
  if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
1494
0
    return false;
1495
0
  }
1496
0
  return true;
1497
0
}
1498
1499
static const JSJitInfo getAllResponseHeaders_methodinfo = {
1500
  { (JSJitGetterOp)getAllResponseHeaders },
1501
  { prototypes::id::XMLHttpRequest },
1502
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1503
  JSJitInfo::Method,
1504
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1505
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1506
  false,  /* isInfallible. False in setters. */
1507
  false,  /* isMovable.  Not relevant for setters. */
1508
  false, /* isEliminatable.  Not relevant for setters. */
1509
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1510
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1511
  false,  /* isTypedMethod.  Only relevant for methods. */
1512
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1513
};
1514
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1515
static_assert(0 < 2, "There is no slot for us");
1516
1517
MOZ_CAN_RUN_SCRIPT static bool
1518
overrideMimeType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1519
0
{
1520
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.overrideMimeType", DOM, cx);
1521
0
1522
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1523
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.overrideMimeType");
1524
0
  }
1525
0
  binding_detail::FakeString arg0;
1526
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1527
0
    return false;
1528
0
  }
1529
0
  FastErrorResult rv;
1530
0
  self->OverrideMimeType(NonNullHelper(Constify(arg0)), rv);
1531
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1532
0
    return false;
1533
0
  }
1534
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1535
0
  args.rval().setUndefined();
1536
0
  return true;
1537
0
}
1538
1539
static const JSJitInfo overrideMimeType_methodinfo = {
1540
  { (JSJitGetterOp)overrideMimeType },
1541
  { prototypes::id::XMLHttpRequest },
1542
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1543
  JSJitInfo::Method,
1544
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1545
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1546
  false,  /* isInfallible. False in setters. */
1547
  false,  /* isMovable.  Not relevant for setters. */
1548
  false, /* isEliminatable.  Not relevant for setters. */
1549
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1550
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1551
  false,  /* isTypedMethod.  Only relevant for methods. */
1552
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1553
};
1554
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1555
static_assert(0 < 2, "There is no slot for us");
1556
1557
MOZ_CAN_RUN_SCRIPT static bool
1558
get_responseType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1559
0
{
1560
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.responseType", DOM, cx);
1561
0
1562
0
  XMLHttpRequestResponseType result(self->ResponseType());
1563
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1564
0
  if (!ToJSValue(cx, result, args.rval())) {
1565
0
    return false;
1566
0
  }
1567
0
  return true;
1568
0
}
1569
1570
MOZ_CAN_RUN_SCRIPT static bool
1571
set_responseType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitSetterCallArgs args)
1572
0
{
1573
0
  AUTO_PROFILER_LABEL_FAST("set XMLHttpRequest.responseType", DOM, cx);
1574
0
1575
0
  XMLHttpRequestResponseType arg0;
1576
0
  {
1577
0
    int index;
1578
0
    if (!FindEnumStringIndex<false>(cx, args[0], XMLHttpRequestResponseTypeValues::strings, "XMLHttpRequestResponseType", "Value being assigned to XMLHttpRequest.responseType", &index)) {
1579
0
      return false;
1580
0
    }
1581
0
    if (index < 0) {
1582
0
      return true;
1583
0
    }
1584
0
    arg0 = static_cast<XMLHttpRequestResponseType>(index);
1585
0
  }
1586
0
  FastErrorResult rv;
1587
0
  self->SetResponseType(arg0, rv);
1588
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1589
0
    return false;
1590
0
  }
1591
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1592
0
1593
0
  return true;
1594
0
}
1595
1596
static const JSJitInfo responseType_getterinfo = {
1597
  { (JSJitGetterOp)get_responseType },
1598
  { prototypes::id::XMLHttpRequest },
1599
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1600
  JSJitInfo::Getter,
1601
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1602
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1603
  false,  /* isInfallible. False in setters. */
1604
  false,  /* isMovable.  Not relevant for setters. */
1605
  false, /* isEliminatable.  Not relevant for setters. */
1606
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1607
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1608
  false,  /* isTypedMethod.  Only relevant for methods. */
1609
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1610
};
1611
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1612
static_assert(0 < 2, "There is no slot for us");
1613
static const JSJitInfo responseType_setterinfo = {
1614
  { (JSJitGetterOp)set_responseType },
1615
  { prototypes::id::XMLHttpRequest },
1616
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1617
  JSJitInfo::Setter,
1618
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1619
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1620
  false,  /* isInfallible. False in setters. */
1621
  false,  /* isMovable.  Not relevant for setters. */
1622
  false, /* isEliminatable.  Not relevant for setters. */
1623
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1624
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1625
  false,  /* isTypedMethod.  Only relevant for methods. */
1626
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1627
};
1628
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1629
static_assert(0 < 2, "There is no slot for us");
1630
1631
MOZ_CAN_RUN_SCRIPT static bool
1632
get_response(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1633
0
{
1634
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.response", DOM, cx);
1635
0
1636
0
  FastErrorResult rv;
1637
0
  JS::Rooted<JS::Value> result(cx);
1638
0
  self->GetResponse(cx, &result, rv);
1639
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1640
0
    return false;
1641
0
  }
1642
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1643
0
  JS::ExposeValueToActiveJS(result);
1644
0
  args.rval().set(result);
1645
0
  if (!MaybeWrapValue(cx, args.rval())) {
1646
0
    return false;
1647
0
  }
1648
0
  return true;
1649
0
}
1650
1651
static const JSJitInfo response_getterinfo = {
1652
  { (JSJitGetterOp)get_response },
1653
  { prototypes::id::XMLHttpRequest },
1654
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1655
  JSJitInfo::Getter,
1656
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1657
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1658
  false,  /* isInfallible. False in setters. */
1659
  false,  /* isMovable.  Not relevant for setters. */
1660
  false, /* isEliminatable.  Not relevant for setters. */
1661
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1662
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1663
  false,  /* isTypedMethod.  Only relevant for methods. */
1664
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1665
};
1666
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1667
static_assert(0 < 2, "There is no slot for us");
1668
1669
MOZ_CAN_RUN_SCRIPT static bool
1670
get_responseText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1671
0
{
1672
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.responseText", DOM, cx);
1673
0
1674
0
  // Have to either root across the getter call or reget after.
1675
0
  bool isXray;
1676
0
  JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
1677
0
  if (!slotStorage) {
1678
0
    return false;
1679
0
  }
1680
0
  const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
1681
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
1682
0
  {
1683
0
    // Scope for cachedVal
1684
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
1685
0
    if (!cachedVal.isUndefined()) {
1686
0
      args.rval().set(cachedVal);
1687
0
      // The cached value is in the compartment of slotStorage,
1688
0
      // so wrap into the caller compartment as needed.
1689
0
      if (MaybeWrapValue(cx, args.rval())) {
1690
0
        return true;
1691
0
      }
1692
0
      return false;
1693
0
    }
1694
0
  }
1695
0
1696
0
  FastErrorResult rv;
1697
0
  DOMString result;
1698
0
  self->GetResponseText(result, rv);
1699
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1700
0
    return false;
1701
0
  }
1702
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1703
0
  {
1704
0
    JS::Rooted<JSObject*> conversionScope(cx, isXray ? JS::CurrentGlobalOrNull(cx) : slotStorage);
1705
0
    JSAutoRealm ar(cx, conversionScope);
1706
0
    do { // block we break out of when done wrapping
1707
0
      if (!xpc::StringToJsval(cx, result, args.rval())) {
1708
0
        return false;
1709
0
      }
1710
0
      break;
1711
0
    } while (false);
1712
0
  }
1713
0
  { // And now store things in the realm of our slotStorage.
1714
0
    JSAutoRealm ar(cx, slotStorage);
1715
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
1716
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
1717
0
    if (!MaybeWrapValue(cx, &storedVal)) {
1718
0
      return false;
1719
0
    }
1720
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
1721
0
    if (!isXray) {
1722
0
      // In the Xray case we don't need to do this, because getting the
1723
0
      // expando object already preserved our wrapper.
1724
0
      PreserveWrapper(self);
1725
0
    }
1726
0
  }
1727
0
  // And now make sure args.rval() is in the caller realm.
1728
0
  if (MaybeWrapValue(cx, args.rval())) {
1729
0
    return true;
1730
0
  }
1731
0
  return false;
1732
0
}
1733
1734
static const JSJitInfo responseText_getterinfo = {
1735
  { (JSJitGetterOp)get_responseText },
1736
  { prototypes::id::XMLHttpRequest },
1737
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1738
  JSJitInfo::Getter,
1739
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1740
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1741
  false,  /* isInfallible. False in setters. */
1742
  false,  /* isMovable.  Not relevant for setters. */
1743
  false, /* isEliminatable.  Not relevant for setters. */
1744
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1745
  true, /* isLazilyCachedInSlot.  Only relevant for getters. */
1746
  false,  /* isTypedMethod.  Only relevant for methods. */
1747
  (DOM_INSTANCE_RESERVED_SLOTS + 0)   /* Reserved slot index, if we're stored in a slot, else 0. */
1748
};
1749
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
1750
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
1751
1752
MOZ_CAN_RUN_SCRIPT static bool
1753
get_responseXML(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1754
0
{
1755
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.responseXML", DOM, cx);
1756
0
1757
0
  FastErrorResult rv;
1758
0
  auto result(StrongOrRawPtr<nsIDocument>(self->GetResponseXML(rv)));
1759
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1760
0
    return false;
1761
0
  }
1762
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1763
0
  if (!result) {
1764
0
    args.rval().setNull();
1765
0
    return true;
1766
0
  }
1767
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1768
0
    MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing");
1769
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1770
0
    return false;
1771
0
  }
1772
0
  return true;
1773
0
}
1774
1775
static const JSJitInfo responseXML_getterinfo = {
1776
  { (JSJitGetterOp)get_responseXML },
1777
  { prototypes::id::XMLHttpRequest },
1778
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1779
  JSJitInfo::Getter,
1780
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1781
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1782
  false,  /* isInfallible. False in setters. */
1783
  false,  /* isMovable.  Not relevant for setters. */
1784
  false, /* isEliminatable.  Not relevant for setters. */
1785
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1786
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1787
  false,  /* isTypedMethod.  Only relevant for methods. */
1788
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1789
};
1790
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1791
static_assert(0 < 2, "There is no slot for us");
1792
1793
MOZ_CAN_RUN_SCRIPT static bool
1794
get_mozBackgroundRequest(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1795
0
{
1796
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.mozBackgroundRequest", DOM, cx);
1797
0
1798
0
  bool result(self->MozBackgroundRequest());
1799
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1800
0
  args.rval().setBoolean(result);
1801
0
  return true;
1802
0
}
1803
1804
MOZ_CAN_RUN_SCRIPT static bool
1805
set_mozBackgroundRequest(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitSetterCallArgs args)
1806
0
{
1807
0
  AUTO_PROFILER_LABEL_FAST("set XMLHttpRequest.mozBackgroundRequest", DOM, cx);
1808
0
1809
0
  bool arg0;
1810
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
1811
0
    return false;
1812
0
  }
1813
0
  FastErrorResult rv;
1814
0
  self->SetMozBackgroundRequest(arg0, rv);
1815
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1816
0
    return false;
1817
0
  }
1818
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1819
0
1820
0
  return true;
1821
0
}
1822
1823
static const JSJitInfo mozBackgroundRequest_getterinfo = {
1824
  { (JSJitGetterOp)get_mozBackgroundRequest },
1825
  { prototypes::id::XMLHttpRequest },
1826
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1827
  JSJitInfo::Getter,
1828
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1829
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1830
  true,  /* isInfallible. False in setters. */
1831
  false,  /* isMovable.  Not relevant for setters. */
1832
  false, /* isEliminatable.  Not relevant for setters. */
1833
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1834
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1835
  false,  /* isTypedMethod.  Only relevant for methods. */
1836
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1837
};
1838
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1839
static_assert(0 < 2, "There is no slot for us");
1840
static const JSJitInfo mozBackgroundRequest_setterinfo = {
1841
  { (JSJitGetterOp)set_mozBackgroundRequest },
1842
  { prototypes::id::XMLHttpRequest },
1843
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1844
  JSJitInfo::Setter,
1845
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1846
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1847
  false,  /* isInfallible. False in setters. */
1848
  false,  /* isMovable.  Not relevant for setters. */
1849
  false, /* isEliminatable.  Not relevant for setters. */
1850
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1851
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1852
  false,  /* isTypedMethod.  Only relevant for methods. */
1853
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1854
};
1855
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1856
static_assert(0 < 2, "There is no slot for us");
1857
1858
MOZ_CAN_RUN_SCRIPT static bool
1859
get_channel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
1860
0
{
1861
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.channel", DOM, cx);
1862
0
1863
0
  auto result(StrongOrRawPtr<nsIChannel>(self->GetChannel()));
1864
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1865
0
  if (!result) {
1866
0
    args.rval().setNull();
1867
0
    return true;
1868
0
  }
1869
0
  if (!WrapObject(cx, result, &NS_GET_IID(nsIChannel), args.rval())) {
1870
0
    return false;
1871
0
  }
1872
0
  return true;
1873
0
}
1874
1875
static const JSJitInfo channel_getterinfo = {
1876
  { (JSJitGetterOp)get_channel },
1877
  { prototypes::id::XMLHttpRequest },
1878
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1879
  JSJitInfo::Getter,
1880
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1881
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1882
  false,  /* isInfallible. False in setters. */
1883
  false,  /* isMovable.  Not relevant for setters. */
1884
  false, /* isEliminatable.  Not relevant for setters. */
1885
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1886
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1887
  false,  /* isTypedMethod.  Only relevant for methods. */
1888
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1889
};
1890
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1891
static_assert(0 < 2, "There is no slot for us");
1892
1893
MOZ_CAN_RUN_SCRIPT static bool
1894
getInterface(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1895
0
{
1896
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.getInterface", DOM, cx);
1897
0
1898
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1899
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.getInterface");
1900
0
  }
1901
0
  nsIJSID* arg0;
1902
0
  RefPtr<nsIJSID> arg0_holder;
1903
0
  if (args[0].isObject()) {
1904
0
    JS::Rooted<JSObject*> source(cx, &args[0].toObject());
1905
0
    if (NS_FAILED(UnwrapArg<nsIJSID>(cx, source, getter_AddRefs(arg0_holder)))) {
1906
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XMLHttpRequest.getInterface", "IID");
1907
0
      return false;
1908
0
    }
1909
0
    MOZ_ASSERT(arg0_holder);
1910
0
    arg0 = arg0_holder;
1911
0
  } else {
1912
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XMLHttpRequest.getInterface");
1913
0
    return false;
1914
0
  }
1915
0
  FastErrorResult rv;
1916
0
  JS::Rooted<JS::Value> result(cx);
1917
0
  self->GetInterface(cx, MOZ_KnownLive(NonNullHelper(arg0)), &result, rv);
1918
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1919
0
    return false;
1920
0
  }
1921
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1922
0
  JS::ExposeValueToActiveJS(result);
1923
0
  args.rval().set(result);
1924
0
  if (!MaybeWrapValue(cx, args.rval())) {
1925
0
    return false;
1926
0
  }
1927
0
  return true;
1928
0
}
1929
1930
static const JSJitInfo getInterface_methodinfo = {
1931
  { (JSJitGetterOp)getInterface },
1932
  { prototypes::id::XMLHttpRequest },
1933
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1934
  JSJitInfo::Method,
1935
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1936
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1937
  false,  /* isInfallible. False in setters. */
1938
  false,  /* isMovable.  Not relevant for setters. */
1939
  false, /* isEliminatable.  Not relevant for setters. */
1940
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1941
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1942
  false,  /* isTypedMethod.  Only relevant for methods. */
1943
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1944
};
1945
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1946
static_assert(0 < 2, "There is no slot for us");
1947
1948
MOZ_CAN_RUN_SCRIPT static bool
1949
setOriginAttributes(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1950
0
{
1951
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.setOriginAttributes", DOM, cx);
1952
0
1953
0
  binding_detail::FastOriginAttributesDictionary arg0;
1954
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of XMLHttpRequest.setOriginAttributes", false)) {
1955
0
    return false;
1956
0
  }
1957
0
  self->SetOriginAttributes(Constify(arg0));
1958
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1959
0
  args.rval().setUndefined();
1960
0
  return true;
1961
0
}
1962
1963
static const JSJitInfo setOriginAttributes_methodinfo = {
1964
  { (JSJitGetterOp)setOriginAttributes },
1965
  { prototypes::id::XMLHttpRequest },
1966
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
1967
  JSJitInfo::Method,
1968
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1969
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1970
  false,  /* isInfallible. False in setters. */
1971
  false,  /* isMovable.  Not relevant for setters. */
1972
  false, /* isEliminatable.  Not relevant for setters. */
1973
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1974
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1975
  false,  /* isTypedMethod.  Only relevant for methods. */
1976
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1977
};
1978
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1979
static_assert(0 < 2, "There is no slot for us");
1980
1981
MOZ_CAN_RUN_SCRIPT static bool
1982
sendInputStream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, const JSJitMethodCallArgs& args)
1983
0
{
1984
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest.sendInputStream", DOM, cx);
1985
0
1986
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1987
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest.sendInputStream");
1988
0
  }
1989
0
  nsIInputStream* arg0;
1990
0
  RefPtr<nsIInputStream> arg0_holder;
1991
0
  if (args[0].isObject()) {
1992
0
    JS::Rooted<JSObject*> source(cx, &args[0].toObject());
1993
0
    if (NS_FAILED(UnwrapArg<nsIInputStream>(cx, source, getter_AddRefs(arg0_holder)))) {
1994
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XMLHttpRequest.sendInputStream", "InputStream");
1995
0
      return false;
1996
0
    }
1997
0
    MOZ_ASSERT(arg0_holder);
1998
0
    arg0 = arg0_holder;
1999
0
  } else {
2000
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XMLHttpRequest.sendInputStream");
2001
0
    return false;
2002
0
  }
2003
0
  FastErrorResult rv;
2004
0
  self->SendInputStream(MOZ_KnownLive(NonNullHelper(arg0)), rv);
2005
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2006
0
    return false;
2007
0
  }
2008
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2009
0
  args.rval().setUndefined();
2010
0
  return true;
2011
0
}
2012
2013
static const JSJitInfo sendInputStream_methodinfo = {
2014
  { (JSJitGetterOp)sendInputStream },
2015
  { prototypes::id::XMLHttpRequest },
2016
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
2017
  JSJitInfo::Method,
2018
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2019
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
2020
  false,  /* isInfallible. False in setters. */
2021
  false,  /* isMovable.  Not relevant for setters. */
2022
  false, /* isEliminatable.  Not relevant for setters. */
2023
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2024
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2025
  false,  /* isTypedMethod.  Only relevant for methods. */
2026
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2027
};
2028
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2029
static_assert(0 < 2, "There is no slot for us");
2030
2031
MOZ_CAN_RUN_SCRIPT static bool
2032
get_errorCode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
2033
0
{
2034
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.errorCode", DOM, cx);
2035
0
2036
0
  uint16_t result(self->ErrorCode());
2037
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2038
0
  args.rval().setInt32(int32_t(result));
2039
0
  return true;
2040
0
}
2041
2042
static const JSJitInfo errorCode_getterinfo = {
2043
  { (JSJitGetterOp)get_errorCode },
2044
  { prototypes::id::XMLHttpRequest },
2045
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
2046
  JSJitInfo::Getter,
2047
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2048
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
2049
  true,  /* isInfallible. False in setters. */
2050
  false,  /* isMovable.  Not relevant for setters. */
2051
  false, /* isEliminatable.  Not relevant for setters. */
2052
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2053
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2054
  false,  /* isTypedMethod.  Only relevant for methods. */
2055
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2056
};
2057
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2058
static_assert(0 < 2, "There is no slot for us");
2059
2060
MOZ_CAN_RUN_SCRIPT static bool
2061
get_mozAnon(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
2062
0
{
2063
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.mozAnon", DOM, cx);
2064
0
2065
0
  bool result(self->MozAnon());
2066
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2067
0
  args.rval().setBoolean(result);
2068
0
  return true;
2069
0
}
2070
2071
static const JSJitInfo mozAnon_getterinfo = {
2072
  { (JSJitGetterOp)get_mozAnon },
2073
  { prototypes::id::XMLHttpRequest },
2074
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
2075
  JSJitInfo::Getter,
2076
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2077
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
2078
  true,  /* isInfallible. False in setters. */
2079
  false,  /* isMovable.  Not relevant for setters. */
2080
  false, /* isEliminatable.  Not relevant for setters. */
2081
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2082
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2083
  false,  /* isTypedMethod.  Only relevant for methods. */
2084
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2085
};
2086
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2087
static_assert(0 < 2, "There is no slot for us");
2088
2089
MOZ_CAN_RUN_SCRIPT static bool
2090
get_mozSystem(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XMLHttpRequest* self, JSJitGetterCallArgs args)
2091
0
{
2092
0
  AUTO_PROFILER_LABEL_FAST("get XMLHttpRequest.mozSystem", DOM, cx);
2093
0
2094
0
  bool result(self->MozSystem());
2095
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2096
0
  args.rval().setBoolean(result);
2097
0
  return true;
2098
0
}
2099
2100
static const JSJitInfo mozSystem_getterinfo = {
2101
  { (JSJitGetterOp)get_mozSystem },
2102
  { prototypes::id::XMLHttpRequest },
2103
  { PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth },
2104
  JSJitInfo::Getter,
2105
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2106
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
2107
  true,  /* isInfallible. False in setters. */
2108
  false,  /* isMovable.  Not relevant for setters. */
2109
  false, /* isEliminatable.  Not relevant for setters. */
2110
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2111
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2112
  false,  /* isTypedMethod.  Only relevant for methods. */
2113
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2114
};
2115
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2116
static_assert(0 < 2, "There is no slot for us");
2117
2118
static bool
2119
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
2120
0
{
2121
0
  mozilla::dom::XMLHttpRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XMLHttpRequest>(obj);
2122
0
  // We don't want to preserve if we don't have a wrapper, and we
2123
0
  // obviously can't preserve if we're not initialized.
2124
0
  if (self && self->GetWrapperPreserveColor()) {
2125
0
    PreserveWrapper(self);
2126
0
  }
2127
0
  return true;
2128
0
}
2129
2130
static void
2131
_finalize(js::FreeOp* fop, JSObject* obj)
2132
0
{
2133
0
  mozilla::dom::XMLHttpRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XMLHttpRequest>(obj);
2134
0
  if (self) {
2135
0
    ClearWrapper(self, self, obj);
2136
0
    AddForDeferredFinalization<mozilla::dom::XMLHttpRequest>(self);
2137
0
  }
2138
0
}
2139
2140
static size_t
2141
_objectMoved(JSObject* obj, JSObject* old)
2142
0
{
2143
0
  mozilla::dom::XMLHttpRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XMLHttpRequest>(obj);
2144
0
  if (self) {
2145
0
    UpdateWrapper(self, self, obj, old);
2146
0
  }
2147
0
2148
0
  return 0;
2149
0
}
2150
2151
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2152
#if defined(__clang__)
2153
#pragma clang diagnostic push
2154
#pragma clang diagnostic ignored "-Wmissing-braces"
2155
#endif
2156
static const JSFunctionSpec sMethods_specs[] = {
2157
  JS_FNSPEC("open", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&open_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
2158
  JS_FNSPEC("setRequestHeader", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setRequestHeader_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
2159
  JS_FNSPEC("send", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&send_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2160
  JS_FNSPEC("abort", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&abort_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2161
  JS_FNSPEC("getResponseHeader", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getResponseHeader_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2162
  JS_FNSPEC("getAllResponseHeaders", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAllResponseHeaders_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2163
  JS_FNSPEC("overrideMimeType", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&overrideMimeType_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2164
  JS_FS_END
2165
};
2166
#if defined(__clang__)
2167
#pragma clang diagnostic pop
2168
#endif
2169
2170
2171
static const Prefable<const JSFunctionSpec> sMethods[] = {
2172
  { nullptr, &sMethods_specs[0] },
2173
  { nullptr, nullptr }
2174
};
2175
2176
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2177
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2178
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2179
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2180
2181
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2182
#if defined(__clang__)
2183
#pragma clang diagnostic push
2184
#pragma clang diagnostic ignored "-Wmissing-braces"
2185
#endif
2186
static const JSFunctionSpec sChromeMethods_specs[] = {
2187
  JS_FNSPEC("getInterface", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getInterface_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2188
  JS_FNSPEC("setOriginAttributes", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setOriginAttributes_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2189
  JS_FS_END,
2190
  JS_FNSPEC("sendInputStream", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendInputStream_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2191
  JS_FS_END,
2192
  JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
2193
  JS_FS_END
2194
};
2195
#if defined(__clang__)
2196
#pragma clang diagnostic pop
2197
#endif
2198
2199
// Can't be const because the pref-enabled boolean needs to be writable
2200
static PrefableDisablers sChromeMethods_disablers0 = {
2201
  true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
2202
};
2203
2204
// Can't be const because the pref-enabled boolean needs to be writable
2205
static PrefableDisablers sChromeMethods_disablers5 = {
2206
  true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
2207
};
2208
2209
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
2210
  { &sChromeMethods_disablers0, &sChromeMethods_specs[0] },
2211
  { nullptr, &sChromeMethods_specs[3] },
2212
  { &sChromeMethods_disablers5, &sChromeMethods_specs[5] },
2213
  { nullptr, nullptr }
2214
};
2215
2216
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2217
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2218
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2219
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2220
2221
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2222
#if defined(__clang__)
2223
#pragma clang diagnostic push
2224
#pragma clang diagnostic ignored "-Wmissing-braces"
2225
#endif
2226
static const JSPropertySpec sAttributes_specs[] = {
2227
  { "onreadystatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onreadystatechange_getterinfo, GenericSetter<NormalThisPolicy>, &onreadystatechange_setterinfo },
2228
  { "readyState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &readyState_getterinfo, nullptr, nullptr },
2229
  { "timeout", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &timeout_getterinfo, GenericSetter<NormalThisPolicy>, &timeout_setterinfo },
2230
  { "withCredentials", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &withCredentials_getterinfo, GenericSetter<NormalThisPolicy>, &withCredentials_setterinfo },
2231
  { "upload", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &upload_getterinfo, nullptr, nullptr },
2232
  { "responseURL", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &responseURL_getterinfo, nullptr, nullptr },
2233
  { "status", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &status_getterinfo, nullptr, nullptr },
2234
  { "statusText", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &statusText_getterinfo, nullptr, nullptr },
2235
  { "responseType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &responseType_getterinfo, GenericSetter<NormalThisPolicy>, &responseType_setterinfo },
2236
  { "response", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &response_getterinfo, nullptr, nullptr },
2237
  { "responseText", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &responseText_getterinfo, nullptr, nullptr },
2238
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
2239
  { "responseXML", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &responseXML_getterinfo, nullptr, nullptr },
2240
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
2241
  { "mozAnon", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozAnon_getterinfo, nullptr, nullptr },
2242
  { "mozSystem", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozSystem_getterinfo, nullptr, nullptr },
2243
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
2244
};
2245
#if defined(__clang__)
2246
#pragma clang diagnostic pop
2247
#endif
2248
2249
// Can't be const because the pref-enabled boolean needs to be writable
2250
static PrefableDisablers sAttributes_disablers12 = {
2251
  true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
2252
};
2253
2254
static const Prefable<const JSPropertySpec> sAttributes[] = {
2255
  { nullptr, &sAttributes_specs[0] },
2256
  { &sAttributes_disablers12, &sAttributes_specs[12] },
2257
  { nullptr, &sAttributes_specs[14] },
2258
  { nullptr, nullptr }
2259
};
2260
2261
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2262
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2263
static_assert(11 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2264
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2265
2266
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2267
#if defined(__clang__)
2268
#pragma clang diagnostic push
2269
#pragma clang diagnostic ignored "-Wmissing-braces"
2270
#endif
2271
static const JSPropertySpec sChromeAttributes_specs[] = {
2272
  { "mozBackgroundRequest", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozBackgroundRequest_getterinfo, GenericSetter<NormalThisPolicy>, &mozBackgroundRequest_setterinfo },
2273
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
2274
  { "channel", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &channel_getterinfo, nullptr, nullptr },
2275
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
2276
  { "errorCode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &errorCode_getterinfo, nullptr, nullptr },
2277
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
2278
};
2279
#if defined(__clang__)
2280
#pragma clang diagnostic pop
2281
#endif
2282
2283
// Can't be const because the pref-enabled boolean needs to be writable
2284
static PrefableDisablers sChromeAttributes_disablers2 = {
2285
  true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
2286
};
2287
2288
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
2289
  { nullptr, &sChromeAttributes_specs[0] },
2290
  { &sChromeAttributes_disablers2, &sChromeAttributes_specs[2] },
2291
  { nullptr, &sChromeAttributes_specs[4] },
2292
  { nullptr, nullptr }
2293
};
2294
2295
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2296
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2297
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2298
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2299
2300
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2301
#if defined(__clang__)
2302
#pragma clang diagnostic push
2303
#pragma clang diagnostic ignored "-Wmissing-braces"
2304
#endif
2305
static const ConstantSpec sConstants_specs[] = {
2306
  { "UNSENT", JS::Int32Value(0) },
2307
  { "OPENED", JS::Int32Value(1) },
2308
  { "HEADERS_RECEIVED", JS::Int32Value(2) },
2309
  { "LOADING", JS::Int32Value(3) },
2310
  { "DONE", JS::Int32Value(4) },
2311
  { 0, JS::UndefinedValue() }
2312
};
2313
#if defined(__clang__)
2314
#pragma clang diagnostic pop
2315
#endif
2316
2317
2318
static const Prefable<const ConstantSpec> sConstants[] = {
2319
  { nullptr, &sConstants_specs[0] },
2320
  { nullptr, nullptr }
2321
};
2322
2323
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2324
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2325
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2326
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2327
2328
2329
static uint16_t sNativeProperties_sortedPropertyIndices[26];
2330
static PropertyInfo sNativeProperties_propertyInfos[26];
2331
2332
static const NativePropertiesN<3> sNativeProperties = {
2333
  false, 0,
2334
  false, 0,
2335
  true,  0 /* sMethods */,
2336
  true,  1 /* sAttributes */,
2337
  false, 0,
2338
  false, 0,
2339
  true,  2 /* sConstants */,
2340
  -1,
2341
  26,
2342
  sNativeProperties_sortedPropertyIndices,
2343
  {
2344
    { sMethods, &sNativeProperties_propertyInfos[0] },
2345
    { sAttributes, &sNativeProperties_propertyInfos[7] },
2346
    { sConstants, &sNativeProperties_propertyInfos[21] }
2347
  }
2348
};
2349
static_assert(26 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
2350
    "We have a property info count that is oversized");
2351
2352
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[7];
2353
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[7];
2354
2355
static const NativePropertiesN<2> sChromeOnlyNativeProperties = {
2356
  false, 0,
2357
  false, 0,
2358
  true,  0 /* sChromeMethods */,
2359
  true,  1 /* sChromeAttributes */,
2360
  false, 0,
2361
  false, 0,
2362
  false, 0,
2363
  -1,
2364
  7,
2365
  sChromeOnlyNativeProperties_sortedPropertyIndices,
2366
  {
2367
    { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] },
2368
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[4] }
2369
  }
2370
};
2371
static_assert(7 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
2372
    "We have a property info count that is oversized");
2373
2374
static bool
2375
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
2376
0
{
2377
0
  AUTO_PROFILER_LABEL_FAST("XMLHttpRequest constructor", DOM, cx);
2378
0
2379
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2380
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
2381
0
  if (!args.isConstructing()) {
2382
0
    // XXXbz wish I could get the name from the callee instead of
2383
0
    // Adding more relocations
2384
0
    return ThrowConstructorWithoutNew(cx, "XMLHttpRequest");
2385
0
  }
2386
0
2387
0
  JS::Rooted<JSObject*> desiredProto(cx);
2388
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
2389
0
    return false;
2390
0
  }
2391
0
2392
0
  unsigned argcount = std::min(args.length(), 1u);
2393
0
  switch (argcount) {
2394
0
    case 0: {
2395
0
      GlobalObject global(cx, obj);
2396
0
      if (global.Failed()) {
2397
0
        return false;
2398
0
      }
2399
0
2400
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2401
0
      binding_detail::FastMozXMLHttpRequestParameters arg0;
2402
0
      if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of XMLHttpRequest.constructor", false)) {
2403
0
        return false;
2404
0
      }
2405
0
      Maybe<JSAutoRealm> ar;
2406
0
      if (objIsXray) {
2407
0
        obj = js::CheckedUnwrap(obj);
2408
0
        if (!obj) {
2409
0
          return false;
2410
0
        }
2411
0
        ar.emplace(cx, obj);
2412
0
        if (!JS_WrapObject(cx, &desiredProto)) {
2413
0
          return false;
2414
0
        }
2415
0
      }
2416
0
      FastErrorResult rv;
2417
0
      auto result(StrongOrRawPtr<mozilla::dom::XMLHttpRequest>(mozilla::dom::XMLHttpRequest::Constructor(global, Constify(arg0), rv)));
2418
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2419
0
        return false;
2420
0
      }
2421
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2422
0
      static_assert(!IsPointer<decltype(result)>::value,
2423
0
                    "NewObject implies that we need to keep the object alive with a strong reference.");
2424
0
      if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
2425
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
2426
0
        return false;
2427
0
      }
2428
0
      return true;
2429
0
      break;
2430
0
    }
2431
0
    case 1: {
2432
0
      if (args[0].isNullOrUndefined()) {
2433
0
        binding_detail::FastMozXMLHttpRequestParameters arg0;
2434
0
        if (!arg0.Init(cx, args[0],  "Argument 1 of XMLHttpRequest", false)) {
2435
0
          return false;
2436
0
        }
2437
0
        GlobalObject global(cx, obj);
2438
0
        if (global.Failed()) {
2439
0
          return false;
2440
0
        }
2441
0
2442
0
        bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2443
0
        Maybe<JSAutoRealm> ar;
2444
0
        if (objIsXray) {
2445
0
          obj = js::CheckedUnwrap(obj);
2446
0
          if (!obj) {
2447
0
            return false;
2448
0
          }
2449
0
          ar.emplace(cx, obj);
2450
0
          if (!JS_WrapObject(cx, &desiredProto)) {
2451
0
            return false;
2452
0
          }
2453
0
        }
2454
0
        FastErrorResult rv;
2455
0
        auto result(StrongOrRawPtr<mozilla::dom::XMLHttpRequest>(mozilla::dom::XMLHttpRequest::Constructor(global, Constify(arg0), rv)));
2456
0
        if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2457
0
          return false;
2458
0
        }
2459
0
        MOZ_ASSERT(!JS_IsExceptionPending(cx));
2460
0
        static_assert(!IsPointer<decltype(result)>::value,
2461
0
                      "NewObject implies that we need to keep the object alive with a strong reference.");
2462
0
        if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
2463
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
2464
0
          return false;
2465
0
        }
2466
0
        return true;
2467
0
      }
2468
0
      if (args[0].isObject()) {
2469
0
        do {
2470
0
          binding_detail::FastMozXMLHttpRequestParameters arg0;
2471
0
          if (!arg0.Init(cx, args[0],  "Argument 1 of XMLHttpRequest", false)) {
2472
0
            return false;
2473
0
          }
2474
0
          GlobalObject global(cx, obj);
2475
0
          if (global.Failed()) {
2476
0
            return false;
2477
0
          }
2478
0
2479
0
          bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2480
0
          Maybe<JSAutoRealm> ar;
2481
0
          if (objIsXray) {
2482
0
            obj = js::CheckedUnwrap(obj);
2483
0
            if (!obj) {
2484
0
              return false;
2485
0
            }
2486
0
            ar.emplace(cx, obj);
2487
0
            if (!JS_WrapObject(cx, &desiredProto)) {
2488
0
              return false;
2489
0
            }
2490
0
          }
2491
0
          FastErrorResult rv;
2492
0
          auto result(StrongOrRawPtr<mozilla::dom::XMLHttpRequest>(mozilla::dom::XMLHttpRequest::Constructor(global, Constify(arg0), rv)));
2493
0
          if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2494
0
            return false;
2495
0
          }
2496
0
          MOZ_ASSERT(!JS_IsExceptionPending(cx));
2497
0
          static_assert(!IsPointer<decltype(result)>::value,
2498
0
                        "NewObject implies that we need to keep the object alive with a strong reference.");
2499
0
          if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
2500
0
            MOZ_ASSERT(JS_IsExceptionPending(cx));
2501
0
            return false;
2502
0
          }
2503
0
          return true;
2504
0
        } while (false);
2505
0
      }
2506
0
      GlobalObject global(cx, obj);
2507
0
      if (global.Failed()) {
2508
0
        return false;
2509
0
      }
2510
0
2511
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2512
0
      binding_detail::FakeString arg0;
2513
0
      if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2514
0
        return false;
2515
0
      }
2516
0
      Maybe<JSAutoRealm> ar;
2517
0
      if (objIsXray) {
2518
0
        obj = js::CheckedUnwrap(obj);
2519
0
        if (!obj) {
2520
0
          return false;
2521
0
        }
2522
0
        ar.emplace(cx, obj);
2523
0
        if (!JS_WrapObject(cx, &desiredProto)) {
2524
0
          return false;
2525
0
        }
2526
0
      }
2527
0
      FastErrorResult rv;
2528
0
      auto result(StrongOrRawPtr<mozilla::dom::XMLHttpRequest>(mozilla::dom::XMLHttpRequest::Constructor(global, NonNullHelper(Constify(arg0)), rv)));
2529
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2530
0
        return false;
2531
0
      }
2532
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2533
0
      static_assert(!IsPointer<decltype(result)>::value,
2534
0
                    "NewObject implies that we need to keep the object alive with a strong reference.");
2535
0
      if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
2536
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
2537
0
        return false;
2538
0
      }
2539
0
      return true;
2540
0
      break;
2541
0
    }
2542
0
    default: {
2543
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLHttpRequest");
2544
0
      break;
2545
0
    }
2546
0
  }
2547
0
  MOZ_CRASH("We have an always-returning default case");
2548
0
  return false;
2549
0
}
2550
2551
static const js::ClassOps sInterfaceObjectClassOps = {
2552
    nullptr,               /* addProperty */
2553
    nullptr,               /* delProperty */
2554
    nullptr,               /* enumerate */
2555
    nullptr,               /* newEnumerate */
2556
    nullptr,               /* resolve */
2557
    nullptr,               /* mayResolve */
2558
    nullptr,               /* finalize */
2559
    _constructor, /* call */
2560
    nullptr,               /* hasInstance */
2561
    _constructor, /* construct */
2562
    nullptr,               /* trace */
2563
};
2564
2565
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
2566
  {
2567
    "Function",
2568
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
2569
    &sInterfaceObjectClassOps,
2570
    JS_NULL_CLASS_SPEC,
2571
    JS_NULL_CLASS_EXT,
2572
    &sInterfaceObjectClassObjectOps
2573
  },
2574
  eInterface,
2575
  true,
2576
  prototypes::id::XMLHttpRequest,
2577
  PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth,
2578
  sNativePropertyHooks,
2579
  "function XMLHttpRequest() {\n    [native code]\n}",
2580
  XMLHttpRequestEventTarget_Binding::GetConstructorObject
2581
};
2582
2583
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
2584
  {
2585
    "XMLHttpRequestPrototype",
2586
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
2587
    JS_NULL_CLASS_OPS,
2588
    JS_NULL_CLASS_SPEC,
2589
    JS_NULL_CLASS_EXT,
2590
    JS_NULL_OBJECT_OPS
2591
  },
2592
  eInterfacePrototype,
2593
  false,
2594
  prototypes::id::XMLHttpRequest,
2595
  PrototypeTraits<prototypes::id::XMLHttpRequest>::Depth,
2596
  sNativePropertyHooks,
2597
  "[object XMLHttpRequestPrototype]",
2598
  XMLHttpRequestEventTarget_Binding::GetProtoObject
2599
};
2600
2601
bool
2602
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
2603
0
{
2604
0
  if (!NS_IsMainThread()) {
2605
0
    const char* name = js::GetObjectClass(aObj)->name;
2606
0
    if (strcmp(name, "DedicatedWorkerGlobalScope") && strcmp(name, "SharedWorkerGlobalScope")) {
2607
0
      return false;
2608
0
    }
2609
0
  }
2610
0
2611
0
  return true;
2612
0
}
2613
2614
static const js::ClassOps sClassOps = {
2615
  _addProperty, /* addProperty */
2616
  nullptr,               /* delProperty */
2617
  nullptr,               /* enumerate */
2618
  nullptr, /* newEnumerate */
2619
  nullptr, /* resolve */
2620
  nullptr, /* mayResolve */
2621
  _finalize, /* finalize */
2622
  nullptr, /* call */
2623
  nullptr,               /* hasInstance */
2624
  nullptr,               /* construct */
2625
  nullptr, /* trace */
2626
};
2627
2628
static const js::ClassExtension sClassExtension = {
2629
  nullptr, /* weakmapKeyDelegateOp */
2630
  _objectMoved /* objectMovedOp */
2631
};
2632
2633
static const DOMJSClass sClass = {
2634
  { "XMLHttpRequest",
2635
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2),
2636
    &sClassOps,
2637
    JS_NULL_CLASS_SPEC,
2638
    &sClassExtension,
2639
    JS_NULL_OBJECT_OPS
2640
  },
2641
  { prototypes::id::EventTarget, prototypes::id::XMLHttpRequestEventTarget, prototypes::id::XMLHttpRequest, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
2642
  IsBaseOf<nsISupports, mozilla::dom::XMLHttpRequest >::value,
2643
  sNativePropertyHooks,
2644
  FindAssociatedGlobalForNative<mozilla::dom::XMLHttpRequest>::Get,
2645
  GetProtoObjectHandle,
2646
  GetCCParticipant<mozilla::dom::XMLHttpRequest>::Get()
2647
};
2648
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
2649
              "Must have the right minimal number of reserved slots.");
2650
static_assert(2 >= 2,
2651
              "Must have enough reserved slots.");
2652
2653
const JSClass*
2654
GetJSClass()
2655
0
{
2656
0
  return sClass.ToJSClass();
2657
0
}
2658
2659
bool
2660
Wrap(JSContext* aCx, mozilla::dom::XMLHttpRequest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
2661
0
{
2662
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::XMLHttpRequest>::value,
2663
0
                "Shouldn't have wrappercached things that are not refcounted.");
2664
0
  MOZ_ASSERT(static_cast<mozilla::dom::XMLHttpRequest*>(aObject) ==
2665
0
             reinterpret_cast<mozilla::dom::XMLHttpRequest*>(aObject),
2666
0
             "Multiple inheritance for mozilla::dom::XMLHttpRequest is broken.");
2667
0
  MOZ_ASSERT(static_cast<mozilla::dom::XMLHttpRequestEventTarget*>(aObject) ==
2668
0
             reinterpret_cast<mozilla::dom::XMLHttpRequestEventTarget*>(aObject),
2669
0
             "Multiple inheritance for mozilla::dom::XMLHttpRequestEventTarget is broken.");
2670
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
2671
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
2672
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
2673
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
2674
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
2675
0
  MOZ_ASSERT(!aCache->GetWrapper(),
2676
0
             "You should probably not be using Wrap() directly; use "
2677
0
             "GetOrCreateDOMReflector instead");
2678
0
2679
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
2680
0
             "nsISupports must be on our primary inheritance chain");
2681
0
2682
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
2683
0
  if (!global) {
2684
0
    return false;
2685
0
  }
2686
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
2687
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
2688
0
2689
0
  // That might have ended up wrapping us already, due to the wonders
2690
0
  // of XBL.  Check for that, and bail out as needed.
2691
0
  aReflector.set(aCache->GetWrapper());
2692
0
  if (aReflector) {
2693
#ifdef DEBUG
2694
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
2695
#endif // DEBUG
2696
    return true;
2697
0
  }
2698
0
2699
0
  JSAutoRealm ar(aCx, global);
2700
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
2701
0
  if (!canonicalProto) {
2702
0
    return false;
2703
0
  }
2704
0
  JS::Rooted<JSObject*> proto(aCx);
2705
0
  if (aGivenProto) {
2706
0
    proto = aGivenProto;
2707
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
2708
0
    // coming in, we changed compartments to that of "parent" so may need
2709
0
    // to wrap the proto here.
2710
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
2711
0
      if (!JS_WrapObject(aCx, &proto)) {
2712
0
        return false;
2713
0
      }
2714
0
    }
2715
0
  } else {
2716
0
    proto = canonicalProto;
2717
0
  }
2718
0
2719
0
  BindingJSObjectCreator<mozilla::dom::XMLHttpRequest> creator(aCx);
2720
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
2721
0
  if (!aReflector) {
2722
0
    return false;
2723
0
  }
2724
0
2725
0
  aCache->SetWrapper(aReflector);
2726
0
  creator.InitializationSucceeded();
2727
0
2728
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
2729
0
             aCache->GetWrapperPreserveColor() == aReflector);
2730
0
  // If proto != canonicalProto, we have to preserve our wrapper;
2731
0
  // otherwise we won't be able to properly recreate it later, since
2732
0
  // we won't know what proto to use.  Note that we don't check
2733
0
  // aGivenProto here, since it's entirely possible (and even
2734
0
  // somewhat common) to have a non-null aGivenProto which is the
2735
0
  // same as canonicalProto.
2736
0
  if (proto != canonicalProto) {
2737
0
    PreserveWrapper(aObject);
2738
0
  }
2739
0
2740
0
  return true;
2741
0
}
2742
2743
// This may allocate too many slots, because we only really need
2744
// slots for our non-interface-typed members that we cache.  But
2745
// allocating slots only for those would make the slot index
2746
// computations much more complicated, so let's do this the simple
2747
// way for now.
2748
DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
2749
2750
const NativePropertyHooks sNativePropertyHooks[] = { {
2751
  nullptr,
2752
  nullptr,
2753
  nullptr,
2754
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
2755
  prototypes::id::XMLHttpRequest,
2756
  constructors::id::XMLHttpRequest,
2757
  XMLHttpRequestEventTarget_Binding::sNativePropertyHooks,
2758
  &sXrayExpandoObjectClass
2759
} };
2760
2761
void
2762
ClearCachedResponseTextValue(mozilla::dom::XMLHttpRequest* aObject)
2763
0
{
2764
0
  JSObject* obj;
2765
0
  obj = aObject->GetWrapper();
2766
0
  if (!obj) {
2767
0
    return;
2768
0
  }
2769
0
  js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue());
2770
0
  xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0));
2771
0
}
2772
2773
void
2774
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
2775
0
{
2776
0
  JS::Handle<JSObject*> parentProto(XMLHttpRequestEventTarget_Binding::GetProtoObjectHandle(aCx));
2777
0
  if (!parentProto) {
2778
0
    return;
2779
0
  }
2780
0
2781
0
  JS::Handle<JSObject*> constructorProto(XMLHttpRequestEventTarget_Binding::GetConstructorObjectHandle(aCx));
2782
0
  if (!constructorProto) {
2783
0
    return;
2784
0
  }
2785
0
2786
0
  static bool sIdsInited = false;
2787
0
  if (!sIdsInited && NS_IsMainThread()) {
2788
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
2789
0
      return;
2790
0
    }
2791
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
2792
0
      return;
2793
0
    }
2794
0
    sIdsInited = true;
2795
0
  }
2796
0
2797
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::XMLHttpRequest);
2798
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::XMLHttpRequest);
2799
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
2800
0
                              &sPrototypeClass.mBase, protoCache,
2801
0
                              nullptr,
2802
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
2803
0
                              interfaceCache,
2804
0
                              sNativeProperties.Upcast(),
2805
0
                              sChromeOnlyNativeProperties.Upcast(),
2806
0
                              "XMLHttpRequest", aDefineOnGlobal,
2807
0
                              nullptr,
2808
0
                              false);
2809
0
}
2810
2811
JSObject*
2812
GetConstructorObject(JSContext* aCx)
2813
0
{
2814
0
  return GetConstructorObjectHandle(aCx);
2815
0
}
2816
2817
} // namespace XMLHttpRequest_Binding
2818
2819
2820
2821
} // namespace dom
2822
} // namespace mozilla