Bug 1274505 - Remove SVG-based custom element support. r=wchen
authorJohn Dai <jdai@mozilla.com>
Tue, 26 Jul 2016 00:35:00 -0400
changeset 346944 930128b884449525099dd5d80897bd1d8b7abeff
parent 346943 19ff5ac3420fd8ad7c4af2b795c2670c98d4219b
child 346945 5172702dcd32ea48a5046b059332925017593c0c
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1274505
milestone50.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 1274505 - Remove SVG-based custom element support. r=wchen
dom/base/nsDocument.cpp
dom/svg/SVGElementFactory.cpp
dom/svg/SVGElementFactory.h
dom/tests/mochitest/webcomponents/test_document_register.html
testing/web-platform/meta/custom-elements/v0/instantiating/custom-element-constructor-prototype.html.ini
testing/web-platform/meta/custom-elements/v0/instantiating/custom-element-prototype.html.ini
testing/web-platform/meta/custom-elements/v0/registering/definition-construction-algorithm-svg-namespace.html.ini
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -169,17 +169,16 @@
 #include "mozAutoDocUpdate.h"
 #include "nsGlobalWindow.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "nsDOMNavigationTiming.h"
 
 #include "nsSMILAnimationController.h"
 #include "imgIContainer.h"
 #include "nsSVGUtils.h"
-#include "SVGElementFactory.h"
 
 #include "nsRefreshDriver.h"
 
 // FOR CSP (autogenerated by xpidl)
 #include "nsIContentSecurityPolicy.h"
 #include "mozilla/dom/nsCSPContext.h"
 #include "mozilla/dom/nsCSPService.h"
 #include "mozilla/dom/nsCSPUtils.h"
@@ -187,17 +186,16 @@
 #include "nsHTMLCSSStyleSheet.h"
 #include "SVGAttrAnimationRuleProcessor.h"
 #include "mozilla/dom/DOMImplementation.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/Comment.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/Link.h"
 #include "mozilla/dom/HTMLElementBinding.h"
-#include "mozilla/dom/SVGElementBinding.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/dom/Touch.h"
 #include "mozilla/dom/TouchEvent.h"
 
 #include "mozilla/Preferences.h"
 
 #include "imgILoader.h"
 #include "imgRequestProxy.h"
@@ -6252,31 +6250,24 @@ nsDocument::RegisterElement(JSContext* a
   }
 
   JS::Rooted<JSObject*> global(aCx, sgo->GetGlobalJSObject());
   nsCOMPtr<nsIAtom> nameAtom;
   int32_t namespaceID = kNameSpaceID_XHTML;
   JS::Rooted<JSObject*> protoObject(aCx);
   {
     JS::Rooted<JSObject*> htmlProto(aCx);
-    JS::Rooted<JSObject*> svgProto(aCx);
     {
       JSAutoCompartment ac(aCx, global);
 
       htmlProto = HTMLElementBinding::GetProtoObjectHandle(aCx);
       if (!htmlProto) {
         rv.Throw(NS_ERROR_OUT_OF_MEMORY);
         return;
       }
-
-      svgProto = SVGElementBinding::GetProtoObjectHandle(aCx);
-      if (!svgProto) {
-        rv.Throw(NS_ERROR_OUT_OF_MEMORY);
-        return;
-      }
     }
 
     if (!aOptions.mPrototype) {
       if (!JS_WrapObject(aCx, &htmlProto)) {
         rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
         return;
       }
 
@@ -6318,72 +6309,54 @@ nsDocument::RegisterElement(JSContext* a
 
       if (!desc.configurable()) {
         rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
         return;
       }
 
       JS::Rooted<JSObject*> protoProto(aCx, protoObject);
 
-      if (!JS_WrapObject(aCx, &htmlProto) || !JS_WrapObject(aCx, &svgProto)) {
+      if (!JS_WrapObject(aCx, &htmlProto)) {
         rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
         return;
       }
 
-      // If PROTOTYPE's interface inherits from SVGElement, set NAMESPACE to SVG
-      // Namespace.
       while (protoProto) {
         if (protoProto == htmlProto) {
           break;
         }
 
-        if (protoProto == svgProto) {
-          namespaceID = kNameSpaceID_SVG;
-          break;
-        }
-
         if (!JS_GetPrototype(aCx, protoProto, &protoProto)) {
           rv.Throw(NS_ERROR_UNEXPECTED);
           return;
         }
       }
     } // Done with the checks, leave prototype's compartment.
 
     // If name was provided and not null...
     if (!lcName.IsEmpty()) {
       // Let BASE be the element interface for NAME and NAMESPACE.
-      bool known = false;
       nameAtom = NS_Atomize(lcName);
-      if (namespaceID == kNameSpaceID_XHTML) {
-        nsIParserService* ps = nsContentUtils::GetParserService();
-        if (!ps) {
-          rv.Throw(NS_ERROR_UNEXPECTED);
-          return;
-        }
-
-        known =
-          ps->HTMLCaseSensitiveAtomTagToId(nameAtom) != eHTMLTag_userdefined;
-      } else {
-        known = SVGElementFactory::Exists(nameAtom);
-      }
+      nsIParserService* ps = nsContentUtils::GetParserService();
+      if (!ps) {
+        rv.Throw(NS_ERROR_UNEXPECTED);
+        return;
+      }
+
+      bool known =
+        ps->HTMLCaseSensitiveAtomTagToId(nameAtom) != eHTMLTag_userdefined;
 
       // If BASE does not exist or is an interface for a custom element, set ERROR
       // to InvalidName and stop.
       // If BASE exists, then it cannot be an interface for a custom element.
       if (!known) {
         rv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
         return;
       }
     } else {
-      // If NAMESPACE is SVG Namespace, set ERROR to InvalidName and stop.
-      if (namespaceID == kNameSpaceID_SVG) {
-        rv.Throw(NS_ERROR_UNEXPECTED);
-        return;
-      }
-
       nameAtom = typeAtom;
     }
   } // Leaving the document's compartment for the LifecycleCallbacks init
 
   JS::Rooted<JSObject*> wrappedProto(aCx, protoObject);
   if (!JS_WrapObject(aCx, &wrappedProto)) {
     rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return;
--- a/dom/svg/SVGElementFactory.cpp
+++ b/dom/svg/SVGElementFactory.cpp
@@ -99,24 +99,16 @@ void
 SVGElementFactory::Shutdown()
 {
   if (sTagAtomTable) {
     PL_HashTableDestroy(sTagAtomTable);
     sTagAtomTable = nullptr;
   }
 }
 
-bool
-SVGElementFactory::Exists(nsIAtom *aTag)
-{
-  MOZ_ASSERT(sTagAtomTable, "no lookup table, needs SVGElementFactory::Init");
-  void* tag = PL_HashTableLookupConst(sTagAtomTable, aTag);
-  return tag != nullptr;
-}
-
 nsresult
 NS_NewSVGElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
                  FromParser aFromParser)
 {
   NS_ASSERTION(sTagAtomTable, "no lookup table, needs SVGElementFactory::Init");
 
   RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
   nsIAtom* name = ni->NameAtom();
--- a/dom/svg/SVGElementFactory.h
+++ b/dom/svg/SVGElementFactory.h
@@ -11,16 +11,14 @@ class nsIAtom;
 
 namespace mozilla {
 namespace dom {
 
 class SVGElementFactory {
 public:
   static void Init();
   static void Shutdown();
-
-  static bool Exists(nsIAtom *aTag);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_SVGElementFactory_h */
--- a/dom/tests/mochitest/webcomponents/test_document_register.html
+++ b/dom/tests/mochitest/webcomponents/test_document_register.html
@@ -41,44 +41,34 @@ function startTest() {
 
   // If prototype is an interface prototype object for any interface object,
   // registration will throw.
   testRegisterSimple("x-html-elem", HTMLElement.prototype, true);
   testRegisterSimple("x-html-select", HTMLSelectElement.prototype, true);
   testRegisterSimple("some-elem", HTMLElement.prototype, true);
   testRegisterSimple("x-html-p", HTMLParagraphElement.prototype, true);
   testRegisterSimple("x-html-span", HTMLSpanElement.prototype, true);
-  testRegisterSimple("x-svg-proto", SVGElement.prototype, true);
 
   // Make sure the prototype on unresolved elements is HTMLElement not HTMLUnknownElement.
   var unresolved = document.getElementById("unresolved");
   is(unresolved.__proto__, HTMLElement.prototype, "Unresolved custom elements should have HTMLElement as prototype.");
 
   var anotherUnresolved = document.createElement("maybe-custom-element");
   is(anotherUnresolved.__proto__, HTMLElement.prototype, "Unresolved custom elements should have HTMLElement as prototype.");
 
   // Registering without a prototype should automatically create one inheriting from HTMLElement.
   testRegisterSimple("x-elem-no-proto", null, false);
-  var simpleElem = document.createElement("x-elem-no-proto");
-  is(simpleElem.__proto__.__proto__, HTMLElement.prototype, "Default prototype should inherit from HTMLElement");
 
   var simpleProto = Object.create(HTMLElement.prototype);
   testRegisterSimple("x-elem-simple-proto", simpleProto, false);
-  var simpleProtoElem = document.createElement("x-elem-simple-proto");
-  is(simpleProtoElem.__proto__, simpleProto, "Custom element should use registered prototype.");
-  var anotherSimpleElem = document.createElementNS("http://www.w3.org/1999/xhtml", "x-elem-simple-proto");
-  is(anotherSimpleElem.__proto__, simpleProto, "Custom element should use registered prototype.");
 
   // Test registering some invalid prototypes.
   testRegisterSimple("x-invalid-number", 42, true);
   testRegisterSimple("x-invalid-boolean", false, true);
   testRegisterSimple("x-invalid-float", 1.0, true);
-  // Can not register with a prototype that inherits from SVGElement
-  // without extending an existing element type.
-  testRegisterSimple("x-html-obj-svg", Object.create(SVGElement.prototype), true);
   // A prototype with a non-configurable "constructor" property must throw.
   var nonConfigProto = Object.create(HTMLElement.prototype,
     { constructor: { configurable: false, value: function() {} } });
   testRegisterSimple("x-non-config-proto", nonConfigProto, true);
 
   // Test invalid custom element names.
   testRegisterSimple("invalid", Object.create(HTMLElement.prototype), true);
   testRegisterSimple("annotation-xml", Object.create(HTMLElement.prototype), true);
@@ -91,32 +81,23 @@ function startTest() {
   testRegisterSimple("missing-glyph", Object.create(HTMLElement.prototype), true);
 
   // Test registering elements that extend from an existing element.
   testRegisterExtend("x-extend-span", "span", Object.create(HTMLElement.prototype), false);
   testRegisterExtend("x-extend-span-caps", "SPAN", Object.create(HTMLElement.prototype), false);
 
   // Test registering elements that extend from a non-existing element.
   testRegisterExtend("x-extend-span-nonexist", "nonexisting", Object.create(HTMLElement.prototype), true);
-  testRegisterExtend("x-extend-svg-nonexist", "nonexisting", Object.create(SVGElement.prototype), true);
 
   // Test registration with duplicate type.
   testRegisterSimple("x-dupe-me", Object.create(HTMLElement.prototype), false);
   testRegisterSimple("x-dupe-me", Object.create(HTMLElement.prototype), true);
   testRegisterSimple("X-DUPE-ME", Object.create(HTMLElement.prototype), true);
   testRegisterSimple("x-dupe-me", null, true);
   testRegisterExtend("x-dupe-me", "span", Object.create(HTMLElement.prototype), true);
-  testRegisterExtend("x-dupe-me", "shape", Object.create(SVGElement.prototype), true);
-
-  testRegisterExtend("x-svg-dupe-me", "circle", Object.create(SVGElement.prototype), false);
-  testRegisterSimple("x-svg-dupe-me", Object.create(HTMLElement.prototype), true);
-  testRegisterSimple("X-SVG-DUPE-ME", Object.create(HTMLElement.prototype), true);
-  testRegisterSimple("x-svg-dupe-me", null, true);
-  testRegisterExtend("x-svg-dupe-me", "span", Object.create(HTMLElement.prototype), true);
-  testRegisterExtend("x-svg-dupe-me", "shape", Object.create(SVGElement.prototype), true);
 
   // 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.");
deleted file mode 100644
--- a/testing/web-platform/meta/custom-elements/v0/instantiating/custom-element-constructor-prototype.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[custom-element-constructor-prototype.html]
-  type: testharness
-  [If custom element type is registered with prototype, the custom element constructor should have the prototype specified in registerElement() call]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/custom-elements/v0/instantiating/custom-element-prototype.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[custom-element-prototype.html]
-  type: testharness
-  [If custom element type is registered with prototype, the custom element instance should have the prototype specified in registerElement() call]
-    expected: FAIL
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/custom-elements/v0/registering/definition-construction-algorithm-svg-namespace.html.ini
@@ -0,0 +1,4 @@
+[definition-construction-algorithm-svg-namespace.html]
+  type: testharness
+  [For SVG prototype namespace is SVG namespace]
+    expected: FAIL