Bug 923913 - Make Element.inner/outerHTML [Pure], r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 08 Oct 2013 22:25:01 +0300
changeset 164888 772be3f89d8e51a6ac5b3c19e5e314e7d6e6dd30
parent 164887 7cd3fde42755c29a1538aa5243f5f254c8f89592
child 164889 31aab4ccfcbeac63ace3e44fd3df2d7c38748e0f
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs923913
milestone27.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 923913 - Make Element.inner/outerHTML [Pure], r=bz
content/base/public/Element.h
content/base/src/Element.cpp
content/html/content/src/HTMLElement.cpp
content/html/content/src/HTMLScriptElement.cpp
content/html/content/src/HTMLScriptElement.h
content/html/content/src/HTMLStyleElement.cpp
content/html/content/src/HTMLStyleElement.h
content/html/content/src/nsGenericHTMLElement.h
dom/webidl/Element.webidl
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -720,19 +720,19 @@ public:
   {
     return false;
   }
 
   virtual void SetUndoScope(bool aUndoScope, ErrorResult& aError)
   {
   }
 
-  virtual void GetInnerHTML(nsAString& aInnerHTML, ErrorResult& aError);
+  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML);
   virtual void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
-  void GetOuterHTML(nsAString& aOuterHTML, ErrorResult& aError);
+  void GetOuterHTML(nsAString& aOuterHTML);
   void SetOuterHTML(const nsAString& aOuterHTML, ErrorResult& aError);
   void InsertAdjacentHTML(const nsAString& aPosition, const nsAString& aText,
                           ErrorResult& aError);
 
   //----------------------------------------
 
   /**
    * Add a script event listener with the given event handler name
@@ -1119,17 +1119,17 @@ private:
    * Get this element's client area rect in app units.
    * @return the frame's client area
    */
   nsRect GetClientAreaRect();
 
   nsIScrollableFrame* GetScrollFrame(nsIFrame **aStyledFrame = nullptr,
                                      bool aFlushLayout = true);
 
-  nsresult GetMarkup(bool aIncludeSelf, nsAString& aMarkup);
+  void GetMarkup(bool aIncludeSelf, nsAString& aMarkup);
 
   // Data members
   nsEventStates mState;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(Element, NS_ELEMENT_IID)
 
 inline bool
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -3102,24 +3102,25 @@ Serialize(Element* aRoot, bool aDescende
 
       if (aDescendentsOnly && current == aRoot) {
         return builder.ToString(aOut);
       }
     }
   }
 }
 
-nsresult
+void
 Element::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
 {
   aMarkup.Truncate();
 
   nsIDocument* doc = OwnerDoc();
   if (IsInHTMLDocument()) {
-    return Serialize(this, !aIncludeSelf, aMarkup) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    Serialize(this, !aIncludeSelf, aMarkup);
+    return;
   }
 
   nsAutoString contentType;
   doc->GetContentType(contentType);
 
   nsCOMPtr<nsIDocumentEncoder> docEncoder = doc->GetCachedEncoder();
   if (!docEncoder) {
     docEncoder =
@@ -3130,17 +3131,17 @@ Element::GetMarkup(bool aIncludeSelf, ns
   }
   if (!docEncoder) {
     // This could be some type for which we create a synthetic document.  Try
     // again as XML
     contentType.AssignLiteral("application/xml");
     docEncoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xml");
   }
 
-  NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE_VOID(docEncoder);
 
   uint32_t flags = nsIDocumentEncoder::OutputEncodeBasicEntities |
                    // Output DOM-standard newlines
                    nsIDocumentEncoder::OutputLFLineBreak |
                    // Don't do linebreaking that's not present in
                    // the source
                    nsIDocumentEncoder::OutputRaw |
                    // Only check for mozdirty when necessary (bug 599983)
@@ -3148,29 +3149,29 @@ Element::GetMarkup(bool aIncludeSelf, ns
 
   if (IsEditable()) {
     nsIEditor* editor = GetEditorInternal();
     if (editor && editor->OutputsMozDirty()) {
       flags &= ~nsIDocumentEncoder::OutputIgnoreMozDirty;
     }
   }
 
-  nsresult rv = docEncoder->NativeInit(doc, contentType, flags);
-  NS_ENSURE_SUCCESS(rv, rv);
+  DebugOnly<nsresult> rv = docEncoder->NativeInit(doc, contentType, flags);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   if (aIncludeSelf) {
     docEncoder->SetNativeNode(this);
   } else {
     docEncoder->SetNativeContainerNode(this);
   }
   rv = docEncoder->EncodeToString(aMarkup);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
   if (!aIncludeSelf) {
     doc->SetCachedEncoder(docEncoder.forget());
   }
-  return rv;
 }
 
 /**
  * Fire mutation events for changes caused by parsing directly into a
  * context node.
  *
  * @param aDoc the document of the node
  * @param aDest the destination node that got stuff appended to it
@@ -3192,20 +3193,21 @@ FireMutationEventsForDirectParsing(nsIDo
          child;
          child = child->GetNextSibling()) {
       childNodes.AppendElement(child);
     }
     Element::FireNodeInserted(aDoc, aDest, childNodes);
   }
 }
 
-void
-Element::GetInnerHTML(nsAString& aInnerHTML, ErrorResult& aError)
+NS_IMETHODIMP
+Element::GetInnerHTML(nsAString& aInnerHTML)
 {
-  aError = GetMarkup(false, aInnerHTML);
+  GetMarkup(false, aInnerHTML);
+  return NS_OK;
 }
 
 void
 Element::SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError)
 {
   FragmentOrElement* target = this;
   // Handle template case.
   if (nsNodeUtils::IsTemplateElement(target)) {
@@ -3261,19 +3263,19 @@ Element::SetInnerHTML(const nsAString& a
 
       static_cast<nsINode*>(target)->AppendChild(*fragment, aError);
       mb.NodesAdded();
     }
   }
 }
 
 void
-Element::GetOuterHTML(nsAString& aOuterHTML, ErrorResult& aError)
+Element::GetOuterHTML(nsAString& aOuterHTML)
 {
-  aError = GetMarkup(true, aOuterHTML);
+  GetMarkup(true, aOuterHTML);
 }
 
 void
 Element::SetOuterHTML(const nsAString& aOuterHTML, ErrorResult& aError)
 {
   nsCOMPtr<nsINode> parent = GetParentNode();
   if (!parent) {
     return;
--- a/content/html/content/src/HTMLElement.cpp
+++ b/content/html/content/src/HTMLElement.cpp
@@ -11,19 +11,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
   HTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~HTMLElement();
 
-  using nsGenericHTMLElement::GetInnerHTML;
-  virtual void GetInnerHTML(nsAString& aInnerHTML,
-                            mozilla::ErrorResult& aError) MOZ_OVERRIDE;
+  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo* aNodeInfo,
                          nsINode** aResult) const MOZ_OVERRIDE;
 
 protected:
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
@@ -34,33 +32,33 @@ HTMLElement::HTMLElement(already_AddRefe
 }
 
 HTMLElement::~HTMLElement()
 {
 }
 
 NS_IMPL_ELEMENT_CLONE(HTMLElement)
 
-void
-HTMLElement::GetInnerHTML(nsAString& aInnerHTML, ErrorResult& aError)
+NS_IMETHODIMP
+HTMLElement::GetInnerHTML(nsAString& aInnerHTML)
 {
   /**
    * nsGenericHTMLElement::GetInnerHTML escapes < and > characters (at least).
    * .innerHTML should return the HTML code for xmp and plaintext element.
    *
    * This code is a workaround until we implement a HTML5 Serializer
    * with this behavior.
    */
   if (mNodeInfo->Equals(nsGkAtoms::xmp) ||
       mNodeInfo->Equals(nsGkAtoms::plaintext)) {
     nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
-    return;
+    return NS_OK;
   }
 
-  nsGenericHTMLElement::GetInnerHTML(aInnerHTML, aError);
+  return nsGenericHTMLElement::GetInnerHTML(aInnerHTML);
 }
 
 JSObject*
 HTMLElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return dom::HTMLElementBinding::Wrap(aCx, aScope, this);
 }
 
--- a/content/html/content/src/HTMLScriptElement.cpp
+++ b/content/html/content/src/HTMLScriptElement.cpp
@@ -221,20 +221,21 @@ HTMLScriptElement::AfterSetAttr(int32_t 
 {
   if (nsGkAtoms::async == aName && kNameSpaceID_None == aNamespaceID) {
     mForceAsync = false;
   }
   return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
                                             aNotify);
 }
 
-void
-HTMLScriptElement::GetInnerHTML(nsAString& aInnerHTML, ErrorResult& aError)
+NS_IMETHODIMP
+HTMLScriptElement::GetInnerHTML(nsAString& aInnerHTML)
 {
   nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
+  return NS_OK;
 }
 
 void
 HTMLScriptElement::SetInnerHTML(const nsAString& aInnerHTML,
                                 ErrorResult& aError)
 {
   aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
 }
--- a/content/html/content/src/HTMLScriptElement.h
+++ b/content/html/content/src/HTMLScriptElement.h
@@ -25,19 +25,17 @@ public:
 
   HTMLScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
                       FromParser aFromParser);
   virtual ~HTMLScriptElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
-  using nsGenericHTMLElement::GetInnerHTML;
-  virtual void GetInnerHTML(nsAString& aInnerHTML,
-                            mozilla::ErrorResult& aError) MOZ_OVERRIDE;
+  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE;
   using nsGenericHTMLElement::SetInnerHTML;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
   // nsIDOMHTMLScriptElement
   NS_DECL_NSIDOMHTMLSCRIPTELEMENT
 
   // nsIScriptElement
--- a/content/html/content/src/HTMLStyleElement.cpp
+++ b/content/html/content/src/HTMLStyleElement.cpp
@@ -196,20 +196,21 @@ HTMLStyleElement::UnsetAttr(int32_t aNam
     } else if (aAttribute == nsGkAtoms::scoped) {
       UpdateStyleSheetScopedness(false);
     }
   }
 
   return rv;
 }
 
-void
-HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML, ErrorResult& aError)
+NS_IMETHODIMP
+HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML)
 {
   nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
+  return NS_OK;
 }
 
 void
 HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
                                ErrorResult& aError)
 {
   SetEnableUpdates(false);
 
--- a/content/html/content/src/HTMLStyleElement.h
+++ b/content/html/content/src/HTMLStyleElement.h
@@ -28,19 +28,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLStyleElement,
                                            nsGenericHTMLElement)
 
-  using nsGenericHTMLElement::GetInnerHTML;
-  virtual void GetInnerHTML(nsAString& aInnerHTML,
-                            mozilla::ErrorResult& aError) MOZ_OVERRIDE;
+  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE;
   using nsGenericHTMLElement::SetInnerHTML;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
   // nsIDOMHTMLStyleElement
   NS_DECL_NSIDOMHTMLSTYLEELEMENT
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -459,19 +459,18 @@ public:
     return NS_OK;
   }
   NS_IMETHOD SetSpellcheck(bool aSpellcheck) MOZ_FINAL {
     mozilla::ErrorResult rv;
     SetSpellcheck(aSpellcheck, rv);
     return rv.ErrorCode();
   }
   NS_IMETHOD GetOuterHTML(nsAString& aOuterHTML) MOZ_FINAL {
-    mozilla::ErrorResult rv;
-    mozilla::dom::Element::GetOuterHTML(aOuterHTML, rv);
-    return rv.ErrorCode();
+    mozilla::dom::Element::GetOuterHTML(aOuterHTML);
+    return NS_OK;
   }
   NS_IMETHOD SetOuterHTML(const nsAString& aOuterHTML) MOZ_FINAL {
     mozilla::ErrorResult rv;
     mozilla::dom::Element::SetOuterHTML(aOuterHTML, rv);
     return rv.ErrorCode();
   }                                                                            \
   NS_IMETHOD InsertAdjacentHTML(const nsAString& position,
                                 const nsAString& text) MOZ_FINAL;
@@ -523,21 +522,18 @@ public:
     mozilla::ErrorResult rv;
     Focus(rv);
     return rv.ErrorCode();
   }
   NS_IMETHOD GetDraggable(bool* aDraggable) MOZ_FINAL {
     *aDraggable = Draggable();
     return NS_OK;
   }
-  using mozilla::dom::Element::GetInnerHTML;
-  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_FINAL {
-    mozilla::ErrorResult rv;
-    GetInnerHTML(aInnerHTML, rv);
-    return rv.ErrorCode();
+  NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE {
+    return mozilla::dom::Element::GetInnerHTML(aInnerHTML);
   }
   using mozilla::dom::Element::SetInnerHTML;
   NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) MOZ_FINAL {
     mozilla::ErrorResult rv;
     SetInnerHTML(aInnerHTML, rv);
     return rv.ErrorCode();
   }
 
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -170,19 +170,19 @@ partial interface Element {
   [Pref="dom.undo_manager.enabled"]
   readonly attribute UndoManager? undoManager;
   [SetterThrows,Pref="dom.undo_manager.enabled"]
   attribute boolean undoScope;
 };
 
 // http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
 partial interface Element {
-  [Throws,TreatNullAs=EmptyString]
+  [Pure,SetterThrows,TreatNullAs=EmptyString]
   attribute DOMString innerHTML;
-  [Throws,TreatNullAs=EmptyString]
+  [Pure,SetterThrows,TreatNullAs=EmptyString]
   attribute DOMString outerHTML;
   [Throws]
   void insertAdjacentHTML(DOMString position, DOMString text);
 };
 
 // http://www.w3.org/TR/selectors-api/#interface-definitions
 partial interface Element {
   [Throws]