Bug 1318630 - Part 2: Create correct html element object when "is" is specified for custom element; r=wchen
authorEdgar Chen <echen@mozilla.com>
Thu, 08 Dec 2016 09:33:44 -1000
changeset 325957 38bc75a0a89e742bc4c1d50e0c28e5b64093a7eb
parent 325956 7ce261714f79f784f387f5e3c4d4fd57fe796b94
child 325958 3beb2dd5adea4e91651adf90ba513e900200e3f2
push id31081
push usercbook@mozilla.com
push dateThu, 15 Dec 2016 13:18:38 +0000
treeherdermozilla-central@c750a7de1194 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1318630
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1318630 - Part 2: Create correct html element object when "is" is specified for custom element; r=wchen MozReview-Commit-ID: B7cEhy5ZqL3
dom/html/nsHTMLContentSink.cpp
dom/tests/mochitest/webcomponents/test_document_register.html
--- a/dom/html/nsHTMLContentSink.cpp
+++ b/dom/html/nsHTMLContentSink.cpp
@@ -246,35 +246,37 @@ NS_NewHTMLElement(Element** aResult, alr
   if (!parserService)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsIAtom *name = nodeInfo->NameAtom();
 
   NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
                "Trying to HTML elements that don't have the XHTML namespace");
 
+  int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name);
+
   // Per the Custom Element specification, unknown tags that are valid custom
   // element names should be HTMLElement instead of HTMLUnknownElement.
-  int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name);
-  if ((tag == eHTMLTag_userdefined &&
-      nsContentUtils::IsCustomElementName(name)) ||
-      aIs) {
+  bool isCustomElementName = (tag == eHTMLTag_userdefined &&
+                              nsContentUtils::IsCustomElementName(name));
+  if (isCustomElementName) {
     NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
-    if (!*aResult) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    nsContentUtils::SetupCustomElement(*aResult, aIs);
-
-    return NS_OK;
+  } else {
+    *aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take();
   }
 
-  *aResult = CreateHTMLElement(tag,
-                               nodeInfo.forget(), aFromParser).take();
-  return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+  if (!*aResult) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  if (isCustomElementName || aIs) {
+    nsContentUtils::SetupCustomElement(*aResult, aIs);
+  }
+
+  return NS_OK;
 }
 
 already_AddRefed<nsGenericHTMLElement>
 CreateHTMLElement(uint32_t aNodeType,
                   already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
                   FromParser aFromParser)
 {
   NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX ||
--- a/dom/tests/mochitest/webcomponents/test_document_register.html
+++ b/dom/tests/mochitest/webcomponents/test_document_register.html
@@ -96,16 +96,17 @@ function startTest() {
 
   // document.createElement with extended type.
   var extendedProto = Object.create(HTMLButtonElement.prototype);
   var buttonConstructor = document.registerElement("x-extended-button", { prototype: extendedProto, extends: "button" });
   var extendedButton = document.createElement("button", {is: "x-extended-button"});
   is(extendedButton.tagName, "BUTTON", "Created element should have local name of BUTTON");
   is(extendedButton.__proto__, extendedProto, "Created element should have the prototype of the extended type.");
   is(extendedButton.getAttribute("is"), "x-extended-button", "The |is| attribute of the created element should be the extended type.");
+  is(extendedButton.type, "submit", "Created element should be a button with type of \"submit\"");
 
   // document.createElementNS with different namespace than definition.
   try {
     var svgButton = document.createElementNS("http://www.w3.org/2000/svg", "button", {is: "x-extended-button"});
     ok(false, "An exception should've been thrown");
   } catch(err) {
     is(err.name, "NotFoundError", "A NotFoundError exception should've been thrown");
   }