Source code

Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM TestCallback.webidl BY Codegen.py - DO NOT EDIT */
#ifndef DOM_TESTCALLBACKBINDING_H_
#define DOM_TESTCALLBACKBINDING_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 OwningStringOrLong;
class ProtoAndIfaceCache;
class StringOrLong;
class TestUnionArguments;
} // namespace dom
} // namespace mozilla
namespace mozilla::dom {
class StringOrLong : public AllUnionBase
{
enum TypeOrUninit
{
eUninitialized,
eString,
eLong
};
public:
enum class Type
{
eString = TypeOrUninit::eString,
eLong = TypeOrUninit::eLong
};
private:
union Value
{
UnionMember<binding_detail::FakeString<char16_t> > mString;
UnionMember<int32_t > mLong;
};
TypeOrUninit mType;
Value mValue;
StringOrLong(const StringOrLong&) = delete;
StringOrLong& operator=(const StringOrLong&) = delete;
public:
explicit inline StringOrLong()
: mType(eUninitialized)
{
}
inline ~StringOrLong()
{
Uninit();
}
[[nodiscard]] inline binding_detail::FakeString<char16_t>&
RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] inline binding_detail::FakeString<char16_t>&
SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
template <int N>
inline void
SetStringLiteral(const nsString::char_type (&aData)[N])
{
RawSetAsString().AssignLiteral(aData);
}
inline bool
IsString() const
{
return mType == eString;
}
inline binding_detail::FakeString<char16_t>&
GetAsString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
return mValue.mString.Value();
}
inline const nsAString&
GetAsString() const
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
return mValue.mString.Value();
}
[[nodiscard]] inline int32_t&
RawSetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eLong;
return mValue.mLong.SetValue();
}
[[nodiscard]] inline int32_t&
SetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
Uninit();
mType = eLong;
return mValue.mLong.SetValue();
}
inline bool
IsLong() const
{
return mType == eLong;
}
inline int32_t&
GetAsLong()
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
return mValue.mLong.Value();
}
inline int32_t
GetAsLong() const
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
return mValue.mLong.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 eString: {
DestroyString();
break;
}
case eLong: {
DestroyLong();
break;
}
}
}
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
private:
bool
TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyLong()
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
mValue.mLong.Destroy();
mType = eUninitialized;
}
};
class OwningStringOrLong : public AllOwningUnionBase
{
enum TypeOrUninit
{
eUninitialized,
eString,
eLong
};
public:
enum class Type
{
eString = TypeOrUninit::eString,
eLong = TypeOrUninit::eLong
};
private:
union Value
{
UnionMember<nsString > mString;
UnionMember<int32_t > mLong;
};
TypeOrUninit mType;
Value mValue;
public:
explicit inline OwningStringOrLong()
: mType(eUninitialized)
{
}
OwningStringOrLong(OwningStringOrLong&& aOther);
explicit inline OwningStringOrLong(const OwningStringOrLong& aOther)
: mType(eUninitialized)
{
*this = aOther;
}
inline ~OwningStringOrLong()
{
Uninit();
}
[[nodiscard]] nsString&
RawSetAsString();
[[nodiscard]] nsString&
SetAsString();
template <int N>
inline void
SetStringLiteral(const nsString::char_type (&aData)[N])
{
RawSetAsString().AssignLiteral(aData);
}
inline bool
IsString() const
{
return mType == eString;
}
inline nsString&
GetAsString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
return mValue.mString.Value();
}
inline nsString const &
GetAsString() const
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
return mValue.mString.Value();
}
[[nodiscard]] int32_t&
RawSetAsLong();
[[nodiscard]] int32_t&
SetAsLong();
inline bool
IsLong() const
{
return mType == eLong;
}
inline int32_t&
GetAsLong()
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
return mValue.mLong.Value();
}
inline int32_t const &
GetAsLong() const
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
return mValue.mLong.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;
OwningStringOrLong&
operator=(OwningStringOrLong&& aOther);
inline Type
GetType() const
{
MOZ_RELEASE_ASSERT(mType != eUninitialized);
return static_cast<Type>(mType);
}
OwningStringOrLong&
operator=(const OwningStringOrLong& aOther);
private:
bool
TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyString();
bool
TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyLong();
};
class TestUnionArguments : public CallbackFunction
{
public:
explicit inline TestUnionArguments(JSContext* aCx, JS::Handle<JSObject*> aCallback, JS::Handle<JSObject*> aCallbackGlobal, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCx, aCallback, aCallbackGlobal, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline TestUnionArguments(JSObject* aCallback, JSObject* aCallbackGlobal, const FastCallbackConstructor& )
: CallbackFunction(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline TestUnionArguments(JSObject* aCallback, JSObject* aCallbackGlobal, JSObject* aAsyncStack, nsIGlobalObject* aIncumbentGlobal)
: CallbackFunction(aCallback, aCallbackGlobal, aAsyncStack, aIncumbentGlobal)
{
MOZ_ASSERT(JS::IsCallable(mCallback));
}
explicit inline TestUnionArguments(CallbackFunction* aOther)
: CallbackFunction(aOther)
{
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, const StringOrLong& arg1, const Nullable<StringOrLong>& arg2, const Optional<StringOrLong>& arg3, const Optional<Nullable<StringOrLong>>& arg4, 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 = "TestUnionArguments";
}
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, arg1, arg2, arg3, arg4, aRv);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(const StringOrLong& arg1, const Nullable<StringOrLong>& arg2, const Optional<StringOrLong>& arg3, const Optional<Nullable<StringOrLong>>& arg4, 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 = "TestUnionArguments";
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aRealm);
if (!s.GetContext()) {
MOZ_ASSERT(aRv.Failed());
return;
}
return Call(s.GetCallContext(), JS::UndefinedHandleValue, arg1, arg2, arg3, arg4, aRv);
}
template <typename T>
MOZ_CAN_RUN_SCRIPT inline void
Call(const T& thisVal, const StringOrLong& arg1, const Nullable<StringOrLong>& arg2, const Optional<StringOrLong>& arg3, const Optional<Nullable<StringOrLong>>& arg4, const char* aExecutionReason = nullptr)
{
return Call(thisVal, arg1, arg2, arg3, arg4, IgnoreErrors(), aExecutionReason);
}
MOZ_CAN_RUN_SCRIPT inline void
Call(const StringOrLong& arg1, const Nullable<StringOrLong>& arg2, const Optional<StringOrLong>& arg3, const Optional<Nullable<StringOrLong>>& arg4, const char* aExecutionReason = nullptr)
{
return Call(arg1, arg2, arg3, arg4, IgnoreErrors(), aExecutionReason, eReportExceptions, nullptr);
}
inline bool
operator==(const TestUnionArguments& aOther) const
{
return CallbackFunction::operator==(aOther);
}
private:
MOZ_CAN_RUN_SCRIPT void Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const StringOrLong& arg1, const Nullable<StringOrLong>& arg2, const Optional<StringOrLong>& arg3, const Optional<Nullable<StringOrLong>>& arg4, ErrorResult& aRv);
};
namespace binding_detail {
class FastTestUnionArguments : public TestUnionArguments
{
public:
explicit inline FastTestUnionArguments(JSObject* aCallback, JSObject* aCallbackGlobal)
: TestUnionArguments(aCallback, aCallbackGlobal, FastCallbackConstructor())
{
}
inline void
Trace(JSTracer* aTracer)
{
TestUnionArguments::Trace(aTracer);
}
inline void
FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
{
TestUnionArguments::FinishSlowJSInitIfMoreThanOneOwner(aCx);
}
};
} // namespace binding_detail
} // namespace mozilla::dom
#endif // DOM_TESTCALLBACKBINDING_H_