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