Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM CustomElementRegistry.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "CustomElementRegistryBinding.h"
#include "MainThreadUtils.h"
#include "WrapperFactory.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "jsapi.h"
#include "mozilla/Atomics.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/UseCounter.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/CustomElementRegistry.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FormData.h"
#include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SimpleGlobalObject.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "nsContentUtils.h"
#include "nsIContent.h"
namespace mozilla {
namespace dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
namespace binding_detail {
const nsLiteralCString EnumStrings<RestoreReason>::Values[2] = {
"restore"_ns,
"autocomplete"_ns,
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, RestoreReason aArgument, JS::MutableHandle<JS::Value> aValue)
{
MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(binding_detail::EnumStrings<RestoreReason>::Values));
JSString* resultStr =
JS_NewStringCopyN(aCx, binding_detail::EnumStrings<RestoreReason>::Values[uint32_t(aArgument)].BeginReading(),
binding_detail::EnumStrings<RestoreReason>::Values[uint32_t(aArgument)].Length());
if (!resultStr) {
return false;
}
aValue.setString(resultStr);
return true;
}
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningCustomElementConstructorOrUndefined& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsCustomElementConstructor()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsCustomElementConstructor(), "mCustomElementConstructor", aFlags);
}
}
void
ImplCycleCollectionUnlink(OwningCustomElementConstructorOrUndefined& aUnion)
{
aUnion.Uninit();
}
MOZ_CAN_RUN_SCRIPT void
CustomElementConstructor::Construct(JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "CustomElementConstructor", aExceptionHandling, aRealm);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> constructor(cx, JS::ObjectValue(*mCallback));
JS::Rooted<JSObject*> constructedObj(cx);
if (!JS::Construct(cx, constructor,
JS::HandleValueArray::empty(), &constructedObj)) {
aRv.NoteJSContextException(cx);
return;
}
rval.setObject(*constructedObj);
JS::Rooted<JS::Value> rvalDecl(cx);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of CustomElementConstructor");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = rval;
aRetVal.set(rvalDecl);
}
bool
CustomElementConstructorOrUndefined::TrySetToCustomElementConstructor(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
RootedCallback<OwningNonNull<binding_detail::FastCustomElementConstructor>>& memberSlot = RawSetAsCustomElementConstructor(cx);
if (JS::IsCallable(&value.toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
memberSlot = new binding_detail::FastCustomElementConstructor(&value.toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
DestroyCustomElementConstructor();
tryNext = true;
return true;
}
}
return true;
}
bool
CustomElementConstructorOrUndefined::TrySetToCustomElementConstructor(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToCustomElementConstructor(cx, value, tryNext, passedToJSImpl);
}
bool
CustomElementConstructorOrUndefined::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isUndefined()) {
SetUndefined();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToCustomElementConstructor(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "CustomElementConstructor");
return false;
}
}
return true;
}
bool
CustomElementConstructorOrUndefined::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
CustomElementConstructorOrUndefined::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eCustomElementConstructor: {
rval.setObjectOrNull(GetCallbackFromCallbackObject(cx, mValue.mCustomElementConstructor.Value()));
if (!MaybeWrapObjectValue(cx, rval)) {
return false;
}
return true;
}
case eUndefined: {
rval.setUndefined();
return true;
}
default: {
return false;
}
}
}
OwningCustomElementConstructorOrUndefined::OwningCustomElementConstructorOrUndefined(OwningCustomElementConstructorOrUndefined&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eCustomElementConstructor: {
mType = eCustomElementConstructor;
mValue.mCustomElementConstructor.SetValue(std::move(aOther.mValue.mCustomElementConstructor.Value()));
break;
}
case eUndefined: {
MOZ_ASSERT(mType == eUninitialized);
mType = eUndefined;
break;
}
}
}
bool
OwningCustomElementConstructorOrUndefined::TrySetToCustomElementConstructor(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<CustomElementConstructor>& memberSlot = RawSetAsCustomElementConstructor();
if (JS::IsCallable(&value.toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
JS::Rooted<JSObject*> tempRoot(cx, &value.toObject());
JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
memberSlot = new CustomElementConstructor(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
DestroyCustomElementConstructor();
tryNext = true;
return true;
}
}
return true;
}
bool
OwningCustomElementConstructorOrUndefined::TrySetToCustomElementConstructor(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToCustomElementConstructor(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<CustomElementConstructor>&
OwningCustomElementConstructorOrUndefined::RawSetAsCustomElementConstructor()
{
if (mType == eCustomElementConstructor) {
return mValue.mCustomElementConstructor.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eCustomElementConstructor;
return mValue.mCustomElementConstructor.SetValue();
}
[[nodiscard]] OwningNonNull<CustomElementConstructor>&
OwningCustomElementConstructorOrUndefined::SetAsCustomElementConstructor()
{
if (mType == eCustomElementConstructor) {
return mValue.mCustomElementConstructor.Value();
}
Uninit();
mType = eCustomElementConstructor;
return mValue.mCustomElementConstructor.SetValue();
}
void
OwningCustomElementConstructorOrUndefined::DestroyCustomElementConstructor()
{
MOZ_RELEASE_ASSERT(IsCustomElementConstructor(), "Wrong type!");
mValue.mCustomElementConstructor.Destroy();
mType = eUninitialized;
}
bool
OwningCustomElementConstructorOrUndefined::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
if (value.isUndefined()) {
SetUndefined();
} else {
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToCustomElementConstructor(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "CustomElementConstructor");
return false;
}
}
return true;
}
bool
OwningCustomElementConstructorOrUndefined::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningCustomElementConstructorOrUndefined::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eCustomElementConstructor: {
DestroyCustomElementConstructor();
break;
}
case eUndefined: {
break;
}
}
}
bool
OwningCustomElementConstructorOrUndefined::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eCustomElementConstructor: {
rval.setObjectOrNull(GetCallbackFromCallbackObject(cx, mValue.mCustomElementConstructor.Value()));
if (!MaybeWrapObjectValue(cx, rval)) {
return false;
}
return true;
}
case eUndefined: {
rval.setUndefined();
return true;
}
default: {
return false;
}
}
}
OwningCustomElementConstructorOrUndefined&
OwningCustomElementConstructorOrUndefined::operator=(OwningCustomElementConstructorOrUndefined&& aOther)
{
this->~OwningCustomElementConstructorOrUndefined();
new (this) OwningCustomElementConstructorOrUndefined (std::move(aOther));
return *this;
}
void
CustomElementCreationCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const nsAString& name, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!xpc::NonVoidStringToJsval(cx, name, 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;
}
}
ElementDefinitionOptions::ElementDefinitionOptions()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
ElementDefinitionOptions::InitIds(JSContext* cx, ElementDefinitionOptionsAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->extends_id.init(cx, "extends")) {
return false;
}
return true;
}
bool
ElementDefinitionOptions::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());
ElementDefinitionOptionsAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<ElementDefinitionOptionsAtoms>(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->extends_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mExtends.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mExtends.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
ElementDefinitionOptions::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
ElementDefinitionOptions::TraceDictionary(JSTracer* trc)
{
}
ElementDefinitionOptions&
ElementDefinitionOptions::operator=(const ElementDefinitionOptions& aOther)
{
DictionaryBase::operator=(aOther);
mExtends.Reset();
if (aOther.mExtends.WasPassed()) {
mExtends.Construct(aOther.mExtends.Value());
}
return *this;
}
bool
ElementDefinitionOptions::operator==(const ElementDefinitionOptions& aOther) const
{
if (mExtends != aOther.mExtends) {
return false;
}
return true;
}
FormAssociatedLifecycleCallbacks::FormAssociatedLifecycleCallbacks()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
FormAssociatedLifecycleCallbacks::InitIds(JSContext* cx, FormAssociatedLifecycleCallbacksAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->formStateRestoreCallback_id.init(cx, "formStateRestoreCallback") ||
!atomsCache->formDisabledCallback_id.init(cx, "formDisabledCallback") ||
!atomsCache->formResetCallback_id.init(cx, "formResetCallback") ||
!atomsCache->formAssociatedCallback_id.init(cx, "formAssociatedCallback")) {
return false;
}
return true;
}
bool
FormAssociatedLifecycleCallbacks::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());
FormAssociatedLifecycleCallbacksAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<FormAssociatedLifecycleCallbacksAtoms>(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->formAssociatedCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mFormAssociatedCallback.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));
(mFormAssociatedCallback.Value()) = new LifecycleFormAssociatedCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'formAssociatedCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'formAssociatedCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->formResetCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mFormResetCallback.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));
(mFormResetCallback.Value()) = new LifecycleFormResetCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'formResetCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'formResetCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->formDisabledCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mFormDisabledCallback.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));
(mFormDisabledCallback.Value()) = new LifecycleFormDisabledCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'formDisabledCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'formDisabledCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->formStateRestoreCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mFormStateRestoreCallback.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));
(mFormStateRestoreCallback.Value()) = new LifecycleFormStateRestoreCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'formStateRestoreCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'formStateRestoreCallback' member of FormAssociatedLifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
FormAssociatedLifecycleCallbacks::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
FormAssociatedLifecycleCallbacks::TraceDictionary(JSTracer* trc)
{
}
void
LifecycleAdoptedCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, Document* oldDocument, Document* newDocment, 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 {
if (!newDocment) {
argv[1].setNull();
break;
}
if (!GetOrCreateDOMReflector(cx, newDocment, argv[1])) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
if (!oldDocument) {
argv[0].setNull();
break;
}
if (!GetOrCreateDOMReflector(cx, oldDocument, 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;
}
}
void
LifecycleAttributeChangedCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const nsAString& attrName, const nsAString& oldValue, const nsAString& newValue, const nsAString& namespaceURI, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(4)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 4;
do {
if (!xpc::StringToJsval(cx, namespaceURI, argv[3])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
if (!xpc::StringToJsval(cx, newValue, argv[2])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
if (!xpc::StringToJsval(cx, oldValue, argv[1])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
if (!xpc::NonVoidStringToJsval(cx, attrName, 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;
}
}
LifecycleCallbacks::LifecycleCallbacks()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
LifecycleCallbacks::InitIds(JSContext* cx, LifecycleCallbacksAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->getCustomInterfaceCallback_id.init(cx, "getCustomInterfaceCallback") ||
!atomsCache->attributeChangedCallback_id.init(cx, "attributeChangedCallback") ||
!atomsCache->adoptedCallback_id.init(cx, "adoptedCallback") ||
!atomsCache->disconnectedCallback_id.init(cx, "disconnectedCallback") ||
!atomsCache->connectedCallback_id.init(cx, "connectedCallback")) {
return false;
}
return true;
}
bool
LifecycleCallbacks::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());
LifecycleCallbacksAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<LifecycleCallbacksAtoms>(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->connectedCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mConnectedCallback.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));
(mConnectedCallback.Value()) = new LifecycleConnectedCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'connectedCallback' member of LifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'connectedCallback' member of LifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->disconnectedCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mDisconnectedCallback.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));
(mDisconnectedCallback.Value()) = new LifecycleDisconnectedCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'disconnectedCallback' member of LifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'disconnectedCallback' member of LifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->adoptedCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAdoptedCallback.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));
(mAdoptedCallback.Value()) = new LifecycleAdoptedCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'adoptedCallback' member of LifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'adoptedCallback' member of LifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attributeChangedCallback_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAttributeChangedCallback.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));
(mAttributeChangedCallback.Value()) = new LifecycleAttributeChangedCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'attributeChangedCallback' member of LifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'attributeChangedCallback' member of LifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (nsContentUtils::ThreadsafeIsSystemCaller(cx)) {
if (!JS_GetPropertyById(cx, *object, atomsCache->getCustomInterfaceCallback_id, temp.ptr())) {
return false;
}
} else {
temp->setUndefined();
}
}
if (!isNull && !temp->isUndefined()) {
mGetCustomInterfaceCallback.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));
(mGetCustomInterfaceCallback.Value()) = new LifecycleGetCustomInterfaceCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("'getCustomInterfaceCallback' member of LifecycleCallbacks");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("'getCustomInterfaceCallback' member of LifecycleCallbacks");
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
LifecycleCallbacks::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
LifecycleCallbacks::TraceDictionary(JSTracer* trc)
{
}
void
LifecycleConnectedCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
LifecycleDisconnectedCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
LifecycleFormAssociatedCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, HTMLFormElement* form, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
if (!form) {
argv[0].setNull();
break;
}
if (!GetOrCreateDOMReflector(cx, form, 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;
}
}
void
LifecycleFormDisabledCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, bool disabled, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
argv[0].setBoolean(disabled);
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;
}
}
void
LifecycleFormResetCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, aThisVal, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
void
LifecycleFormStateRestoreCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, const Nullable<FileOrUSVStringOrFormData>& state, RestoreReason reason, 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 {
if (!ToJSValue(cx, reason, argv[1])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
break;
} while (false);
do {
JS::Rooted<JSObject*> callbackObj(cx, CallbackKnownNotGray());
if (state.IsNull()) {
argv[0].setNull();
break;
}
if (!state.Value().ToJSVal(cx, callbackObj, 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;
}
}
void
LifecycleGetCustomInterfaceCallback::Call(BindingCallContext& cx, JS::Handle<JS::Value> aThisVal, JS::Handle<JS::Value> iid, JS::MutableHandle<JSObject*> aRetVal, ErrorResult& aRv)
{
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return;
}
unsigned argc = 1;
do {
JS::ExposeValueToActiveJS(iid);
argv[0].set(iid);
if (!MaybeWrapValue(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;
}
JS::Rooted<JSObject*> rvalDecl(cx);
if (rval.isObject()) {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunreachable-code-return"
#endif // __clang__
if ((false) && !CallerSubsumes(rval)) {
cx.ThrowErrorMessage<MSG_PERMISSION_DENIED_TO_PASS_ARG>("return value of LifecycleGetCustomInterfaceCallback");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
rvalDecl = &rval.toObject();
} else if (rval.isNullOrUndefined()) {
rvalDecl = nullptr;
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Return value of LifecycleGetCustomInterfaceCallback");
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
aRetVal.set(rvalDecl);
}
namespace CustomElementRegistry_Binding {
MOZ_CAN_RUN_SCRIPT static bool
define(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "CustomElementRegistry.define");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "define", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.define", 2)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
RootedCallback<OwningNonNull<binding_detail::FastCustomElementConstructor>> arg1(cx);
if (args[1].isObject()) {
if (JS::IsCallable(&args[1].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg1 = new binding_detail::FastCustomElementConstructor(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 2");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
binding_detail::FastElementDefinitionOptions arg2;
if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3", false)) {
return false;
}
Maybe<AutoCEReaction> ceReaction;
DocGroup* docGroup = self->GetDocGroup();
if (docGroup) {
ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Define(cx, NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), Constify(arg2), rv))>, "Should be returning void here");
MOZ_KnownLive(self)->Define(cx, NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), Constify(arg2), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "CustomElementRegistry.define"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
SetUseCounter(obj, eUseCounter_CustomElementRegistry_define);
args.rval().setUndefined();
return true;
}
static const JSJitInfo define_methodinfo = {
{ (JSJitGetterOp)define },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::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
setElementCreationCallback(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "CustomElementRegistry.setElementCreationCallback");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "setElementCreationCallback", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.setElementCreationCallback", 2)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
RootedCallback<OwningNonNull<binding_detail::FastCustomElementCreationCallback>> arg1(cx);
if (args[1].isObject()) {
if (JS::IsCallable(&args[1].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg1 = new binding_detail::FastCustomElementCreationCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 2");
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)->SetElementCreationCallback(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv))>, "Should be returning void here");
MOZ_KnownLive(self)->SetElementCreationCallback(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "CustomElementRegistry.setElementCreationCallback"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo setElementCreationCallback_methodinfo = {
{ (JSJitGetterOp)setElementCreationCallback },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::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
get(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "get", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.get", 1)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
OwningCustomElementConstructorOrUndefined result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Get(NonNullHelper(Constify(arg0)), result))>, "Should be returning void here");
MOZ_KnownLive(self)->Get(NonNullHelper(Constify(arg0)), result);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result.ToJSVal(cx, obj, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo get_methodinfo = {
{ (JSJitGetterOp)get },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getName(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "CustomElementRegistry.getName");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "getName", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.getName", 1)) {
return false;
}
RootedCallback<OwningNonNull<binding_detail::FastCustomElementConstructor>> arg0(cx);
if (args[0].isObject()) {
if (JS::IsCallable(&args[0].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg0 = new binding_detail::FastCustomElementConstructor(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 1");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
DOMString result;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->GetName(cx, MOZ_KnownLive(NonNullHelper(arg0)), result))>, "Should be returning void here");
MOZ_KnownLive(self)->GetName(cx, MOZ_KnownLive(NonNullHelper(arg0)), result);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!xpc::StringToJsval(cx, result, args.rval())) {
return false;
}
return true;
}
static const JSJitInfo getName_methodinfo = {
{ (JSJitGetterOp)getName },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
whenDefined(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "whenDefined", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.whenDefined", 1)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<Promise>(MOZ_KnownLive(self)->WhenDefined(NonNullHelper(Constify(arg0)), rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "CustomElementRegistry.whenDefined"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!ToJSValue(cx, result, args.rval())) {
return false;
}
return true;
}
MOZ_CAN_RUN_SCRIPT static bool
whenDefined_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
bool ok = whenDefined(cx, obj, void_self, args);
if (ok) {
return true;
}
return ConvertExceptionToPromise(cx, args.rval());
}
static const JSJitInfo whenDefined_methodinfo = {
{ (JSJitGetterOp)whenDefined_promiseWrapper },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::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
upgrade(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "CustomElementRegistry.upgrade");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"CustomElementRegistry", "upgrade", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::CustomElementRegistry*>(void_self);
if (!args.requireAtLeast(cx, "CustomElementRegistry.upgrade", 1)) {
return false;
}
NonNull<nsINode> arg0;
if (args[0].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 1", "Node");
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
Maybe<AutoCEReaction> ceReaction;
DocGroup* docGroup = self->GetDocGroup();
if (docGroup) {
ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
}
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->Upgrade(MOZ_KnownLive(NonNullHelper(arg0))))>, "Should be returning void here");
MOZ_KnownLive(self)->Upgrade(MOZ_KnownLive(NonNullHelper(arg0)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo upgrade_methodinfo = {
{ (JSJitGetterOp)upgrade },
{ prototypes::id::CustomElementRegistry },
{ PrototypeTraits<prototypes::id::CustomElementRegistry>::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. */
};
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::CustomElementRegistry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CustomElementRegistry>(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::CustomElementRegistry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CustomElementRegistry>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::CustomElementRegistry>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::CustomElementRegistry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CustomElementRegistry>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::CustomElementRegistry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CustomElementRegistry>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("define", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&define_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("get", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&get_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getName", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("whenDefined", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&whenDefined_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("upgrade", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&upgrade_methodinfo), 1, 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(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static const JSFunctionSpec sChromeMethods_specs[] = {
JS_FNSPEC("setElementCreationCallback", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setElementCreationCallback_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
{ nullptr, &sChromeMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sNativeProperties_sortedPropertyIndices[5];
static PropertyInfo sNativeProperties_propertyInfos[5];
static const NativePropertiesN<1> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
5,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] }
}
};
static_assert(5 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
false, 0,
false, 0,
true, 0 /* sChromeMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::CustomElementRegistry,
constructors::id::CustomElementRegistry,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
JS::GetRealmFunctionPrototype,
prototypes::id::CustomElementRegistry,
PrototypeTraits<prototypes::id::CustomElementRegistry>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"CustomElementRegistryPrototype",
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::CustomElementRegistry,
PrototypeTraits<prototypes::id::CustomElementRegistry>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
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 = {
{ "CustomElementRegistry",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::CustomElementRegistry, 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::CustomElementRegistry>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::CustomElementRegistry>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::CustomElementRegistry>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::CustomElementRegistry* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::CustomElementRegistry>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::CustomElementRegistry*>);
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::CustomElementRegistry> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CustomElementRegistry);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CustomElementRegistry);
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(),
sChromeOnlyNativeProperties.Upcast(),
"CustomElementRegistry", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace CustomElementRegistry_Binding
} // namespace dom
} // namespace mozilla