Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/HeadersBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Headers.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "HeadersBinding.h"
4
#include "WrapperFactory.h"
5
#include "jsapi.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/Headers.h"
10
#include "mozilla/dom/IterableIterator.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/Nullable.h"
13
#include "mozilla/dom/PrimitiveConversions.h"
14
#include "mozilla/dom/ToJSValue.h"
15
#include "mozilla/dom/UnionConversions.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
#include "nsContentUtils.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace HeadersGuardEnumValues {
27
extern const EnumEntry strings[6] = {
28
  {"none", 4},
29
  {"request", 7},
30
  {"request-no-cors", 15},
31
  {"response", 8},
32
  {"immutable", 9},
33
  { nullptr, 0 }
34
};
35
} // namespace HeadersGuardEnumValues
36
37
bool
38
ToJSValue(JSContext* aCx, HeadersGuardEnum aArgument, JS::MutableHandle<JS::Value> aValue)
39
0
{
40
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(HeadersGuardEnumValues::strings));
41
0
  JSString* resultStr =
42
0
    JS_NewStringCopyN(aCx, HeadersGuardEnumValues::strings[uint32_t(aArgument)].value,
43
0
                      HeadersGuardEnumValues::strings[uint32_t(aArgument)].length);
44
0
  if (!resultStr) {
45
0
    return false;
46
0
  }
47
0
  aValue.setString(resultStr);
48
0
  return true;
49
0
}
50
51
52
void
53
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aUnion, const char* aName, uint32_t aFlags)
54
0
{
55
0
  if (aUnion.IsHeaders()) {
56
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsHeaders(), "mHeaders", aFlags);
57
0
  }
58
0
}
59
60
61
void
62
ImplCycleCollectionUnlink(OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aUnion)
63
0
{
64
0
  aUnion.Uninit();
65
0
}
66
67
68
bool
69
HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
70
0
{
71
0
  switch (mType) {
72
0
    case eUninitialized: {
73
0
      return false;
74
0
      break;
75
0
    }
76
0
    case eHeaders: {
77
0
      if (!GetOrCreateDOMReflector(cx, mValue.mHeaders.Value(), rval)) {
78
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
79
0
        return false;
80
0
      }
81
0
      return true;
82
0
      break;
83
0
    }
84
0
    case eByteStringSequenceSequence: {
85
0
86
0
      uint32_t length = mValue.mByteStringSequenceSequence.Value().Length();
87
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
88
0
      if (!returnArray) {
89
0
        return false;
90
0
      }
91
0
      // Scope for 'tmp'
92
0
      {
93
0
        JS::Rooted<JS::Value> tmp(cx);
94
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
95
0
          // Control block to let us common up the JS_DefineElement calls when there
96
0
          // are different ways to succeed at wrapping the object.
97
0
          do {
98
0
99
0
            uint32_t length = mValue.mByteStringSequenceSequence.Value()[sequenceIdx0].Length();
100
0
            JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
101
0
            if (!returnArray) {
102
0
              return false;
103
0
            }
104
0
            // Scope for 'tmp'
105
0
            {
106
0
              JS::Rooted<JS::Value> tmp(cx);
107
0
              for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
108
0
                // Control block to let us common up the JS_DefineElement calls when there
109
0
                // are different ways to succeed at wrapping the object.
110
0
                do {
111
0
                  if (!NonVoidByteStringToJsval(cx, mValue.mByteStringSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
112
0
                    return false;
113
0
                  }
114
0
                  break;
115
0
                } while (false);
116
0
                if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
117
0
                                      JSPROP_ENUMERATE)) {
118
0
                  return false;
119
0
                }
120
0
              }
121
0
            }
122
0
            tmp.setObject(*returnArray);
123
0
            break;
124
0
          } while (false);
125
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
126
0
                                JSPROP_ENUMERATE)) {
127
0
            return false;
128
0
          }
129
0
        }
130
0
      }
131
0
      rval.setObject(*returnArray);
132
0
      return true;
133
0
      break;
134
0
    }
135
0
    case eByteStringByteStringRecord: {
136
0
137
0
      JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
138
0
      if (!returnObj) {
139
0
        return false;
140
0
      }
141
0
      // Scope for 'tmp'
142
0
      {
143
0
        JS::Rooted<JS::Value> tmp(cx);
144
0
        for (auto& entry : mValue.mByteStringByteStringRecord.Value().Entries()) {
145
0
          auto& recordValue0 = entry.mValue;
146
0
          // Control block to let us common up the JS_DefineUCProperty calls when there
147
0
          // are different ways to succeed at wrapping the value.
148
0
          do {
149
0
            if (!NonVoidByteStringToJsval(cx, recordValue0, &tmp)) {
150
0
              return false;
151
0
            }
152
0
            break;
153
0
          } while (false);
154
0
          NS_ConvertASCIItoUTF16 expandedKey(entry.mKey);
155
0
          if (!JS_DefineUCProperty(cx, returnObj,
156
0
                                   expandedKey.BeginReading(),
157
0
                                   expandedKey.Length(), tmp,
158
0
                                   JSPROP_ENUMERATE)) {
159
0
            return false;
160
0
          }
161
0
        }
162
0
      }
163
0
      rval.setObject(*returnObj);
164
0
      return true;
165
0
      break;
166
0
    }
167
0
    default: {
168
0
      return false;
169
0
      break;
170
0
    }
171
0
  }
172
0
173
0
  return false;
174
0
}
175
176
177
OwningNonNull<mozilla::dom::Headers>&
178
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::RawSetAsHeaders()
179
0
{
180
0
  if (mType == eHeaders) {
181
0
    return mValue.mHeaders.Value();
182
0
  }
183
0
  MOZ_ASSERT(mType == eUninitialized);
184
0
  mType = eHeaders;
185
0
  return mValue.mHeaders.SetValue();
186
0
}
187
188
OwningNonNull<mozilla::dom::Headers>&
189
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::SetAsHeaders()
190
0
{
191
0
  if (mType == eHeaders) {
192
0
    return mValue.mHeaders.Value();
193
0
  }
194
0
  Uninit();
195
0
  mType = eHeaders;
196
0
  return mValue.mHeaders.SetValue();
197
0
}
198
199
bool
200
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::TrySetToHeaders(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
201
0
{
202
0
  tryNext = false;
203
0
  { // scope for memberSlot
204
0
    OwningNonNull<mozilla::dom::Headers>& memberSlot = RawSetAsHeaders();
205
0
    static_assert(IsRefcounted<mozilla::dom::Headers>::value, "We can only store refcounted classes.");{
206
0
      nsresult rv = UnwrapObject<prototypes::id::Headers, mozilla::dom::Headers>(value, memberSlot);
207
0
      if (NS_FAILED(rv)) {
208
0
        DestroyHeaders();
209
0
        tryNext = true;
210
0
        return true;
211
0
      }
212
0
    }
213
0
  }
214
0
  return true;
215
0
}
216
217
void
218
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::DestroyHeaders()
219
0
{
220
0
  MOZ_ASSERT(IsHeaders(), "Wrong type!");
221
0
  mValue.mHeaders.Destroy();
222
0
  mType = eUninitialized;
223
0
}
224
225
226
227
228
Sequence<Sequence<nsCString>>&
229
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::RawSetAsByteStringSequenceSequence()
230
0
{
231
0
  if (mType == eByteStringSequenceSequence) {
232
0
    return mValue.mByteStringSequenceSequence.Value();
233
0
  }
234
0
  MOZ_ASSERT(mType == eUninitialized);
235
0
  mType = eByteStringSequenceSequence;
236
0
  return mValue.mByteStringSequenceSequence.SetValue();
237
0
}
238
239
Sequence<Sequence<nsCString>>&
240
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::SetAsByteStringSequenceSequence()
241
0
{
242
0
  if (mType == eByteStringSequenceSequence) {
243
0
    return mValue.mByteStringSequenceSequence.Value();
244
0
  }
245
0
  Uninit();
246
0
  mType = eByteStringSequenceSequence;
247
0
  return mValue.mByteStringSequenceSequence.SetValue();
248
0
}
249
250
bool
251
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::TrySetToByteStringSequenceSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
252
0
{
253
0
  tryNext = false;
254
0
  { // scope for memberSlot
255
0
    Sequence<Sequence<nsCString>>& memberSlot = RawSetAsByteStringSequenceSequence();
256
0
    JS::ForOfIterator iter(cx);
257
0
    if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
258
0
      return false;
259
0
    }
260
0
    if (!iter.valueIsIterable()) {
261
0
      DestroyByteStringSequenceSequence();
262
0
      tryNext = true;
263
0
      return true;
264
0
    }
265
0
    Sequence<Sequence<nsCString>> &arr = memberSlot;
266
0
    JS::Rooted<JS::Value> temp(cx);
267
0
    while (true) {
268
0
      bool done;
269
0
      if (!iter.next(&temp, &done)) {
270
0
        return false;
271
0
      }
272
0
      if (done) {
273
0
        break;
274
0
      }
275
0
      Sequence<nsCString>* slotPtr = arr.AppendElement(mozilla::fallible);
276
0
      if (!slotPtr) {
277
0
        JS_ReportOutOfMemory(cx);
278
0
        return false;
279
0
      }
280
0
      Sequence<nsCString>& slot = *slotPtr;
281
0
      if (temp.isObject()) {
282
0
        JS::ForOfIterator iter1(cx);
283
0
        if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
284
0
          return false;
285
0
        }
286
0
        if (!iter1.valueIsIterable()) {
287
0
          ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord");
288
0
          return false;
289
0
        }
290
0
        Sequence<nsCString> &arr1 = slot;
291
0
        JS::Rooted<JS::Value> temp1(cx);
292
0
        while (true) {
293
0
          bool done1;
294
0
          if (!iter1.next(&temp1, &done1)) {
295
0
            return false;
296
0
          }
297
0
          if (done1) {
298
0
            break;
299
0
          }
300
0
          nsCString* slotPtr1 = arr1.AppendElement(mozilla::fallible);
301
0
          if (!slotPtr1) {
302
0
            JS_ReportOutOfMemory(cx);
303
0
            return false;
304
0
          }
305
0
          nsCString& slot1 = *slotPtr1;
306
0
          if (!ConvertJSValueToByteString(cx, temp1, false, slot1)) {
307
0
            return false;
308
0
          }
309
0
        }
310
0
      } else {
311
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord");
312
0
        return false;
313
0
      }
314
0
    }
315
0
  }
316
0
  return true;
317
0
}
318
319
void
320
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::DestroyByteStringSequenceSequence()
321
0
{
322
0
  MOZ_ASSERT(IsByteStringSequenceSequence(), "Wrong type!");
323
0
  mValue.mByteStringSequenceSequence.Destroy();
324
0
  mType = eUninitialized;
325
0
}
326
327
328
329
330
Record<nsCString, nsCString>&
331
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::RawSetAsByteStringByteStringRecord()
332
0
{
333
0
  if (mType == eByteStringByteStringRecord) {
334
0
    return mValue.mByteStringByteStringRecord.Value();
335
0
  }
336
0
  MOZ_ASSERT(mType == eUninitialized);
337
0
  mType = eByteStringByteStringRecord;
338
0
  return mValue.mByteStringByteStringRecord.SetValue();
339
0
}
340
341
Record<nsCString, nsCString>&
342
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::SetAsByteStringByteStringRecord()
343
0
{
344
0
  if (mType == eByteStringByteStringRecord) {
345
0
    return mValue.mByteStringByteStringRecord.Value();
346
0
  }
347
0
  Uninit();
348
0
  mType = eByteStringByteStringRecord;
349
0
  return mValue.mByteStringByteStringRecord.SetValue();
350
0
}
351
352
bool
353
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::TrySetToByteStringByteStringRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
354
0
{
355
0
  tryNext = false;
356
0
  { // scope for memberSlot
357
0
    Record<nsCString, nsCString>& memberSlot = RawSetAsByteStringByteStringRecord();
358
0
    auto& recordEntries = memberSlot.Entries();
359
0
360
0
    JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
361
0
    JS::AutoIdVector ids(cx);
362
0
    if (!js::GetPropertyKeys(cx, recordObj,
363
0
                             JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
364
0
      return false;
365
0
    }
366
0
    if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
367
0
      JS_ReportOutOfMemory(cx);
368
0
      return false;
369
0
    }
370
0
    JS::Rooted<JS::Value> propNameValue(cx);
371
0
    JS::Rooted<JS::Value> temp(cx);
372
0
    JS::Rooted<jsid> curId(cx);
373
0
    JS::Rooted<JS::Value> idVal(cx);
374
0
    // Use a hashset to keep track of ids seen, to avoid
375
0
    // introducing nasty O(N^2) behavior scanning for them all the
376
0
    // time.  Ideally we'd use a data structure with O(1) lookup
377
0
    // _and_ ordering for the MozMap, but we don't have one lying
378
0
    // around.
379
0
    nsTHashtable<nsCStringHashKey> idsSeen;
380
0
    for (size_t i = 0; i < ids.length(); ++i) {
381
0
      curId = ids[i];
382
0
383
0
      JS::Rooted<JS::PropertyDescriptor> desc(cx);
384
0
      if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
385
0
                                           &desc)) {
386
0
        return false;
387
0
      }
388
0
389
0
      if (!desc.object() /* == undefined in spec terms */ ||
390
0
          !desc.enumerable()) {
391
0
        continue;
392
0
      }
393
0
394
0
      idVal = js::IdToValue(curId);
395
0
      nsCString propName;
396
0
      // This will just throw if idVal is a Symbol, like the spec says
397
0
      // to do.
398
0
      if (!ConvertJSValueToByteString(cx, idVal, propName)) {
399
0
        return false;
400
0
      }
401
0
402
0
      if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
403
0
        return false;
404
0
      }
405
0
406
0
      Record<nsCString, nsCString>::EntryType* entry;
407
0
      if (!idsSeen.EnsureInserted(propName)) {
408
0
        // Find the existing entry.
409
0
        auto idx = recordEntries.IndexOf(propName);
410
0
        MOZ_ASSERT(idx != recordEntries.NoIndex,
411
0
                   "Why is it not found?");
412
0
        // Now blow it away to make it look like it was just added
413
0
        // to the array, because it's not obvious that it's
414
0
        // safe to write to its already-initialized mValue via our
415
0
        // normal codegen conversions.  For example, the value
416
0
        // could be a union and this would change its type, but
417
0
        // codegen assumes we won't do that.
418
0
        entry = recordEntries.ReconstructElementAt(idx);
419
0
      } else {
420
0
        // Safe to do an infallible append here, because we did a
421
0
        // SetCapacity above to the right capacity.
422
0
        entry = recordEntries.AppendElement();
423
0
      }
424
0
      entry->mKey = propName;
425
0
      nsCString& slot = entry->mValue;
426
0
      if (!ConvertJSValueToByteString(cx, temp, false, slot)) {
427
0
        return false;
428
0
      }
429
0
    }
430
0
  }
431
0
  return true;
432
0
}
433
434
void
435
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::DestroyByteStringByteStringRecord()
436
0
{
437
0
  MOZ_ASSERT(IsByteStringByteStringRecord(), "Wrong type!");
438
0
  mValue.mByteStringByteStringRecord.Destroy();
439
0
  mType = eUninitialized;
440
0
}
441
442
443
444
445
void
446
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::Uninit()
447
{
448
  switch (mType) {
449
    case eUninitialized: {
450
      break;
451
    }
452
    case eHeaders: {
453
      DestroyHeaders();
454
      break;
455
    }
456
    case eByteStringSequenceSequence: {
457
      DestroyByteStringSequenceSequence();
458
      break;
459
    }
460
    case eByteStringByteStringRecord: {
461
      DestroyByteStringByteStringRecord();
462
      break;
463
    }
464
  }
465
}
466
467
bool
468
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
469
0
{
470
0
  switch (mType) {
471
0
    case eUninitialized: {
472
0
      return false;
473
0
      break;
474
0
    }
475
0
    case eHeaders: {
476
0
      if (!GetOrCreateDOMReflector(cx, mValue.mHeaders.Value(), rval)) {
477
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
478
0
        return false;
479
0
      }
480
0
      return true;
481
0
      break;
482
0
    }
483
0
    case eByteStringSequenceSequence: {
484
0
485
0
      uint32_t length = mValue.mByteStringSequenceSequence.Value().Length();
486
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
487
0
      if (!returnArray) {
488
0
        return false;
489
0
      }
490
0
      // Scope for 'tmp'
491
0
      {
492
0
        JS::Rooted<JS::Value> tmp(cx);
493
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
494
0
          // Control block to let us common up the JS_DefineElement calls when there
495
0
          // are different ways to succeed at wrapping the object.
496
0
          do {
497
0
498
0
            uint32_t length = mValue.mByteStringSequenceSequence.Value()[sequenceIdx0].Length();
499
0
            JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
500
0
            if (!returnArray) {
501
0
              return false;
502
0
            }
503
0
            // Scope for 'tmp'
504
0
            {
505
0
              JS::Rooted<JS::Value> tmp(cx);
506
0
              for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
507
0
                // Control block to let us common up the JS_DefineElement calls when there
508
0
                // are different ways to succeed at wrapping the object.
509
0
                do {
510
0
                  if (!NonVoidByteStringToJsval(cx, mValue.mByteStringSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
511
0
                    return false;
512
0
                  }
513
0
                  break;
514
0
                } while (false);
515
0
                if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
516
0
                                      JSPROP_ENUMERATE)) {
517
0
                  return false;
518
0
                }
519
0
              }
520
0
            }
521
0
            tmp.setObject(*returnArray);
522
0
            break;
523
0
          } while (false);
524
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
525
0
                                JSPROP_ENUMERATE)) {
526
0
            return false;
527
0
          }
528
0
        }
529
0
      }
530
0
      rval.setObject(*returnArray);
531
0
      return true;
532
0
      break;
533
0
    }
534
0
    case eByteStringByteStringRecord: {
535
0
536
0
      JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
537
0
      if (!returnObj) {
538
0
        return false;
539
0
      }
540
0
      // Scope for 'tmp'
541
0
      {
542
0
        JS::Rooted<JS::Value> tmp(cx);
543
0
        for (auto& entry : mValue.mByteStringByteStringRecord.Value().Entries()) {
544
0
          auto& recordValue0 = entry.mValue;
545
0
          // Control block to let us common up the JS_DefineUCProperty calls when there
546
0
          // are different ways to succeed at wrapping the value.
547
0
          do {
548
0
            if (!NonVoidByteStringToJsval(cx, recordValue0, &tmp)) {
549
0
              return false;
550
0
            }
551
0
            break;
552
0
          } while (false);
553
0
          NS_ConvertASCIItoUTF16 expandedKey(entry.mKey);
554
0
          if (!JS_DefineUCProperty(cx, returnObj,
555
0
                                   expandedKey.BeginReading(),
556
0
                                   expandedKey.Length(), tmp,
557
0
                                   JSPROP_ENUMERATE)) {
558
0
            return false;
559
0
          }
560
0
        }
561
0
      }
562
0
      rval.setObject(*returnObj);
563
0
      return true;
564
0
      break;
565
0
    }
566
0
    default: {
567
0
      return false;
568
0
      break;
569
0
    }
570
0
  }
571
0
572
0
  return false;
573
0
}
574
575
void
576
OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord::TraceUnion(JSTracer* trc)
577
0
{
578
0
}
579
580
581
namespace Headers_Binding {
582
583
MOZ_CAN_RUN_SCRIPT static bool
584
append(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
585
0
{
586
0
  AUTO_PROFILER_LABEL_FAST("Headers.append", DOM, cx);
587
0
588
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
589
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Headers.append");
590
0
  }
591
0
  nsCString arg0;
592
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
593
0
    return false;
594
0
  }
595
0
  nsCString arg1;
596
0
  if (!ConvertJSValueToByteString(cx, args[1], false, arg1)) {
597
0
    return false;
598
0
  }
599
0
  FastErrorResult rv;
600
0
  self->Append(Constify(arg0), Constify(arg1), rv);
601
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
602
0
    return false;
603
0
  }
604
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
605
0
  args.rval().setUndefined();
606
0
  return true;
607
0
}
608
609
static const JSJitInfo append_methodinfo = {
610
  { (JSJitGetterOp)append },
611
  { prototypes::id::Headers },
612
  { PrototypeTraits<prototypes::id::Headers>::Depth },
613
  JSJitInfo::Method,
614
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
615
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
616
  false,  /* isInfallible. False in setters. */
617
  false,  /* isMovable.  Not relevant for setters. */
618
  false, /* isEliminatable.  Not relevant for setters. */
619
  false, /* isAlwaysInSlot.  Only relevant for getters. */
620
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
621
  false,  /* isTypedMethod.  Only relevant for methods. */
622
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
623
};
624
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
625
static_assert(0 < 1, "There is no slot for us");
626
627
MOZ_CAN_RUN_SCRIPT static bool
628
_delete_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
629
0
{
630
0
  AUTO_PROFILER_LABEL_FAST("Headers.delete", DOM, cx);
631
0
632
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
633
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Headers.delete");
634
0
  }
635
0
  nsCString arg0;
636
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
637
0
    return false;
638
0
  }
639
0
  FastErrorResult rv;
640
0
  self->Delete(Constify(arg0), rv);
641
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
642
0
    return false;
643
0
  }
644
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
645
0
  args.rval().setUndefined();
646
0
  return true;
647
0
}
648
649
static const JSJitInfo delete_methodinfo = {
650
  { (JSJitGetterOp)_delete_ },
651
  { prototypes::id::Headers },
652
  { PrototypeTraits<prototypes::id::Headers>::Depth },
653
  JSJitInfo::Method,
654
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
655
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
656
  false,  /* isInfallible. False in setters. */
657
  false,  /* isMovable.  Not relevant for setters. */
658
  false, /* isEliminatable.  Not relevant for setters. */
659
  false, /* isAlwaysInSlot.  Only relevant for getters. */
660
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
661
  false,  /* isTypedMethod.  Only relevant for methods. */
662
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
663
};
664
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
665
static_assert(0 < 1, "There is no slot for us");
666
667
MOZ_CAN_RUN_SCRIPT static bool
668
get(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
669
0
{
670
0
  AUTO_PROFILER_LABEL_FAST("Headers.get", DOM, cx);
671
0
672
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
673
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Headers.get");
674
0
  }
675
0
  nsCString arg0;
676
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
677
0
    return false;
678
0
  }
679
0
  FastErrorResult rv;
680
0
  nsCString result;
681
0
  self->Get(Constify(arg0), result, rv);
682
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
683
0
    return false;
684
0
  }
685
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
686
0
  if (!ByteStringToJsval(cx, result, args.rval())) {
687
0
    return false;
688
0
  }
689
0
  return true;
690
0
}
691
692
static const JSJitInfo get_methodinfo = {
693
  { (JSJitGetterOp)get },
694
  { prototypes::id::Headers },
695
  { PrototypeTraits<prototypes::id::Headers>::Depth },
696
  JSJitInfo::Method,
697
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
698
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
699
  false,  /* isInfallible. False in setters. */
700
  false,  /* isMovable.  Not relevant for setters. */
701
  false, /* isEliminatable.  Not relevant for setters. */
702
  false, /* isAlwaysInSlot.  Only relevant for getters. */
703
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
704
  false,  /* isTypedMethod.  Only relevant for methods. */
705
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
706
};
707
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
708
static_assert(0 < 1, "There is no slot for us");
709
710
MOZ_CAN_RUN_SCRIPT static bool
711
has(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
712
0
{
713
0
  AUTO_PROFILER_LABEL_FAST("Headers.has", DOM, cx);
714
0
715
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
716
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Headers.has");
717
0
  }
718
0
  nsCString arg0;
719
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
720
0
    return false;
721
0
  }
722
0
  FastErrorResult rv;
723
0
  bool result(self->Has(Constify(arg0), rv));
724
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
725
0
    return false;
726
0
  }
727
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
728
0
  args.rval().setBoolean(result);
729
0
  return true;
730
0
}
731
732
static const JSJitInfo has_methodinfo = {
733
  { (JSJitGetterOp)has },
734
  { prototypes::id::Headers },
735
  { PrototypeTraits<prototypes::id::Headers>::Depth },
736
  JSJitInfo::Method,
737
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
738
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
739
  false,  /* isInfallible. False in setters. */
740
  false,  /* isMovable.  Not relevant for setters. */
741
  false, /* isEliminatable.  Not relevant for setters. */
742
  false, /* isAlwaysInSlot.  Only relevant for getters. */
743
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
744
  false,  /* isTypedMethod.  Only relevant for methods. */
745
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
746
};
747
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
748
static_assert(0 < 1, "There is no slot for us");
749
750
MOZ_CAN_RUN_SCRIPT static bool
751
set(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
752
0
{
753
0
  AUTO_PROFILER_LABEL_FAST("Headers.set", DOM, cx);
754
0
755
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
756
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Headers.set");
757
0
  }
758
0
  nsCString arg0;
759
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
760
0
    return false;
761
0
  }
762
0
  nsCString arg1;
763
0
  if (!ConvertJSValueToByteString(cx, args[1], false, arg1)) {
764
0
    return false;
765
0
  }
766
0
  FastErrorResult rv;
767
0
  self->Set(Constify(arg0), Constify(arg1), rv);
768
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
769
0
    return false;
770
0
  }
771
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
772
0
  args.rval().setUndefined();
773
0
  return true;
774
0
}
775
776
static const JSJitInfo set_methodinfo = {
777
  { (JSJitGetterOp)set },
778
  { prototypes::id::Headers },
779
  { PrototypeTraits<prototypes::id::Headers>::Depth },
780
  JSJitInfo::Method,
781
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
782
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
783
  false,  /* isInfallible. False in setters. */
784
  false,  /* isMovable.  Not relevant for setters. */
785
  false, /* isEliminatable.  Not relevant for setters. */
786
  false, /* isAlwaysInSlot.  Only relevant for getters. */
787
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
788
  false,  /* isTypedMethod.  Only relevant for methods. */
789
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
790
};
791
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
792
static_assert(0 < 1, "There is no slot for us");
793
794
MOZ_CAN_RUN_SCRIPT static bool
795
get_guard(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, JSJitGetterCallArgs args)
796
0
{
797
0
  AUTO_PROFILER_LABEL_FAST("get Headers.guard", DOM, cx);
798
0
799
0
  HeadersGuardEnum result(self->Guard());
800
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
801
0
  if (!ToJSValue(cx, result, args.rval())) {
802
0
    return false;
803
0
  }
804
0
  return true;
805
0
}
806
807
MOZ_CAN_RUN_SCRIPT static bool
808
set_guard(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, JSJitSetterCallArgs args)
809
0
{
810
0
  AUTO_PROFILER_LABEL_FAST("set Headers.guard", DOM, cx);
811
0
812
0
  HeadersGuardEnum arg0;
813
0
  {
814
0
    int index;
815
0
    if (!FindEnumStringIndex<false>(cx, args[0], HeadersGuardEnumValues::strings, "HeadersGuardEnum", "Value being assigned to Headers.guard", &index)) {
816
0
      return false;
817
0
    }
818
0
    if (index < 0) {
819
0
      return true;
820
0
    }
821
0
    arg0 = static_cast<HeadersGuardEnum>(index);
822
0
  }
823
0
  FastErrorResult rv;
824
0
  self->SetGuard(arg0, rv);
825
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
826
0
    return false;
827
0
  }
828
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
829
0
830
0
  return true;
831
0
}
832
833
static const JSJitInfo guard_getterinfo = {
834
  { (JSJitGetterOp)get_guard },
835
  { prototypes::id::Headers },
836
  { PrototypeTraits<prototypes::id::Headers>::Depth },
837
  JSJitInfo::Getter,
838
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
839
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
840
  false,  /* isInfallible. False in setters. */
841
  false,  /* isMovable.  Not relevant for setters. */
842
  false, /* isEliminatable.  Not relevant for setters. */
843
  false, /* isAlwaysInSlot.  Only relevant for getters. */
844
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
845
  false,  /* isTypedMethod.  Only relevant for methods. */
846
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
847
};
848
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
849
static_assert(0 < 1, "There is no slot for us");
850
static const JSJitInfo guard_setterinfo = {
851
  { (JSJitGetterOp)set_guard },
852
  { prototypes::id::Headers },
853
  { PrototypeTraits<prototypes::id::Headers>::Depth },
854
  JSJitInfo::Setter,
855
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
856
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
857
  false,  /* isInfallible. False in setters. */
858
  false,  /* isMovable.  Not relevant for setters. */
859
  false, /* isEliminatable.  Not relevant for setters. */
860
  false, /* isAlwaysInSlot.  Only relevant for getters. */
861
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
862
  false,  /* isTypedMethod.  Only relevant for methods. */
863
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
864
};
865
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
866
static_assert(0 < 1, "There is no slot for us");
867
868
MOZ_CAN_RUN_SCRIPT static bool
869
entries(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
870
0
{
871
0
  AUTO_PROFILER_LABEL_FAST("Headers.entries", DOM, cx);
872
0
873
0
  typedef mozilla::dom::IterableIterator<mozilla::dom::Headers> itrType;
874
0
  RefPtr<itrType> result(new itrType(self,
875
0
                                       itrType::IterableIteratorType::Entries,
876
0
                                       &HeadersIterator_Binding::Wrap));
877
0
  static_assert(!IsPointer<decltype(result)>::value,
878
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
879
0
  if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval())) {
880
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
881
0
    return false;
882
0
  }
883
0
  return true;
884
0
}
885
886
static const JSJitInfo::ArgType entries_methodinfo_argTypes[] = { JSJitInfo::ArgTypeListEnd };
887
static const JSTypedMethodJitInfo entries_methodinfo = {
888
  {
889
    { (JSJitGetterOp)entries },
890
    { prototypes::id::Headers },
891
    { PrototypeTraits<prototypes::id::Headers>::Depth },
892
    JSJitInfo::Method,
893
    JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
894
    JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
895
    false,  /* isInfallible. False in setters. */
896
    false,  /* isMovable.  Not relevant for setters. */
897
    false, /* isEliminatable.  Not relevant for setters. */
898
    false, /* isAlwaysInSlot.  Only relevant for getters. */
899
    false, /* isLazilyCachedInSlot.  Only relevant for getters. */
900
    true,  /* isTypedMethod.  Only relevant for methods. */
901
    0   /* Reserved slot index, if we're stored in a slot, else 0. */
902
  },
903
  entries_methodinfo_argTypes
904
};
905
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
906
static_assert(0 < 1, "There is no slot for us");
907
908
MOZ_CAN_RUN_SCRIPT static bool
909
keys(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
910
0
{
911
0
  AUTO_PROFILER_LABEL_FAST("Headers.keys", DOM, cx);
912
0
913
0
  typedef mozilla::dom::IterableIterator<mozilla::dom::Headers> itrType;
914
0
  RefPtr<itrType> result(new itrType(self,
915
0
                                       itrType::IterableIteratorType::Keys,
916
0
                                       &HeadersIterator_Binding::Wrap));
917
0
  static_assert(!IsPointer<decltype(result)>::value,
918
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
919
0
  if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval())) {
920
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
921
0
    return false;
922
0
  }
923
0
  return true;
924
0
}
925
926
static const JSJitInfo::ArgType keys_methodinfo_argTypes[] = { JSJitInfo::ArgTypeListEnd };
927
static const JSTypedMethodJitInfo keys_methodinfo = {
928
  {
929
    { (JSJitGetterOp)keys },
930
    { prototypes::id::Headers },
931
    { PrototypeTraits<prototypes::id::Headers>::Depth },
932
    JSJitInfo::Method,
933
    JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
934
    JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
935
    false,  /* isInfallible. False in setters. */
936
    false,  /* isMovable.  Not relevant for setters. */
937
    false, /* isEliminatable.  Not relevant for setters. */
938
    false, /* isAlwaysInSlot.  Only relevant for getters. */
939
    false, /* isLazilyCachedInSlot.  Only relevant for getters. */
940
    true,  /* isTypedMethod.  Only relevant for methods. */
941
    0   /* Reserved slot index, if we're stored in a slot, else 0. */
942
  },
943
  keys_methodinfo_argTypes
944
};
945
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
946
static_assert(0 < 1, "There is no slot for us");
947
948
MOZ_CAN_RUN_SCRIPT static bool
949
values(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
950
0
{
951
0
  AUTO_PROFILER_LABEL_FAST("Headers.values", DOM, cx);
952
0
953
0
  typedef mozilla::dom::IterableIterator<mozilla::dom::Headers> itrType;
954
0
  RefPtr<itrType> result(new itrType(self,
955
0
                                       itrType::IterableIteratorType::Values,
956
0
                                       &HeadersIterator_Binding::Wrap));
957
0
  static_assert(!IsPointer<decltype(result)>::value,
958
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
959
0
  if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval())) {
960
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
961
0
    return false;
962
0
  }
963
0
  return true;
964
0
}
965
966
static const JSJitInfo::ArgType values_methodinfo_argTypes[] = { JSJitInfo::ArgTypeListEnd };
967
static const JSTypedMethodJitInfo values_methodinfo = {
968
  {
969
    { (JSJitGetterOp)values },
970
    { prototypes::id::Headers },
971
    { PrototypeTraits<prototypes::id::Headers>::Depth },
972
    JSJitInfo::Method,
973
    JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
974
    JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
975
    false,  /* isInfallible. False in setters. */
976
    false,  /* isMovable.  Not relevant for setters. */
977
    false, /* isEliminatable.  Not relevant for setters. */
978
    false, /* isAlwaysInSlot.  Only relevant for getters. */
979
    false, /* isLazilyCachedInSlot.  Only relevant for getters. */
980
    true,  /* isTypedMethod.  Only relevant for methods. */
981
    0   /* Reserved slot index, if we're stored in a slot, else 0. */
982
  },
983
  values_methodinfo_argTypes
984
};
985
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
986
static_assert(0 < 1, "There is no slot for us");
987
988
MOZ_CAN_RUN_SCRIPT static bool
989
forEach(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Headers* self, const JSJitMethodCallArgs& args)
990
0
{
991
0
  AUTO_PROFILER_LABEL_FAST("Headers.forEach", DOM, cx);
992
0
993
0
  JS::Rooted<JSObject*> arg0(cx);
994
0
  if (args.get(0).isObject()) {
995
0
    arg0 = &args.get(0).toObject();
996
0
  } else {
997
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Headers.forEach");
998
0
    return false;
999
0
  }
1000
0
  JS::Rooted<JS::Value> arg1(cx);
1001
0
  if (args.hasDefined(1)) {
1002
0
    arg1 = args.get(1);
1003
0
  } else {
1004
0
    arg1 = JS::UndefinedValue();
1005
0
  }
1006
0
  if (!JS::IsCallable(arg0)) {
1007
0
    ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of Headers.forEach");
1008
0
    return false;
1009
0
  }
1010
0
  JS::AutoValueArray<3> callArgs(cx);
1011
0
  callArgs[2].setObject(*obj);
1012
0
  JS::Rooted<JS::Value> ignoredReturnVal(cx);
1013
0
  auto GetKeyAtIndex = &mozilla::dom::Headers::GetKeyAtIndex;
1014
0
  auto GetValueAtIndex = &mozilla::dom::Headers::GetValueAtIndex;
1015
0
  for (size_t i = 0; i < self->GetIterableLength(); ++i) {
1016
0
    if (!CallIterableGetter(cx, GetValueAtIndex, self, i,
1017
0
                            callArgs[0])) {
1018
0
      return false;
1019
0
    }
1020
0
    if (!CallIterableGetter(cx, GetKeyAtIndex, self, i,
1021
0
                            callArgs[1])) {
1022
0
      return false;
1023
0
    }
1024
0
    if (!JS::Call(cx, arg1, arg0, JS::HandleValueArray(callArgs),
1025
0
                  &ignoredReturnVal)) {
1026
0
      return false;
1027
0
    }
1028
0
  }
1029
0
  args.rval().setUndefined();
1030
0
  return true;
1031
0
}
1032
1033
static const JSJitInfo forEach_methodinfo = {
1034
  { (JSJitGetterOp)forEach },
1035
  { prototypes::id::Headers },
1036
  { PrototypeTraits<prototypes::id::Headers>::Depth },
1037
  JSJitInfo::Method,
1038
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1039
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1040
  false,  /* isInfallible. False in setters. */
1041
  false,  /* isMovable.  Not relevant for setters. */
1042
  false, /* isEliminatable.  Not relevant for setters. */
1043
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1044
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1045
  false,  /* isTypedMethod.  Only relevant for methods. */
1046
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1047
};
1048
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1049
static_assert(0 < 1, "There is no slot for us");
1050
1051
static bool
1052
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1053
0
{
1054
0
  mozilla::dom::Headers* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Headers>(obj);
1055
0
  // We don't want to preserve if we don't have a wrapper, and we
1056
0
  // obviously can't preserve if we're not initialized.
1057
0
  if (self && self->GetWrapperPreserveColor()) {
1058
0
    PreserveWrapper(self);
1059
0
  }
1060
0
  return true;
1061
0
}
1062
1063
static void
1064
_finalize(js::FreeOp* fop, JSObject* obj)
1065
0
{
1066
0
  mozilla::dom::Headers* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Headers>(obj);
1067
0
  if (self) {
1068
0
    ClearWrapper(self, self, obj);
1069
0
    AddForDeferredFinalization<mozilla::dom::Headers>(self);
1070
0
  }
1071
0
}
1072
1073
static size_t
1074
_objectMoved(JSObject* obj, JSObject* old)
1075
0
{
1076
0
  mozilla::dom::Headers* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Headers>(obj);
1077
0
  if (self) {
1078
0
    UpdateWrapper(self, self, obj, old);
1079
0
  }
1080
0
1081
0
  return 0;
1082
0
}
1083
1084
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1085
#if defined(__clang__)
1086
#pragma clang diagnostic push
1087
#pragma clang diagnostic ignored "-Wmissing-braces"
1088
#endif
1089
static const JSFunctionSpec sMethods_specs[] = {
1090
  JS_FNSPEC("append", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&append_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
1091
  JS_FNSPEC("delete", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&delete_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1092
  JS_FNSPEC("get", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&get_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1093
  JS_FNSPEC("has", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&has_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1094
  JS_FNSPEC("set", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&set_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
1095
  JS_FNSPEC("entries", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&entries_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1096
  JS_FNSPEC("keys", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&keys_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1097
  JS_FNSPEC("values", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&values_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1098
  JS_FNSPEC("forEach", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&forEach_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1099
  JS_FS_END
1100
};
1101
#if defined(__clang__)
1102
#pragma clang diagnostic pop
1103
#endif
1104
1105
1106
static const Prefable<const JSFunctionSpec> sMethods[] = {
1107
  { nullptr, &sMethods_specs[0] },
1108
  { nullptr, nullptr }
1109
};
1110
1111
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1112
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1113
static_assert(9 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1114
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1115
1116
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1117
#if defined(__clang__)
1118
#pragma clang diagnostic push
1119
#pragma clang diagnostic ignored "-Wmissing-braces"
1120
#endif
1121
static const JSPropertySpec sChromeAttributes_specs[] = {
1122
  { "guard", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &guard_getterinfo, GenericSetter<NormalThisPolicy>, &guard_setterinfo },
1123
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1124
};
1125
#if defined(__clang__)
1126
#pragma clang diagnostic pop
1127
#endif
1128
1129
1130
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
1131
  { nullptr, &sChromeAttributes_specs[0] },
1132
  { nullptr, nullptr }
1133
};
1134
1135
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1136
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1137
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1138
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1139
1140
1141
static uint16_t sNativeProperties_sortedPropertyIndices[9];
1142
static PropertyInfo sNativeProperties_propertyInfos[9];
1143
1144
static const NativePropertiesN<1> sNativeProperties = {
1145
  false, 0,
1146
  false, 0,
1147
  true,  0 /* sMethods */,
1148
  false, 0,
1149
  false, 0,
1150
  false, 0,
1151
  false, 0,
1152
  5,
1153
  9,
1154
  sNativeProperties_sortedPropertyIndices,
1155
  {
1156
    { sMethods, &sNativeProperties_propertyInfos[0] }
1157
  }
1158
};
1159
static_assert(5 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.iteratorAliasMethodIndex) - 1),
1160
    "We have an iterator alias index that is oversized");
1161
static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1162
    "We have a property info count that is oversized");
1163
1164
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
1165
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
1166
1167
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
1168
  false, 0,
1169
  false, 0,
1170
  false, 0,
1171
  true,  0 /* sChromeAttributes */,
1172
  false, 0,
1173
  false, 0,
1174
  false, 0,
1175
  5,
1176
  1,
1177
  sChromeOnlyNativeProperties_sortedPropertyIndices,
1178
  {
1179
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
1180
  }
1181
};
1182
static_assert(5 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.iteratorAliasMethodIndex) - 1),
1183
    "We have an iterator alias index that is oversized");
1184
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1185
    "We have a property info count that is oversized");
1186
1187
static bool
1188
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1189
0
{
1190
0
  AUTO_PROFILER_LABEL_FAST("Headers constructor", DOM, cx);
1191
0
1192
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1193
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1194
0
  if (!args.isConstructing()) {
1195
0
    // XXXbz wish I could get the name from the callee instead of
1196
0
    // Adding more relocations
1197
0
    return ThrowConstructorWithoutNew(cx, "Headers");
1198
0
  }
1199
0
1200
0
  JS::Rooted<JSObject*> desiredProto(cx);
1201
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1202
0
    return false;
1203
0
  }
1204
0
1205
0
  GlobalObject global(cx, obj);
1206
0
  if (global.Failed()) {
1207
0
    return false;
1208
0
  }
1209
0
1210
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1211
0
  Optional<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord> arg0;
1212
0
  Maybe<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecordArgument> arg0_holder;
1213
0
  if (args.hasDefined(0)) {
1214
0
    arg0.Construct();
1215
0
    arg0_holder.emplace(arg0.Value());
1216
0
    {
1217
0
      bool done = false, failed = false, tryNext;
1218
0
      if (args[0].isObject()) {
1219
0
        done = (failed = !arg0_holder.ref().TrySetToHeaders(cx, args[0], tryNext, false)) || !tryNext;
1220
0
1221
0
        if (!done) {
1222
0
          done = (failed = !arg0_holder.ref().TrySetToByteStringSequenceSequence(cx, args[0], tryNext, false)) || !tryNext;
1223
0
        }
1224
0
        if (!done) {
1225
0
          done = (failed = !arg0_holder.ref().TrySetToByteStringByteStringRecord(cx, args[0], tryNext, false)) || !tryNext;
1226
0
        }
1227
0
      }
1228
0
      if (failed) {
1229
0
        return false;
1230
0
      }
1231
0
      if (!done) {
1232
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Headers.constructor", "Headers, ByteStringSequenceSequence, ByteStringByteStringRecord");
1233
0
        return false;
1234
0
      }
1235
0
    }
1236
0
  }
1237
0
  Maybe<JSAutoRealm> ar;
1238
0
  if (objIsXray) {
1239
0
    obj = js::CheckedUnwrap(obj);
1240
0
    if (!obj) {
1241
0
      return false;
1242
0
    }
1243
0
    ar.emplace(cx, obj);
1244
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1245
0
      return false;
1246
0
    }
1247
0
  }
1248
0
  FastErrorResult rv;
1249
0
  auto result(StrongOrRawPtr<mozilla::dom::Headers>(mozilla::dom::Headers::Constructor(global, Constify(arg0), rv)));
1250
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1251
0
    return false;
1252
0
  }
1253
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1254
0
  static_assert(!IsPointer<decltype(result)>::value,
1255
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1256
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1257
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1258
0
    return false;
1259
0
  }
1260
0
  return true;
1261
0
}
1262
1263
static const js::ClassOps sInterfaceObjectClassOps = {
1264
    nullptr,               /* addProperty */
1265
    nullptr,               /* delProperty */
1266
    nullptr,               /* enumerate */
1267
    nullptr,               /* newEnumerate */
1268
    nullptr,               /* resolve */
1269
    nullptr,               /* mayResolve */
1270
    nullptr,               /* finalize */
1271
    _constructor, /* call */
1272
    nullptr,               /* hasInstance */
1273
    _constructor, /* construct */
1274
    nullptr,               /* trace */
1275
};
1276
1277
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1278
  {
1279
    "Function",
1280
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1281
    &sInterfaceObjectClassOps,
1282
    JS_NULL_CLASS_SPEC,
1283
    JS_NULL_CLASS_EXT,
1284
    &sInterfaceObjectClassObjectOps
1285
  },
1286
  eInterface,
1287
  true,
1288
  prototypes::id::Headers,
1289
  PrototypeTraits<prototypes::id::Headers>::Depth,
1290
  sNativePropertyHooks,
1291
  "function Headers() {\n    [native code]\n}",
1292
  JS::GetRealmFunctionPrototype
1293
};
1294
1295
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1296
  {
1297
    "HeadersPrototype",
1298
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1299
    JS_NULL_CLASS_OPS,
1300
    JS_NULL_CLASS_SPEC,
1301
    JS_NULL_CLASS_EXT,
1302
    JS_NULL_OBJECT_OPS
1303
  },
1304
  eInterfacePrototype,
1305
  false,
1306
  prototypes::id::Headers,
1307
  PrototypeTraits<prototypes::id::Headers>::Depth,
1308
  sNativePropertyHooks,
1309
  "[object HeadersPrototype]",
1310
  JS::GetRealmObjectPrototype
1311
};
1312
1313
static const js::ClassOps sClassOps = {
1314
  _addProperty, /* addProperty */
1315
  nullptr,               /* delProperty */
1316
  nullptr,               /* enumerate */
1317
  nullptr, /* newEnumerate */
1318
  nullptr, /* resolve */
1319
  nullptr, /* mayResolve */
1320
  _finalize, /* finalize */
1321
  nullptr, /* call */
1322
  nullptr,               /* hasInstance */
1323
  nullptr,               /* construct */
1324
  nullptr, /* trace */
1325
};
1326
1327
static const js::ClassExtension sClassExtension = {
1328
  nullptr, /* weakmapKeyDelegateOp */
1329
  _objectMoved /* objectMovedOp */
1330
};
1331
1332
static const DOMJSClass sClass = {
1333
  { "Headers",
1334
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1335
    &sClassOps,
1336
    JS_NULL_CLASS_SPEC,
1337
    &sClassExtension,
1338
    JS_NULL_OBJECT_OPS
1339
  },
1340
  { prototypes::id::Headers, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1341
  IsBaseOf<nsISupports, mozilla::dom::Headers >::value,
1342
  sNativePropertyHooks,
1343
  FindAssociatedGlobalForNative<mozilla::dom::Headers>::Get,
1344
  GetProtoObjectHandle,
1345
  GetCCParticipant<mozilla::dom::Headers>::Get()
1346
};
1347
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1348
              "Must have the right minimal number of reserved slots.");
1349
static_assert(1 >= 1,
1350
              "Must have enough reserved slots.");
1351
1352
const JSClass*
1353
GetJSClass()
1354
0
{
1355
0
  return sClass.ToJSClass();
1356
0
}
1357
1358
bool
1359
Wrap(JSContext* aCx, mozilla::dom::Headers* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1360
0
{
1361
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Headers>::value,
1362
0
                "Shouldn't have wrappercached things that are not refcounted.");
1363
0
  MOZ_ASSERT(static_cast<mozilla::dom::Headers*>(aObject) ==
1364
0
             reinterpret_cast<mozilla::dom::Headers*>(aObject),
1365
0
             "Multiple inheritance for mozilla::dom::Headers is broken.");
1366
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1367
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1368
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1369
0
             "You should probably not be using Wrap() directly; use "
1370
0
             "GetOrCreateDOMReflector instead");
1371
0
1372
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1373
0
             "nsISupports must be on our primary inheritance chain");
1374
0
1375
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1376
0
  if (!global) {
1377
0
    return false;
1378
0
  }
1379
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1380
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1381
0
1382
0
  // That might have ended up wrapping us already, due to the wonders
1383
0
  // of XBL.  Check for that, and bail out as needed.
1384
0
  aReflector.set(aCache->GetWrapper());
1385
0
  if (aReflector) {
1386
#ifdef DEBUG
1387
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1388
#endif // DEBUG
1389
    return true;
1390
0
  }
1391
0
1392
0
  JSAutoRealm ar(aCx, global);
1393
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1394
0
  if (!canonicalProto) {
1395
0
    return false;
1396
0
  }
1397
0
  JS::Rooted<JSObject*> proto(aCx);
1398
0
  if (aGivenProto) {
1399
0
    proto = aGivenProto;
1400
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1401
0
    // coming in, we changed compartments to that of "parent" so may need
1402
0
    // to wrap the proto here.
1403
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1404
0
      if (!JS_WrapObject(aCx, &proto)) {
1405
0
        return false;
1406
0
      }
1407
0
    }
1408
0
  } else {
1409
0
    proto = canonicalProto;
1410
0
  }
1411
0
1412
0
  BindingJSObjectCreator<mozilla::dom::Headers> creator(aCx);
1413
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1414
0
  if (!aReflector) {
1415
0
    return false;
1416
0
  }
1417
0
1418
0
  aCache->SetWrapper(aReflector);
1419
0
  creator.InitializationSucceeded();
1420
0
1421
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1422
0
             aCache->GetWrapperPreserveColor() == aReflector);
1423
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1424
0
  // otherwise we won't be able to properly recreate it later, since
1425
0
  // we won't know what proto to use.  Note that we don't check
1426
0
  // aGivenProto here, since it's entirely possible (and even
1427
0
  // somewhat common) to have a non-null aGivenProto which is the
1428
0
  // same as canonicalProto.
1429
0
  if (proto != canonicalProto) {
1430
0
    PreserveWrapper(aObject);
1431
0
  }
1432
0
1433
0
  return true;
1434
0
}
1435
1436
const NativePropertyHooks sNativePropertyHooks[] = { {
1437
  nullptr,
1438
  nullptr,
1439
  nullptr,
1440
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1441
  prototypes::id::Headers,
1442
  constructors::id::Headers,
1443
  nullptr,
1444
  &DefaultXrayExpandoObjectClass
1445
} };
1446
1447
void
1448
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1449
0
{
1450
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1451
0
  if (!parentProto) {
1452
0
    return;
1453
0
  }
1454
0
1455
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1456
0
  if (!constructorProto) {
1457
0
    return;
1458
0
  }
1459
0
1460
0
  static bool sIdsInited = false;
1461
0
  if (!sIdsInited && NS_IsMainThread()) {
1462
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1463
0
      return;
1464
0
    }
1465
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1466
0
      return;
1467
0
    }
1468
0
    sIdsInited = true;
1469
0
  }
1470
0
1471
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Headers);
1472
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Headers);
1473
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1474
0
                              &sPrototypeClass.mBase, protoCache,
1475
0
                              nullptr,
1476
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1477
0
                              interfaceCache,
1478
0
                              sNativeProperties.Upcast(),
1479
0
                              sChromeOnlyNativeProperties.Upcast(),
1480
0
                              "Headers", aDefineOnGlobal,
1481
0
                              nullptr,
1482
0
                              false);
1483
0
1484
0
  // Set up aliases on the interface prototype object we just created.
1485
0
  JS::Handle<JSObject*> proto = GetProtoObjectHandle(aCx);
1486
0
  if (!proto) {
1487
0
    *protoCache = nullptr;
1488
0
    if (interfaceCache) {
1489
0
      *interfaceCache = nullptr;
1490
0
    }
1491
0
    return;
1492
0
  }
1493
0
1494
0
  JS::Rooted<JS::Value> aliasedVal(aCx);
1495
0
1496
0
  if (!JS_GetProperty(aCx, proto, "entries", &aliasedVal)) {
1497
0
    *protoCache = nullptr;
1498
0
    if (interfaceCache) {
1499
0
      *interfaceCache = nullptr;
1500
0
    }
1501
0
    return;
1502
0
  }
1503
0
  JS::Rooted<jsid> iteratorId(aCx, SYMBOL_TO_JSID(JS::GetWellKnownSymbol(aCx, JS::SymbolCode::iterator)));
1504
0
  if (!JS_DefinePropertyById(aCx, proto, iteratorId, aliasedVal, 0)) {
1505
0
    *protoCache = nullptr;
1506
0
    if (interfaceCache) {
1507
0
      *interfaceCache = nullptr;
1508
0
    }
1509
0
    return;
1510
0
  }
1511
0
}
1512
1513
JSObject*
1514
GetConstructorObject(JSContext* aCx)
1515
0
{
1516
0
  return GetConstructorObjectHandle(aCx);
1517
0
}
1518
1519
} // namespace Headers_Binding
1520
1521
1522
1523
namespace HeadersIterator_Binding {
1524
1525
MOZ_CAN_RUN_SCRIPT static bool
1526
next(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IterableIterator<mozilla::dom::Headers>* self, const JSJitMethodCallArgs& args)
1527
0
{
1528
0
  AUTO_PROFILER_LABEL_FAST("HeadersIterator.next", DOM, cx);
1529
0
1530
0
  FastErrorResult rv;
1531
0
  JS::Rooted<JSObject*> result(cx);
1532
0
  self->Next(cx, &result, rv);
1533
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1534
0
    return false;
1535
0
  }
1536
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1537
0
  JS::ExposeObjectToActiveJS(result);
1538
0
  args.rval().setObject(*result);
1539
0
  if (!MaybeWrapObjectValue(cx, args.rval())) {
1540
0
    return false;
1541
0
  }
1542
0
  return true;
1543
0
}
1544
1545
static const JSJitInfo next_methodinfo = {
1546
  { (JSJitGetterOp)next },
1547
  { prototypes::id::HeadersIterator },
1548
  { PrototypeTraits<prototypes::id::HeadersIterator>::Depth },
1549
  JSJitInfo::Method,
1550
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1551
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1552
  false,  /* isInfallible. False in setters. */
1553
  false,  /* isMovable.  Not relevant for setters. */
1554
  false, /* isEliminatable.  Not relevant for setters. */
1555
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1556
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1557
  false,  /* isTypedMethod.  Only relevant for methods. */
1558
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1559
};
1560
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1561
static_assert(0 < 1, "There is no slot for us");
1562
1563
static void
1564
_finalize(js::FreeOp* fop, JSObject* obj)
1565
0
{
1566
0
  mozilla::dom::IterableIterator<mozilla::dom::Headers>* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IterableIterator<mozilla::dom::Headers>>(obj);
1567
0
  if (self) {
1568
0
    AddForDeferredFinalization<mozilla::dom::IterableIterator<mozilla::dom::Headers>>(self);
1569
0
  }
1570
0
}
1571
1572
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1573
#if defined(__clang__)
1574
#pragma clang diagnostic push
1575
#pragma clang diagnostic ignored "-Wmissing-braces"
1576
#endif
1577
static const JSFunctionSpec sMethods_specs[] = {
1578
  JS_FNSPEC("next", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&next_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1579
  JS_FS_END
1580
};
1581
#if defined(__clang__)
1582
#pragma clang diagnostic pop
1583
#endif
1584
1585
1586
static const Prefable<const JSFunctionSpec> sMethods[] = {
1587
  { nullptr, &sMethods_specs[0] },
1588
  { nullptr, nullptr }
1589
};
1590
1591
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1592
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1593
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1594
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1595
1596
1597
static uint16_t sNativeProperties_sortedPropertyIndices[1];
1598
static PropertyInfo sNativeProperties_propertyInfos[1];
1599
1600
static const NativePropertiesN<1> sNativeProperties = {
1601
  false, 0,
1602
  false, 0,
1603
  true,  0 /* sMethods */,
1604
  false, 0,
1605
  false, 0,
1606
  false, 0,
1607
  false, 0,
1608
  -1,
1609
  1,
1610
  sNativeProperties_sortedPropertyIndices,
1611
  {
1612
    { sMethods, &sNativeProperties_propertyInfos[0] }
1613
  }
1614
};
1615
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1616
    "We have a property info count that is oversized");
1617
1618
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1619
  {
1620
    "Headers IteratorPrototype",
1621
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1622
    JS_NULL_CLASS_OPS,
1623
    JS_NULL_CLASS_SPEC,
1624
    JS_NULL_CLASS_EXT,
1625
    JS_NULL_OBJECT_OPS
1626
  },
1627
  eInterfacePrototype,
1628
  false,
1629
  prototypes::id::HeadersIterator,
1630
  PrototypeTraits<prototypes::id::HeadersIterator>::Depth,
1631
  sNativePropertyHooks,
1632
  "[object Headers IteratorPrototype]",
1633
  JS::GetRealmIteratorPrototype
1634
};
1635
1636
static const js::ClassOps sClassOps = {
1637
  nullptr, /* addProperty */
1638
  nullptr,               /* delProperty */
1639
  nullptr,               /* enumerate */
1640
  nullptr, /* newEnumerate */
1641
  nullptr, /* resolve */
1642
  nullptr, /* mayResolve */
1643
  _finalize, /* finalize */
1644
  nullptr, /* call */
1645
  nullptr,               /* hasInstance */
1646
  nullptr,               /* construct */
1647
  nullptr, /* trace */
1648
};
1649
1650
static const js::ClassExtension sClassExtension = {
1651
  nullptr, /* weakmapKeyDelegateOp */
1652
  nullptr /* objectMovedOp */
1653
};
1654
1655
static const DOMJSClass sClass = {
1656
  { "Headers Iterator",
1657
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1658
    &sClassOps,
1659
    JS_NULL_CLASS_SPEC,
1660
    &sClassExtension,
1661
    JS_NULL_OBJECT_OPS
1662
  },
1663
  { prototypes::id::HeadersIterator, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1664
  IsBaseOf<nsISupports, mozilla::dom::IterableIterator<mozilla::dom::Headers> >::value,
1665
  sNativePropertyHooks,
1666
  FindAssociatedGlobalForNative<mozilla::dom::IterableIterator<mozilla::dom::Headers>>::Get,
1667
  GetProtoObjectHandle,
1668
  GetCCParticipant<mozilla::dom::IterableIterator<mozilla::dom::Headers>>::Get()
1669
};
1670
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1671
              "Must have the right minimal number of reserved slots.");
1672
static_assert(1 >= 1,
1673
              "Must have enough reserved slots.");
1674
1675
const JSClass*
1676
GetJSClass()
1677
0
{
1678
0
  return sClass.ToJSClass();
1679
0
}
1680
1681
bool
1682
Wrap(JSContext* aCx, mozilla::dom::IterableIterator<mozilla::dom::Headers>* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1683
0
{
1684
0
  MOZ_ASSERT(static_cast<mozilla::dom::IterableIterator<mozilla::dom::Headers>*>(aObject) ==
1685
0
             reinterpret_cast<mozilla::dom::IterableIterator<mozilla::dom::Headers>*>(aObject),
1686
0
             "Multiple inheritance for mozilla::dom::IterableIterator<mozilla::dom::Headers> is broken.");
1687
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1688
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1689
0
1690
0
  JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
1691
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1692
0
  if (!canonicalProto) {
1693
0
    return false;
1694
0
  }
1695
0
  JS::Rooted<JSObject*> proto(aCx);
1696
0
  if (aGivenProto) {
1697
0
    proto = aGivenProto;
1698
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1699
0
    // coming in, we changed compartments to that of "parent" so may need
1700
0
    // to wrap the proto here.
1701
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1702
0
      if (!JS_WrapObject(aCx, &proto)) {
1703
0
        return false;
1704
0
      }
1705
0
    }
1706
0
  } else {
1707
0
    proto = canonicalProto;
1708
0
  }
1709
0
1710
0
  BindingJSObjectCreator<mozilla::dom::IterableIterator<mozilla::dom::Headers>> creator(aCx);
1711
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1712
0
  if (!aReflector) {
1713
0
    return false;
1714
0
  }
1715
0
1716
0
1717
0
1718
0
  creator.InitializationSucceeded();
1719
0
  return true;
1720
0
}
1721
1722
const NativePropertyHooks sNativePropertyHooks[] = { {
1723
  nullptr,
1724
  nullptr,
1725
  nullptr,
1726
  { sNativeProperties.Upcast(), nullptr },
1727
  prototypes::id::HeadersIterator,
1728
  constructors::id::_ID_Count,
1729
  nullptr,
1730
  &DefaultXrayExpandoObjectClass
1731
} };
1732
1733
void
1734
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1735
0
{
1736
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmIteratorPrototype(aCx));
1737
0
  if (!parentProto) {
1738
0
    return;
1739
0
  }
1740
0
1741
0
  static bool sIdsInited = false;
1742
0
  if (!sIdsInited && NS_IsMainThread()) {
1743
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1744
0
      return;
1745
0
    }
1746
0
    sIdsInited = true;
1747
0
  }
1748
0
1749
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HeadersIterator);
1750
0
  JS::Heap<JSObject*>* interfaceCache = nullptr;
1751
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1752
0
                              &sPrototypeClass.mBase, protoCache,
1753
0
                              "Headers Iterator",
1754
0
                              nullptr, nullptr, 0, nullptr,
1755
0
                              interfaceCache,
1756
0
                              sNativeProperties.Upcast(),
1757
0
                              nullptr,
1758
0
                              nullptr, aDefineOnGlobal,
1759
0
                              nullptr,
1760
0
                              false);
1761
0
}
1762
1763
} // namespace HeadersIterator_Binding
1764
1765
1766
1767
} // namespace dom
1768
} // namespace mozilla