Bug 987031 - Use kNamespaceID_Unknown to match any namespace in the web components custom element registry. r=mrbkap
authorWilliam Chen <wchen@mozilla.com>
Thu, 27 Mar 2014 11:55:44 -0700
changeset 175672 3c09159e01dab93329c2c66a33f6778a929d84a7
parent 175671 35dc75b1a5e3d29a978a23bbc3fb7a251bd088f4
child 175743 1d7c1557055a58c32c0adfbbe7890af9855a8f0e
child 175796 2c636b3c79c1780726ebb03b26f3fb820bbaa24f
push id26496
push userkwierso@gmail.com
push dateFri, 28 Mar 2014 02:28:34 +0000
treeherdermozilla-central@3c09159e01da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs987031
milestone31.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 987031 - Use kNamespaceID_Unknown to match any namespace in the web components custom element registry. r=mrbkap
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
dom/tests/mochitest/webcomponents/test_document_register.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -5459,17 +5459,17 @@ nsDocument::CustomElementConstructor(JSC
   JSString* jsFunName =
     JS_GetFunctionId(JS_ValueToFunction(aCx, args.calleev()));
   nsDependentJSString elemName;
   if (!elemName.init(aCx, jsFunName)) {
     return true;
   }
 
   nsCOMPtr<nsIAtom> typeAtom(do_GetAtom(elemName));
-  CustomElementHashKey key(kNameSpaceID_None, typeAtom);
+  CustomElementHashKey key(kNameSpaceID_Unknown, typeAtom);
   CustomElementDefinition* definition;
   if (!document->mRegistry ||
       !document->mRegistry->mCustomDefinitions.Get(&key, &definition)) {
     return true;
   }
 
   nsDependentAtomString localName(definition->mLocalName);
 
@@ -5786,17 +5786,17 @@ nsDocument::RegisterElement(JSContext* a
   if (!nsContentUtils::IsCustomElementName(typeAtom)) {
     rv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return nullptr;
   }
 
   // If there already exists a definition with the same TYPE, set ERROR to
   // DuplicateDefinition and stop.
   // Note that we need to find existing custom elements from either namespace.
-  CustomElementHashKey duplicateFinder(kNameSpaceID_None, typeAtom);
+  CustomElementHashKey duplicateFinder(kNameSpaceID_Unknown, typeAtom);
   if (definitions.Get(&duplicateFinder)) {
     rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
   }
 
   nsIGlobalObject* sgo = GetScopeObject();
   if (!sgo) {
     rv.Throw(NS_ERROR_UNEXPECTED);
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -259,21 +259,21 @@ public:
       mAtom(aKey->mAtom)
   {}
   ~CustomElementHashKey()
   {}
 
   KeyType GetKey() const { return const_cast<KeyType>(this); }
   bool KeyEquals(const KeyTypePointer aKey) const
   {
-    MOZ_ASSERT(mNamespaceID != kNameSpaceID_None,
+    MOZ_ASSERT(mNamespaceID != kNameSpaceID_Unknown,
                "This equals method is not transitive, nor symmetric. "
-               "A key with a namespace of kNamespaceID_None should "
+               "A key with a namespace of kNamespaceID_Unknown should "
                "not be stored in a hashtable.");
-    return (kNameSpaceID_None == aKey->mNamespaceID ||
+    return (kNameSpaceID_Unknown == aKey->mNamespaceID ||
             mNamespaceID == aKey->mNamespaceID) &&
            aKey->mAtom == mAtom;
   }
 
   static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
   static PLDHashNumber HashKey(const KeyTypePointer aKey)
   {
     return aKey->mAtom->hash();
--- a/dom/tests/mochitest/webcomponents/test_document_register.html
+++ b/dom/tests/mochitest/webcomponents/test_document_register.html
@@ -120,16 +120,20 @@ function startTest() {
   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.");
 
   // document.createElementNS with different namespace than definition.
   var svgButton = document.createElementNS("http://www.w3.org/2000/svg", "button", "x-extended-button");
   isnot(svgButton.__proto__, extendedProto, "Definition for element is in html namespace, registration should not apply for SVG elements.");
 
+  // document.createElementNS with no namespace.
+  var noNamespaceButton = document.createElementNS("", "button", "x-extended-button");
+  isnot(noNamespaceButton.__proto__, extendedProto, "Definition for element is in html namespace, registration should not apply for elements with no namespace.");
+
   // document.createElement with non-existant extended type.
   var normalButton = document.createElement("button", "x-non-existant");
   is(normalButton.__proto__, HTMLButtonElement.prototype, "When the extended type doesn't exist, prototype should not change.");
 
   // document.createElement with exteneded type that does not match with local name of element.
   var normalDiv = document.createElement("div", "x-extended-button");
   is(normalDiv.__proto__, HTMLDivElement.prototype, "Prototype should not change when local name of extended type defintion does not match.");