Coverage Report

Created: 2018-09-25 14:53

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