From fb657f7a1e3ef326214e0c42a5a0dd6dc0109338 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 22:59:16 -0500 Subject: Bug 1406325 - Part 4: Use mType for LookupCustomElementDefinition and also removing parts of v0. Tag UXP Issue #1344 --- dom/base/CustomElementRegistry.cpp | 64 +++++++------------------------------- dom/base/CustomElementRegistry.h | 17 ++++------ dom/base/Element.cpp | 6 ++-- dom/base/nsContentUtils.cpp | 37 ++-------------------- dom/base/nsContentUtils.h | 5 +-- dom/base/nsNodeUtils.cpp | 2 +- 6 files changed, 25 insertions(+), 106 deletions(-) (limited to 'dom/base') diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index f17c2c7d9..fe2837f2a 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -36,7 +36,6 @@ CustomElementCallback::Call() nsIDocument* document = mThisObject->GetComposedDoc(); if (document) { NodeInfo* ni = mThisObject->NodeInfo(); - nsDependentAtomString extType(mOwnerData->mType); // We need to do this because at this point, CustomElementDefinition is // not set to CustomElementData yet, so EnqueueLifecycleCallback will @@ -45,7 +44,8 @@ CustomElementCallback::Call() CustomElementDefinition* definition = nsContentUtils::LookupCustomElementDefinition(document, ni->LocalName(), ni->NamespaceID(), - extType.IsEmpty() ? nullptr : &extType); + mOwnerData->GetCustomElementType()); + nsContentUtils::EnqueueLifecycleCallback( nsIDocument::eConnected, mThisObject, nullptr, nullptr, definition); } @@ -131,10 +131,10 @@ CustomElementData::CustomElementData(nsIAtom* aType) } CustomElementData::CustomElementData(nsIAtom* aType, State aState) - : mType(aType) - , mElementIsBeingCreated(false) + : mElementIsBeingCreated(false) , mCreatedCallbackInvoked(true) , mState(aState) + , mType(aType) { } @@ -157,6 +157,12 @@ CustomElementData::GetCustomElementDefinition() return mCustomElementDefinition; } +nsIAtom* +CustomElementData::GetCustomElementType() +{ + return mType; +} + void CustomElementData::Traverse(nsCycleCollectionTraversalCallback& aCb) const { @@ -274,12 +280,10 @@ CustomElementRegistry::~CustomElementRegistry() CustomElementDefinition* CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName, - const nsAString* aIs) const + nsIAtom* aTypeAtom) const { nsCOMPtr localNameAtom = NS_Atomize(aLocalName); - nsCOMPtr typeAtom = aIs ? NS_Atomize(*aIs) : localNameAtom; - - CustomElementDefinition* data = mCustomDefinitions.GetWeak(typeAtom); + CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom); if (data && data->mLocalName == localNameAtom) { return data; } @@ -329,50 +333,6 @@ CustomElementRegistry::RegisterUnresolvedElement(Element* aElement, nsIAtom* aTy return; } -void -CustomElementRegistry::SetupCustomElement(Element* aElement, - const nsAString* aTypeExtension) -{ - nsCOMPtr tagAtom = aElement->NodeInfo()->NameAtom(); - nsCOMPtr typeAtom = aTypeExtension ? - NS_Atomize(*aTypeExtension) : tagAtom; - - if (aTypeExtension && !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::is)) { - // Custom element setup in the parser happens after the "is" - // attribute is added. - aElement->SetAttr(kNameSpaceID_None, nsGkAtoms::is, *aTypeExtension, true); - } - - // SetupCustomElement() should be called with an element that don't have - // CustomElementData setup, if not we will hit the assertion in - // SetCustomElementData(). - aElement->SetCustomElementData(new CustomElementData(typeAtom)); - - CustomElementDefinition* definition = LookupCustomElementDefinition( - aElement->NodeInfo()->LocalName(), aTypeExtension); - - if (!definition) { - // The type extension doesn't exist in the registry, - // thus we don't need to enqueue callback or adjust - // the "is" attribute, but it is possibly an upgrade candidate. - RegisterUnresolvedElement(aElement, typeAtom); - return; - } - - if (definition->mLocalName != tagAtom) { - // The element doesn't match the local name for the - // definition, thus the element isn't a custom element - // and we don't need to do anything more. - return; - } - - // Enqueuing the created callback will set the CustomElementData on the - // element, causing prototype swizzling to occur in Element::WrapObject. - // We make it synchronously for createElement/createElementNS in order to - // pass tests. It'll be removed when we deprecate custom elements v0. - // SyncInvokeReactions(nsIDocument::eCreated, aElement, definition); -} - /* static */ UniquePtr CustomElementRegistry::CreateCustomElementCallback( nsIDocument::ElementCallbackType aType, Element* aCustomElement, diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index d3dfef682..81d1c003c 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -112,9 +112,7 @@ struct CustomElementData explicit CustomElementData(nsIAtom* aType); CustomElementData(nsIAtom* aType, State aState); - // Custom element type, for