Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM UnderlyingSource.webidl BY Codegen.py - DO NOT EDIT */
#ifndef DOM_UNDERLYINGSOURCEBINDING_H_
#define DOM_UNDERLYINGSOURCEBINDING_H_
#include "ReadableStreamDefaultReaderBinding.h"
#include "js/CallAndConstruct.h"
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackFunction.h"
#include "mozilla/dom/FakeString.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/UnionMember.h"
namespace mozilla {
namespace dom {
struct NativePropertyHooks;
class OwningReadableStreamDefaultControllerOrReadableByteStreamController;
class Promise;
class ProtoAndIfaceCache;
class ReadableByteStreamController;
class ReadableStreamDefaultController;
class ReadableStreamDefaultControllerOrReadableByteStreamController;
struct UnderlyingSourceAtoms;
class UnderlyingSourceCancelCallback;
class UnderlyingSourcePullCallback;
class UnderlyingSourceStartCallback;
} // namespace dom
} // namespace mozilla
namespace mozilla::dom {
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningReadableStreamDefaultControllerOrReadableByteStreamController& aUnion, const char* aName, uint32_t aFlags = 0);
void
ImplCycleCollectionUnlink(OwningReadableStreamDefaultControllerOrReadableByteStreamController& aUnion);
class ReadableStreamDefaultControllerOrReadableByteStreamController : public AllUnionBase
{
enum TypeOrUninit
{
eUninitialized,
eReadableStreamDefaultController,
eReadableByteStreamController
};
public:
enum class Type
{
eReadableStreamDefaultController = TypeOrUninit::eReadableStreamDefaultController,
eReadableByteStreamController = TypeOrUninit::eReadableByteStreamController
};
private:
union Value
{
UnionMember<NonNull<mozilla::dom::ReadableStreamDefaultController> > mReadableStreamDefaultController;
UnionMember<NonNull<mozilla::dom::ReadableByteStreamController> > mReadableByteStreamController;
};
TypeOrUninit mType;
Value mValue;
ReadableStreamDefaultControllerOrReadableByteStreamController(const ReadableStreamDefaultControllerOrReadableByteStreamController&) = delete;
ReadableStreamDefaultControllerOrReadableByteStreamController& operator=(const ReadableStreamDefaultControllerOrReadableByteStreamController&) = delete;
public:
explicit inline ReadableStreamDefaultControllerOrReadableByteStreamController()
: mType(eUninitialized)
{
}
inline ~ReadableStreamDefaultControllerOrReadableByteStreamController()
{
Uninit();
}
[[nodiscard]] inline NonNull<mozilla::dom::ReadableStreamDefaultController>&
RawSetAsReadableStreamDefaultController()
{
if (mType == eReadableStreamDefaultController) {
return mValue.mReadableStreamDefaultController.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eReadableStreamDefaultController;
return mValue.mReadableStreamDefaultController.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::dom::ReadableStreamDefaultController>&
SetAsReadableStreamDefaultController()
{
if (mType == eReadableStreamDefaultController) {
return mValue.mReadableStreamDefaultController.Value();
}
Uninit();
mType = eReadableStreamDefaultController;
return mValue.mReadableStreamDefaultController.SetValue();
}
inline bool
IsReadableStreamDefaultController() const
{
return mType == eReadableStreamDefaultController;
}
inline NonNull<mozilla::dom::ReadableStreamDefaultController>&
GetAsReadableStreamDefaultController()
{
MOZ_RELEASE_ASSERT(IsReadableStreamDefaultController(), "Wrong type!");
return mValue.mReadableStreamDefaultController.Value();
}
inline mozilla::dom::ReadableStreamDefaultController&
GetAsReadableStreamDefaultController() const
{
MOZ_RELEASE_ASSERT(IsReadableStreamDefaultController(), "Wrong type!");
return mValue.mReadableStreamDefaultController.Value();
}
[[nodiscard]] inline NonNull<mozilla::dom::ReadableByteStreamController>&
RawSetAsReadableByteStreamController()
{
if (mType == eReadableByteStreamController) {
return mValue.mReadableByteStreamController.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eReadableByteStreamController;
return mValue.mReadableByteStreamController.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::dom::ReadableByteStreamController>&
SetAsReadableByteStreamController()
{
if (mType == eReadableByteStreamController) {
return mValue.mReadableByteStreamController.Value();
}
Uninit();
mType = eReadableByteStreamController;
return mValue.mReadableByteStreamController.SetValue();
}
inline bool
IsReadableByteStreamController() const
{
return mType == eReadableByteStreamController;
}
inline NonNull<mozilla::dom::ReadableByteStreamController>&
GetAsReadableByteStreamController()
{
MOZ_RELEASE_ASSERT(IsReadableByteStreamController(), "Wrong type!");
return mValue.mReadableByteStreamController.Value();
}
inline mozilla::dom::ReadableByteStreamController&
GetAsReadableByteStreamController() const
{
MOZ_RELEASE_ASSERT(IsReadableByteStreamController(), "Wrong type!");
return mValue.mReadableByteStreamController.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
inline void
Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eReadableStreamDefaultController: {
DestroyReadableStreamDefaultController();
break;
}
case eReadableByteStreamController: {
DestroyReadableByteStreamController();
break;
}
}
}
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
private:
bool
TrySetToReadableStreamDefaultController(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToReadableStreamDefaultController(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyReadableStreamDefaultController()
{
MOZ_RELEASE_ASSERT(IsReadableStreamDefaultController(), "Wrong type!");
mValue.mReadableStreamDefaultController.Destroy();
mType = eUninitialized;
}
bool
TrySetToReadableByteStreamController(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToReadableByteStreamController(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyReadableByteStreamController()
{
MOZ_RELEASE_ASSERT(IsReadableByteStreamController(), "Wrong type!");
mValue.mReadableByteStreamController.Destroy();
mType = eUninitialized;
}
};
class OwningReadableStreamDefaultControllerOrReadableByteStreamController : public AllOwningUnionBase
{
friend void ImplCycleCollectionUnlink(OwningReadableStreamDefaultControllerOrReadableByteStreamController& aUnion);
enum TypeOrUninit
{
eUninitialized,
eReadableStreamDefaultController,
eReadableByteStreamController
};
public:
enum class Type
{
eReadableStreamDefaultController = TypeOrUninit::eReadableStreamDefaultController,
eReadableByteStreamController = TypeOrUninit::eReadableByteStreamController
};
private:
union Value
{
UnionMember<OwningNonNull<mozilla::dom::ReadableStreamDefaultController> > mReadableStreamDefaultController;
UnionMember<OwningNonNull<mozilla::dom::ReadableByteStreamController> > mReadableByteStreamController;
};
TypeOrUninit mType;
Value mValue;
public:
explicit inline OwningReadableStreamDefaultControllerOrReadableByteStreamController()
: mType(eUninitialized)
{
}
OwningReadableStreamDefaultControllerOrReadableByteStreamController(OwningReadableStreamDefaultControllerOrReadableByteStreamController&& aOther);
explicit inline OwningReadableStreamDefaultControllerOrReadableByteStreamController(const OwningReadableStreamDefaultControllerOrReadableByteStreamController& aOther)
: mType(eUninitialized)
{
*this = aOther;
}
inline ~OwningReadableStreamDefaultControllerOrReadableByteStreamController()
{
Uninit();
}
[[nodiscard]] OwningNonNull<mozilla::dom::ReadableStreamDefaultController>&
RawSetAsReadableStreamDefaultController();
[[nodiscard]] OwningNonNull<mozilla::dom::ReadableStreamDefaultController>&
SetAsReadableStreamDefaultController();
inline bool
IsReadableStreamDefaultController() const
{
return mType == eReadableStreamDefaultController;
}
inline OwningNonNull<mozilla::dom::ReadableStreamDefaultController>&
GetAsReadableStreamDefaultController()
{
MOZ_RELEASE_ASSERT(IsReadableStreamDefaultController(), "Wrong type!");
return mValue.mReadableStreamDefaultController.Value();
}
inline OwningNonNull<mozilla::dom::ReadableStreamDefaultController> const &
GetAsReadableStreamDefaultController() const
{
MOZ_RELEASE_ASSERT(IsReadableStreamDefaultController(), "Wrong type!");
return mValue.mReadableStreamDefaultController.Value();
}
[[nodiscard]] OwningNonNull<mozilla::dom::ReadableByteStreamController>&
RawSetAsReadableByteStreamController();
[[nodiscard]] OwningNonNull<mozilla::dom::ReadableByteStreamController>&
SetAsReadableByteStreamController();
inline bool
IsReadableByteStreamController() const
{
return mType == eReadableByteStreamController;
}
inline OwningNonNull<mozilla::dom::ReadableByteStreamController>&
GetAsReadableByteStreamController()
{
MOZ_RELEASE_ASSERT(IsReadableByteStreamController(), "Wrong type!");
return mValue.mReadableByteStreamController.Value();
}
inline OwningNonNull<mozilla::dom::ReadableByteStreamController> const &
GetAsReadableByteStreamController() const
{
MOZ_RELEASE_ASSERT(IsReadableByteStreamController(), "Wrong type!");
return mValue.mReadableByteStreamController.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
Uninit();
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
OwningReadableStreamDefaultControllerOrReadableByteStreamController&
operator=(OwningReadableStreamDefaultControllerOrReadableByteStreamController&& aOther);
inline Type
GetType() const
{
MOZ_RELEASE_ASSERT(mType != eUninitialized);
return static_cast<Type>(mType);
}
OwningReadableStreamDefaultControllerOrReadableByteStreamController&
operator=(const OwningReadableStreamDefaultControllerOrReadableByteStreamController& aOther);
private:
bool
TrySetToReadableStreamDefaultController(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToReadableStreamDefaultController(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyReadableStreamDefaultController();
bool
TrySetToReadableByteStreamController(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToReadableByteStreamController(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyReadableByteStreamController();
};
struct UnderlyingSource : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR Optional<uint64_t> mAutoAllocateChunkSize;
MOZ_INIT_OUTSIDE_CTOR Optional<OwningNonNull<UnderlyingSourceCancelCallback>> mCancel;
MOZ_INIT_OUTSIDE_CTOR Optional<OwningNonNull<UnderlyingSourcePullCallback>> mPull;
MOZ_INIT_OUTSIDE_CTOR Optional<OwningNonNull<UnderlyingSourceStartCallback>> mStart;
MOZ_INIT_OUTSIDE_CTOR Optional<ReadableStreamType> mType;
UnderlyingSource();
explicit inline UnderlyingSource(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
UnderlyingSource(UnderlyingSource&& aOther) = default;
private:
UnderlyingSource(const UnderlyingSource&) = delete;
UnderlyingSource& operator=(const UnderlyingSource&) = delete;
static bool
InitIds(JSContext* cx, UnderlyingSourceAtoms* atomsCache);
public:
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
inline void
TraverseForCC(nsCycleCollectionTraversalCallback& aCallback, uint32_t aFlags)
{
ImplCycleCollectionTraverse(aCallback, mCancel, "mCancel", aFlags);
ImplCycleCollectionTraverse(aCallback, mPull, "mPull", aFlags);
ImplCycleCollectionTraverse(aCallback, mStart, "mStart", aFlags);
}
inline void
UnlinkForCC()
{
ImplCycleCollectionUnlink(mCancel);
ImplCycleCollectionUnlink(mPull);
ImplCycleCollectionUnlink(mStart);
}
};
namespace binding_detail {
struct FastUnderlyingSource : public UnderlyingSource
{
inline FastUnderlyingSource()
: UnderlyingSource(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
class UnderlyingSourceCancelCallback : public CallbackFunction
{
public:
explicit inline UnderlyingSourceCancelCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceCancelCallback(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackFunction(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceCancelCallback(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceCancelCallback(CallbackFunction* aOther)
: CallbackFunction(aOther)
{
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const T& thisVal, const Optional<JS::Handle<JS::Value>>& reason, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourceCancelCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return nullptr;
}
JS::Rooted<JS::Value> thisValJS(s.GetContext());
if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return Call(s.GetCallContext(), thisValJS, reason, aRv);
}
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const Optional<JS::Handle<JS::Value>>& reason, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourceCancelCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return nullptr;
}
return Call(s.GetCallContext(), JS::UndefinedHandleValue, reason, aRv);
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const T& thisVal, const Optional<JS::Handle<JS::Value>>& reason, const char* aExecutionReason = nullptr)
{
return Call(thisVal, reason, IgnoreErrors(), aExecutionReason);
}
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const Optional<JS::Handle<JS::Value>>& reason, const char* aExecutionReason = nullptr)
{
return Call(reason, IgnoreErrors(), aExecutionReason, eReportExceptions, nullptr);
}
inline bool
operator==(const UnderlyingSourceCancelCallback& aOther) const
{
return CallbackFunction::operator==(aOther);
}
private:
MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const Optional<JS::Handle<JS::Value>>& reason, ErrorResult& aRv);
};
namespace binding_detail {
class FastUnderlyingSourceCancelCallback : public UnderlyingSourceCancelCallback
{
public:
explicit inline FastUnderlyingSourceCancelCallback(JSObject* aCallback, JSObject* aCallbackGlobal)
: UnderlyingSourceCancelCallback(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
inline void
Trace(JSTracer* aTracer)
{
UnderlyingSourceCancelCallback::Trace(aTracer);
}
inline void
FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
{
UnderlyingSourceCancelCallback::FinishSlowJSInitIfMoreThanOneOwner(aCx);
}
};
} // namespace binding_detail
class UnderlyingSourcePullCallback : public CallbackFunction
{
public:
explicit inline UnderlyingSourcePullCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourcePullCallback(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackFunction(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourcePullCallback(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourcePullCallback(CallbackFunction* aOther)
: CallbackFunction(aOther)
{
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const T& thisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourcePullCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return nullptr;
}
JS::Rooted<JS::Value> thisValJS(s.GetContext());
if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return Call(s.GetCallContext(), thisValJS, controller, aRv);
}
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourcePullCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return nullptr;
}
return Call(s.GetCallContext(), JS::UndefinedHandleValue, controller, aRv);
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const T& thisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, const char* aExecutionReason = nullptr)
{
return Call(thisVal, controller, IgnoreErrors(), aExecutionReason);
}
MOZ_CAN_RUN_SCRIPT inline already_AddRefed<Promise>
Call(const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, const char* aExecutionReason = nullptr)
{
return Call(controller, IgnoreErrors(), aExecutionReason, eReportExceptions, nullptr);
}
inline bool
operator==(const UnderlyingSourcePullCallback& aOther) const
{
return CallbackFunction::operator==(aOther);
}
private:
MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, ErrorResult& aRv);
};
namespace binding_detail {
class FastUnderlyingSourcePullCallback : public UnderlyingSourcePullCallback
{
public:
explicit inline FastUnderlyingSourcePullCallback(JSObject* aCallback, JSObject* aCallbackGlobal)
: UnderlyingSourcePullCallback(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
inline void
Trace(JSTracer* aTracer)
{
UnderlyingSourcePullCallback::Trace(aTracer);
}
inline void
FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
{
UnderlyingSourcePullCallback::FinishSlowJSInitIfMoreThanOneOwner(aCx);
}
};
} // namespace binding_detail
class UnderlyingSourceStartCallback : public CallbackFunction
{
public:
explicit inline UnderlyingSourceStartCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceStartCallback(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackFunction(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceStartCallback(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline UnderlyingSourceStartCallback(CallbackFunction* aOther)
: CallbackFunction(aOther)
{
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourceStartCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return;
}
JS::Rooted<JS::Value> thisValJS(s.GetContext());
if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
return Call(s.GetCallContext(), thisValJS, controller, aRetVal, aRv);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JS::Realm* aRealm = nullptr)
{
MOZ_ASSERT(!aRv.Failed(), "Don't pass an already-failed ErrorResult to a callback!");
if (!aExecutionReason) {
aExecutionReason = "UnderlyingSourceStartCallback";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return;
}
return Call(s.GetCallContext(), JS::UndefinedHandleValue, controller, aRetVal, aRv);
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, JS::MutableHandle<JS::Value> aRetVal, const char* aExecutionReason = nullptr)
{
return Call(thisVal, controller, aRetVal, IgnoreErrors(), aExecutionReason);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, JS::MutableHandle<JS::Value> aRetVal, const char* aExecutionReason = nullptr)
{
return Call(controller, aRetVal, IgnoreErrors(), aExecutionReason, eReportExceptions, nullptr);
}
inline bool
operator==(const UnderlyingSourceStartCallback& aOther) const
{
return CallbackFunction::operator==(aOther);
}
private:
MOZ_CAN_RUN_SCRIPT void Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const ReadableStreamDefaultControllerOrReadableByteStreamController& controller, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv);
};
namespace binding_detail {
class FastUnderlyingSourceStartCallback : public UnderlyingSourceStartCallback
{
public:
explicit inline FastUnderlyingSourceStartCallback(JSObject* aCallback, JSObject* aCallbackGlobal)
: UnderlyingSourceStartCallback(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
inline void
Trace(JSTracer* aTracer)
{
UnderlyingSourceStartCallback::Trace(aTracer);
}
inline void
FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
{
UnderlyingSourceStartCallback::FinishSlowJSInitIfMoreThanOneOwner(aCx);
}
};
} // namespace binding_detail
} // namespace mozilla::dom
#endif // DOM_UNDERLYINGSOURCEBINDING_H_