Bug 1338889 - Part 2: Support DOMString as Argument 3 of Document.createElementNS. r=bz
authorJohn Dai <jdai@mozilla.com>
Wed, 15 Feb 2017 00:07:00 +0800
changeset 343067 1fe1c039817861a09bfb7ffd361ec0ebde9d834c
parent 343066 8b2b7bf67ff7f54cce45f1bbecb5bf371ce025fd
child 343068 4c483e15fb91e4aaa6fb99e548d48516de194a78
push id31369
push userkwierso@gmail.com
push dateThu, 16 Feb 2017 00:18:40 +0000
treeherdermozilla-central@e9b926463f9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1338889
milestone54.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 1338889 - Part 2: Support DOMString as Argument 3 of Document.createElementNS. r=bz
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
dom/webidl/Document.webidl
dom/xml/XMLDocument.cpp
dom/xslt/xslt/txMozillaXSLTProcessor.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -5654,45 +5654,50 @@ nsDocument::CreateElement(const nsAStrin
 }
 
 NS_IMETHODIMP
 nsDocument::CreateElementNS(const nsAString& aNamespaceURI,
                             const nsAString& aQualifiedName,
                             nsIDOMElement** aReturn)
 {
   *aReturn = nullptr;
-  ElementCreationOptions options;
+  ElementCreationOptionsOrString options;
+
+  options.SetAsString();
   ErrorResult rv;
   nsCOMPtr<Element> element =
     CreateElementNS(aNamespaceURI, aQualifiedName, options, rv);
   NS_ENSURE_FALSE(rv.Failed(), rv.StealNSResult());
   return CallQueryInterface(element, aReturn);
 }
 
 already_AddRefed<Element>
 nsDocument::CreateElementNS(const nsAString& aNamespaceURI,
                             const nsAString& aQualifiedName,
-                            const ElementCreationOptions& aOptions,
+                            const ElementCreationOptionsOrString& aOptions,
                             ErrorResult& rv)
 {
   RefPtr<mozilla::dom::NodeInfo> nodeInfo;
   rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI,
                                             aQualifiedName,
                                             mNodeInfoManager,
                                             nsIDOMNode::ELEMENT_NODE,
                                             getter_AddRefs(nodeInfo));
   if (rv.Failed()) {
     return nullptr;
   }
 
-  // Throw NotFoundError if 'is' is not-null and definition is null
-  const nsString* is = CheckCustomElementName(
-    aOptions, aQualifiedName, nodeInfo->NamespaceID(), rv);
-  if (rv.Failed()) {
-    return nullptr;
+  const nsString* is = nullptr;
+  if (aOptions.IsElementCreationOptions()) {
+    // Throw NotFoundError if 'is' is not-null and definition is null
+    is = CheckCustomElementName(aOptions.GetAsElementCreationOptions(),
+                                aQualifiedName, nodeInfo->NamespaceID(), rv);
+    if (rv.Failed()) {
+      return nullptr;
+    }
   }
 
   nsCOMPtr<Element> element;
   rv = NS_NewElement(getter_AddRefs(element), nodeInfo.forget(),
                      NOT_FROM_PARSER, is);
   if (rv.Failed()) {
     return nullptr;
   }
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1135,17 +1135,17 @@ public:
   virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
   virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
   virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) override;
   virtual already_AddRefed<Element> CreateElement(const nsAString& aTagName,
                                                   const mozilla::dom::ElementCreationOptionsOrString& aOptions,
                                                   ErrorResult& rv) override;
   virtual already_AddRefed<Element> CreateElementNS(const nsAString& aNamespaceURI,
                                                     const nsAString& aQualifiedName,
-                                                    const mozilla::dom::ElementCreationOptions& aOptions,
+                                                    const mozilla::dom::ElementCreationOptionsOrString& aOptions,
                                                     mozilla::ErrorResult& rv) override;
 
   virtual nsIDocument* MasterDocument() override
   {
     return mMasterDocument ? mMasterDocument.get()
                            : this;
   }
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -2603,17 +2603,17 @@ public:
   // GetElementById defined above
   virtual already_AddRefed<Element>
     CreateElement(const nsAString& aTagName,
                   const mozilla::dom::ElementCreationOptionsOrString& aOptions,
                   mozilla::ErrorResult& rv) = 0;
   virtual already_AddRefed<Element>
     CreateElementNS(const nsAString& aNamespaceURI,
                     const nsAString& aQualifiedName,
-                    const mozilla::dom::ElementCreationOptions& aOptions,
+                    const mozilla::dom::ElementCreationOptionsOrString& aOptions,
                     mozilla::ErrorResult& rv) = 0;
   already_AddRefed<mozilla::dom::DocumentFragment>
     CreateDocumentFragment() const;
   already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
   already_AddRefed<mozilla::dom::Comment>
     CreateComment(const nsAString& aData) const;
   already_AddRefed<mozilla::dom::ProcessingInstruction>
     CreateProcessingInstruction(const nsAString& target, const nsAString& data,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -50,17 +50,17 @@ interface Document : Node {
   [Pure]
   HTMLCollection getElementsByClassName(DOMString classNames);
   [Pure]
   Element? getElementById(DOMString elementId);
 
   [NewObject, Throws]
   Element createElement(DOMString localName, optional (ElementCreationOptions or DOMString) options);
   [NewObject, Throws]
-  Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options);
+  Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional (ElementCreationOptions or DOMString) options);
   [NewObject]
   DocumentFragment createDocumentFragment();
   [NewObject]
   Text createTextNode(DOMString data);
   [NewObject]
   Comment createComment(DOMString data);
   [NewObject, Throws]
   ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
--- a/dom/xml/XMLDocument.cpp
+++ b/dom/xml/XMLDocument.cpp
@@ -159,19 +159,21 @@ NS_NewDOMDocument(nsIDOMDocument** aInst
     d->AppendChild(*doctypeAsNode, result);
     if (NS_WARN_IF(result.Failed())) {
       return result.StealNSResult();
     }
   }
 
   if (!aQualifiedName.IsEmpty()) {
     ErrorResult result;
+    ElementCreationOptionsOrString options;
+    options.SetAsString();
+
     nsCOMPtr<Element> root =
-      doc->CreateElementNS(aNamespaceURI, aQualifiedName,
-                           ElementCreationOptions(), result);
+      doc->CreateElementNS(aNamespaceURI, aQualifiedName, options, result);
     if (NS_WARN_IF(result.Failed())) {
       return result.StealNSResult();
     }
 
     d->AppendChild(*root, result);
     if (NS_WARN_IF(result.Failed())) {
       return result.StealNSResult();
     }
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -1121,19 +1121,22 @@ txMozillaXSLTProcessor::notifyError()
     MOZ_ASSERT(document->GetReadyStateEnum() ==
                  nsIDocument::READYSTATE_UNINITIALIZED,
                "Bad readyState.");
     document->SetReadyStateInternal(nsIDocument::READYSTATE_LOADING);
 
     NS_NAMED_LITERAL_STRING(ns, "http://www.mozilla.org/newlayout/xml/parsererror.xml");
 
     IgnoredErrorResult rv;
+    ElementCreationOptionsOrString options;
+    options.SetAsString();
+
     nsCOMPtr<Element> element =
         document->CreateElementNS(ns, NS_LITERAL_STRING("parsererror"),
-                                  ElementCreationOptions(), rv);
+                                  options, rv);
     if (rv.Failed()) {
         return;
     }
 
     document->AppendChild(*element, rv);
     if (rv.Failed()) {
         return;
     }
@@ -1141,19 +1144,22 @@ txMozillaXSLTProcessor::notifyError()
     RefPtr<nsTextNode> text = document->CreateTextNode(mErrorText);
 
     element->AppendChild(*text, rv);
     if (rv.Failed()) {
         return;
     }
 
     if (!mSourceText.IsEmpty()) {
+        ElementCreationOptionsOrString options;
+        options.SetAsString();
+
         nsCOMPtr<Element> sourceElement =
             document->CreateElementNS(ns, NS_LITERAL_STRING("sourcetext"),
-                                      ElementCreationOptions(), rv);
+                                      options, rv);
         if (rv.Failed()) {
             return;
         }
 
         element->AppendChild(*sourceElement, rv);
         if (rv.Failed()) {
             return;
         }