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