Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM TestInterfaceObservableArray.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "MainThreadUtils.h"
#include "TestInterfaceObservableArrayBinding.h"
#include "WrapperFactory.h"
#include "XrayWrapper.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/NonRefcountedDOMObject.h"
#include "mozilla/dom/ObservableArrayProxyHandler.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TestInterfaceObservableArray.h"
#include "mozilla/dom/XrayExpandoClass.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
ObservableArrayCallbacks::ObservableArrayCallbacks()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
ObservableArrayCallbacks::InitIds(JSContext* cx, ObservableArrayCallbacksAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->setObjectCallback_id.init(cx, "setObjectCallback") ||
!atomsCache->setInterfaceCallback_id.init(cx, "setInterfaceCallback") ||
!atomsCache->setBooleanCallback_id.init(cx, "setBooleanCallback") ||
!atomsCache->deleteObjectCallback_id.init(cx, "deleteObjectCallback") ||
!atomsCache->deleteInterfaceCallback_id.init(cx, "deleteInterfaceCallback") ||
!atomsCache->deleteBooleanCallback_id.init(cx, "deleteBooleanCallback")) {
return false;
}
return true;
}
bool
ObservableArrayCallbacks::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());
ObservableArrayCallbacksAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<ObservableArrayCallbacksAtoms>(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->deleteBooleanCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mDeleteBooleanCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mDeleteBooleanCallback.Value()) = new SetDeleteBooleanCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'deleteBooleanCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'deleteBooleanCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->deleteInterfaceCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mDeleteInterfaceCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mDeleteInterfaceCallback.Value()) = new SetDeleteInterfaceCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'deleteInterfaceCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'deleteInterfaceCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->deleteObjectCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mDeleteObjectCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mDeleteObjectCallback.Value()) = new SetDeleteObjectCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'deleteObjectCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'deleteObjectCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->setBooleanCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mSetBooleanCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mSetBooleanCallback.Value()) = new SetDeleteBooleanCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'setBooleanCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'setBooleanCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->setInterfaceCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mSetInterfaceCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mSetInterfaceCallback.Value()) = new SetDeleteInterfaceCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'setInterfaceCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'setInterfaceCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->setObjectCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mSetObjectCallback.Construct();
if (temp.ref().isObject()) {
if (JS::IsCallable(&temp.ref().toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
(mSetObjectCallback.Value()) = new SetDeleteObjectCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'setObjectCallback' member of ObservableArrayCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'setObjectCallback' member of ObservableArrayCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
ObservableArrayCallbacks::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);
}
void
ObservableArrayCallbacks::TraceDictionary(JSTracer* trc)
{
}
MOZ_CAN_RUN_SCRIPT void
SetDeleteBooleanCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, bool value, uint32_t index, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(2)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 2;
do {
argv[1].setNumber(index);
break;
} while (false);
do {
argv[0].setBoolean(value);
break;
} while (false);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
MOZ_CAN_RUN_SCRIPT void
SetDeleteInterfaceCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, TestInterfaceObservableArray& value, uint32_t index, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(2)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 2;
do {
argv[1].setNumber(index);
break;
} while (false);
do {
if (!GetOrCreateDOMReflector(cx, value, argv[0])) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
MOZ_CAN_RUN_SCRIPT void
SetDeleteObjectCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, JS::Handle<JSObject*> value, uint32_t index, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(2)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 2;
do {
argv[1].setNumber(index);
break;
} while (false);
do {
JS::ExposeObjectToActiveJS(value);
argv[0].setObject(*value);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
namespace TestInterfaceObservableArray_Binding {
namespace ObservableArrayBoolean_Binding {
class ObservableArrayProxyHandler : public mozilla::dom::ObservableArrayProxyHandler
{
protected:
bool
OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const override;
bool
SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const override;
public:
static const ObservableArrayProxyHandler*
getInstance();
};
bool
ObservableArrayProxyHandler::OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
BindingCallContext cx(aCx, "ObservableArray OnDeleteItem");
bool decl;
if (!ValueToPrimitive<bool, eDefault>(cx, aValue, "Element in ObservableArray backing list", &decl)) {
MOZ_ASSERT_UNREACHABLE("The item in ObservableArray backing list is not Boolean?");
return false;
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnDeleteObservableArrayBoolean(decl, aIndex, rv);
return !rv.MaybeSetPendingException(cx);
}
bool
ObservableArrayProxyHandler::SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
uint32_t oldLen;
if (!JS::GetArrayLength(aCx, aBackingList, &oldLen)) {
return false;
}
if (aIndex > oldLen) {
return aResult.failBadIndex();
}
BindingCallContext cx(aCx, "ObservableArray SetIndexedValue");
bool decl;
if (!ValueToPrimitive<bool, eDefault>(cx, aValue, "Element in ObservableArray backing list", &decl)) {
return false;
}
if (aIndex < oldLen) {
JS::Rooted<JS::Value> value(aCx);
if (!JS_GetElement(aCx, aBackingList, aIndex, &value)) {
return false;
}
if (!OnDeleteItem(aCx, aProxy, value, aIndex)) {
return false;
}
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnSetObservableArrayBoolean(decl, aIndex, rv);
if (rv.MaybeSetPendingException(cx)) {
return false;
}
if (!JS_SetElement(aCx, aBackingList, aIndex, aValue)) {
return false;
}
return aResult.succeed();
}
const ObservableArrayProxyHandler*
ObservableArrayProxyHandler::getInstance()
{
static const ObservableArrayProxyHandler instance;
return &instance;
}
} // namespace ObservableArrayBoolean_Binding
namespace ObservableArrayBooleanHelpers {
bool
ElementAt(mozilla::dom::TestInterfaceObservableArray* self, uint32_t aIndex, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return bool(0);
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return bool(0);
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return bool(0);
}
if (created) {
PreserveWrapper(self);
}
JS::Rooted<JS::Value> result(cx);
aRv.MightThrowJSException();
if (!JS_GetElement(cx, backingObj, aIndex, &result)) {
aRv.StealExceptionFromJSContext(cx);
return bool(0);
}
if (result.isUndefined()) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return bool(0);
}
bool rvalDecl;
if (!ValueToPrimitive<bool, eDefault>(cx, result, "Return value of ElementAt", &rvalDecl)) {
aRv.NoteJSContextException(cx);
return bool(0);
}
return rvalDecl;
}
void
ReplaceElementAt(mozilla::dom::TestInterfaceObservableArray* self, uint32_t aIndex, bool aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
argv[0].setBoolean(aValue);
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (aIndex > length) {
aRv.ThrowRangeError("Invalid index");
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, aIndex, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
AppendElement(mozilla::dom::TestInterfaceObservableArray* self, bool aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
argv[0].setBoolean(aValue);
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, length, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
RemoveLastElement(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (length == 0) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
aRv.MightThrowJSException();
if (!JS::SetArrayLength(cx, backingObj, length - 1)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
uint32_t
Length(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
if (created) {
PreserveWrapper(self);
}
uint32_t retVal;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &retVal)) {
aRv.StealExceptionFromJSContext(cx);
return uint32_t(0);
}
return retVal;
}
} // namespace ObservableArrayBooleanHelpers
MOZ_CAN_RUN_SCRIPT static bool
get_observableArrayBoolean(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayBoolean", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setObject(*backingObj);
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
set_observableArrayBoolean(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.observableArrayBoolean setter");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayBoolean", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
binding_detail::AutoSequence<bool> 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>("Value being assigned", "observable array");
return false;
}
binding_detail::AutoSequence<bool> &arr = arg0;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
bool* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
bool& slot = *slotPtr;
if (!ValueToPrimitive<bool, eDefault>(cx, temp, "Element of value being assigned", &slot)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Value being assigned", "observable array");
return false;
}
if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
JS_ReportErrorASCII(cx, "Accessing from Xray wrapper is not supported.");
return false;
}
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 0),
&backingObj, &created, ObservableArrayBoolean_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
const ObservableArrayProxyHandler* handler = GetObservableArrayProxyHandler(backingObj);
if (!handler->SetLength(cx, backingObj, 0)) {
return false;
}
JS::Rooted<JS::Value> val(cx);
for (size_t i = 0; i < arg0.Length(); i++) {
val.setBoolean(arg0.ElementAt(i));
if (!JS_SetElement(cx, backingObj, i, val)) {
return false;
}
}
return true;
}
static const JSJitInfo observableArrayBoolean_getterinfo = {
{ get_observableArrayBoolean },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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. */
true, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
(DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */
};
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 4, "There is no slot for us");
static const JSJitInfo observableArrayBoolean_setterinfo = {
{ (JSJitGetterOp)set_observableArrayBoolean },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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. */
};
namespace ObservableArrayObject_Binding {
class ObservableArrayProxyHandler : public mozilla::dom::ObservableArrayProxyHandler
{
protected:
bool
OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const override;
bool
SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const override;
public:
static const ObservableArrayProxyHandler*
getInstance();
};
bool
ObservableArrayProxyHandler::OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
BindingCallContext cx(aCx, "ObservableArray OnDeleteItem");
JS::Rooted<JSObject*> decl(cx);
if (aValue.isObject()) {
decl = &aValue.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element in ObservableArray backing list");
MOZ_ASSERT_UNREACHABLE("The item in ObservableArray backing list is not Object?");
return false;
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnDeleteObservableArrayObject(cx, decl, aIndex, rv);
return !rv.MaybeSetPendingException(cx);
}
bool
ObservableArrayProxyHandler::SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
uint32_t oldLen;
if (!JS::GetArrayLength(aCx, aBackingList, &oldLen)) {
return false;
}
if (aIndex > oldLen) {
return aResult.failBadIndex();
}
BindingCallContext cx(aCx, "ObservableArray SetIndexedValue");
JS::Rooted<JSObject*> decl(cx);
if (aValue.isObject()) {
decl = &aValue.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element in ObservableArray backing list");
return false;
}
if (aIndex < oldLen) {
JS::Rooted<JS::Value> value(aCx);
if (!JS_GetElement(aCx, aBackingList, aIndex, &value)) {
return false;
}
if (!OnDeleteItem(aCx, aProxy, value, aIndex)) {
return false;
}
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnSetObservableArrayObject(cx, decl, aIndex, rv);
if (rv.MaybeSetPendingException(cx)) {
return false;
}
if (!JS_SetElement(aCx, aBackingList, aIndex, aValue)) {
return false;
}
return aResult.succeed();
}
const ObservableArrayProxyHandler*
ObservableArrayProxyHandler::getInstance()
{
static const ObservableArrayProxyHandler instance;
return &instance;
}
} // namespace ObservableArrayObject_Binding
namespace ObservableArrayObjectHelpers {
void
ElementAt(mozilla::dom::TestInterfaceObservableArray* self, JSContext* cx, uint32_t aIndex, JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv)
{
MOZ_ASSERT(self);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JS::Rooted<JS::Value> result(cx);
{
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
aRv.MightThrowJSException();
if (!JS_GetElement(cx, backingObj, aIndex, &result)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (result.isUndefined()) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
}
if (!JS_WrapValue(cx, &result)) {
aRv.NoteJSContextException(cx);
return;
}
JS::Rooted<JSObject*> rvalDecl(cx);
rvalDecl = &result.toObject();
aRetVal.set(rvalDecl);
}
void
ReplaceElementAt(mozilla::dom::TestInterfaceObservableArray* self, uint32_t aIndex, JS::Handle<JSObject*> aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
JS::ExposeObjectToActiveJS(aValue);
argv[0].setObject(*aValue);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (aIndex > length) {
aRv.ThrowRangeError("Invalid index");
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, aIndex, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
AppendElement(mozilla::dom::TestInterfaceObservableArray* self, JS::Handle<JSObject*> aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
JS::ExposeObjectToActiveJS(aValue);
argv[0].setObject(*aValue);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, length, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
RemoveLastElement(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (length == 0) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
aRv.MightThrowJSException();
if (!JS::SetArrayLength(cx, backingObj, length - 1)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
uint32_t
Length(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
if (created) {
PreserveWrapper(self);
}
uint32_t retVal;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &retVal)) {
aRv.StealExceptionFromJSContext(cx);
return uint32_t(0);
}
return retVal;
}
} // namespace ObservableArrayObjectHelpers
MOZ_CAN_RUN_SCRIPT static bool
get_observableArrayObject(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayObject", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setObject(*backingObj);
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
set_observableArrayObject(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.observableArrayObject setter");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayObject", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
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>("Value being assigned", "observable array");
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()) {
slot = &temp.toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element of value being assigned");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Value being assigned", "observable array");
return false;
}
if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
JS_ReportErrorASCII(cx, "Accessing from Xray wrapper is not supported.");
return false;
}
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 1),
&backingObj, &created, ObservableArrayObject_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
const ObservableArrayProxyHandler* handler = GetObservableArrayProxyHandler(backingObj);
if (!handler->SetLength(cx, backingObj, 0)) {
return false;
}
JS::Rooted<JS::Value> val(cx);
for (size_t i = 0; i < arg0.Length(); i++) {
JS::ExposeObjectToActiveJS(arg0.ElementAt(i));
val.setObject(*arg0.ElementAt(i));
if (!MaybeWrapObjectValue(cx, &val)) {
return false;
}
if (!JS_SetElement(cx, backingObj, i, val)) {
return false;
}
}
return true;
}
static const JSJitInfo observableArrayObject_getterinfo = {
{ get_observableArrayObject },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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. */
true, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
(DOM_INSTANCE_RESERVED_SLOTS + 1) /* Reserved slot index, if we're stored in a slot, else 0. */
};
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) <= JSJitInfo::maxSlotIndex, "We won't fit");
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) < 4, "There is no slot for us");
static const JSJitInfo observableArrayObject_setterinfo = {
{ (JSJitGetterOp)set_observableArrayObject },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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. */
};
namespace ObservableArrayInterface_Binding {
class ObservableArrayProxyHandler : public mozilla::dom::ObservableArrayProxyHandler
{
protected:
bool
OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const override;
bool
SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const override;
public:
static const ObservableArrayProxyHandler*
getInstance();
};
bool
ObservableArrayProxyHandler::OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JS::Value> aValue, uint32_t aIndex) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
BindingCallContext cx(aCx, "ObservableArray OnDeleteItem");
NonNull<mozilla::dom::TestInterfaceObservableArray> decl;
if (aValue.isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(aValue, decl, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Element in ObservableArray backing list", "TestInterfaceObservableArray");
MOZ_ASSERT_UNREACHABLE("The item in ObservableArray backing list is not TestInterfaceObservableArray (Wrapper)?");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element in ObservableArray backing list");
MOZ_ASSERT_UNREACHABLE("The item in ObservableArray backing list is not TestInterfaceObservableArray (Wrapper)?");
return false;
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnDeleteObservableArrayInterface(decl, aIndex, rv);
return !rv.MaybeSetPendingException(cx);
}
bool
ObservableArrayProxyHandler::SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<JSObject*> aBackingList, uint32_t aIndex, JS::Handle<JS::Value> aValue, JS::ObjectOpResult& aResult) const
{
MOZ_ASSERT(IsObservableArrayProxy(aProxy));
uint32_t oldLen;
if (!JS::GetArrayLength(aCx, aBackingList, &oldLen)) {
return false;
}
if (aIndex > oldLen) {
return aResult.failBadIndex();
}
BindingCallContext cx(aCx, "ObservableArray SetIndexedValue");
NonNull<mozilla::dom::TestInterfaceObservableArray> decl;
if (aValue.isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(aValue, decl, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Element in ObservableArray backing list", "TestInterfaceObservableArray");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element in ObservableArray backing list");
return false;
}
if (aIndex < oldLen) {
JS::Rooted<JS::Value> value(aCx);
if (!JS_GetElement(aCx, aBackingList, aIndex, &value)) {
return false;
}
if (!OnDeleteItem(aCx, aProxy, value, aIndex)) {
return false;
}
}
JS::Value val = js::GetProxyReservedSlot(aProxy, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT);
auto* interface = static_cast<mozilla::dom::TestInterfaceObservableArray*>(val.toPrivate());
MOZ_ASSERT(interface);
ErrorResult rv;
MOZ_KnownLive(interface)->OnSetObservableArrayInterface(decl, aIndex, rv);
if (rv.MaybeSetPendingException(cx)) {
return false;
}
if (!JS_SetElement(aCx, aBackingList, aIndex, aValue)) {
return false;
}
return aResult.succeed();
}
const ObservableArrayProxyHandler*
ObservableArrayProxyHandler::getInstance()
{
static const ObservableArrayProxyHandler instance;
return &instance;
}
} // namespace ObservableArrayInterface_Binding
namespace ObservableArrayInterfaceHelpers {
already_AddRefed<TestInterfaceObservableArray>
ElementAt(mozilla::dom::TestInterfaceObservableArray* self, uint32_t aIndex, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (created) {
PreserveWrapper(self);
}
JS::Rooted<JS::Value> result(cx);
aRv.MightThrowJSException();
if (!JS_GetElement(cx, backingObj, aIndex, &result)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
if (result.isUndefined()) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return nullptr;
}
RefPtr<mozilla::dom::TestInterfaceObservableArray> rvalDecl;
static_assert(IsRefcounted<mozilla::dom::TestInterfaceObservableArray>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(result, rvalDecl, cx);
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
void
ReplaceElementAt(mozilla::dom::TestInterfaceObservableArray* self, uint32_t aIndex, TestInterfaceObservableArray& aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
if (!GetOrCreateDOMReflector(cx, aValue, argv[0])) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (aIndex > length) {
aRv.ThrowRangeError("Invalid index");
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, aIndex, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
AppendElement(mozilla::dom::TestInterfaceObservableArray* self, TestInterfaceObservableArray& aValue, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
do {
if (!GetOrCreateDOMReflector(cx, aValue, argv[0])) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
aRv.MightThrowJSException();
if (!JS_SetElement(cx, backingObj, length, argv[0])) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
void
RemoveLastElement(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
if (created) {
PreserveWrapper(self);
}
uint32_t length;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &length)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
if (length == 0) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
aRv.MightThrowJSException();
if (!JS::SetArrayLength(cx, backingObj, length - 1)) {
aRv.StealExceptionFromJSContext(cx);
return;
}
}
uint32_t
Length(mozilla::dom::TestInterfaceObservableArray* self, ErrorResult& aRv)
{
MOZ_ASSERT(self);
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
// It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here because
// all we want is to wrap into _some_ scope and then unwrap to find
// the reflector, and wrapping has no side-effects.
JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
if (!scope) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
JSAutoRealm tempRealm(cx, scope);
JS::Rooted<JS::Value> v(cx);
if(!ToJSValue(cx, self, &v)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
// This is a reflector, but due to trying to name things
// similarly across method generators, it's called obj here.
JS::Rooted<JSObject*> obj(cx);
obj = js::UncheckedUnwrap(&v.toObject(), /* stopAtWindowProxy = */ false);
JSAutoRealm reflectorRealm(cx, obj);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return uint32_t(0);
}
if (created) {
PreserveWrapper(self);
}
uint32_t retVal;
aRv.MightThrowJSException();
if (!JS::GetArrayLength(cx, backingObj, &retVal)) {
aRv.StealExceptionFromJSContext(cx);
return uint32_t(0);
}
return retVal;
}
} // namespace ObservableArrayInterfaceHelpers
MOZ_CAN_RUN_SCRIPT static bool
get_observableArrayInterface(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayInterface", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setObject(*backingObj);
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
set_observableArrayInterface(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, JSJitSetterCallArgs args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.observableArrayInterface setter");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "observableArrayInterface", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
binding_detail::AutoSequence<OwningNonNull<mozilla::dom::TestInterfaceObservableArray>> 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>("Value being assigned", "observable array");
return false;
}
binding_detail::AutoSequence<OwningNonNull<mozilla::dom::TestInterfaceObservableArray>> &arr = arg0;
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningNonNull<mozilla::dom::TestInterfaceObservableArray>* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningNonNull<mozilla::dom::TestInterfaceObservableArray>& slot = *slotPtr;
if (temp.isObject()) {
static_assert(IsRefcounted<mozilla::dom::TestInterfaceObservableArray>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(&temp, slot, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Element of value being assigned", "TestInterfaceObservableArray");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Element of value being assigned");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("Value being assigned", "observable array");
return false;
}
if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
JS_ReportErrorASCII(cx, "Accessing from Xray wrapper is not supported.");
return false;
}
JS::Rooted<JSObject*> backingObj(cx);
bool created = false;
if (!GetObservableArrayBackingObject(cx, obj, (DOM_INSTANCE_RESERVED_SLOTS + 2),
&backingObj, &created, ObservableArrayInterface_Binding::ObservableArrayProxyHandler::getInstance(),
self)) {
return false;
}
if (created) {
PreserveWrapper(self);
}
const ObservableArrayProxyHandler* handler = GetObservableArrayProxyHandler(backingObj);
if (!handler->SetLength(cx, backingObj, 0)) {
return false;
}
JS::Rooted<JS::Value> val(cx);
for (size_t i = 0; i < arg0.Length(); i++) {
if (!GetOrCreateDOMReflector(cx, arg0.ElementAt(i), &val)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
if (!JS_SetElement(cx, backingObj, i, val)) {
return false;
}
}
return true;
}
static const JSJitInfo observableArrayInterface_getterinfo = {
{ get_observableArrayInterface },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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. */
true, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
(DOM_INSTANCE_RESERVED_SLOTS + 2) /* Reserved slot index, if we're stored in a slot, else 0. */
};
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) <= JSJitInfo::maxSlotIndex, "We won't fit");
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) < 4, "There is no slot for us");
static const JSJitInfo observableArrayInterface_setterinfo = {
{ (JSJitGetterOp)set_observableArrayInterface },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
booleanElementAtInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "booleanElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.booleanElementAtInternal", 1)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
FastErrorResult rv;
bool result(MOZ_KnownLive(self)->BooleanElementAtInternal(arg0, rv));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.booleanElementAtInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setBoolean(result);
return true;
}
static const JSJitInfo booleanElementAtInternal_methodinfo = {
{ (JSJitGetterOp)booleanElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_BOOLEAN, /* 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
interfaceElementAtInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "interfaceElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.interfaceElementAtInternal", 1)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestInterfaceObservableArray>(MOZ_KnownLive(self)->InterfaceElementAtInternal(arg0, rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.interfaceElementAtInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo interfaceElementAtInternal_methodinfo = {
{ (JSJitGetterOp)interfaceElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
objectElementAtInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "objectElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.objectElementAtInternal", 1)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
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)->ObjectElementAtInternal(cx, arg0, &result, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->ObjectElementAtInternal(cx, arg0, &result, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.objectElementAtInternal"))) {
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 objectElementAtInternal_methodinfo = {
{ (JSJitGetterOp)objectElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
booleanReplaceElementAtInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "booleanReplaceElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.booleanReplaceElementAtInternal", 2)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
bool arg1;
if (!ValueToPrimitive<bool, eDefault>(cx, args[1], "Argument 2", &arg1)) {
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->BooleanReplaceElementAtInternal(arg0, arg1, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->BooleanReplaceElementAtInternal(arg0, arg1, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.booleanReplaceElementAtInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo booleanReplaceElementAtInternal_methodinfo = {
{ (JSJitGetterOp)booleanReplaceElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
interfaceReplaceElementAtInternal(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.interfaceReplaceElementAtInternal");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "interfaceReplaceElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.interfaceReplaceElementAtInternal", 2)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
NonNull<mozilla::dom::TestInterfaceObservableArray> arg1;
if (args[1].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(args[1], arg1, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 2", "TestInterfaceObservableArray");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->InterfaceReplaceElementAtInternal(arg0, MOZ_KnownLive(NonNullHelper(arg1)), rv))>, "Should be returning void here");
MOZ_KnownLive(self)->InterfaceReplaceElementAtInternal(arg0, MOZ_KnownLive(NonNullHelper(arg1)), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.interfaceReplaceElementAtInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo interfaceReplaceElementAtInternal_methodinfo = {
{ (JSJitGetterOp)interfaceReplaceElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
objectReplaceElementAtInternal(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.objectReplaceElementAtInternal");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "objectReplaceElementAtInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.objectReplaceElementAtInternal", 2)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
JS::Rooted<JSObject*> arg1(cx);
if (args[1].isObject()) {
arg1 = &args[1].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ObjectReplaceElementAtInternal(cx, arg0, arg1, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->ObjectReplaceElementAtInternal(cx, arg0, arg1, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.objectReplaceElementAtInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo objectReplaceElementAtInternal_methodinfo = {
{ (JSJitGetterOp)objectReplaceElementAtInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
booleanAppendElementInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "booleanAppendElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.booleanAppendElementInternal", 1)) {
return false;
}
bool arg0;
if (!ValueToPrimitive<bool, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->BooleanAppendElementInternal(arg0, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->BooleanAppendElementInternal(arg0, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.booleanAppendElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo booleanAppendElementInternal_methodinfo = {
{ (JSJitGetterOp)booleanAppendElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
interfaceAppendElementInternal(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.interfaceAppendElementInternal");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "interfaceAppendElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.interfaceAppendElementInternal", 1)) {
return false;
}
NonNull<mozilla::dom::TestInterfaceObservableArray> arg0;
if (args[0].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::TestInterfaceObservableArray, mozilla::dom::TestInterfaceObservableArray>(args[0], arg0, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 1", "TestInterfaceObservableArray");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->InterfaceAppendElementInternal(MOZ_KnownLive(NonNullHelper(arg0)), rv))>, "Should be returning void here");
MOZ_KnownLive(self)->InterfaceAppendElementInternal(MOZ_KnownLive(NonNullHelper(arg0)), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.interfaceAppendElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo interfaceAppendElementInternal_methodinfo = {
{ (JSJitGetterOp)interfaceAppendElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
objectAppendElementInternal(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray.objectAppendElementInternal");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "objectAppendElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
if (!args.requireAtLeast(cx, "TestInterfaceObservableArray.objectAppendElementInternal", 1)) {
return false;
}
JS::Rooted<JSObject*> arg0(cx);
if (args[0].isObject()) {
arg0 = &args[0].toObject();
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ObjectAppendElementInternal(cx, arg0, rv))>, "Should be returning void here");
MOZ_KnownLive(self)->ObjectAppendElementInternal(cx, arg0, rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.objectAppendElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo objectAppendElementInternal_methodinfo = {
{ (JSJitGetterOp)objectAppendElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
booleanRemoveLastElementInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "booleanRemoveLastElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->BooleanRemoveLastElementInternal(rv))>, "Should be returning void here");
MOZ_KnownLive(self)->BooleanRemoveLastElementInternal(rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.booleanRemoveLastElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo booleanRemoveLastElementInternal_methodinfo = {
{ (JSJitGetterOp)booleanRemoveLastElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
interfaceRemoveLastElementInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "interfaceRemoveLastElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->InterfaceRemoveLastElementInternal(rv))>, "Should be returning void here");
MOZ_KnownLive(self)->InterfaceRemoveLastElementInternal(rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.interfaceRemoveLastElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo interfaceRemoveLastElementInternal_methodinfo = {
{ (JSJitGetterOp)interfaceRemoveLastElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
objectRemoveLastElementInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "objectRemoveLastElementInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->ObjectRemoveLastElementInternal(rv))>, "Should be returning void here");
MOZ_KnownLive(self)->ObjectRemoveLastElementInternal(rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.objectRemoveLastElementInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo objectRemoveLastElementInternal_methodinfo = {
{ (JSJitGetterOp)objectRemoveLastElementInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::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
booleanLengthInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "booleanLengthInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
uint32_t result(MOZ_KnownLive(self)->BooleanLengthInternal(rv));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.booleanLengthInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setNumber(result);
return true;
}
static const JSJitInfo booleanLengthInternal_methodinfo = {
{ (JSJitGetterOp)booleanLengthInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* 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
interfaceLengthInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "interfaceLengthInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
uint32_t result(MOZ_KnownLive(self)->InterfaceLengthInternal(rv));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.interfaceLengthInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setNumber(result);
return true;
}
static const JSJitInfo interfaceLengthInternal_methodinfo = {
{ (JSJitGetterOp)interfaceLengthInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* 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
objectLengthInternal(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "objectLengthInternal", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::TestInterfaceObservableArray*>(void_self);
FastErrorResult rv;
uint32_t result(MOZ_KnownLive(self)->ObjectLengthInternal(rv));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray.objectLengthInternal"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setNumber(result);
return true;
}
static const JSJitInfo objectLengthInternal_methodinfo = {
{ (JSJitGetterOp)objectLengthInternal },
{ prototypes::id::TestInterfaceObservableArray },
{ PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* 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::TestInterfaceObservableArray* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceObservableArray>(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::TestInterfaceObservableArray* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceObservableArray>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
{
JS::Value val = JS::GetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0));
if (!val.isUndefined()) {
JSObject* obj = &val.toObject();
js::SetProxyReservedSlot(obj, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT, JS::UndefinedValue());
}
}
{
JS::Value val = JS::GetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 1));
if (!val.isUndefined()) {
JSObject* obj = &val.toObject();
js::SetProxyReservedSlot(obj, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT, JS::UndefinedValue());
}
}
{
JS::Value val = JS::GetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 2));
if (!val.isUndefined()) {
JSObject* obj = &val.toObject();
js::SetProxyReservedSlot(obj, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT, JS::UndefinedValue());
}
}
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestInterfaceObservableArray>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestInterfaceObservableArray* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceObservableArray>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestInterfaceObservableArray* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestInterfaceObservableArray>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("booleanElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&booleanElementAtInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("interfaceElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&interfaceElementAtInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectElementAtInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("booleanReplaceElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&booleanReplaceElementAtInternal_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("interfaceReplaceElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&interfaceReplaceElementAtInternal_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectReplaceElementAtInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectReplaceElementAtInternal_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("booleanAppendElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&booleanAppendElementInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("interfaceAppendElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&interfaceAppendElementInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectAppendElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectAppendElementInternal_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("booleanRemoveLastElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&booleanRemoveLastElementInternal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("interfaceRemoveLastElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&interfaceRemoveLastElementInternal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectRemoveLastElementInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectRemoveLastElementInternal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("booleanLengthInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&booleanLengthInternal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("interfaceLengthInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&interfaceLengthInternal_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("objectLengthInternal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&objectLengthInternal_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(15 <= 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("observableArrayBoolean", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &observableArrayBoolean_getterinfo, GenericSetter<NormalThisPolicy>, &observableArrayBoolean_setterinfo),
JSPropertySpec::nativeAccessors("observableArrayObject", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &observableArrayObject_getterinfo, GenericSetter<NormalThisPolicy>, &observableArrayObject_setterinfo),
JSPropertySpec::nativeAccessors("observableArrayInterface", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &observableArrayInterface_getterinfo, GenericSetter<NormalThisPolicy>, &observableArrayInterface_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(3 <= 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[18];
static PropertyInfo sNativeProperties_propertyInfos[18];
static const NativePropertiesN<2> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
true, 1 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
18,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] },
{ sAttributes, &sNativeProperties_propertyInfos[15] }
}
};
static_assert(18 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
// This may allocate too many slots, because we only really need
// slots for our non-interface-typed members that we cache. But
// allocating slots only for those would make the slot index
// computations much more complicated, so let's do this the simple
// way for now.
DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 3);
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited },
prototypes::id::TestInterfaceObservableArray,
constructors::id::TestInterfaceObservableArray,
&sXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "TestInterfaceObservableArray constructor");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestInterfaceObservableArray", "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, "TestInterfaceObservableArray");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestInterfaceObservableArray,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
binding_detail::FastObservableArrayCallbacks arg0;
if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1", false)) {
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;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestInterfaceObservableArray>(mozilla::dom::TestInterfaceObservableArray::Constructor(global, Constify(arg0), rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestInterfaceObservableArray 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 },
JS::GetRealmFunctionPrototype,
prototypes::id::TestInterfaceObservableArray,
PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestInterfaceObservableArrayPrototype",
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::TestInterfaceObservableArray,
PrototypeTraits<prototypes::id::TestInterfaceObservableArray>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
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 = {
{ "TestInterfaceObservableArray",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(4),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TestInterfaceObservableArray, prototypes::id::_ID_Count, 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::TestInterfaceObservableArray>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestInterfaceObservableArray>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestInterfaceObservableArray>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(4 >= 4,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestInterfaceObservableArray* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestInterfaceObservableArray>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestInterfaceObservableArray*>);
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::TestInterfaceObservableArray> 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
ClearCachedObservableArrayBooleanValue(mozilla::dom::TestInterfaceObservableArray* aObject)
{
JSObject* obj;
obj = aObject->GetWrapper();
if (!obj) {
return;
}
JS::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue());
xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0));
}
void
ClearCachedObservableArrayObjectValue(mozilla::dom::TestInterfaceObservableArray* aObject)
{
JSObject* obj;
obj = aObject->GetWrapper();
if (!obj) {
return;
}
JS::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 1), JS::UndefinedValue());
xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 1));
}
void
ClearCachedObservableArrayInterfaceValue(mozilla::dom::TestInterfaceObservableArray* aObject)
{
JSObject* obj;
obj = aObject->GetWrapper();
if (!obj) {
return;
}
JS::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 2), JS::UndefinedValue());
xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 2));
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestInterfaceObservableArray);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestInterfaceObservableArray);
JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
if (!parentProto) {
return;
}
JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"TestInterfaceObservableArray", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestInterfaceObservableArray_Binding
} // namespace mozilla::dom