From 7e2fb3fe0d8e0e3cddd58bd76fd10d18c6058940 Mon Sep 17 00:00:00 2001 From: John Dai Date: Wed, 5 Aug 2020 09:35:56 +0000 Subject: [PATCH] Bug 1556342 - Implement customElements.define's form-associated; r=edgar,smaug Differential Revision: https://phabricator.services.mozilla.com/D85734 --- dom/base/CustomElementRegistry.cpp | 29 ++++++++++++++++--- dom/base/CustomElementRegistry.h | 7 ++++- dom/base/Element.cpp | 3 +- dom/webidl/ElementInternals.webidl | 2 +- dom/webidl/HTMLElement.webidl | 2 +- modules/libpref/init/StaticPrefList.yaml | 4 +-- .../CustomElementRegistry.html.ini | 9 ------ .../meta/custom-elements/__dir__.ini | 2 +- .../meta/html/dom/idlharness.https.html.ini | 2 +- .../web-platform/meta/shadow-dom/__dir__.ini | 2 +- 10 files changed, 40 insertions(+), 22 deletions(-) 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