diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 3ceb8e0c73d3..0fd8c2e14fe6 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/CustomElementRegistryBinding.h" #include "mozilla/dom/ElementBinding.h" #include "mozilla/dom/HTMLElementBinding.h" +#include "mozilla/dom/PrimitiveConversions.h" #include "mozilla/dom/ShadowIncludingTreeIterator.h" #include "mozilla/dom/XULElementBinding.h" #include "mozilla/dom/Promise.h" @@ -847,6 +848,7 @@ void CustomElementRegistry::Define( auto callbacksHolder = MakeUnique(); nsTArray> observedAttributes; AutoTArray, 2> disabledFeatures; + bool formAssociated = false; bool disableInternals = false; bool disableShadow = false; { // Set mIsCustomDefinitionRunning. @@ -921,7 +923,7 @@ void CustomElementRegistry::Define( * disabledFeaturesIterable to a sequence. * Rethrow any exceptions from the conversion. */ - if (StaticPrefs::dom_webcomponents_elementInternals_enabled()) { + if (StaticPrefs::dom_webcomponents_formAssociatedCustomElement_enabled()) { if (!JSObjectToAtomArray(aCx, constructor, u"disabledFeatures"_ns, disabledFeatures, aRv)) { return; @@ -936,6 +938,24 @@ void CustomElementRegistry::Define( // "shadow". disableShadow = disabledFeatures.Contains( static_cast(nsGkAtoms::shadow)); + + // 14.11. Let formAssociatedValue be Get(constructor, "formAssociated"). + // Rethrow any exceptions. + JS::Rooted formAssociatedValue(aCx); + if (!JS_GetProperty(aCx, constructor, "formAssociated", + &formAssociatedValue)) { + aRv.NoteJSContextException(aCx); + return; + } + + // 14.12. Set formAssociated to the result of converting + // formAssociatedValue to a boolean. Rethrow any exceptions from + // the conversion. + if (!ValueToPrimitive( + aCx, formAssociatedValue, "formAssociated", &formAssociated)) { + aRv.NoteJSContextException(aCx); + return; + } } } // Unset mIsCustomDefinitionRunning @@ -958,7 +978,7 @@ void CustomElementRegistry::Define( RefPtr definition = new CustomElementDefinition( nameAtom, localNameAtom, nameSpaceID, &aFunctionConstructor, - std::move(observedAttributes), std::move(callbacksHolder), + std::move(observedAttributes), std::move(callbacksHolder), formAssociated, disableInternals, disableShadow); CustomElementDefinition* def = definition.get(); @@ -1470,14 +1490,15 @@ CustomElementDefinition::CustomElementDefinition( nsAtom* aType, nsAtom* aLocalName, int32_t aNamespaceID, CustomElementConstructor* aConstructor, nsTArray>&& aObservedAttributes, - UniquePtr&& aCallbacks, bool aDisableInternals, - bool aDisableShadow) + UniquePtr&& aCallbacks, bool aFormAssociated, + bool aDisableInternals, bool aDisableShadow) : mType(aType), mLocalName(aLocalName), mNamespaceID(aNamespaceID), mConstructor(aConstructor), mObservedAttributes(std::move(aObservedAttributes)), mCallbacks(std::move(aCallbacks)), + mFormAssociated(aFormAssociated), mDisableInternals(aDisableInternals), mDisableShadow(aDisableShadow) {} diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index fac6485c54d1..a3b9726bfc93 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -141,7 +141,8 @@ struct CustomElementDefinition { CustomElementConstructor* aConstructor, nsTArray>&& aObservedAttributes, UniquePtr&& aCallbacks, - bool aDisableInternals, bool aDisableShadow); + bool aFormAssociated, bool aDisableInternals, + bool aDisableShadow); // The type (name) for this custom element, for