Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/ImageBitmapBinding.h
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ImageBitmap.webidl BY Codegen.py - DO NOT EDIT */
2
3
#ifndef mozilla_dom_ImageBitmapBinding_h
4
#define mozilla_dom_ImageBitmapBinding_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
class CanvasRenderingContext2D;
23
struct ChannelPixelLayoutAtoms;
24
class HTMLCanvasElement;
25
class HTMLImageElement;
26
class HTMLVideoElement;
27
class ImageBitmap;
28
struct ImageBitmapAtoms;
29
class ImageData;
30
struct NativePropertyHooks;
31
class OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer;
32
class ProtoAndIfaceCache;
33
34
} // namespace dom
35
} // namespace mozilla
36
37
namespace mozilla {
38
namespace dom {
39
40
enum class ImageBitmapFormat : uint8_t {
41
  RGBA32,
42
  BGRA32,
43
  RGB24,
44
  BGR24,
45
  GRAY8,
46
  YUV444P,
47
  YUV422P,
48
  YUV420P,
49
  YUV420SP_NV12,
50
  YUV420SP_NV21,
51
  HSV,
52
  Lab,
53
  DEPTH,
54
  EndGuard_
55
};
56
57
namespace ImageBitmapFormatValues {
58
extern const EnumEntry strings[14];
59
} // namespace ImageBitmapFormatValues
60
61
bool
62
ToJSValue(JSContext* aCx, ImageBitmapFormat aArgument, JS::MutableHandle<JS::Value> aValue);
63
64
65
enum class ChannelPixelLayoutDataType : uint8_t {
66
  Uint8,
67
  Int8,
68
  Uint16,
69
  Int16,
70
  Uint32,
71
  Int32,
72
  Float32,
73
  Float64,
74
  EndGuard_
75
};
76
77
namespace ChannelPixelLayoutDataTypeValues {
78
extern const EnumEntry strings[9];
79
} // namespace ChannelPixelLayoutDataTypeValues
80
81
bool
82
ToJSValue(JSContext* aCx, ChannelPixelLayoutDataType aArgument, JS::MutableHandle<JS::Value> aValue);
83
84
85
void
86
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& aUnion, const char* aName, uint32_t aFlags = 0);
87
88
89
void
90
ImplCycleCollectionUnlink(OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& aUnion);
91
92
93
struct ChannelPixelLayout : public DictionaryBase
94
{
95
  MOZ_INIT_OUTSIDE_CTOR ChannelPixelLayoutDataType mDataType;
96
  MOZ_INIT_OUTSIDE_CTOR uint32_t mHeight;
97
  MOZ_INIT_OUTSIDE_CTOR uint32_t mOffset;
98
  MOZ_INIT_OUTSIDE_CTOR uint32_t mSkip;
99
  MOZ_INIT_OUTSIDE_CTOR uint32_t mStride;
100
  MOZ_INIT_OUTSIDE_CTOR uint32_t mWidth;
101
102
  ChannelPixelLayout();
103
104
  explicit inline ChannelPixelLayout(const FastDictionaryInitializer& )
105
0
  {
106
0
    // Do nothing here; this is used by our "Fast" subclass
107
0
  }
108
109
  explicit inline ChannelPixelLayout(const ChannelPixelLayout& aOther)
110
0
  {
111
0
    *this = aOther;
112
0
  }
113
114
  bool
115
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
116
117
  bool
118
  Init(const nsAString& aJSON);
119
120
  bool
121
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
122
123
  bool
124
  ToJSON(nsAString& aJSON) const;
125
126
  void
127
  TraceDictionary(JSTracer* trc);
128
129
  ChannelPixelLayout&
130
  operator=(const ChannelPixelLayout& aOther);
131
132
private:
133
  static bool
134
  InitIds(JSContext* cx, ChannelPixelLayoutAtoms* atomsCache);
135
};
136
137
namespace binding_detail {
138
struct FastChannelPixelLayout : public ChannelPixelLayout
139
{
140
  inline FastChannelPixelLayout()
141
    : ChannelPixelLayout(FastDictionaryInitializer())
142
0
  {
143
0
    // Doesn't matter what int we pass to the parent constructor
144
0
  }
145
};
146
} // namespace binding_detail
147
148
149
class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer
150
{
151
  friend class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument;
152
  enum Type
153
  {
154
    eUninitialized,
155
    eHTMLImageElement,
156
    eHTMLVideoElement,
157
    eHTMLCanvasElement,
158
    eBlob,
159
    eImageData,
160
    eCanvasRenderingContext2D,
161
    eImageBitmap,
162
    eArrayBufferView,
163
    eArrayBuffer
164
  };
165
166
  union Value
167
  {
168
    UnionMember<NonNull<mozilla::dom::HTMLImageElement> > mHTMLImageElement;
169
    UnionMember<NonNull<mozilla::dom::HTMLVideoElement> > mHTMLVideoElement;
170
    UnionMember<NonNull<mozilla::dom::HTMLCanvasElement> > mHTMLCanvasElement;
171
    UnionMember<NonNull<mozilla::dom::Blob> > mBlob;
172
    UnionMember<NonNull<mozilla::dom::ImageData> > mImageData;
173
    UnionMember<NonNull<mozilla::dom::CanvasRenderingContext2D> > mCanvasRenderingContext2D;
174
    UnionMember<NonNull<mozilla::dom::ImageBitmap> > mImageBitmap;
175
    UnionMember<RootedSpiderMonkeyInterface<ArrayBufferView> > mArrayBufferView;
176
    UnionMember<RootedSpiderMonkeyInterface<ArrayBuffer> > mArrayBuffer;
177
178
  };
179
180
  Type mType;
181
  Value mValue;
182
183
  HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer(const HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer&) = delete;
184
  HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& operator=(const HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer&) = delete;
185
public:
186
  explicit inline HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer()
187
    : mType(eUninitialized)
188
0
  {
189
0
  }
190
191
  inline ~HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer()
192
0
  {
193
0
    Uninit();
194
0
  }
195
196
  inline NonNull<mozilla::dom::HTMLImageElement>&
197
  RawSetAsHTMLImageElement()
198
0
  {
199
0
    if (mType == eHTMLImageElement) {
200
0
      return mValue.mHTMLImageElement.Value();
201
0
    }
202
0
    MOZ_ASSERT(mType == eUninitialized);
203
0
    mType = eHTMLImageElement;
204
0
    return mValue.mHTMLImageElement.SetValue();
205
0
  }
206
207
  inline NonNull<mozilla::dom::HTMLImageElement>&
208
  SetAsHTMLImageElement()
209
0
  {
210
0
    if (mType == eHTMLImageElement) {
211
0
      return mValue.mHTMLImageElement.Value();
212
0
    }
213
0
    Uninit();
214
0
    mType = eHTMLImageElement;
215
0
    return mValue.mHTMLImageElement.SetValue();
216
0
  }
217
218
  inline bool
219
  IsHTMLImageElement() const
220
0
  {
221
0
    return mType == eHTMLImageElement;
222
0
  }
223
224
  inline NonNull<mozilla::dom::HTMLImageElement>&
225
  GetAsHTMLImageElement()
226
0
  {
227
0
    MOZ_ASSERT(IsHTMLImageElement(), "Wrong type!");
228
0
    return mValue.mHTMLImageElement.Value();
229
0
  }
230
231
  inline mozilla::dom::HTMLImageElement&
232
  GetAsHTMLImageElement() const
233
0
  {
234
0
    MOZ_ASSERT(IsHTMLImageElement(), "Wrong type!");
235
0
    return mValue.mHTMLImageElement.Value();
236
0
  }
237
238
  inline NonNull<mozilla::dom::HTMLVideoElement>&
239
  RawSetAsHTMLVideoElement()
240
0
  {
241
0
    if (mType == eHTMLVideoElement) {
242
0
      return mValue.mHTMLVideoElement.Value();
243
0
    }
244
0
    MOZ_ASSERT(mType == eUninitialized);
245
0
    mType = eHTMLVideoElement;
246
0
    return mValue.mHTMLVideoElement.SetValue();
247
0
  }
248
249
  inline NonNull<mozilla::dom::HTMLVideoElement>&
250
  SetAsHTMLVideoElement()
251
0
  {
252
0
    if (mType == eHTMLVideoElement) {
253
0
      return mValue.mHTMLVideoElement.Value();
254
0
    }
255
0
    Uninit();
256
0
    mType = eHTMLVideoElement;
257
0
    return mValue.mHTMLVideoElement.SetValue();
258
0
  }
259
260
  inline bool
261
  IsHTMLVideoElement() const
262
0
  {
263
0
    return mType == eHTMLVideoElement;
264
0
  }
265
266
  inline NonNull<mozilla::dom::HTMLVideoElement>&
267
  GetAsHTMLVideoElement()
268
0
  {
269
0
    MOZ_ASSERT(IsHTMLVideoElement(), "Wrong type!");
270
0
    return mValue.mHTMLVideoElement.Value();
271
0
  }
272
273
  inline mozilla::dom::HTMLVideoElement&
274
  GetAsHTMLVideoElement() const
275
0
  {
276
0
    MOZ_ASSERT(IsHTMLVideoElement(), "Wrong type!");
277
0
    return mValue.mHTMLVideoElement.Value();
278
0
  }
279
280
  inline NonNull<mozilla::dom::HTMLCanvasElement>&
281
  RawSetAsHTMLCanvasElement()
282
0
  {
283
0
    if (mType == eHTMLCanvasElement) {
284
0
      return mValue.mHTMLCanvasElement.Value();
285
0
    }
286
0
    MOZ_ASSERT(mType == eUninitialized);
287
0
    mType = eHTMLCanvasElement;
288
0
    return mValue.mHTMLCanvasElement.SetValue();
289
0
  }
290
291
  inline NonNull<mozilla::dom::HTMLCanvasElement>&
292
  SetAsHTMLCanvasElement()
293
0
  {
294
0
    if (mType == eHTMLCanvasElement) {
295
0
      return mValue.mHTMLCanvasElement.Value();
296
0
    }
297
0
    Uninit();
298
0
    mType = eHTMLCanvasElement;
299
0
    return mValue.mHTMLCanvasElement.SetValue();
300
0
  }
301
302
  inline bool
303
  IsHTMLCanvasElement() const
304
0
  {
305
0
    return mType == eHTMLCanvasElement;
306
0
  }
307
308
  inline NonNull<mozilla::dom::HTMLCanvasElement>&
309
  GetAsHTMLCanvasElement()
310
0
  {
311
0
    MOZ_ASSERT(IsHTMLCanvasElement(), "Wrong type!");
312
0
    return mValue.mHTMLCanvasElement.Value();
313
0
  }
314
315
  inline mozilla::dom::HTMLCanvasElement&
316
  GetAsHTMLCanvasElement() const
317
0
  {
318
0
    MOZ_ASSERT(IsHTMLCanvasElement(), "Wrong type!");
319
0
    return mValue.mHTMLCanvasElement.Value();
320
0
  }
321
322
  inline NonNull<mozilla::dom::Blob>&
323
  RawSetAsBlob()
324
0
  {
325
0
    if (mType == eBlob) {
326
0
      return mValue.mBlob.Value();
327
0
    }
328
0
    MOZ_ASSERT(mType == eUninitialized);
329
0
    mType = eBlob;
330
0
    return mValue.mBlob.SetValue();
331
0
  }
332
333
  inline NonNull<mozilla::dom::Blob>&
334
  SetAsBlob()
335
0
  {
336
0
    if (mType == eBlob) {
337
0
      return mValue.mBlob.Value();
338
0
    }
339
0
    Uninit();
340
0
    mType = eBlob;
341
0
    return mValue.mBlob.SetValue();
342
0
  }
343
344
  inline bool
345
  IsBlob() const
346
0
  {
347
0
    return mType == eBlob;
348
0
  }
349
350
  inline NonNull<mozilla::dom::Blob>&
351
  GetAsBlob()
352
0
  {
353
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
354
0
    return mValue.mBlob.Value();
355
0
  }
356
357
  inline mozilla::dom::Blob&
358
  GetAsBlob() const
359
0
  {
360
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
361
0
    return mValue.mBlob.Value();
362
0
  }
363
364
  inline NonNull<mozilla::dom::ImageData>&
365
  RawSetAsImageData()
366
0
  {
367
0
    if (mType == eImageData) {
368
0
      return mValue.mImageData.Value();
369
0
    }
370
0
    MOZ_ASSERT(mType == eUninitialized);
371
0
    mType = eImageData;
372
0
    return mValue.mImageData.SetValue();
373
0
  }
374
375
  inline NonNull<mozilla::dom::ImageData>&
376
  SetAsImageData()
377
0
  {
378
0
    if (mType == eImageData) {
379
0
      return mValue.mImageData.Value();
380
0
    }
381
0
    Uninit();
382
0
    mType = eImageData;
383
0
    return mValue.mImageData.SetValue();
384
0
  }
385
386
  inline bool
387
  IsImageData() const
388
0
  {
389
0
    return mType == eImageData;
390
0
  }
391
392
  inline NonNull<mozilla::dom::ImageData>&
393
  GetAsImageData()
394
0
  {
395
0
    MOZ_ASSERT(IsImageData(), "Wrong type!");
396
0
    return mValue.mImageData.Value();
397
0
  }
398
399
  inline mozilla::dom::ImageData&
400
  GetAsImageData() const
401
0
  {
402
0
    MOZ_ASSERT(IsImageData(), "Wrong type!");
403
0
    return mValue.mImageData.Value();
404
0
  }
405
406
  inline NonNull<mozilla::dom::CanvasRenderingContext2D>&
407
  RawSetAsCanvasRenderingContext2D()
408
0
  {
409
0
    if (mType == eCanvasRenderingContext2D) {
410
0
      return mValue.mCanvasRenderingContext2D.Value();
411
0
    }
412
0
    MOZ_ASSERT(mType == eUninitialized);
413
0
    mType = eCanvasRenderingContext2D;
414
0
    return mValue.mCanvasRenderingContext2D.SetValue();
415
0
  }
416
417
  inline NonNull<mozilla::dom::CanvasRenderingContext2D>&
418
  SetAsCanvasRenderingContext2D()
419
0
  {
420
0
    if (mType == eCanvasRenderingContext2D) {
421
0
      return mValue.mCanvasRenderingContext2D.Value();
422
0
    }
423
0
    Uninit();
424
0
    mType = eCanvasRenderingContext2D;
425
0
    return mValue.mCanvasRenderingContext2D.SetValue();
426
0
  }
427
428
  inline bool
429
  IsCanvasRenderingContext2D() const
430
0
  {
431
0
    return mType == eCanvasRenderingContext2D;
432
0
  }
433
434
  inline NonNull<mozilla::dom::CanvasRenderingContext2D>&
435
  GetAsCanvasRenderingContext2D()
436
0
  {
437
0
    MOZ_ASSERT(IsCanvasRenderingContext2D(), "Wrong type!");
438
0
    return mValue.mCanvasRenderingContext2D.Value();
439
0
  }
440
441
  inline mozilla::dom::CanvasRenderingContext2D&
442
  GetAsCanvasRenderingContext2D() const
443
0
  {
444
0
    MOZ_ASSERT(IsCanvasRenderingContext2D(), "Wrong type!");
445
0
    return mValue.mCanvasRenderingContext2D.Value();
446
0
  }
447
448
  inline NonNull<mozilla::dom::ImageBitmap>&
449
  RawSetAsImageBitmap()
450
0
  {
451
0
    if (mType == eImageBitmap) {
452
0
      return mValue.mImageBitmap.Value();
453
0
    }
454
0
    MOZ_ASSERT(mType == eUninitialized);
455
0
    mType = eImageBitmap;
456
0
    return mValue.mImageBitmap.SetValue();
457
0
  }
458
459
  inline NonNull<mozilla::dom::ImageBitmap>&
460
  SetAsImageBitmap()
461
0
  {
462
0
    if (mType == eImageBitmap) {
463
0
      return mValue.mImageBitmap.Value();
464
0
    }
465
0
    Uninit();
466
0
    mType = eImageBitmap;
467
0
    return mValue.mImageBitmap.SetValue();
468
0
  }
469
470
  inline bool
471
  IsImageBitmap() const
472
0
  {
473
0
    return mType == eImageBitmap;
474
0
  }
475
476
  inline NonNull<mozilla::dom::ImageBitmap>&
477
  GetAsImageBitmap()
478
0
  {
479
0
    MOZ_ASSERT(IsImageBitmap(), "Wrong type!");
480
0
    return mValue.mImageBitmap.Value();
481
0
  }
482
483
  inline mozilla::dom::ImageBitmap&
484
  GetAsImageBitmap() const
485
0
  {
486
0
    MOZ_ASSERT(IsImageBitmap(), "Wrong type!");
487
0
    return mValue.mImageBitmap.Value();
488
0
  }
489
490
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
491
  RawSetAsArrayBufferView(JSContext* cx)
492
0
  {
493
0
    if (mType == eArrayBufferView) {
494
0
      return mValue.mArrayBufferView.Value();
495
0
    }
496
0
    MOZ_ASSERT(mType == eUninitialized);
497
0
    mType = eArrayBufferView;
498
0
    return mValue.mArrayBufferView.SetValue(cx);
499
0
  }
500
501
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
502
  SetAsArrayBufferView(JSContext* cx)
503
0
  {
504
0
    if (mType == eArrayBufferView) {
505
0
      return mValue.mArrayBufferView.Value();
506
0
    }
507
0
    Uninit();
508
0
    mType = eArrayBufferView;
509
0
    return mValue.mArrayBufferView.SetValue(cx);
510
0
  }
511
512
  inline bool
513
  IsArrayBufferView() const
514
0
  {
515
0
    return mType == eArrayBufferView;
516
0
  }
517
518
  inline RootedSpiderMonkeyInterface<ArrayBufferView>&
519
  GetAsArrayBufferView()
520
0
  {
521
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
522
0
    return mValue.mArrayBufferView.Value();
523
0
  }
524
525
  inline ArrayBufferView const &
526
  GetAsArrayBufferView() const
527
0
  {
528
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
529
0
    return mValue.mArrayBufferView.Value();
530
0
  }
531
532
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
533
  RawSetAsArrayBuffer(JSContext* cx)
534
0
  {
535
0
    if (mType == eArrayBuffer) {
536
0
      return mValue.mArrayBuffer.Value();
537
0
    }
538
0
    MOZ_ASSERT(mType == eUninitialized);
539
0
    mType = eArrayBuffer;
540
0
    return mValue.mArrayBuffer.SetValue(cx);
541
0
  }
542
543
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
544
  SetAsArrayBuffer(JSContext* cx)
545
0
  {
546
0
    if (mType == eArrayBuffer) {
547
0
      return mValue.mArrayBuffer.Value();
548
0
    }
549
0
    Uninit();
550
0
    mType = eArrayBuffer;
551
0
    return mValue.mArrayBuffer.SetValue(cx);
552
0
  }
553
554
  inline bool
555
  IsArrayBuffer() const
556
0
  {
557
0
    return mType == eArrayBuffer;
558
0
  }
559
560
  inline RootedSpiderMonkeyInterface<ArrayBuffer>&
561
  GetAsArrayBuffer()
562
0
  {
563
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
564
0
    return mValue.mArrayBuffer.Value();
565
0
  }
566
567
  inline ArrayBuffer const &
568
  GetAsArrayBuffer() const
569
0
  {
570
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
571
0
    return mValue.mArrayBuffer.Value();
572
0
  }
573
574
  inline void
575
  Uninit()
576
  {
577
    switch (mType) {
578
      case eUninitialized: {
579
        break;
580
      }
581
      case eHTMLImageElement: {
582
        DestroyHTMLImageElement();
583
        break;
584
      }
585
      case eHTMLVideoElement: {
586
        DestroyHTMLVideoElement();
587
        break;
588
      }
589
      case eHTMLCanvasElement: {
590
        DestroyHTMLCanvasElement();
591
        break;
592
      }
593
      case eBlob: {
594
        DestroyBlob();
595
        break;
596
      }
597
      case eImageData: {
598
        DestroyImageData();
599
        break;
600
      }
601
      case eCanvasRenderingContext2D: {
602
        DestroyCanvasRenderingContext2D();
603
        break;
604
      }
605
      case eImageBitmap: {
606
        DestroyImageBitmap();
607
        break;
608
      }
609
      case eArrayBufferView: {
610
        DestroyArrayBufferView();
611
        break;
612
      }
613
      case eArrayBuffer: {
614
        DestroyArrayBuffer();
615
        break;
616
      }
617
    }
618
  }
619
620
  bool
621
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
622
623
private:
624
  inline void
625
  DestroyHTMLImageElement()
626
0
  {
627
0
    MOZ_ASSERT(IsHTMLImageElement(), "Wrong type!");
628
0
    mValue.mHTMLImageElement.Destroy();
629
0
    mType = eUninitialized;
630
0
  }
631
632
  inline void
633
  DestroyHTMLVideoElement()
634
0
  {
635
0
    MOZ_ASSERT(IsHTMLVideoElement(), "Wrong type!");
636
0
    mValue.mHTMLVideoElement.Destroy();
637
0
    mType = eUninitialized;
638
0
  }
639
640
  inline void
641
  DestroyHTMLCanvasElement()
642
0
  {
643
0
    MOZ_ASSERT(IsHTMLCanvasElement(), "Wrong type!");
644
0
    mValue.mHTMLCanvasElement.Destroy();
645
0
    mType = eUninitialized;
646
0
  }
647
648
  inline void
649
  DestroyBlob()
650
0
  {
651
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
652
0
    mValue.mBlob.Destroy();
653
0
    mType = eUninitialized;
654
0
  }
655
656
  inline void
657
  DestroyImageData()
658
0
  {
659
0
    MOZ_ASSERT(IsImageData(), "Wrong type!");
660
0
    mValue.mImageData.Destroy();
661
0
    mType = eUninitialized;
662
0
  }
663
664
  inline void
665
  DestroyCanvasRenderingContext2D()
666
0
  {
667
0
    MOZ_ASSERT(IsCanvasRenderingContext2D(), "Wrong type!");
668
0
    mValue.mCanvasRenderingContext2D.Destroy();
669
0
    mType = eUninitialized;
670
0
  }
671
672
  inline void
673
  DestroyImageBitmap()
674
0
  {
675
0
    MOZ_ASSERT(IsImageBitmap(), "Wrong type!");
676
0
    mValue.mImageBitmap.Destroy();
677
0
    mType = eUninitialized;
678
0
  }
679
680
  inline void
681
  DestroyArrayBufferView()
682
0
  {
683
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
684
0
    mValue.mArrayBufferView.Destroy();
685
0
    mType = eUninitialized;
686
0
  }
687
688
  inline void
689
  DestroyArrayBuffer()
690
0
  {
691
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
692
0
    mValue.mArrayBuffer.Destroy();
693
0
    mType = eUninitialized;
694
0
  }
695
};
696
697
698
class OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer : public AllOwningUnionBase
699
{
700
  friend void ImplCycleCollectionUnlink(OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& aUnion);
701
  enum Type
702
  {
703
    eUninitialized,
704
    eHTMLImageElement,
705
    eHTMLVideoElement,
706
    eHTMLCanvasElement,
707
    eBlob,
708
    eImageData,
709
    eCanvasRenderingContext2D,
710
    eImageBitmap,
711
    eArrayBufferView,
712
    eArrayBuffer
713
  };
714
715
  union Value
716
  {
717
    UnionMember<OwningNonNull<mozilla::dom::HTMLImageElement> > mHTMLImageElement;
718
    UnionMember<OwningNonNull<mozilla::dom::HTMLVideoElement> > mHTMLVideoElement;
719
    UnionMember<OwningNonNull<mozilla::dom::HTMLCanvasElement> > mHTMLCanvasElement;
720
    UnionMember<OwningNonNull<mozilla::dom::Blob> > mBlob;
721
    UnionMember<OwningNonNull<mozilla::dom::ImageData> > mImageData;
722
    UnionMember<OwningNonNull<mozilla::dom::CanvasRenderingContext2D> > mCanvasRenderingContext2D;
723
    UnionMember<OwningNonNull<mozilla::dom::ImageBitmap> > mImageBitmap;
724
    UnionMember<ArrayBufferView > mArrayBufferView;
725
    UnionMember<ArrayBuffer > mArrayBuffer;
726
727
  };
728
729
  Type mType;
730
  Value mValue;
731
732
  OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer(const OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer&) = delete;
733
  OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer& operator=(const OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer&) = delete;
734
public:
735
  explicit inline OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer()
736
    : mType(eUninitialized)
737
0
  {
738
0
  }
739
740
  inline ~OwningHTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer()
741
0
  {
742
0
    Uninit();
743
0
  }
744
745
  OwningNonNull<mozilla::dom::HTMLImageElement>&
746
  RawSetAsHTMLImageElement();
747
748
  OwningNonNull<mozilla::dom::HTMLImageElement>&
749
  SetAsHTMLImageElement();
750
751
  bool
752
  TrySetToHTMLImageElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
753
754
  inline bool
755
  IsHTMLImageElement() const
756
0
  {
757
0
    return mType == eHTMLImageElement;
758
0
  }
759
760
  inline OwningNonNull<mozilla::dom::HTMLImageElement>&
761
  GetAsHTMLImageElement()
762
0
  {
763
0
    MOZ_ASSERT(IsHTMLImageElement(), "Wrong type!");
764
0
    return mValue.mHTMLImageElement.Value();
765
0
  }
766
767
  inline OwningNonNull<mozilla::dom::HTMLImageElement> const &
768
  GetAsHTMLImageElement() const
769
0
  {
770
0
    MOZ_ASSERT(IsHTMLImageElement(), "Wrong type!");
771
0
    return mValue.mHTMLImageElement.Value();
772
0
  }
773
774
  OwningNonNull<mozilla::dom::HTMLVideoElement>&
775
  RawSetAsHTMLVideoElement();
776
777
  OwningNonNull<mozilla::dom::HTMLVideoElement>&
778
  SetAsHTMLVideoElement();
779
780
  bool
781
  TrySetToHTMLVideoElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
782
783
  inline bool
784
  IsHTMLVideoElement() const
785
0
  {
786
0
    return mType == eHTMLVideoElement;
787
0
  }
788
789
  inline OwningNonNull<mozilla::dom::HTMLVideoElement>&
790
  GetAsHTMLVideoElement()
791
0
  {
792
0
    MOZ_ASSERT(IsHTMLVideoElement(), "Wrong type!");
793
0
    return mValue.mHTMLVideoElement.Value();
794
0
  }
795
796
  inline OwningNonNull<mozilla::dom::HTMLVideoElement> const &
797
  GetAsHTMLVideoElement() const
798
0
  {
799
0
    MOZ_ASSERT(IsHTMLVideoElement(), "Wrong type!");
800
0
    return mValue.mHTMLVideoElement.Value();
801
0
  }
802
803
  OwningNonNull<mozilla::dom::HTMLCanvasElement>&
804
  RawSetAsHTMLCanvasElement();
805
806
  OwningNonNull<mozilla::dom::HTMLCanvasElement>&
807
  SetAsHTMLCanvasElement();
808
809
  bool
810
  TrySetToHTMLCanvasElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
811
812
  inline bool
813
  IsHTMLCanvasElement() const
814
0
  {
815
0
    return mType == eHTMLCanvasElement;
816
0
  }
817
818
  inline OwningNonNull<mozilla::dom::HTMLCanvasElement>&
819
  GetAsHTMLCanvasElement()
820
0
  {
821
0
    MOZ_ASSERT(IsHTMLCanvasElement(), "Wrong type!");
822
0
    return mValue.mHTMLCanvasElement.Value();
823
0
  }
824
825
  inline OwningNonNull<mozilla::dom::HTMLCanvasElement> const &
826
  GetAsHTMLCanvasElement() const
827
0
  {
828
0
    MOZ_ASSERT(IsHTMLCanvasElement(), "Wrong type!");
829
0
    return mValue.mHTMLCanvasElement.Value();
830
0
  }
831
832
  OwningNonNull<mozilla::dom::Blob>&
833
  RawSetAsBlob();
834
835
  OwningNonNull<mozilla::dom::Blob>&
836
  SetAsBlob();
837
838
  bool
839
  TrySetToBlob(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
840
841
  inline bool
842
  IsBlob() const
843
0
  {
844
0
    return mType == eBlob;
845
0
  }
846
847
  inline OwningNonNull<mozilla::dom::Blob>&
848
  GetAsBlob()
849
0
  {
850
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
851
0
    return mValue.mBlob.Value();
852
0
  }
853
854
  inline OwningNonNull<mozilla::dom::Blob> const &
855
  GetAsBlob() const
856
0
  {
857
0
    MOZ_ASSERT(IsBlob(), "Wrong type!");
858
0
    return mValue.mBlob.Value();
859
0
  }
860
861
  OwningNonNull<mozilla::dom::ImageData>&
862
  RawSetAsImageData();
863
864
  OwningNonNull<mozilla::dom::ImageData>&
865
  SetAsImageData();
866
867
  bool
868
  TrySetToImageData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
869
870
  inline bool
871
  IsImageData() const
872
0
  {
873
0
    return mType == eImageData;
874
0
  }
875
876
  inline OwningNonNull<mozilla::dom::ImageData>&
877
  GetAsImageData()
878
0
  {
879
0
    MOZ_ASSERT(IsImageData(), "Wrong type!");
880
0
    return mValue.mImageData.Value();
881
0
  }
882
883
  inline OwningNonNull<mozilla::dom::ImageData> const &
884
  GetAsImageData() const
885
0
  {
886
0
    MOZ_ASSERT(IsImageData(), "Wrong type!");
887
0
    return mValue.mImageData.Value();
888
0
  }
889
890
  OwningNonNull<mozilla::dom::CanvasRenderingContext2D>&
891
  RawSetAsCanvasRenderingContext2D();
892
893
  OwningNonNull<mozilla::dom::CanvasRenderingContext2D>&
894
  SetAsCanvasRenderingContext2D();
895
896
  bool
897
  TrySetToCanvasRenderingContext2D(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
898
899
  inline bool
900
  IsCanvasRenderingContext2D() const
901
0
  {
902
0
    return mType == eCanvasRenderingContext2D;
903
0
  }
904
905
  inline OwningNonNull<mozilla::dom::CanvasRenderingContext2D>&
906
  GetAsCanvasRenderingContext2D()
907
0
  {
908
0
    MOZ_ASSERT(IsCanvasRenderingContext2D(), "Wrong type!");
909
0
    return mValue.mCanvasRenderingContext2D.Value();
910
0
  }
911
912
  inline OwningNonNull<mozilla::dom::CanvasRenderingContext2D> const &
913
  GetAsCanvasRenderingContext2D() const
914
0
  {
915
0
    MOZ_ASSERT(IsCanvasRenderingContext2D(), "Wrong type!");
916
0
    return mValue.mCanvasRenderingContext2D.Value();
917
0
  }
918
919
  OwningNonNull<mozilla::dom::ImageBitmap>&
920
  RawSetAsImageBitmap();
921
922
  OwningNonNull<mozilla::dom::ImageBitmap>&
923
  SetAsImageBitmap();
924
925
  bool
926
  TrySetToImageBitmap(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
927
928
  inline bool
929
  IsImageBitmap() const
930
0
  {
931
0
    return mType == eImageBitmap;
932
0
  }
933
934
  inline OwningNonNull<mozilla::dom::ImageBitmap>&
935
  GetAsImageBitmap()
936
0
  {
937
0
    MOZ_ASSERT(IsImageBitmap(), "Wrong type!");
938
0
    return mValue.mImageBitmap.Value();
939
0
  }
940
941
  inline OwningNonNull<mozilla::dom::ImageBitmap> const &
942
  GetAsImageBitmap() const
943
0
  {
944
0
    MOZ_ASSERT(IsImageBitmap(), "Wrong type!");
945
0
    return mValue.mImageBitmap.Value();
946
0
  }
947
948
  ArrayBufferView&
949
  RawSetAsArrayBufferView();
950
951
  ArrayBufferView&
952
  SetAsArrayBufferView();
953
954
  bool
955
  TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
956
957
  inline bool
958
  IsArrayBufferView() const
959
0
  {
960
0
    return mType == eArrayBufferView;
961
0
  }
962
963
  inline ArrayBufferView&
964
  GetAsArrayBufferView()
965
0
  {
966
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
967
0
    return mValue.mArrayBufferView.Value();
968
0
  }
969
970
  inline ArrayBufferView const &
971
  GetAsArrayBufferView() const
972
0
  {
973
0
    MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
974
0
    return mValue.mArrayBufferView.Value();
975
0
  }
976
977
  ArrayBuffer&
978
  RawSetAsArrayBuffer();
979
980
  ArrayBuffer&
981
  SetAsArrayBuffer();
982
983
  bool
984
  TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
985
986
  inline bool
987
  IsArrayBuffer() const
988
0
  {
989
0
    return mType == eArrayBuffer;
990
0
  }
991
992
  inline ArrayBuffer&
993
  GetAsArrayBuffer()
994
0
  {
995
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
996
0
    return mValue.mArrayBuffer.Value();
997
0
  }
998
999
  inline ArrayBuffer const &
1000
  GetAsArrayBuffer() const
1001
0
  {
1002
0
    MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
1003
0
    return mValue.mArrayBuffer.Value();
1004
0
  }
1005
1006
  void
1007
  Uninit();
1008
1009
  bool
1010
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
1011
1012
  void
1013
  TraceUnion(JSTracer* trc);
1014
1015
private:
1016
  void
1017
  DestroyHTMLImageElement();
1018
1019
  void
1020
  DestroyHTMLVideoElement();
1021
1022
  void
1023
  DestroyHTMLCanvasElement();
1024
1025
  void
1026
  DestroyBlob();
1027
1028
  void
1029
  DestroyImageData();
1030
1031
  void
1032
  DestroyCanvasRenderingContext2D();
1033
1034
  void
1035
  DestroyImageBitmap();
1036
1037
  void
1038
  DestroyArrayBufferView();
1039
1040
  void
1041
  DestroyArrayBuffer();
1042
};
1043
1044
1045
namespace ImageBitmap_Binding {
1046
1047
  typedef mozilla::dom::ImageBitmap NativeType;
1048
1049
  const JSClass*
1050
  GetJSClass();
1051
1052
  bool
1053
  Wrap(JSContext* aCx, mozilla::dom::ImageBitmap* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
1054
1055
  template <class T>
1056
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
1057
0
  {
1058
0
    JS::Rooted<JSObject*> reflector(aCx);
1059
0
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
1060
0
  }
1061
1062
  // We declare this as an array so that retrieving a pointer to this
1063
  // binding's property hooks only requires compile/link-time resolvable
1064
  // address arithmetic.  Declaring it as a pointer instead would require
1065
  // doing a run-time load to fetch a pointer to this binding's property
1066
  // hooks.  And then structures which embedded a pointer to this structure
1067
  // would require a run-time load for proper initialization, which would
1068
  // then induce static constructors.  Lots of static constructors.
1069
  extern const NativePropertyHooks sNativePropertyHooks[];
1070
1071
  void
1072
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);
1073
1074
  inline JS::Handle<JSObject*> GetProtoObjectHandle(JSContext* aCx)
1075
0
  {
1076
0
    /* Get the interface prototype object for this class.  This will create the
1077
0
       object as needed. */
1078
0
    return GetPerInterfaceObjectHandle(aCx, prototypes::id::ImageBitmap,
1079
0
                                       &CreateInterfaceObjects,
1080
0
                                       /* aDefineOnGlobal = */ true);
1081
0
1082
0
  }
1083
1084
  inline JS::Handle<JSObject*> GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true)
1085
0
  {
1086
0
    /* Get the interface object for this class.  This will create the object as
1087
0
       needed. */
1088
0
1089
0
    return GetPerInterfaceObjectHandle(aCx, constructors::id::ImageBitmap,
1090
0
                                       &CreateInterfaceObjects,
1091
0
                                       aDefineOnGlobal);
1092
0
  }
1093
1094
  JSObject*
1095
  GetConstructorObject(JSContext* aCx);
1096
1097
} // namespace ImageBitmap_Binding
1098
1099
1100
1101
} // namespace dom
1102
} // namespace mozilla
1103
1104
#endif // mozilla_dom_ImageBitmapBinding_h