Bug 1419643 - Don't need to lookup custom element definition for a non-custom element; draft
authorEdgar Chen <echen@mozilla.com>
Fri, 24 Nov 2017 00:16:00 +0800
changeset 703013 ddd54c5c0756e983582a6623046e0cc8234722aa
parent 702882 3f5d48c08903475b5f556f3d5906773978b30489
child 703094 1e19c88e1622f1f637265e5683f6fbaf63bb4809
child 703096 c8fb6353d2a46eb90e44bbe8d6480d117e1a7933
child 703098 a66967ed7b1e6da3f44e794e1e6acfb674c9f9af
push id90665
push userechen@mozilla.com
push dateFri, 24 Nov 2017 07:03:07 +0000
bugs1419643
milestone59.0a1
Bug 1419643 - Don't need to lookup custom element definition for a non-custom element; MozReview-Commit-ID: 5zWna7LLJOd
dom/html/nsHTMLContentSink.cpp
--- a/dom/html/nsHTMLContentSink.cpp
+++ b/dom/html/nsHTMLContentSink.cpp
@@ -261,23 +261,28 @@ NS_NewHTMLElement(Element** aResult, alr
   nsAtom *name = nodeInfo->NameAtom();
   RefPtr<nsAtom> tagAtom = nodeInfo->NameAtom();
   RefPtr<nsAtom> typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom;
 
   NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
                "Trying to HTML elements that don't have the XHTML namespace");
 
   int32_t tag = nsHTMLTags::CaseSensitiveAtomTagToId(name);
+  bool isCustomElementName = (tag == eHTMLTag_userdefined &&
+                              nsContentUtils::IsCustomElementName(name));
+  bool isCustomElement = isCustomElementName || aIs;
+  MOZ_ASSERT_IF(aDefinition, isCustomElement);
 
   // https://dom.spec.whatwg.org/#concept-create-element
   // We only handle the "synchronous custom elements flag is set" now.
   // For the unset case (e.g. cloning a node), see bug 1319342 for that.
   // Step 4.
   CustomElementDefinition* definition = aDefinition;
-  if (!definition && CustomElementRegistry::IsCustomElementEnabled()) {
+  if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement &&
+      !definition) {
     definition =
       nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
                                                     nodeInfo->LocalName(),
                                                     nodeInfo->NamespaceID(),
                                                     typeAtom);
   }
 
   // It might be a problem that parser synchronously calls constructor, so filed
@@ -350,30 +355,27 @@ NS_NewHTMLElement(Element** aResult, alr
     NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
     (*aResult)->SetCustomElementData(new CustomElementData(definition->mType));
     nsContentUtils::EnqueueUpgradeReaction(*aResult, definition);
     return NS_OK;
   }
 
   // Per the Custom Element specification, unknown tags that are valid custom
   // element names should be HTMLElement instead of HTMLUnknownElement.
-  bool isCustomElementName = (tag == eHTMLTag_userdefined &&
-                              nsContentUtils::IsCustomElementName(name));
   if (isCustomElementName) {
     NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
   } else {
     *aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take();
   }
 
   if (!*aResult) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  if (CustomElementRegistry::IsCustomElementEnabled() &&
-      (isCustomElementName || aIs)) {
+  if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement) {
     (*aResult)->SetCustomElementData(new CustomElementData(typeAtom));
   }
 
   return NS_OK;
 }
 
 already_AddRefed<nsGenericHTMLElement>
 CreateHTMLElement(uint32_t aNodeType,