Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM TestInterfaceJS.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "EventHandlerBinding.h"
#include "EventTargetBinding.h"
#include "FunctionBinding.h"
#include "MainThreadUtils.h"
#include "PromiseBinding.h"
#include "TestInterfaceJSBinding.h"
#include "TestInterfaceJSDictionariesBinding.h"
#include "WrapperFactory.h"
#include "js/Array.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/ForOfIterator.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "mozilla/Atomics.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/Location.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "nsContentUtils.h"
#include "nsIGlobalObject.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningLocationOrTestInterfaceJS& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsLocation()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsLocation(), "mLocation", aFlags);
} else if (aUnion.IsTestInterfaceJS()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsTestInterfaceJS(), "mTestInterfaceJS", aFlags);
}
}
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningStringOrTestInterfaceJSOrNull& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsTestInterfaceJS()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsTestInterfaceJS(), "mTestInterfaceJS", aFlags);
}
}
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningTestInterfaceJSOrLong& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsTestInterfaceJS()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsTestInterfaceJS(), "mTestInterfaceJS", aFlags);
}
}
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningTestInterfaceJSOrNullOrString& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsTestInterfaceJS()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsTestInterfaceJS(), "mTestInterfaceJS", aFlags);
}
}
void
ImplCycleCollectionUnlink(OwningLocationOrTestInterfaceJS& aUnion)
{
aUnion.Uninit();
}
void
ImplCycleCollectionUnlink(OwningStringOrTestInterfaceJSOrNull& aUnion)
{
aUnion.Uninit();
}
void
ImplCycleCollectionUnlink(OwningTestInterfaceJSOrLong& aUnion)
{
aUnion.Uninit();
}
void
ImplCycleCollectionUnlink(OwningTestInterfaceJSOrNullOrString& aUnion)
{
aUnion.Uninit();
}
bool
LocationOrTestInterfaceJS::TrySetToLocation(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::Location>& memberSlot = RawSetAsLocation();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Location, mozilla::dom::Location>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyLocation();
tryNext = true;
return true;
}
}
}
return true;
}
bool
LocationOrTestInterfaceJS::TrySetToLocation(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToLocation(cx, value, tryNext, passedToJSImpl);
}
bool
LocationOrTestInterfaceJS::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
LocationOrTestInterfaceJS::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
bool
LocationOrTestInterfaceJS::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToLocation(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "Location, TestInterfaceJS");
return false;
}
return true;
}
bool
LocationOrTestInterfaceJS::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
LocationOrTestInterfaceJS::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eLocation: {
if (!GetOrCreateDOMReflector(cx, mValue.mLocation.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningLocationOrTestInterfaceJS::OwningLocationOrTestInterfaceJS(OwningLocationOrTestInterfaceJS&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eLocation: {
mType = eLocation;
mValue.mLocation.SetValue(std::move(aOther.mValue.mLocation.Value()));
break;
}
case eTestInterfaceJS: {
mType = eTestInterfaceJS;
mValue.mTestInterfaceJS.SetValue(std::move(aOther.mValue.mTestInterfaceJS.Value()));
break;
}
}
}
bool
OwningLocationOrTestInterfaceJS::TrySetToLocation(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::Location>& memberSlot = RawSetAsLocation();
static_assert(IsRefcounted<mozilla::dom::Location>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Location, mozilla::dom::Location>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyLocation();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningLocationOrTestInterfaceJS::TrySetToLocation(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToLocation(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::Location>&
OwningLocationOrTestInterfaceJS::RawSetAsLocation()
{
if (mType == eLocation) {
return mValue.mLocation.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eLocation;
return mValue.mLocation.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::Location>&
OwningLocationOrTestInterfaceJS::SetAsLocation()
{
if (mType == eLocation) {
return mValue.mLocation.Value();
}
Uninit();
mType = eLocation;
return mValue.mLocation.SetValue();
}
void
OwningLocationOrTestInterfaceJS::DestroyLocation()
{
MOZ_RELEASE_ASSERT(IsLocation(), "Wrong type!");
mValue.mLocation.Destroy();
mType = eUninitialized;
}
bool
OwningLocationOrTestInterfaceJS::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
static_assert(IsRefcounted<mozilla::dom::TestInterfaceJS>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningLocationOrTestInterfaceJS::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningLocationOrTestInterfaceJS::RawSetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningLocationOrTestInterfaceJS::SetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
Uninit();
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
void
OwningLocationOrTestInterfaceJS::DestroyTestInterfaceJS()
{
MOZ_RELEASE_ASSERT(IsTestInterfaceJS(), "Wrong type!");
mValue.mTestInterfaceJS.Destroy();
mType = eUninitialized;
}
bool
OwningLocationOrTestInterfaceJS::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToLocation(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "Location, TestInterfaceJS");
return false;
}
return true;
}
bool
OwningLocationOrTestInterfaceJS::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningLocationOrTestInterfaceJS::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eLocation: {
DestroyLocation();
break;
}
case eTestInterfaceJS: {
DestroyTestInterfaceJS();
break;
}
}
}
bool
OwningLocationOrTestInterfaceJS::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eLocation: {
if (!GetOrCreateDOMReflector(cx, mValue.mLocation.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningLocationOrTestInterfaceJS&
OwningLocationOrTestInterfaceJS::operator=(OwningLocationOrTestInterfaceJS&& aOther)
{
this->~OwningLocationOrTestInterfaceJS();
new (this) OwningLocationOrTestInterfaceJS (std::move(aOther));
return *this;
}
OwningLocationOrTestInterfaceJS&
OwningLocationOrTestInterfaceJS::operator=(const OwningLocationOrTestInterfaceJS& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eLocation: {
SetAsLocation() = aOther.GetAsLocation();
break;
}
case eTestInterfaceJS: {
SetAsTestInterfaceJS() = aOther.GetAsTestInterfaceJS();
break;
}
}
return *this;
}
bool
StringOrTestInterfaceJSOrNull::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
StringOrTestInterfaceJSOrNull::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
StringOrTestInterfaceJSOrNull::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
bool
StringOrTestInterfaceJSOrNull::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isNullOrUndefined()) {
SetNull();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
}
return true;
}
bool
StringOrTestInterfaceJSOrNull::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
StringOrTestInterfaceJSOrNull::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eNull: {
rval.setNull();
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningStringOrTestInterfaceJSOrNull::OwningStringOrTestInterfaceJSOrNull(OwningStringOrTestInterfaceJSOrNull&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eNull: {
MOZ_ASSERT(mType == eUninitialized);
mType = eNull;
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
case eTestInterfaceJS: {
mType = eTestInterfaceJS;
mValue.mTestInterfaceJS.SetValue(std::move(aOther.mValue.mTestInterfaceJS.Value()));
break;
}
}
}
bool
OwningStringOrTestInterfaceJSOrNull::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningStringOrTestInterfaceJSOrNull::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningStringOrTestInterfaceJSOrNull::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningStringOrTestInterfaceJSOrNull::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrTestInterfaceJSOrNull::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
static_assert(IsRefcounted<mozilla::dom::TestInterfaceJS>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningStringOrTestInterfaceJSOrNull::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningStringOrTestInterfaceJSOrNull::RawSetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningStringOrTestInterfaceJSOrNull::SetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
Uninit();
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
void
OwningStringOrTestInterfaceJSOrNull::DestroyTestInterfaceJS()
{
MOZ_RELEASE_ASSERT(IsTestInterfaceJS(), "Wrong type!");
mValue.mTestInterfaceJS.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrTestInterfaceJSOrNull::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isNullOrUndefined()) {
SetNull();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
}
return true;
}
bool
OwningStringOrTestInterfaceJSOrNull::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningStringOrTestInterfaceJSOrNull::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eNull: {
break;
}
case eString: {
DestroyString();
break;
}
case eTestInterfaceJS: {
DestroyTestInterfaceJS();
break;
}
}
}
bool
OwningStringOrTestInterfaceJSOrNull::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eNull: {
rval.setNull();
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningStringOrTestInterfaceJSOrNull&
OwningStringOrTestInterfaceJSOrNull::operator=(OwningStringOrTestInterfaceJSOrNull&& aOther)
{
this->~OwningStringOrTestInterfaceJSOrNull();
new (this) OwningStringOrTestInterfaceJSOrNull (std::move(aOther));
return *this;
}
OwningStringOrTestInterfaceJSOrNull&
OwningStringOrTestInterfaceJSOrNull::operator=(const OwningStringOrTestInterfaceJSOrNull& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eNull: {
MOZ_ASSERT(mType == eUninitialized);
mType = eNull;
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
case eTestInterfaceJS: {
SetAsTestInterfaceJS() = aOther.GetAsTestInterfaceJS();
break;
}
}
return *this;
}
bool
StringSequenceOrString::TrySetToStringSequence(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::AutoSequence<nsString>& memberSlot = RawSetAsStringSequence();
JS::ForOfIterator iter(cx);
if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
DestroyStringSequence();
tryNext = true;
return true;
}
binding_detail::AutoSequence<nsString> &arr = memberSlot;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
}
return true;
}
bool
StringSequenceOrString::TrySetToStringSequence(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToStringSequence(cx, value, tryNext, passedToJSImpl);
}
bool
StringSequenceOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
StringSequenceOrString::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToStringSequence(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "sequence<DOMString>");
return false;
}
return true;
}
bool
StringSequenceOrString::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
StringSequenceOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eStringSequence: {
uint32_t length = mValue.mStringSequence.Value().Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
rval.setObject(*returnArray);
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningStringSequenceOrString::OwningStringSequenceOrString(OwningStringSequenceOrString&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eStringSequence: {
mType = eStringSequence;
mValue.mStringSequence.SetValue(std::move(aOther.mValue.mStringSequence.Value()));
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
}
}
bool
OwningStringSequenceOrString::TrySetToStringSequence(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
Sequence<nsString>& memberSlot = RawSetAsStringSequence();
JS::ForOfIterator iter(cx);
if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
DestroyStringSequence();
tryNext = true;
return true;
}
Sequence<nsString> &arr = memberSlot;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
}
return true;
}
bool
OwningStringSequenceOrString::TrySetToStringSequence(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToStringSequence(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] Sequence<nsString>&
OwningStringSequenceOrString::RawSetAsStringSequence()
{
if (mType == eStringSequence) {
return mValue.mStringSequence.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eStringSequence;
return mValue.mStringSequence.SetValue();
}
[[nodiscard]] Sequence<nsString>&
OwningStringSequenceOrString::SetAsStringSequence()
{
if (mType == eStringSequence) {
return mValue.mStringSequence.Value();
}
Uninit();
mType = eStringSequence;
return mValue.mStringSequence.SetValue();
}
void
OwningStringSequenceOrString::DestroyStringSequence()
{
MOZ_RELEASE_ASSERT(IsStringSequence(), "Wrong type!");
mValue.mStringSequence.Destroy();
mType = eUninitialized;
}
bool
OwningStringSequenceOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningStringSequenceOrString::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningStringSequenceOrString::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningStringSequenceOrString::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningStringSequenceOrString::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToStringSequence(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "sequence<DOMString>");
return false;
}
return true;
}
bool
OwningStringSequenceOrString::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningStringSequenceOrString::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eStringSequence: {
DestroyStringSequence();
break;
}
case eString: {
DestroyString();
break;
}
}
}
bool
OwningStringSequenceOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eStringSequence: {
uint32_t length = mValue.mStringSequence.Value().Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
return false;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
return false;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
return false;
}
}
}
rval.setObject(*returnArray);
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningStringSequenceOrString&
OwningStringSequenceOrString::operator=(OwningStringSequenceOrString&& aOther)
{
this->~OwningStringSequenceOrString();
new (this) OwningStringSequenceOrString (std::move(aOther));
return *this;
}
OwningStringSequenceOrString&
OwningStringSequenceOrString::operator=(const OwningStringSequenceOrString& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eStringSequence: {
SetAsStringSequence() = aOther.GetAsStringSequence();
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
}
return *this;
}
bool
TestInterfaceJSOrLong::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
TestInterfaceJSOrLong::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
bool
TestInterfaceJSOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
int32_t& memberSlot = RawSetAsLong();
if (!ValueToPrimitive<int32_t, eDefault>(cx, value, "Long branch of (TestInterfaceJS or long)", &memberSlot)) {
return false;
}
}
return true;
}
bool
TestInterfaceJSOrLong::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
return true;
}
bool
TestInterfaceJSOrLong::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
TestInterfaceJSOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eLong: {
rval.setInt32(int32_t(mValue.mLong.Value()));
return true;
}
default: {
return false;
}
}
}
OwningTestInterfaceJSOrLong::OwningTestInterfaceJSOrLong(OwningTestInterfaceJSOrLong&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eTestInterfaceJS: {
mType = eTestInterfaceJS;
mValue.mTestInterfaceJS.SetValue(std::move(aOther.mValue.mTestInterfaceJS.Value()));
break;
}
case eLong: {
mType = eLong;
mValue.mLong.SetValue(std::move(aOther.mValue.mLong.Value()));
break;
}
}
}
bool
OwningTestInterfaceJSOrLong::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
static_assert(IsRefcounted<mozilla::dom::TestInterfaceJS>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningTestInterfaceJSOrLong::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningTestInterfaceJSOrLong::RawSetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningTestInterfaceJSOrLong::SetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
Uninit();
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
void
OwningTestInterfaceJSOrLong::DestroyTestInterfaceJS()
{
MOZ_RELEASE_ASSERT(IsTestInterfaceJS(), "Wrong type!");
mValue.mTestInterfaceJS.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
int32_t& memberSlot = RawSetAsLong();
if (!ValueToPrimitive<int32_t, eDefault>(cx, value, "Long branch of (TestInterfaceJS or long)", &memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] int32_t&
OwningTestInterfaceJSOrLong::RawSetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eLong;
return mValue.mLong.SetValue();
}
[[nodiscard]] int32_t&
OwningTestInterfaceJSOrLong::SetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
Uninit();
mType = eLong;
return mValue.mLong.SetValue();
}
void
OwningTestInterfaceJSOrLong::DestroyLong()
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
mValue.mLong.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSOrLong::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
return true;
}
bool
OwningTestInterfaceJSOrLong::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningTestInterfaceJSOrLong::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eTestInterfaceJS: {
DestroyTestInterfaceJS();
break;
}
case eLong: {
DestroyLong();
break;
}
}
}
bool
OwningTestInterfaceJSOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eLong: {
rval.setInt32(int32_t(mValue.mLong.Value()));
return true;
}
default: {
return false;
}
}
}
OwningTestInterfaceJSOrLong&
OwningTestInterfaceJSOrLong::operator=(OwningTestInterfaceJSOrLong&& aOther)
{
this->~OwningTestInterfaceJSOrLong();
new (this) OwningTestInterfaceJSOrLong (std::move(aOther));
return *this;
}
OwningTestInterfaceJSOrLong&
OwningTestInterfaceJSOrLong::operator=(const OwningTestInterfaceJSOrLong& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eTestInterfaceJS: {
SetAsTestInterfaceJS() = aOther.GetAsTestInterfaceJS();
break;
}
case eLong: {
SetAsLong() = aOther.GetAsLong();
break;
}
}
return *this;
}
bool
TestInterfaceJSOrNullOrString::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
TestInterfaceJSOrNullOrString::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
bool
TestInterfaceJSOrNullOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
TestInterfaceJSOrNullOrString::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isNullOrUndefined()) {
SetNull();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
}
return true;
}
bool
TestInterfaceJSOrNullOrString::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
TestInterfaceJSOrNullOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eNull: {
rval.setNull();
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningTestInterfaceJSOrNullOrString::OwningTestInterfaceJSOrNullOrString(OwningTestInterfaceJSOrNullOrString&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eNull: {
MOZ_ASSERT(mType == eUninitialized);
mType = eNull;
break;
}
case eTestInterfaceJS: {
mType = eTestInterfaceJS;
mValue.mTestInterfaceJS.SetValue(std::move(aOther.mValue.mTestInterfaceJS.Value()));
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
}
}
bool
OwningTestInterfaceJSOrNullOrString::TrySetToTestInterfaceJS(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::TestInterfaceJS>& memberSlot = RawSetAsTestInterfaceJS();
static_assert(IsRefcounted<mozilla::dom::TestInterfaceJS>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceJS, mozilla::dom::TestInterfaceJS>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyTestInterfaceJS();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningTestInterfaceJSOrNullOrString::TrySetToTestInterfaceJS(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningTestInterfaceJSOrNullOrString::RawSetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::TestInterfaceJS>&
OwningTestInterfaceJSOrNullOrString::SetAsTestInterfaceJS()
{
if (mType == eTestInterfaceJS) {
return mValue.mTestInterfaceJS.Value();
}
Uninit();
mType = eTestInterfaceJS;
return mValue.mTestInterfaceJS.SetValue();
}
void
OwningTestInterfaceJSOrNullOrString::DestroyTestInterfaceJS()
{
MOZ_RELEASE_ASSERT(IsTestInterfaceJS(), "Wrong type!");
mValue.mTestInterfaceJS.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSOrNullOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningTestInterfaceJSOrNullOrString::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningTestInterfaceJSOrNullOrString::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningTestInterfaceJSOrNullOrString::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSOrNullOrString::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isNullOrUndefined()) {
SetNull();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToTestInterfaceJS(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJS");
return false;
}
}
return true;
}
bool
OwningTestInterfaceJSOrNullOrString::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningTestInterfaceJSOrNullOrString::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eNull: {
break;
}
case eTestInterfaceJS: {
DestroyTestInterfaceJS();
break;
}
case eString: {
DestroyString();
break;
}
}
}
bool
OwningTestInterfaceJSOrNullOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eNull: {
rval.setNull();
return true;
}
case eTestInterfaceJS: {
if (!GetOrCreateDOMReflector(cx, mValue.mTestInterfaceJS.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eString: {
if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningTestInterfaceJSOrNullOrString&
OwningTestInterfaceJSOrNullOrString::operator=(OwningTestInterfaceJSOrNullOrString&& aOther)
{
this->~OwningTestInterfaceJSOrNullOrString();
new (this) OwningTestInterfaceJSOrNullOrString (std::move(aOther));
return *this;
}
OwningTestInterfaceJSOrNullOrString&
OwningTestInterfaceJSOrNullOrString::operator=(const OwningTestInterfaceJSOrNullOrString& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eNull: {
MOZ_ASSERT(mType == eUninitialized);
mType = eNull;
break;
}
case eTestInterfaceJS: {
SetAsTestInterfaceJS() = aOther.GetAsTestInterfaceJS();
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
}
return *this;
}
TestInterfaceJSUnionableDictionary::TestInterfaceJSUnionableDictionary()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
TestInterfaceJSUnionableDictionary::InitIds(JSContext* cx, TestInterfaceJSUnionableDictionaryAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->objectMember_id.init(cx, "objectMember") ||
!atomsCache->anyMember_id.init(cx, "anyMember")) {
return false;
}
return true;
}
bool
TestInterfaceJSUnionableDictionary::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
TestInterfaceJSUnionableDictionaryAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<TestInterfaceJSUnionableDictionaryAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->anyMember_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("'anyMember' member of TestInterfaceJSUnionableDictionary");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
mAnyMember = temp.ref();
} else {
mAnyMember = JS::UndefinedValue();
}
mIsAnyMemberPresent = true;
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->objectMember_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mObjectMember.Construct();
if (temp.ref().isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("'objectMember' member of TestInterfaceJSUnionableDictionary");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
(mObjectMember.Value()) = &temp.ref().toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'objectMember' member of TestInterfaceJSUnionableDictionary");
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
TestInterfaceJSUnionableDictionary::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
bool
TestInterfaceJSUnionableDictionary::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
{
TestInterfaceJSUnionableDictionaryAtoms* atomsCache = GetAtomCache<TestInterfaceJSUnionableDictionaryAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
if (!obj) {
return false;
}
rval.set(JS::ObjectValue(*obj));
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
JS::Value const & currentValue = mAnyMember;
JS::ExposeValueToActiveJS(currentValue);
temp.set(currentValue);
if (!MaybeWrapValue(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->anyMember_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
if (mObjectMember.WasPassed()) {
do {
// block for our 'break' successCode and scope for 'temp' and 'currentValue'
JS::Rooted<JS::Value> temp(cx);
JSObject* const & currentValue = mObjectMember.InternalValue();
JS::ExposeObjectToActiveJS(currentValue);
temp.setObject(*currentValue);
if (!MaybeWrapObjectValue(cx, &temp)) {
return false;
}
if (!JS_DefinePropertyById(cx, obj, atomsCache->objectMember_id, temp, JSPROP_ENUMERATE)) {
return false;
}
break;
} while(false);
}
return true;
}
void
TestInterfaceJSUnionableDictionary::TraceDictionary(JSTracer* trc)
{
JS::TraceRoot(trc, &mAnyMember, "TestInterfaceJSUnionableDictionary.mAnyMember");
if (mObjectMember.WasPassed()) {
JS::TraceRoot(trc, &mObjectMember.Value(), "TestInterfaceJSUnionableDictionary.mObjectMember");
}
}
bool
TestInterfaceJSUnionableDictionaryOrLong::TrySetToTestInterfaceJSUnionableDictionary(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
RootedDictionary<binding_detail::FastTestInterfaceJSUnionableDictionary>& memberSlot = RawSetAsTestInterfaceJSUnionableDictionary(cx);
if (!IsConvertibleToDictionary(value)) {
DestroyTestInterfaceJSUnionableDictionary();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "TestInterfaceJSUnionableDictionary branch of (TestInterfaceJSUnionableDictionary or long)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
TestInterfaceJSUnionableDictionaryOrLong::TrySetToTestInterfaceJSUnionableDictionary(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJSUnionableDictionary(cx, value, tryNext, passedToJSImpl);
}
bool
TestInterfaceJSUnionableDictionaryOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
int32_t& memberSlot = RawSetAsLong();
if (!ValueToPrimitive<int32_t, eDefault>(cx, value, "Long branch of (TestInterfaceJSUnionableDictionary or long)", &memberSlot)) {
return false;
}
}
return true;
}
bool
TestInterfaceJSUnionableDictionaryOrLong::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToTestInterfaceJSUnionableDictionary(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJSUnionableDictionary");
return false;
}
return true;
}
bool
TestInterfaceJSUnionableDictionaryOrLong::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
TestInterfaceJSUnionableDictionaryOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eTestInterfaceJSUnionableDictionary: {
if (!mValue.mTestInterfaceJSUnionableDictionary.Value().ToObjectInternal(cx, rval)) {
return false;
}
return true;
}
case eLong: {
rval.setInt32(int32_t(mValue.mLong.Value()));
return true;
}
default: {
return false;
}
}
}
OwningTestInterfaceJSUnionableDictionaryOrLong::OwningTestInterfaceJSUnionableDictionaryOrLong(OwningTestInterfaceJSUnionableDictionaryOrLong&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eTestInterfaceJSUnionableDictionary: {
mType = eTestInterfaceJSUnionableDictionary;
mValue.mTestInterfaceJSUnionableDictionary.SetValue(std::move(aOther.mValue.mTestInterfaceJSUnionableDictionary.Value()));
break;
}
case eLong: {
mType = eLong;
mValue.mLong.SetValue(std::move(aOther.mValue.mLong.Value()));
break;
}
}
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::TrySetToTestInterfaceJSUnionableDictionary(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
TestInterfaceJSUnionableDictionary& memberSlot = RawSetAsTestInterfaceJSUnionableDictionary();
if (!IsConvertibleToDictionary(value)) {
DestroyTestInterfaceJSUnionableDictionary();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "TestInterfaceJSUnionableDictionary branch of (TestInterfaceJSUnionableDictionary or long)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::TrySetToTestInterfaceJSUnionableDictionary(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToTestInterfaceJSUnionableDictionary(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] TestInterfaceJSUnionableDictionary&
OwningTestInterfaceJSUnionableDictionaryOrLong::RawSetAsTestInterfaceJSUnionableDictionary()
{
if (mType == eTestInterfaceJSUnionableDictionary) {
return mValue.mTestInterfaceJSUnionableDictionary.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eTestInterfaceJSUnionableDictionary;
return mValue.mTestInterfaceJSUnionableDictionary.SetValue();
}
[[nodiscard]] TestInterfaceJSUnionableDictionary&
OwningTestInterfaceJSUnionableDictionaryOrLong::SetAsTestInterfaceJSUnionableDictionary()
{
if (mType == eTestInterfaceJSUnionableDictionary) {
return mValue.mTestInterfaceJSUnionableDictionary.Value();
}
Uninit();
mType = eTestInterfaceJSUnionableDictionary;
return mValue.mTestInterfaceJSUnionableDictionary.SetValue();
}
void
OwningTestInterfaceJSUnionableDictionaryOrLong::DestroyTestInterfaceJSUnionableDictionary()
{
MOZ_RELEASE_ASSERT(IsTestInterfaceJSUnionableDictionary(), "Wrong type!");
mValue.mTestInterfaceJSUnionableDictionary.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
int32_t& memberSlot = RawSetAsLong();
if (!ValueToPrimitive<int32_t, eDefault>(cx, value, "Long branch of (TestInterfaceJSUnionableDictionary or long)", &memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] int32_t&
OwningTestInterfaceJSUnionableDictionaryOrLong::RawSetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eLong;
return mValue.mLong.SetValue();
}
[[nodiscard]] int32_t&
OwningTestInterfaceJSUnionableDictionaryOrLong::SetAsLong()
{
if (mType == eLong) {
return mValue.mLong.Value();
}
Uninit();
mType = eLong;
return mValue.mLong.SetValue();
}
void
OwningTestInterfaceJSUnionableDictionaryOrLong::DestroyLong()
{
MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!");
mValue.mLong.Destroy();
mType = eUninitialized;
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToTestInterfaceJSUnionableDictionary(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "TestInterfaceJSUnionableDictionary");
return false;
}
return true;
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningTestInterfaceJSUnionableDictionaryOrLong::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eTestInterfaceJSUnionableDictionary: {
DestroyTestInterfaceJSUnionableDictionary();
break;
}
case eLong: {
DestroyLong();
break;
}
}
}
bool
OwningTestInterfaceJSUnionableDictionaryOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eTestInterfaceJSUnionableDictionary: {
if (!mValue.mTestInterfaceJSUnionableDictionary.Value().ToObjectInternal(cx, rval)) {
return false;
}
return true;
}
case eLong: {
rval.setInt32(int32_t(mValue.mLong.Value()));
return true;
}
default: {
return false;
}
}
}
void
OwningTestInterfaceJSUnionableDictionaryOrLong::TraceUnion(JSTracer* trc)
{
switch (mType) {
case eTestInterfaceJSUnionableDictionary: {
mValue.mTestInterfaceJSUnionableDictionary.Value().TraceDictionary(trc);
break;
}
default: {
}
}
}
OwningTestInterfaceJSUnionableDictionaryOrLong&
OwningTestInterfaceJSUnionableDictionaryOrLong::operator=(OwningTestInterfaceJSUnionableDictionaryOrLong&& aOther)
{
this->~OwningTestInterfaceJSUnionableDictionaryOrLong();
new (this) OwningTestInterfaceJSUnionableDictionaryOrLong (std::move(aOther));
return *this;
}
namespace TestInterfaceJS_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
MOZ_CAN_RUN_SCRIPT static bool
get_anyArg(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "anyArg", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JS::Value> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAnyArg(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAnyArg(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.anyArg getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeValueToActiveJS(result);
args.rval().set(result);
if (!MaybeWrapValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo anyArg_getterinfo = {
{ get_anyArg },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_objectArg(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "objectArg", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetObjectArg(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetObjectArg(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.objectArg getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo objectArg_getterinfo = {
{ get_objectArg },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getDictionaryArg(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "getDictionaryArg", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
RootedDictionary<TestInterfaceJSDictionary> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetDictionaryArg(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetDictionaryArg(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.getDictionaryArg"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getDictionaryArg_methodinfo = {
{ (JSJitGetterOp)getDictionaryArg },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_anyAttr(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "anyAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JS::Value> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetAnyAttr(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetAnyAttr(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.anyAttr getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeValueToActiveJS(result);
args.rval().set(result);
if (!MaybeWrapValue(cx, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
set_anyAttr(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.anyAttr setter");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "anyAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
JS::Rooted<JS::Value> arg0(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("value being assigned");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = args[0];
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->SetAnyAttr(arg0, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->SetAnyAttr(arg0, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.anyAttr setter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return true;
}
static const JSJitInfo anyAttr_getterinfo = {
{ get_anyAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static const JSJitInfo anyAttr_setterinfo = {
{ (JSJitGetterOp)set_anyAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Setter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_objectAttr(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "objectAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetObjectAttr(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetObjectAttr(&result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.objectAttr getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapObjectValue(cx, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
set_objectAttr(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.objectAttr setter");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "objectAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
JS::Rooted<JSObject*> arg0(cx);
if (args[0].isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("value being assigned");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = &args[0].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Value being assigned");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->SetObjectAttr(arg0, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->SetObjectAttr(arg0, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.objectAttr setter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return true;
}
static const JSJitInfo objectAttr_getterinfo = {
{ get_objectAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static const JSJitInfo objectAttr_setterinfo = {
{ (JSJitGetterOp)set_objectAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Setter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getDictionaryAttr(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "getDictionaryAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
RootedDictionary<TestInterfaceJSDictionary> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetDictionaryAttr(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetDictionaryAttr(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.getDictionaryAttr"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getDictionaryAttr_methodinfo = {
{ (JSJitGetterOp)getDictionaryAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
setDictionaryAttr(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.setDictionaryAttr");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "setDictionaryAttr", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedDictionary<binding_detail::FastTestInterfaceJSDictionary> arg0(cx);
if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->SetDictionaryAttr(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->SetDictionaryAttr(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.setDictionaryAttr"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo setDictionaryAttr_methodinfo = {
{ (JSJitGetterOp)setDictionaryAttr },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongAny(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongAny");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongAny", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongAny", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
JS::Rooted<JS::Value> arg0(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = args[0];
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JS::Value> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongAny(arg0, &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongAny(arg0, &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongAny"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeValueToActiveJS(result);
args.rval().set(result);
if (!MaybeWrapValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongAny_methodinfo = {
{ (JSJitGetterOp)pingPongAny },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongObject(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongObject");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongObject", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongObject", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
JS::Rooted<JSObject*> arg0(cx);
if (args[0].isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = &args[0].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JSObject*> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongObject(arg0, &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongObject(arg0, &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongObject"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeObjectToActiveJS(result);
args.rval().setObject(*result);
if (!MaybeWrapObjectValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongObject_methodinfo = {
{ (JSJitGetterOp)pingPongObject },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongObjectOrString(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongObjectOrString");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongObjectOrString", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongObjectOrString", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
ObjectOrString arg0;
if (!arg0.Init(cx, args[0], "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
JS::Rooted<JS::Value> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongObjectOrString(Constify(arg0), &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongObjectOrString(Constify(arg0), &result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongObjectOrString"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
JS::ExposeValueToActiveJS(result);
args.rval().set(result);
if (!MaybeWrapValue(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongObjectOrString_methodinfo = {
{ (JSJitGetterOp)pingPongObjectOrString },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongDictionary(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongDictionary");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongDictionary", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedDictionary<binding_detail::FastTestInterfaceJSDictionary> arg0(cx);
if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
RootedDictionary<TestInterfaceJSDictionary> result(cx);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongDictionary(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongDictionary(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongDictionary"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToObjectInternal(cx, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongDictionary_methodinfo = {
{ (JSJitGetterOp)pingPongDictionary },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongDictionaryOrLong(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongDictionaryOrLong");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongDictionaryOrLong", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
TestInterfaceJSUnionableDictionaryOrLong arg0;
if (!(args.hasDefined(0))) {
if (!arg0.RawSetAsTestInterfaceJSUnionableDictionary(cx).Init(cx, JS::NullHandleValue, "Member of (TestInterfaceJSUnionableDictionary or long)")) {
return false;
}
} else {
if (!arg0.Init(cx, args[0], "Argument 1", true)) {
return false;
}
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
int32_t result(MOZ_KnownLive(self)->PingPongDictionaryOrLong(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongDictionaryOrLong"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setInt32(int32_t(result));
return true;
}
static const JSJitInfo pingPongDictionaryOrLong_methodinfo = {
{ (JSJitGetterOp)pingPongDictionaryOrLong },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongRecord(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongRecord");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongRecord", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongRecord", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
Record<nsString, JS::Value> arg0;
RecordRooter<nsString, JS::Value> arg0_holder(cx, &arg0);
if (args[0].isObject()) {
auto& recordEntries = arg0.Entries();
JS::Rooted<JSObject*> recordObj(cx, &args[0].toObject());
JS::RootedVector<jsid> ids(cx);
if (!js::GetPropertyKeys(cx, recordObj,
JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
return false;
}
if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}
JS::Rooted<JS::Value> propNameValue(cx);
JS::Rooted<JS::Value> temp(cx);
JS::Rooted<jsid> curId(cx);
JS::Rooted<JS::Value> idVal(cx);
// Use a hashset to keep track of ids seen, to avoid
// introducing nasty O(N^2) behavior scanning for them all the
// time. Ideally we'd use a data structure with O(1) lookup
// _and_ ordering for the MozMap, but we don't have one lying
// around.
nsTHashtable<nsStringHashKey> idsSeen;
for (size_t i = 0; i < ids.length(); ++i) {
curId = ids[i];
JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(cx);
if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
&desc)) {
return false;
}
if (desc.isNothing() || !desc->enumerable()) {
continue;
}
idVal = js::IdToValue(curId);
nsString propName;
// This will just throw if idVal is a Symbol, like the spec says
// to do.
if (!ConvertJSValueToString(cx, idVal, "key of argument 1", propName)) {
return false;
}
if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
return false;
}
Record<nsString, JS::Value>::EntryType* entry;
if (!idsSeen.EnsureInserted(propName)) {
// Find the existing entry.
auto idx = recordEntries.IndexOf(propName);
MOZ_ASSERT(idx != recordEntries.NoIndex,
"Why is it not found?");
// Now blow it away to make it look like it was just added
// to the array, because it's not obvious that it's
// safe to write to its already-initialized mValue via our
// normal codegen conversions. For example, the value
// could be a union and this would change its type, but
// codegen assumes we won't do that.
entry = recordEntries.ReconstructElementAt(idx);
} else {
// Safe to do an infallible append here, because we did a
// SetCapacity above to the right capacity.
entry = recordEntries.AppendElement();
}
entry->mKey = propName;
JS::Value& slot = entry->mValue;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(temp)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("value in argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
slot = temp;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
DOMString result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongRecord(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongRecord(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongRecord"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongRecord_methodinfo = {
{ (JSJitGetterOp)pingPongRecord },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
objectSequenceLength(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.objectSequenceLength");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "objectSequenceLength", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.objectSequenceLength", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
binding_detail::AutoSequence<JSObject*> arg0;
SequenceRooter<JSObject*> arg0_holder(cx, &arg0);
if (args[0].isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Argument 1", "sequence");
return false;
}
binding_detail::AutoSequence<JSObject*> &arr = arg0;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
JSObject** slotPtr = arr.AppendElement(nullptr, mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
JSObject*& slot = *slotPtr;
if (temp.isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(temp)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("element of argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
slot = &temp.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element of argument 1");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Argument 1", "sequence");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
int32_t result(MOZ_KnownLive(self)->ObjectSequenceLength(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.objectSequenceLength"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setInt32(int32_t(result));
return true;
}
static const JSJitInfo objectSequenceLength_methodinfo = {
{ (JSJitGetterOp)objectSequenceLength },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
anySequenceLength(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.anySequenceLength");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "anySequenceLength", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.anySequenceLength", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
binding_detail::AutoSequence<JS::Value> arg0;
SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
if (args[0].isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Argument 1", "sequence");
return false;
}
binding_detail::AutoSequence<JS::Value> &arr = arg0;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
JS::Value* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
JS::Value& slot = *slotPtr;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(temp)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("element of argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
slot = temp;
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Argument 1", "sequence");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
int32_t result(MOZ_KnownLive(self)->AnySequenceLength(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.anySequenceLength"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setInt32(int32_t(result));
return true;
}
static const JSJitInfo anySequenceLength_methodinfo = {
{ (JSJitGetterOp)anySequenceLength },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getCallerPrincipal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "getCallerPrincipal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
DOMString result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetCallerPrincipal(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->GetCallerPrincipal(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.getCallerPrincipal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getCallerPrincipal_methodinfo = {
{ (JSJitGetterOp)getCallerPrincipal },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
convertSVS(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "convertSVS", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.convertSVS", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
if (!NormalizeUSVString(arg0)) {
JS_ReportOutOfMemory(cx);
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
DOMString result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ConvertSVS(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->ConvertSVS(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.convertSVS"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo convertSVS_methodinfo = {
{ (JSJitGetterOp)convertSVS },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongUnion(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongUnion");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongUnion", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongUnion", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
TestInterfaceJSOrLong arg0;
if (!arg0.Init(cx, args[0], "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
OwningTestInterfaceJSOrLong result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongUnion(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongUnion(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongUnion"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToJSVal(cx, obj, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongUnion_methodinfo = {
{ (JSJitGetterOp)pingPongUnion },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongUnionContainingNull(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongUnionContainingNull");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongUnionContainingNull", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongUnionContainingNull", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
TestInterfaceJSOrNullOrString arg0;
if (!arg0.Init(cx, args[0], "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
OwningStringOrTestInterfaceJSOrNull result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongUnionContainingNull(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongUnionContainingNull(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongUnionContainingNull"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToJSVal(cx, obj, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongUnionContainingNull_methodinfo = {
{ (JSJitGetterOp)pingPongUnionContainingNull },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
pingPongNullableUnion(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.pingPongNullableUnion");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "pingPongNullableUnion", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.pingPongNullableUnion", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
Nullable<TestInterfaceJSOrLong > arg0;
if (args[0].isNullOrUndefined()) {
arg0.SetNull();
} else {
if (!arg0.SetValue().Init(cx, args[0], "Argument 1", true)) {
return false;
}
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
Nullable<OwningTestInterfaceJSOrLong> result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->PingPongNullableUnion(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->PingPongNullableUnion(Constify(arg0), result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.pingPongNullableUnion"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (result.IsNull()) {
args.rval().setNull();
return true;
}
if (!result.Value().ToJSVal(cx, obj, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo pingPongNullableUnion_methodinfo = {
{ (JSJitGetterOp)pingPongNullableUnion },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
returnBadUnion(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "returnBadUnion", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
OwningLocationOrTestInterfaceJS result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ReturnBadUnion(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->ReturnBadUnion(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.returnBadUnion"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToJSVal(cx, obj, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo returnBadUnion_methodinfo = {
{ (JSJitGetterOp)returnBadUnion },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testSequenceOverload(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testSequenceOverload");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testSequenceOverload", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
unsigned argcount = std::min(args.length(), 1u);
switch (argcount) {
case 1: {
if (args[0].isObject()) {
do {
binding_detail::AutoSequence<nsString> arg0;
JS::ForOfIterator iter(cx);
if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
break;
}
binding_detail::AutoSequence<nsString> &arr = arg0;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
nsString* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
nsString& slot = *slotPtr;
if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
return false;
}
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestSequenceOverload(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestSequenceOverload(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testSequenceOverload"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
} while (false);
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestSequenceOverload(NonNullHelper(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestSequenceOverload(NonNullHelper(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testSequenceOverload"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
break;
}
default: {
// Using nsPrintfCString here would require including that
// header. Let's not worry about it.
nsAutoCString argCountStr;
argCountStr.AppendPrintf("%u", args.length());
return cx.ThrowErrorMessage<MSG_INVALID_OVERLOAD_ARGCOUNT>(argCountStr.get());
}
}
MOZ_CRASH("We have an always-returning default case");
return false;
}
static const JSJitInfo testSequenceOverload_methodinfo = {
{ (JSJitGetterOp)testSequenceOverload },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testSequenceUnion(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testSequenceUnion");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testSequenceUnion", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.testSequenceUnion", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
StringSequenceOrString arg0;
if (!arg0.Init(cx, args[0], "Argument 1", true)) {
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestSequenceUnion(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestSequenceUnion(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testSequenceUnion"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testSequenceUnion_methodinfo = {
{ (JSJitGetterOp)testSequenceUnion },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowError(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowError", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowError(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowError(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowError"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowError_methodinfo = {
{ (JSJitGetterOp)testThrowError },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowDOMException(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowDOMException", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowDOMException(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowDOMException(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowDOMException"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowDOMException_methodinfo = {
{ (JSJitGetterOp)testThrowDOMException },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowTypeError(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowTypeError", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowTypeError(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowTypeError(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowTypeError"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowTypeError_methodinfo = {
{ (JSJitGetterOp)testThrowTypeError },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowCallbackError(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testThrowCallbackError");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowCallbackError", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.testThrowCallbackError", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedCallback<OwningNonNull<binding_detail::FastFunction>> arg0(cx);
if (args[0].isObject()) {
if (JS::IsCallable(&args[0].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg0 = new binding_detail::FastFunction(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 1");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowCallbackError(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowCallbackError(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowCallbackError"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowCallbackError_methodinfo = {
{ (JSJitGetterOp)testThrowCallbackError },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowXraySelfHosted(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowXraySelfHosted", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowXraySelfHosted(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowXraySelfHosted(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowXraySelfHosted"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowXraySelfHosted_methodinfo = {
{ (JSJitGetterOp)testThrowXraySelfHosted },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testThrowSelfHosted(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testThrowSelfHosted", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->TestThrowSelfHosted(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->TestThrowSelfHosted(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testThrowSelfHosted"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo testThrowSelfHosted_methodinfo = {
{ (JSJitGetterOp)testThrowSelfHosted },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromePromiseInit(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingChromePromiseInit", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingChromePromiseInit(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingChromePromiseInit"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromePromiseInit_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingChromePromiseInit(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingChromePromiseInit_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingChromePromiseInit_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentPromiseInit(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testPromiseWithThrowingContentPromiseInit");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingContentPromiseInit", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.testPromiseWithThrowingContentPromiseInit", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedCallback<OwningNonNull<binding_detail::FastFunction>> arg0(cx);
if (args[0].isObject()) {
if (JS::IsCallable(&args[0].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg0 = new binding_detail::FastFunction(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 1");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingContentPromiseInit(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingContentPromiseInit"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentPromiseInit_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingContentPromiseInit(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingContentPromiseInit_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingContentPromiseInit_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingPromiseInit(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithDOMExceptionThrowingPromiseInit", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithDOMExceptionThrowingPromiseInit(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingPromiseInit"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingPromiseInit_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithDOMExceptionThrowingPromiseInit(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithDOMExceptionThrowingPromiseInit_methodinfo = {
{ (JSJitGetterOp)testPromiseWithDOMExceptionThrowingPromiseInit_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromeThenFunction(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingChromeThenFunction", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingChromeThenFunction(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingChromeThenFunction"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromeThenFunction_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingChromeThenFunction(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingChromeThenFunction_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingChromeThenFunction_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentThenFunction(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testPromiseWithThrowingContentThenFunction");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingContentThenFunction", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.testPromiseWithThrowingContentThenFunction", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedCallback<OwningNonNull<binding_detail::FastAnyCallback>> arg0(cx);
if (args[0].isObject()) {
if (JS::IsCallable(&args[0].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg0 = new binding_detail::FastAnyCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 1");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingContentThenFunction(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingContentThenFunction"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentThenFunction_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingContentThenFunction(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingContentThenFunction_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingContentThenFunction_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingThenFunction(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithDOMExceptionThrowingThenFunction", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithDOMExceptionThrowingThenFunction(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenFunction"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingThenFunction_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithDOMExceptionThrowingThenFunction(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithDOMExceptionThrowingThenFunction_methodinfo = {
{ (JSJitGetterOp)testPromiseWithDOMExceptionThrowingThenFunction_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromeThenable(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingChromeThenable", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingChromeThenable(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingChromeThenable"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingChromeThenable_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingChromeThenable(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingChromeThenable_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingChromeThenable_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentThenable(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceJS.testPromiseWithThrowingContentThenable");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithThrowingContentThenable", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceJS.testPromiseWithThrowingContentThenable", 1)) {
return false;
}
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
JS::Rooted<JSObject*> arg0(cx);
if (args[0].isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = &args[0].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithThrowingContentThenable(arg0, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithThrowingContentThenable"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithThrowingContentThenable_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithThrowingContentThenable(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithThrowingContentThenable_methodinfo = {
{ (JSJitGetterOp)testPromiseWithThrowingContentThenable_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingThenable(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "testPromiseWithDOMExceptionThrowingThenable", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->TestPromiseWithDOMExceptionThrowingThenable(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenable"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
testPromiseWithDOMExceptionThrowingThenable_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = testPromiseWithDOMExceptionThrowingThenable(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo testPromiseWithDOMExceptionThrowingThenable_methodinfo = {
{ (JSJitGetterOp)testPromiseWithDOMExceptionThrowingThenable_promiseWrapper },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_onsomething(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "onsomething", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
RefPtr<EventHandlerNonNull> result(MOZ_KnownLive(self)->GetOnsomething(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.onsomething getter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (result) {
args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
return false;
}
return true;
} else {
args.rval().setNull();
return true;
}
}
MOZ_CAN_RUN_SCRIPT static bool
set_onsomething(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "onsomething", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceJS*>(void_self);
Maybe<JS::Rooted<JSObject*> > unwrappedObj;
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (objIsXray) {
unwrappedObj.emplace(cx, obj);
}
RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
if (args[0].isObject()) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
arg0 = nullptr;
}
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
unwrappedObj.ref() = js::CheckedUnwrapStatic(unwrappedObj.ref());
if (!unwrappedObj.ref()) {
return false;
}
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->SetOnsomething(MOZ_KnownLive(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))))>, "Should be returning void here");
MOZ_KnownLive(self)->SetOnsomething(MOZ_KnownLive(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS.onsomething setter"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return true;
}
static const JSJitInfo onsomething_getterinfo = {
{ get_onsomething },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static const JSJitInfo onsomething_setterinfo = {
{ (JSJitGetterOp)set_onsomething },
{ prototypes::id::TestInterfaceJS },
{ PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth },
JSJitInfo::Setter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestInterfaceJS* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceJS>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestInterfaceJS* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceJS>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestInterfaceJS>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestInterfaceJS* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceJS>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestInterfaceJS* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceJS>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestInterfaceJS::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("getDictionaryArg", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDictionaryArg_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getDictionaryAttr", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDictionaryAttr_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("setDictionaryAttr", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setDictionaryAttr_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongAny", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongAny_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongObject", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongObject_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongObjectOrString", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongObjectOrString_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongDictionary", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongDictionary_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongDictionaryOrLong", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongDictionaryOrLong_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongRecord", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongRecord_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectSequenceLength", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectSequenceLength_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("anySequenceLength", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&anySequenceLength_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getCallerPrincipal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getCallerPrincipal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("convertSVS", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&convertSVS_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongUnion", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongUnion_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongUnionContainingNull", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongUnionContainingNull_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("pingPongNullableUnion", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pingPongNullableUnion_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("returnBadUnion", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&returnBadUnion_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testSequenceOverload", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testSequenceOverload_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testSequenceUnion", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testSequenceUnion_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowError", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowError_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowDOMException", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowDOMException_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowTypeError", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowTypeError_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowCallbackError", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowCallbackError_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowXraySelfHosted", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowXraySelfHosted_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testThrowSelfHosted", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&testThrowSelfHosted_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingChromePromiseInit", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingChromePromiseInit_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingContentPromiseInit", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingContentPromiseInit_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithDOMExceptionThrowingPromiseInit", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithDOMExceptionThrowingPromiseInit_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingChromeThenFunction", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingChromeThenFunction_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingContentThenFunction", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingContentThenFunction_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithDOMExceptionThrowingThenFunction", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithDOMExceptionThrowingThenFunction_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingChromeThenable", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingChromeThenable_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithThrowingContentThenable", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithThrowingContentThenable_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("testPromiseWithDOMExceptionThrowingThenable", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&testPromiseWithDOMExceptionThrowingThenable_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ nullptr, &sMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(34 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("anyArg", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &anyArg_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("objectArg", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &objectArg_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("anyAttr", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &anyAttr_getterinfo, GenericSetter<NormalThisPolicy>, &anyAttr_setterinfo),
JSPropertySpec::nativeAccessors("objectAttr", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &objectAttr_getterinfo, GenericSetter<NormalThisPolicy>, &objectAttr_setterinfo),
JSPropertySpec::nativeAccessors("onsomething", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onsomething_getterinfo, GenericSetter<NormalThisPolicy>, &onsomething_setterinfo),
JS_PS_END
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ nullptr, &sAttributes_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sNativeProperties_sortedPropertyIndices[39];
static PropertyInfo sNativeProperties_propertyInfos[39];
static const NativePropertiesN<2> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
true, 1 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
39,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] },
{ sAttributes, &sNativeProperties_propertyInfos[34] }
}
};
static_assert(39 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestInterfaceJS,
constructors::id::TestInterfaceJS,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "TestInterfaceJS constructor");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceJS", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestInterfaceJS");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestInterfaceJS,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
JS::Rooted<JS::Value> arg0(cx);
if (args.hasDefined(0)) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[0])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("argument 1");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg0 = args[0];
} else {
arg0 = JS::UndefinedValue();
}
Optional<JS::Handle<JSObject*>> arg1;
if (args.hasDefined(1)) {
arg1.Construct(cx);
if (args[1].isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((true) && !CallerSubsumes(args[1])) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("argument 2");
return false;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
arg1.Value() = &args[1].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
}
RootedDictionary<binding_detail::FastTestInterfaceJSDictionary> arg2(cx);
if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3", true)) {
return false;
}
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
if (!JS_WrapValue(cx, &arg0)) {
return false;
}
if (arg1.WasPassed()) {
if (!JS_WrapObject(cx, &arg1.Value())) {
return false;
}
}
if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg2.mAnyMember))) {
return false;
}
if (arg2.mAnySequenceMember.WasPassed()) {
for (uint32_t indexName0 = 0; indexName0 < arg2.mAnySequenceMember.Value().Length(); ++indexName0) {
if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg2.mAnySequenceMember.Value()[indexName0]))) {
return false;
}
}
}
if (arg2.mInnerDictionary.WasPassed()) {
if (arg2.mInnerDictionary.Value().mInnerObject.WasPassed()) {
if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&arg2.mInnerDictionary.Value().mInnerObject.Value()))) {
return false;
}
}
}
if (arg2.mObjectMember.WasPassed()) {
if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&arg2.mObjectMember.Value()))) {
return false;
}
}
if (arg2.mObjectOrStringMember.WasPassed()) {
if (arg2.mObjectOrStringMember.Value().IsObject()) {
if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&arg2.mObjectOrStringMember.Value().GetAsObject()))) {
return false;
}
}
}
if (arg2.mObjectRecordMember.WasPassed()) {
for (auto& mapEntry0 : arg2.mObjectRecordMember.Value().Entries()) {
if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&mapEntry0.mValue))) {
return false;
}
}
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestInterfaceJS>(mozilla::dom::TestInterfaceJS::Constructor(global, cx, arg0, Constify(arg1), Constify(arg2), rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceJS constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
EventTarget_Binding::GetConstructorObject,
prototypes::id::TestInterfaceJS,
PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestInterfaceJSPrototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestInterfaceJS,
PrototypeTraits<prototypes::id::TestInterfaceJS>::Depth,
&sNativePropertyHooks,
EventTarget_Binding::GetProtoObject
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::dom_expose_test_interfaces();
}
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestInterfaceJS",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::EventTarget, prototypes::id::TestInterfaceJS, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestInterfaceJS>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestInterfaceJS>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestInterfaceJS>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestInterfaceJS* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestInterfaceJS>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestInterfaceJS*>);
MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
"Multiple inheritance for mozilla::dom::EventTarget is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestInterfaceJS> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestInterfaceJS);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestInterfaceJS);
JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
sChromeOnlyNativeProperties.Upcast(),
"TestInterfaceJS", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestInterfaceJS_Binding
void
TestInterfaceJSJSImpl::GetDictionaryArg(TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.getDictionaryArg", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->getDictionaryArg_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
TestInterfaceJSDictionary& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.getDictionaryArg", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::GetDictionaryAttr(TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.getDictionaryAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->getDictionaryAttr_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
TestInterfaceJSDictionary& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.getDictionaryAttr", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::SetDictionaryAttr(const TestInterfaceJSDictionary& dict, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.setDictionaryAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!dict.ToObjectInternal(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->setDictionaryAttr_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::PingPongAny(JS::Handle<JS::Value> arg, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongAny", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::ExposeValueToActiveJS(arg);
argv[0].set(arg);
if (!MaybeWrapValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongAny_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
JS::Rooted<JS::Value> rvalDecl(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.pingPongAny");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = rval;
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::PingPongObject(JS::Handle<JSObject*> obj, JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongObject", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::ExposeObjectToActiveJS(obj);
argv[0].setObject(*obj);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongObject_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
JS::Rooted<JSObject*> rvalDecl(cx);
if (rval.isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.pingPongObject");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = &rval.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Return value of TestInterfaceJS.pingPongObject");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::PingPongObjectOrString(const ObjectOrString& objOrString, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongObjectOrString", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (!objOrString.ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongObjectOrString_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
JS::Rooted<JS::Value> rvalDecl(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.pingPongObjectOrString");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = rval;
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::PingPongDictionary(const TestInterfaceJSDictionary& dict, TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongDictionary", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!dict.ToObjectInternal(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongDictionary_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
TestInterfaceJSDictionary& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.pingPongDictionary", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
int32_t
TestInterfaceJSJSImpl::PingPongDictionaryOrLong(const TestInterfaceJSUnionableDictionaryOrLong& dictOrLong, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongDictionaryOrLong", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return int32_t(0);
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return int32_t(0);
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (!dictOrLong.ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongDictionaryOrLong_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return int32_t(0);
}
int32_t rvalDecl;
if (!ValueToPrimitive<int32_t, eDefault>(cx, rval, "Return value of TestInterfaceJS.pingPongDictionaryOrLong", &rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
return rvalDecl;
}
void
TestInterfaceJSJSImpl::PingPongRecord(const Record<nsString, JS::Value>& rec, nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongRecord", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
if (!returnObj) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (auto& entry : rec.Entries()) {
auto& recordValue0 = entry.mValue;
// Control block to let us common up the JS_DefineUCProperty calls when there
// are different ways to succeed at wrapping the value.
do {
JS::ExposeValueToActiveJS(recordValue0);
tmp.set(recordValue0);
if (!MaybeWrapValue(cx, &tmp)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
if (!JS_DefineUCProperty(cx, returnObj,
entry.mKey.BeginReading(),
entry.mKey.Length(), tmp,
JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
}
argv[0].setObject(*returnObj);
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongRecord_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
binding_detail::FakeString<char16_t> rvalDecl;
if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal = rvalDecl;
}
int32_t
TestInterfaceJSJSImpl::ObjectSequenceLength(const Sequence<JSObject*>& seq, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.objectSequenceLength", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return int32_t(0);
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return int32_t(0);
}
unsigned argc = 1;
do {
uint32_t length = seq.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
JS::ExposeObjectToActiveJS(seq[sequenceIdx0]);
tmp.setObject(*seq[sequenceIdx0]);
if (!MaybeWrapObjectValue(cx, &tmp)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
}
}
argv[0].setObject(*returnArray);
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->objectSequenceLength_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return int32_t(0);
}
int32_t rvalDecl;
if (!ValueToPrimitive<int32_t, eDefault>(cx, rval, "Return value of TestInterfaceJS.objectSequenceLength", &rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
return rvalDecl;
}
int32_t
TestInterfaceJSJSImpl::AnySequenceLength(const Sequence<JS::Value>& seq, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.anySequenceLength", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return int32_t(0);
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return int32_t(0);
}
unsigned argc = 1;
do {
uint32_t length = seq.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
JS::ExposeValueToActiveJS(seq[sequenceIdx0]);
tmp.set(seq[sequenceIdx0]);
if (!MaybeWrapValue(cx, &tmp)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
}
}
argv[0].setObject(*returnArray);
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->anySequenceLength_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return int32_t(0);
}
int32_t rvalDecl;
if (!ValueToPrimitive<int32_t, eDefault>(cx, rval, "Return value of TestInterfaceJS.anySequenceLength", &rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return int32_t(0);
}
return rvalDecl;
}
void
TestInterfaceJSJSImpl::GetCallerPrincipal(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.getCallerPrincipal", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->getCallerPrincipal_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
binding_detail::FakeString<char16_t> rvalDecl;
if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal = rvalDecl;
}
void
TestInterfaceJSJSImpl::ConvertSVS(const nsAString& svs, nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.convertSVS", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!xpc::NonVoidStringToJsval(cx, svs, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->convertSVS_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
binding_detail::FakeString<char16_t> rvalDecl;
if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal = rvalDecl;
}
void
TestInterfaceJSJSImpl::PingPongUnion(const TestInterfaceJSOrLong& something, OwningTestInterfaceJSOrLong& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongUnion", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (!something.ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongUnion_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
OwningTestInterfaceJSOrLong& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.pingPongUnion", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::PingPongUnionContainingNull(const TestInterfaceJSOrNullOrString& something, OwningStringOrTestInterfaceJSOrNull& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongUnionContainingNull", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (!something.ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongUnionContainingNull_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
OwningStringOrTestInterfaceJSOrNull& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.pingPongUnionContainingNull", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::PingPongNullableUnion(const Nullable<TestInterfaceJSOrLong>& something, Nullable<OwningTestInterfaceJSOrLong>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.pingPongNullableUnion", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (something.IsNull()) {
argv[0].setNull();
break;
}
if (!something.Value().ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->pingPongNullableUnion_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
Nullable<OwningTestInterfaceJSOrLong >& rvalDecl(aRetVal);
if (rval.isNullOrUndefined()) {
rvalDecl.SetNull();
} else {
if (!rvalDecl.SetValue().Init(cx, rval, "Return value of TestInterfaceJS.pingPongNullableUnion", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
}
void
TestInterfaceJSJSImpl::ReturnBadUnion(OwningLocationOrTestInterfaceJS& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.returnBadUnion", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->returnBadUnion_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
OwningLocationOrTestInterfaceJS& rvalDecl(aRetVal);
if (!rvalDecl.Init(cx, rval, "Return value of TestInterfaceJS.returnBadUnion", false)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::TestSequenceOverload(const Sequence<nsString>& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testSequenceOverload", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
uint32_t length = arg.Length();
JS::Rooted<JSObject*> returnArray(cx, JS::NewArrayObject(cx, length));
if (!returnArray) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// Scope for 'tmp'
{
JS::Rooted<JS::Value> tmp(cx);
for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
// Control block to let us common up the JS_DefineElement calls when there
// are different ways to succeed at wrapping the object.
do {
if (!xpc::NonVoidStringToJsval(cx, arg[sequenceIdx0], &tmp)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
}
argv[0].setObject(*returnArray);
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testSequenceOverload_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestSequenceOverload(const nsAString& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testSequenceOverload", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!xpc::NonVoidStringToJsval(cx, arg, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testSequenceOverload_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestSequenceUnion(const StringSequenceOrString& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testSequenceUnion", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (!arg.ToJSVal(cx, callbackObj, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testSequenceUnion_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowError(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowError", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowError_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowDOMException(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowDOMException", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowDOMException_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowTypeError(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowTypeError", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowTypeError_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowCallbackError(Function& callback, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowCallbackError", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, callback));
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowCallbackError_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowXraySelfHosted(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowXraySelfHosted", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowXraySelfHosted_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
TestInterfaceJSJSImpl::TestThrowSelfHosted(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testThrowSelfHosted", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testThrowSelfHosted_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingChromePromiseInit(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingChromePromiseInit", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingChromePromiseInit_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromePromiseInit");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromePromiseInit");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingContentPromiseInit(Function& func, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingContentPromiseInit", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return nullptr;
}
unsigned argc = 1;
do {
argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, func));
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingContentPromiseInit_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentPromiseInit");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentPromiseInit");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithDOMExceptionThrowingPromiseInit(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingPromiseInit", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithDOMExceptionThrowingPromiseInit_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingPromiseInit");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingPromiseInit");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingChromeThenFunction(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingChromeThenFunction", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingChromeThenFunction_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromeThenFunction");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromeThenFunction");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingContentThenFunction(AnyCallback& func, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingContentThenFunction", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return nullptr;
}
unsigned argc = 1;
do {
argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, func));
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingContentThenFunction_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentThenFunction");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentThenFunction");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithDOMExceptionThrowingThenFunction(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenFunction", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithDOMExceptionThrowingThenFunction_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenFunction");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenFunction");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingChromeThenable(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingChromeThenable", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingChromeThenable_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromeThenable");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingChromeThenable");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithThrowingContentThenable(JS::Handle<JSObject*> thenable, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithThrowingContentThenable", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return nullptr;
}
unsigned argc = 1;
do {
JS::ExposeObjectToActiveJS(thenable);
argv[0].setObject(*thenable);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithThrowingContentThenable_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentThenable");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithThrowingContentThenable");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
already_AddRefed<Promise>
TestInterfaceJSJSImpl::TestPromiseWithDOMExceptionThrowingThenable(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenable", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->testPromiseWithDOMExceptionThrowingThenable_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
RefPtr<Promise> rvalDecl;
{ // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
// etc.
JS::Rooted<JSObject*> globalObj(cx);
if (!rval.isObject()) {
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenable");
return nullptr;
}
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&rval.toObject());
if (!unwrappedVal) {
// A slight lie, but not much of one, for a dead object wrapper.
aRv.ThrowTypeError<MSG_NOT_OBJECT>("return value of TestInterfaceJS.testPromiseWithDOMExceptionThrowingThenable");
return nullptr;
}
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
JSAutoRealm ar(cx, globalObj);
GlobalObject promiseGlobal(cx, globalObj);
if (promiseGlobal.Failed()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Rooted<JS::Value> valueToResolve(cx, rval);
if (!JS_WrapValue(cx, &valueToResolve)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
binding_detail::FastErrorResult promiseRv;
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(promiseGlobal.GetAsSupports());
if (!global) {
promiseRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
rvalDecl = Promise::Resolve(global, cx, valueToResolve,
promiseRv);
if (promiseRv.MaybeSetPendingException(cx)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
void
TestInterfaceJSJSImpl::__Init(JS::Handle<JS::Value> anyArg, const Optional<JS::Handle<JSObject*>>& objectArg, const TestInterfaceJSDictionary& dictionaryArg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(3)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 3;
do {
if (!dictionaryArg.ToObjectInternal(cx, argv[2])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
if (objectArg.WasPassed()) {
JS::ExposeObjectToActiveJS(objectArg.Value());
argv[1].setObject(*objectArg.Value());
if (!MaybeWrapObjectValue(cx, argv[1])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} else if (argc == 2) {
// This is our current trailing argument; reduce argc
--argc;
} else {
argv[1].setUndefined();
}
} while (false);
do {
JS::ExposeValueToActiveJS(anyArg);
argv[0].set(anyArg);
if (!MaybeWrapValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestInterfaceJSJSImpl::InitIds(JSContext* cx, TestInterfaceJSAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init") ||
!atomsCache->onsomething_id.init(cx, "onsomething") ||
!atomsCache->testPromiseWithDOMExceptionThrowingThenable_id.init(cx, "testPromiseWithDOMExceptionThrowingThenable") ||
!atomsCache->testPromiseWithThrowingContentThenable_id.init(cx, "testPromiseWithThrowingContentThenable") ||
!atomsCache->testPromiseWithThrowingChromeThenable_id.init(cx, "testPromiseWithThrowingChromeThenable") ||
!atomsCache->testPromiseWithDOMExceptionThrowingThenFunction_id.init(cx, "testPromiseWithDOMExceptionThrowingThenFunction") ||
!atomsCache->testPromiseWithThrowingContentThenFunction_id.init(cx, "testPromiseWithThrowingContentThenFunction") ||
!atomsCache->testPromiseWithThrowingChromeThenFunction_id.init(cx, "testPromiseWithThrowingChromeThenFunction") ||
!atomsCache->testPromiseWithDOMExceptionThrowingPromiseInit_id.init(cx, "testPromiseWithDOMExceptionThrowingPromiseInit") ||
!atomsCache->testPromiseWithThrowingContentPromiseInit_id.init(cx, "testPromiseWithThrowingContentPromiseInit") ||
!atomsCache->testPromiseWithThrowingChromePromiseInit_id.init(cx, "testPromiseWithThrowingChromePromiseInit") ||
!atomsCache->testThrowSelfHosted_id.init(cx, "testThrowSelfHosted") ||
!atomsCache->testThrowXraySelfHosted_id.init(cx, "testThrowXraySelfHosted") ||
!atomsCache->testThrowCallbackError_id.init(cx, "testThrowCallbackError") ||
!atomsCache->testThrowTypeError_id.init(cx, "testThrowTypeError") ||
!atomsCache->testThrowDOMException_id.init(cx, "testThrowDOMException") ||
!atomsCache->testThrowError_id.init(cx, "testThrowError") ||
!atomsCache->testSequenceUnion_id.init(cx, "testSequenceUnion") ||
!atomsCache->testSequenceOverload_id.init(cx, "testSequenceOverload") ||
!atomsCache->returnBadUnion_id.init(cx, "returnBadUnion") ||
!atomsCache->pingPongNullableUnion_id.init(cx, "pingPongNullableUnion") ||
!atomsCache->pingPongUnionContainingNull_id.init(cx, "pingPongUnionContainingNull") ||
!atomsCache->pingPongUnion_id.init(cx, "pingPongUnion") ||
!atomsCache->convertSVS_id.init(cx, "convertSVS") ||
!atomsCache->getCallerPrincipal_id.init(cx, "getCallerPrincipal") ||
!atomsCache->anySequenceLength_id.init(cx, "anySequenceLength") ||
!atomsCache->objectSequenceLength_id.init(cx, "objectSequenceLength") ||
!atomsCache->pingPongRecord_id.init(cx, "pingPongRecord") ||
!atomsCache->pingPongDictionaryOrLong_id.init(cx, "pingPongDictionaryOrLong") ||
!atomsCache->pingPongDictionary_id.init(cx, "pingPongDictionary") ||
!atomsCache->pingPongObjectOrString_id.init(cx, "pingPongObjectOrString") ||
!atomsCache->pingPongObject_id.init(cx, "pingPongObject") ||
!atomsCache->pingPongAny_id.init(cx, "pingPongAny") ||
!atomsCache->setDictionaryAttr_id.init(cx, "setDictionaryAttr") ||
!atomsCache->getDictionaryAttr_id.init(cx, "getDictionaryAttr") ||
!atomsCache->objectAttr_id.init(cx, "objectAttr") ||
!atomsCache->anyAttr_id.init(cx, "anyAttr") ||
!atomsCache->getDictionaryArg_id.init(cx, "getDictionaryArg") ||
!atomsCache->objectArg_id.init(cx, "objectArg") ||
!atomsCache->anyArg_id.init(cx, "anyArg")) {
return false;
}
return true;
}
void
TestInterfaceJSJSImpl::GetAnyArg(JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.anyArg", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JSObject *> callback(cx, mCallback);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid()
&& !InitIds(cx, atomsCache)) ||
!JS_GetPropertyById(cx, callback, atomsCache->anyArg_id, &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> rvalDecl(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.anyArg");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = rval;
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::GetObjectArg(JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.objectArg", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JSObject *> callback(cx, mCallback);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid()
&& !InitIds(cx, atomsCache)) ||
!JS_GetPropertyById(cx, callback, atomsCache->objectArg_id, &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JSObject*> rvalDecl(cx);
if (rval.isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.objectArg");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = &rval.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Return value of TestInterfaceJS.objectArg");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::GetAnyAttr(JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.anyAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JSObject *> callback(cx, mCallback);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid()
&& !InitIds(cx, atomsCache)) ||
!JS_GetPropertyById(cx, callback, atomsCache->anyAttr_id, &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> rvalDecl(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.anyAttr");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = rval;
aRetVal.set(rvalDecl);
}
void
TestInterfaceJSJSImpl::GetObjectAttr(JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.objectAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JSObject *> callback(cx, mCallback);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid()
&& !InitIds(cx, atomsCache)) ||
!JS_GetPropertyById(cx, callback, atomsCache->objectAttr_id, &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JSObject*> rvalDecl(cx);
if (rval.isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of TestInterfaceJS.objectAttr");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = &rval.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Return value of TestInterfaceJS.objectAttr");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal.set(rvalDecl);
}
already_AddRefed<EventHandlerNonNull>
TestInterfaceJSJSImpl::GetOnsomething(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.onsomething", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JSObject *> callback(cx, mCallback);
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid()
&& !InitIds(cx, atomsCache)) ||
!JS_GetPropertyById(cx, callback, atomsCache->onsomething_id, &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
RefPtr<EventHandlerNonNull> rvalDecl;
if (rval.isObject()) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
rvalDecl = nullptr;
}
return rvalDecl.forget();
}
void
TestInterfaceJSJSImpl::SetAnyAttr(JS::Handle<JS::Value> arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.anyAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
do {
JS::ExposeValueToActiveJS(arg);
argv[0].set(arg);
if (!MaybeWrapValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
MOZ_ASSERT(argv.length() == 1);
JS::Rooted<JSObject*> callback(cx, CallbackKnownNotGray());
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!JS_SetPropertyById(cx, callback, atomsCache->anyAttr_id, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::SetObjectAttr(JS::Handle<JSObject*> arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.objectAttr", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
do {
JS::ExposeObjectToActiveJS(arg);
argv[0].setObject(*arg);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
MOZ_ASSERT(argv.length() == 1);
JS::Rooted<JSObject*> callback(cx, CallbackKnownNotGray());
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!JS_SetPropertyById(cx, callback, atomsCache->objectAttr_id, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void
TestInterfaceJSJSImpl::SetOnsomething(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "TestInterfaceJS.onsomething", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
do {
if (arg) {
argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} else {
argv[0].setNull();
break;
}
} while (false);
MOZ_ASSERT(argv.length() == 1);
JS::Rooted<JSObject*> callback(cx, CallbackKnownNotGray());
TestInterfaceJSAtoms* atomsCache = GetAtomCache<TestInterfaceJSAtoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!JS_SetPropertyById(cx, callback, atomsCache->onsomething_id, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestInterfaceJS, mozilla::DOMEventTargetHelper, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestInterfaceJS, mozilla::DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TestInterfaceJS, mozilla::DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceJS)
NS_INTERFACE_MAP_END_INHERITING(mozilla::DOMEventTargetHelper)
TestInterfaceJS::TestInterfaceJS(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::DOMEventTargetHelper(aParent),
mImpl(new TestInterfaceJSJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestInterfaceJS::~TestInterfaceJS()
{
}
nsISupports*
TestInterfaceJS::GetParentObject() const
{
return mParent;
}
JSObject*
TestInterfaceJS::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestInterfaceJS_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestInterfaceJS>
TestInterfaceJS::Constructor(const GlobalObject& global, JSContext* cx, JS::Handle<JS::Value> anyArg, const Optional<JS::Handle<JSObject*>>& objectArg, const TestInterfaceJSDictionary& dictionaryArg, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestInterfaceJS> impl =
ConstructJSImplementation<TestInterfaceJS>("@mozilla.org/dom/test-interface-js;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// Wrap the object before calling __Init so that __DOM_IMPL__ is available.
JS::Rooted<JSObject*> scopeObj(cx, global.Get());
MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
JS::Rooted<JS::Value> wrappedVal(cx);
if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal, aGivenProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
// Initialize the object with the constructor arguments.
impl->mImpl->__Init(anyArg, objectArg, dictionaryArg, aRv, js::GetNonCCWObjectRealm(scopeObj));
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
void
TestInterfaceJS::GetAnyArg(JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
{
return mImpl->GetAnyArg(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::GetObjectArg(JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
{
return mImpl->GetObjectArg(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::GetDictionaryArg(TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->GetDictionaryArg(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::GetAnyAttr(JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
{
return mImpl->GetAnyAttr(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::SetAnyAttr(JS::Handle<JS::Value> arg, ErrorResult& aRv, JS::Realm* aRealm)
{
mImpl->SetAnyAttr(arg, aRv, aRealm);
}
void
TestInterfaceJS::GetObjectAttr(JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
{
return mImpl->GetObjectAttr(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::SetObjectAttr(JS::Handle<JSObject*> arg, ErrorResult& aRv, JS::Realm* aRealm)
{
mImpl->SetObjectAttr(arg, aRv, aRealm);
}
void
TestInterfaceJS::GetDictionaryAttr(TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->GetDictionaryAttr(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::SetDictionaryAttr(const TestInterfaceJSDictionary& dict, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->SetDictionaryAttr(dict, aRv, aRealm);
}
void
TestInterfaceJS::PingPongAny(JS::Handle<JS::Value> arg, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongAny(arg, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongObject(JS::Handle<JSObject*> obj, JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongObject(obj, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongObjectOrString(const ObjectOrString& objOrString, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongObjectOrString(objOrString, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongDictionary(const TestInterfaceJSDictionary& dict, TestInterfaceJSDictionary& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongDictionary(dict, aRetVal, aRv, aRealm);
}
int32_t
TestInterfaceJS::PingPongDictionaryOrLong(const TestInterfaceJSUnionableDictionaryOrLong& dictOrLong, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongDictionaryOrLong(dictOrLong, aRv, aRealm);
}
void
TestInterfaceJS::PingPongRecord(const Record<nsString, JS::Value>& rec, nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongRecord(rec, aRetVal, aRv, aRealm);
}
int32_t
TestInterfaceJS::ObjectSequenceLength(const Sequence<JSObject*>& seq, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->ObjectSequenceLength(seq, aRv, aRealm);
}
int32_t
TestInterfaceJS::AnySequenceLength(const Sequence<JS::Value>& seq, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->AnySequenceLength(seq, aRv, aRealm);
}
void
TestInterfaceJS::GetCallerPrincipal(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->GetCallerPrincipal(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::ConvertSVS(const nsAString& svs, nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->ConvertSVS(svs, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongUnion(const TestInterfaceJSOrLong& something, OwningTestInterfaceJSOrLong& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongUnion(something, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongUnionContainingNull(const TestInterfaceJSOrNullOrString& something, OwningStringOrTestInterfaceJSOrNull& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongUnionContainingNull(something, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::PingPongNullableUnion(const Nullable<TestInterfaceJSOrLong>& something, Nullable<OwningTestInterfaceJSOrLong>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->PingPongNullableUnion(something, aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::ReturnBadUnion(OwningLocationOrTestInterfaceJS& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->ReturnBadUnion(aRetVal, aRv, aRealm);
}
void
TestInterfaceJS::TestSequenceOverload(const Sequence<nsString>& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestSequenceOverload(arg, aRv, aRealm);
}
void
TestInterfaceJS::TestSequenceOverload(const nsAString& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestSequenceOverload(arg, aRv, aRealm);
}
void
TestInterfaceJS::TestSequenceUnion(const StringSequenceOrString& arg, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestSequenceUnion(arg, aRv, aRealm);
}
void
TestInterfaceJS::TestThrowError(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowError(aRv, aRealm);
}
void
TestInterfaceJS::TestThrowDOMException(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowDOMException(aRv, aRealm);
}
void
TestInterfaceJS::TestThrowTypeError(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowTypeError(aRv, aRealm);
}
void
TestInterfaceJS::TestThrowCallbackError(Function& callback, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowCallbackError(callback, aRv, aRealm);
}
void
TestInterfaceJS::TestThrowXraySelfHosted(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowXraySelfHosted(aRv, aRealm);
}
void
TestInterfaceJS::TestThrowSelfHosted(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestThrowSelfHosted(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingChromePromiseInit(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingChromePromiseInit(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingContentPromiseInit(Function& func, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingContentPromiseInit(func, aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithDOMExceptionThrowingPromiseInit(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithDOMExceptionThrowingPromiseInit(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingChromeThenFunction(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingChromeThenFunction(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingContentThenFunction(AnyCallback& func, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingContentThenFunction(func, aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithDOMExceptionThrowingThenFunction(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithDOMExceptionThrowingThenFunction(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingChromeThenable(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingChromeThenable(aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithThrowingContentThenable(JS::Handle<JSObject*> thenable, ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithThrowingContentThenable(thenable, aRv, aRealm);
}
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
already_AddRefed<Promise>
TestInterfaceJS::TestPromiseWithDOMExceptionThrowingThenable(ErrorResult& aRv, JS::Realm* aRealm)
{
return mImpl->TestPromiseWithDOMExceptionThrowingThenable(aRv, aRealm);
}
already_AddRefed<EventHandlerNonNull>
TestInterfaceJS::GetOnsomething(ErrorResult& aRv, JS::Realm* aRealm) const
{
return mImpl->GetOnsomething(aRv, aRealm);
}
void
TestInterfaceJS::SetOnsomething(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
{
mImpl->SetOnsomething(arg, aRv, aRealm);
}
bool
TestInterfaceJS::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestInterfaceJS._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestInterfaceJS._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestInterfaceJS> impl = new TestInterfaceJS(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
} // namespace mozilla::dom