Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/BlobBinding.h
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Blob.webidl BY Codegen.py - DO NOT EDIT */
2
3
#ifndef mozilla_dom_BlobBinding_h
4
#define mozilla_dom_BlobBinding_h
5
6
#include "GeckoProfiler.h"
7
#include "js/RootingAPI.h"
8
#include "jsfriendapi.h"
9
#include "jspubtd.h"
10
#include "mozilla/ErrorResult.h"
11
#include "mozilla/dom/BindingDeclarations.h"
12
#include "mozilla/dom/FakeString.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/PrototypeList.h"
15
#include "mozilla/dom/TypedArray.h"
16
#include "mozilla/dom/UnionMember.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
class Blob;
22
struct BlobAtoms;
23
struct BlobPropertyBagAtoms;
24
struct NativePropertyHooks;
25
class OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString;
26
class ProtoAndIfaceCache;
27
28
} // namespace dom
29
} // namespace mozilla
30
31
namespace mozilla {
32
namespace dom {
33
34
enum class EndingTypes : uint8_t {
35
  Transparent,
36
  Native,
37
  EndGuard_
38
};
39
40
namespace EndingTypesValues {
41
extern const EnumEntry strings[3];
42
} // namespace EndingTypesValues
43
44
bool
45
ToJSValue(JSContext* aCx, EndingTypes aArgument, JS::MutableHandle<JS::Value> aValue);
46
47
48
void
49
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString& aUnion, const char* aName, uint32_t aFlags = 0);
50
51
52
void
53
ImplCycleCollectionUnlink(OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString& aUnion);
54
55
56
class ArrayBufferViewOrArrayBufferOrBlobOrUSVString
57
{
58
  friend class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringArgument;
59
  enum Type
60
  {
61
    eUninitialized,
62
    eArrayBufferView,
63
    eArrayBuffer,
64
    eBlob,
65
    eUSVString
66
  };
67
68
  union Value
69
  {
70
    UnionMember<RootedSpiderMonkeyInterface<ArrayBufferView> > mArrayBufferView;
71
    UnionMember<RootedSpiderMonkeyInterface<ArrayBuffer> > mArrayBuffer;
72
    UnionMember<NonNull<mozilla::dom::Blob> > mBlob;
73
    UnionMember<binding_detail::FakeString > mUSVString;
74
75
  };
76
77
  Type mType;
78
  Value mValue;
79
80
  ArrayBufferViewOrArrayBufferOrBlobOrUSVString(const ArrayBufferViewOrArrayBufferOrBlobOrUSVString&) = delete;
81
  ArrayBufferViewOrArrayBufferOrBlobOrUSVString& operator=(const ArrayBufferViewOrArrayBufferOrBlobOrUSVString&) = delete;
82
public:
83
  explicit inline ArrayBufferViewOrArrayBufferOrBlobOrUSVString()
84
    : mType(eUninitialized)
85
0
  {
86
0
  }
87
88
  inline ~ArrayBufferViewOrArrayBufferOrBlobOrUSVString()
89
0
  {
90
0
    Uninit();
91
0
  }
92
93
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
94
  RawSetAsArrayBufferView(JSContext* cx)
95
0
  {
96
0
    if (mType == eArrayBufferView) {
97
0
      return mValue.mArrayBufferView.Value();
98
0
    }
99
0
    MOZ_ASSERT(mType == eUninitialized);
100
0
    mType = eArrayBufferView;
101
0
    return mValue.mArrayBufferView.SetValue(cx);
102
0
  }
103
104
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
105
  SetAsArrayBufferView(JSContext* cx)
106
0
  {
107
0
    if (mType == eArrayBufferView) {
108
0
      return mValue.mArrayBufferView.Value();
109
0
    }
110
0
    Uninit();
111
0
    mType = eArrayBufferView;
112
0
    return mValue.mArrayBufferView.SetValue(cx);
113
0
  }
114
115
  inline bool
116
  IsArrayBufferView() const
117
0
  {
118
0
    return mType == eArrayBufferView;
119
0
  }
120
121
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
122
  GetAsArrayBufferView()
123
0
  {
124
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
125
0
    return mValue.mArrayBufferView.Value();
126
0
  }
127
128
  inline ArrayBufferView const &
129
  GetAsArrayBufferView() const
130
0
  {
131
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
132
0
    return mValue.mArrayBufferView.Value();
133
0
  }
134
135
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
136
  RawSetAsArrayBuffer(JSContext* cx)
137
0
  {
138
0
    if (mType == eArrayBuffer) {
139
0
      return mValue.mArrayBuffer.Value();
140
0
    }
141
0
    MOZ_ASSERT(mType == eUninitialized);
142
0
    mType = eArrayBuffer;
143
0
    return mValue.mArrayBuffer.SetValue(cx);
144
0
  }
145
146
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
147
  SetAsArrayBuffer(JSContext* cx)
148
0
  {
149
0
    if (mType == eArrayBuffer) {
150
0
      return mValue.mArrayBuffer.Value();
151
0
    }
152
0
    Uninit();
153
0
    mType = eArrayBuffer;
154
0
    return mValue.mArrayBuffer.SetValue(cx);
155
0
  }
156
157
  inline bool
158
  IsArrayBuffer() const
159
0
  {
160
0
    return mType == eArrayBuffer;
161
0
  }
162
163
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
164
  GetAsArrayBuffer()
165
0
  {
166
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
167
0
    return mValue.mArrayBuffer.Value();
168
0
  }
169
170
  inline ArrayBuffer const &
171
  GetAsArrayBuffer() const
172
0
  {
173
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
174
0
    return mValue.mArrayBuffer.Value();
175
0
  }
176
177
  inline NonNull<mozilla::dom::Blob>&
178
  RawSetAsBlob()
179
0
  {
180
0
    if (mType == eBlob) {
181
0
      return mValue.mBlob.Value();
182
0
    }
183
0
    MOZ_ASSERT(mType == eUninitialized);
184
0
    mType = eBlob;
185
0
    return mValue.mBlob.SetValue();
186
0
  }
187
188
  inline NonNull<mozilla::dom::Blob>&
189
  SetAsBlob()
190
0
  {
191
0
    if (mType == eBlob) {
192
0
      return mValue.mBlob.Value();
193
0
    }
194
0
    Uninit();
195
0
    mType = eBlob;
196
0
    return mValue.mBlob.SetValue();
197
0
  }
198
199
  inline bool
200
  IsBlob() const
201
0
  {
202
0
    return mType == eBlob;
203
0
  }
204
205
  inline NonNull<mozilla::dom::Blob>&
206
  GetAsBlob()
207
0
  {
208
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
209
0
    return mValue.mBlob.Value();
210
0
  }
211
212
  inline mozilla::dom::Blob&
213
  GetAsBlob() const
214
0
  {
215
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
216
0
    return mValue.mBlob.Value();
217
0
  }
218
219
  inline binding_detail::FakeString&
220
  RawSetAsUSVString()
221
0
  {
222
0
    if (mType == eUSVString) {
223
0
      return mValue.mUSVString.Value();
224
0
    }
225
0
    MOZ_ASSERT(mType == eUninitialized);
226
0
    mType = eUSVString;
227
0
    return mValue.mUSVString.SetValue();
228
0
  }
229
230
  inline binding_detail::FakeString&
231
  SetAsUSVString()
232
0
  {
233
0
    if (mType == eUSVString) {
234
0
      return mValue.mUSVString.Value();
235
0
    }
236
0
    Uninit();
237
0
    mType = eUSVString;
238
0
    return mValue.mUSVString.SetValue();
239
0
  }
240
241
  inline bool
242
  IsUSVString() const
243
0
  {
244
0
    return mType == eUSVString;
245
0
  }
246
247
  inline binding_detail::FakeString&
248
  GetAsUSVString()
249
0
  {
250
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
251
0
    return mValue.mUSVString.Value();
252
0
  }
253
254
  inline const nsAString&
255
  GetAsUSVString() const
256
0
  {
257
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
258
0
    return mValue.mUSVString.Value();
259
0
  }
260
261
  inline void
262
  Uninit()
263
0
  {
264
0
    switch (mType) {
265
0
      case eUninitialized: {
266
0
        break;
267
0
      }
268
0
      case eArrayBufferView: {
269
0
        DestroyArrayBufferView();
270
0
        break;
271
0
      }
272
0
      case eArrayBuffer: {
273
0
        DestroyArrayBuffer();
274
0
        break;
275
0
      }
276
0
      case eBlob: {
277
0
        DestroyBlob();
278
0
        break;
279
0
      }
280
0
      case eUSVString: {
281
0
        DestroyUSVString();
282
0
        break;
283
0
      }
284
0
    }
285
0
  }
286
287
  bool
288
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
289
290
private:
291
  inline void
292
  DestroyArrayBufferView()
293
0
  {
294
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
295
0
    mValue.mArrayBufferView.Destroy();
296
0
    mType = eUninitialized;
297
0
  }
298
299
  inline void
300
  DestroyArrayBuffer()
301
0
  {
302
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
303
0
    mValue.mArrayBuffer.Destroy();
304
0
    mType = eUninitialized;
305
0
  }
306
307
  inline void
308
  DestroyBlob()
309
0
  {
310
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
311
0
    mValue.mBlob.Destroy();
312
0
    mType = eUninitialized;
313
0
  }
314
315
  inline void
316
  DestroyUSVString()
317
0
  {
318
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
319
0
    mValue.mUSVString.Destroy();
320
0
    mType = eUninitialized;
321
0
  }
322
};
323
324
325
class OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString : public AllOwningUnionBase
326
{
327
  friend void ImplCycleCollectionUnlink(OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString& aUnion);
328
  enum Type
329
  {
330
    eUninitialized,
331
    eArrayBufferView,
332
    eArrayBuffer,
333
    eBlob,
334
    eUSVString
335
  };
336
337
  union Value
338
  {
339
    UnionMember<ArrayBufferView > mArrayBufferView;
340
    UnionMember<ArrayBuffer > mArrayBuffer;
341
    UnionMember<OwningNonNull<mozilla::dom::Blob> > mBlob;
342
    UnionMember<nsString > mUSVString;
343
344
  };
345
346
  Type mType;
347
  Value mValue;
348
349
  OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString(const OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString&) = delete;
350
  OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString& operator=(const OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString&) = delete;
351
public:
352
  explicit inline OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString()
353
    : mType(eUninitialized)
354
0
  {
355
0
  }
356
357
  inline ~OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString()
358
0
  {
359
0
    Uninit();
360
0
  }
361
362
  ArrayBufferView&
363
  RawSetAsArrayBufferView();
364
365
  ArrayBufferView&
366
  SetAsArrayBufferView();
367
368
  bool
369
  TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
370
371
  inline bool
372
  IsArrayBufferView() const
373
0
  {
374
0
    return mType == eArrayBufferView;
375
0
  }
376
377
  inline ArrayBufferView&
378
  GetAsArrayBufferView()
379
0
  {
380
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
381
0
    return mValue.mArrayBufferView.Value();
382
0
  }
383
384
  inline ArrayBufferView const &
385
  GetAsArrayBufferView() const
386
0
  {
387
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
388
0
    return mValue.mArrayBufferView.Value();
389
0
  }
390
391
  ArrayBuffer&
392
  RawSetAsArrayBuffer();
393
394
  ArrayBuffer&
395
  SetAsArrayBuffer();
396
397
  bool
398
  TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
399
400
  inline bool
401
  IsArrayBuffer() const
402
0
  {
403
0
    return mType == eArrayBuffer;
404
0
  }
405
406
  inline ArrayBuffer&
407
  GetAsArrayBuffer()
408
0
  {
409
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
410
0
    return mValue.mArrayBuffer.Value();
411
0
  }
412
413
  inline ArrayBuffer const &
414
  GetAsArrayBuffer() const
415
0
  {
416
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
417
0
    return mValue.mArrayBuffer.Value();
418
0
  }
419
420
  OwningNonNull<mozilla::dom::Blob>&
421
  RawSetAsBlob();
422
423
  OwningNonNull<mozilla::dom::Blob>&
424
  SetAsBlob();
425
426
  bool
427
  TrySetToBlob(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
428
429
  inline bool
430
  IsBlob() const
431
0
  {
432
0
    return mType == eBlob;
433
0
  }
434
435
  inline OwningNonNull<mozilla::dom::Blob>&
436
  GetAsBlob()
437
0
  {
438
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
439
0
    return mValue.mBlob.Value();
440
0
  }
441
442
  inline OwningNonNull<mozilla::dom::Blob> const &
443
  GetAsBlob() const
444
0
  {
445
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
446
0
    return mValue.mBlob.Value();
447
0
  }
448
449
  nsString&
450
  RawSetAsUSVString();
451
452
  nsString&
453
  SetAsUSVString();
454
455
  bool
456
  TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
457
458
  inline void
459
  SetStringData(const nsString::char_type* aData, nsString::size_type aLength)
460
0
  {
461
0
    RawSetAsUSVString().Assign(aData, aLength);
462
0
  }
463
464
  inline bool
465
  IsUSVString() const
466
0
  {
467
0
    return mType == eUSVString;
468
0
  }
469
470
  inline nsString&
471
  GetAsUSVString()
472
0
  {
473
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
474
0
    return mValue.mUSVString.Value();
475
0
  }
476
477
  inline nsString const &
478
  GetAsUSVString() const
479
0
  {
480
0
    MOZ_ASSERT(IsUSVString(), "Wrong type!");
481
0
    return mValue.mUSVString.Value();
482
0
  }
483
484
  void
485
  Uninit();
486
487
  bool
488
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
489
490
  void
491
  TraceUnion(JSTracer* trc);
492
493
private:
494
  void
495
  DestroyArrayBufferView();
496
497
  void
498
  DestroyArrayBuffer();
499
500
  void
501
  DestroyBlob();
502
503
  void
504
  DestroyUSVString();
505
};
506
507
508
struct BlobPropertyBag : public DictionaryBase
509
{
510
  MOZ_INIT_OUTSIDE_CTOR EndingTypes mEndings;
511
  MOZ_INIT_OUTSIDE_CTOR nsString mType;
512
513
  BlobPropertyBag();
514
515
  explicit inline BlobPropertyBag(const FastDictionaryInitializer& )
516
0
  {
517
0
    // Do nothing here; this is used by our "Fast" subclass
518
0
  }
519
520
  explicit inline BlobPropertyBag(const BlobPropertyBag& aOther)
521
0
  {
522
0
    *this = aOther;
523
0
  }
524
525
  bool
526
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
527
528
  bool
529
  Init(const nsAString& aJSON);
530
531
  bool
532
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
533
534
  bool
535
  ToJSON(nsAString& aJSON) const;
536
537
  void
538
  TraceDictionary(JSTracer* trc);
539
540
  BlobPropertyBag&
541
  operator=(const BlobPropertyBag& aOther);
542
543
private:
544
  static bool
545
  InitIds(JSContext* cx, BlobPropertyBagAtoms* atomsCache);
546
};
547
548
namespace binding_detail {
549
struct FastBlobPropertyBag : public BlobPropertyBag
550
{
551
  inline FastBlobPropertyBag()
552
    : BlobPropertyBag(FastDictionaryInitializer())
553
0
  {
554
0
    // Doesn't matter what int we pass to the parent constructor
555
0
  }
556
};
557
} // namespace binding_detail
558
559
560
namespace Blob_Binding {
561
562
  typedef mozilla::dom::Blob NativeType;
563
564
  const JSClass*
565
  GetJSClass();
566
567
  bool
568
  Wrap(JSContext* aCx, mozilla::dom::Blob* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
569
570
  template <class T>
571
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
572
0
  {
573
0
    JS::Rooted<JSObject*> reflector(aCx);
574
0
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
575
0
  }
576
577
  // We declare this as an array so that retrieving a pointer to this
578
  // binding's property hooks only requires compile/link-time resolvable
579
  // address arithmetic.  Declaring it as a pointer instead would require
580
  // doing a run-time load to fetch a pointer to this binding's property
581
  // hooks.  And then structures which embedded a pointer to this structure
582
  // would require a run-time load for proper initialization, which would
583
  // then induce static constructors.  Lots of static constructors.
584
  extern const NativePropertyHooks sNativePropertyHooks[];
585
586
  void
587
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
588
589
  inline JS::Handle<JSObject*> GetProtoObjectHandle(JSContext* aCx)
590
0
  {
591
0
    /* Get the interface prototype object for this class.  This will create the
592
0
       object as needed. */
593
0
    return GetPerInterfaceObjectHandle(aCx, prototypes::id::Blob,
594
0
                                       &CreateInterfaceObjects,
595
0
                                       /* aDefineOnGlobal = */ true);
596
0
597
0
  }
598
599
  JSObject*
600
  GetProtoObject(JSContext* aCx);
601
602
  inline JS::Handle<JSObject*> GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true)
603
0
  {
604
0
    /* Get the interface object for this class.  This will create the object as
605
0
       needed. */
606
0
607
0
    return GetPerInterfaceObjectHandle(aCx, constructors::id::Blob,
608
0
                                       &CreateInterfaceObjects,
609
0
                                       aDefineOnGlobal);
610
0
  }
611
612
  JSObject*
613
  GetConstructorObject(JSContext* aCx);
614
615
} // namespace Blob_Binding
616
617
618
619
} // namespace dom
620
} // namespace mozilla
621
622
#endif // mozilla_dom_BlobBinding_h