Coverage Report

Created: 2018-09-25 14:53

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