Fix for bug 804950 (New DOM binding APIs for Element). r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 16 Oct 2012 13:51:00 +0200
changeset 112977 b2bdbfe06b10d57adfd6a4573d07b966c443d17c
parent 112976 d785c6a18a3eef270b234dda56642d54ae6453ac
child 112978 96e7580fb756584faa1e59644af537b85bb7c4b3
child 112980 dbc3eb4a6931a8a21670c005086f106eef06a92b
child 117343 a090e3ede2e7fc1d58b2ff64f280157f65b99b82
push id23844
push userryanvm@gmail.com
push dateSun, 11 Nov 2012 19:29:10 +0000
treeherdermozilla-central@b2bdbfe06b10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs804950
milestone19.0a1
first release with
nightly linux32
b2bdbfe06b10 / 19.0a1 / 20121112030753 / files
nightly linux64
b2bdbfe06b10 / 19.0a1 / 20121112030753 / files
nightly mac
b2bdbfe06b10 / 19.0a1 / 20121112030753 / files
nightly win32
b2bdbfe06b10 / 19.0a1 / 20121112030753 / files
nightly win64
b2bdbfe06b10 / 19.0a1 / 20121112030753 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 804950 (New DOM binding APIs for Element). r=bz.
content/base/public/Element.h
content/base/public/FragmentOrElement.h
content/base/public/nsINode.h
content/base/src/FragmentOrElement.cpp
content/base/src/nsContentList.h
content/base/src/nsContentUtils.cpp
content/base/src/nsDOMAttribute.h
content/base/src/nsDOMAttributeMap.cpp
content/base/src/nsDOMAttributeMap.h
content/base/src/nsDOMSettableTokenList.cpp
content/base/src/nsDOMTokenList.cpp
content/base/src/nsDOMTokenList.h
content/base/src/nsDocument.h
content/base/src/nsGenericElement.cpp
content/base/src/nsGenericElement.h
content/base/src/nsINode.cpp
content/html/content/public/nsHTMLAudioElement.h
content/html/content/public/nsHTMLCanvasElement.h
content/html/content/public/nsHTMLVideoElement.h
content/html/content/public/nsIHTMLCollection.h
content/html/content/src/HTMLPropertiesCollection.h
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsGenericHTMLElement.h
content/html/content/src/nsHTMLAnchorElement.cpp
content/html/content/src/nsHTMLAreaElement.cpp
content/html/content/src/nsHTMLBRElement.cpp
content/html/content/src/nsHTMLBodyElement.cpp
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLDataListElement.cpp
content/html/content/src/nsHTMLDivElement.cpp
content/html/content/src/nsHTMLElement.cpp
content/html/content/src/nsHTMLFieldSetElement.h
content/html/content/src/nsHTMLFontElement.cpp
content/html/content/src/nsHTMLFormElement.cpp
content/html/content/src/nsHTMLFormElement.h
content/html/content/src/nsHTMLFrameElement.cpp
content/html/content/src/nsHTMLFrameSetElement.h
content/html/content/src/nsHTMLHRElement.cpp
content/html/content/src/nsHTMLHeadingElement.cpp
content/html/content/src/nsHTMLIFrameElement.h
content/html/content/src/nsHTMLImageElement.h
content/html/content/src/nsHTMLInputElement.h
content/html/content/src/nsHTMLLIElement.cpp
content/html/content/src/nsHTMLLabelElement.h
content/html/content/src/nsHTMLLegendElement.h
content/html/content/src/nsHTMLLinkElement.cpp
content/html/content/src/nsHTMLMapElement.cpp
content/html/content/src/nsHTMLMenuElement.h
content/html/content/src/nsHTMLMenuItemElement.h
content/html/content/src/nsHTMLMetaElement.cpp
content/html/content/src/nsHTMLMeterElement.cpp
content/html/content/src/nsHTMLModElement.cpp
content/html/content/src/nsHTMLOListElement.cpp
content/html/content/src/nsHTMLObjectElement.cpp
content/html/content/src/nsHTMLOptGroupElement.h
content/html/content/src/nsHTMLOptionElement.h
content/html/content/src/nsHTMLOutputElement.cpp
content/html/content/src/nsHTMLParagraphElement.cpp
content/html/content/src/nsHTMLPreElement.cpp
content/html/content/src/nsHTMLProgressElement.cpp
content/html/content/src/nsHTMLScriptElement.cpp
content/html/content/src/nsHTMLSelectElement.cpp
content/html/content/src/nsHTMLSelectElement.h
content/html/content/src/nsHTMLSharedElement.cpp
content/html/content/src/nsHTMLSharedObjectElement.cpp
content/html/content/src/nsHTMLSourceElement.cpp
content/html/content/src/nsHTMLSpanElement.cpp
content/html/content/src/nsHTMLStyleElement.cpp
content/html/content/src/nsHTMLTableCaptionElement.cpp
content/html/content/src/nsHTMLTableCellElement.cpp
content/html/content/src/nsHTMLTableColElement.cpp
content/html/content/src/nsHTMLTableElement.cpp
content/html/content/src/nsHTMLTableElement.h
content/html/content/src/nsHTMLTableRowElement.cpp
content/html/content/src/nsHTMLTableSectionElement.cpp
content/html/content/src/nsHTMLTextAreaElement.cpp
content/html/content/src/nsHTMLTitleElement.cpp
content/html/content/src/nsHTMLUnknownElement.cpp
content/mathml/content/src/nsMathMLElement.h
content/svg/content/src/SVGFragmentIdentifier.cpp
content/svg/content/src/nsSVGAElement.h
content/svg/content/src/nsSVGAltGlyphElement.cpp
content/svg/content/src/nsSVGAnimateElement.cpp
content/svg/content/src/nsSVGAnimateMotionElement.h
content/svg/content/src/nsSVGAnimateTransformElement.cpp
content/svg/content/src/nsSVGCircleElement.cpp
content/svg/content/src/nsSVGClipPathElement.h
content/svg/content/src/nsSVGDefsElement.cpp
content/svg/content/src/nsSVGDescElement.cpp
content/svg/content/src/nsSVGEllipseElement.cpp
content/svg/content/src/nsSVGFilterElement.h
content/svg/content/src/nsSVGFilters.cpp
content/svg/content/src/nsSVGFilters.h
content/svg/content/src/nsSVGForeignObjectElement.h
content/svg/content/src/nsSVGGElement.cpp
content/svg/content/src/nsSVGGradientElement.h
content/svg/content/src/nsSVGImageElement.h
content/svg/content/src/nsSVGLineElement.cpp
content/svg/content/src/nsSVGMarkerElement.h
content/svg/content/src/nsSVGMaskElement.h
content/svg/content/src/nsSVGMetadataElement.cpp
content/svg/content/src/nsSVGMpathElement.h
content/svg/content/src/nsSVGPathElement.h
content/svg/content/src/nsSVGPatternElement.h
content/svg/content/src/nsSVGPolygonElement.cpp
content/svg/content/src/nsSVGPolylineElement.cpp
content/svg/content/src/nsSVGRectElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGSVGElement.h
content/svg/content/src/nsSVGScriptElement.cpp
content/svg/content/src/nsSVGSetElement.cpp
content/svg/content/src/nsSVGStopElement.cpp
content/svg/content/src/nsSVGStyleElement.cpp
content/svg/content/src/nsSVGSwitchElement.h
content/svg/content/src/nsSVGSymbolElement.cpp
content/svg/content/src/nsSVGTSpanElement.cpp
content/svg/content/src/nsSVGTextElement.cpp
content/svg/content/src/nsSVGTextPathElement.h
content/svg/content/src/nsSVGTitleElement.cpp
content/svg/content/src/nsSVGUnknownElement.cpp
content/svg/content/src/nsSVGUseElement.h
content/svg/content/src/nsSVGViewElement.h
content/xml/content/src/nsXMLElement.h
content/xtf/src/nsXTFElementWrapper.cpp
content/xtf/src/nsXTFElementWrapper.h
content/xul/content/src/nsXULElement.cpp
content/xul/content/src/nsXULElement.h
dom/base/nsDOMClassInfo.cpp
dom/bindings/BindingUtils.h
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/webidl/Element.webidl
js/xpconnect/src/dom_quickstubs.qsconf
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -261,16 +261,18 @@ public:
      * SetDirectionality for every element, and UpdateState is very very slow
      * for some elements.
      */
     if (aNotify) {
       UpdateState(true);
     }
   }
 
+  bool GetBindingURL(nsIDocument *aDocument, css::URLValue **aResult);
+
 protected:
   /**
    * Method to get the _intrinsic_ content state of this element.  This is the
    * state that is independent of the element's presentation.  To get the full
    * content state, use State().  See nsEventStates.h for
    * the possible bits that could be set here.
    */
   virtual nsEventStates IntrinsicState() const;
--- a/content/base/public/FragmentOrElement.h
+++ b/content/base/public/FragmentOrElement.h
@@ -27,16 +27,17 @@ class ContentUnbinder;
 class nsContentList;
 class nsDOMAttributeMap;
 class nsDOMTokenList;
 class nsIControllers;
 class nsICSSDeclaration;
 class nsIDocument;
 class nsDOMStringMap;
 class nsIDOMNamedNodeMap;
+class nsIHTMLCollection;
 class nsINodeInfo;
 class nsIURI;
 
 /**
  * Class that implements the nsIDOMNodeList interface (a list of children of
  * the content), by holding a reference to the content and delegating GetLength
  * and Item to its existing child list.
  * @see nsIDOMNodeList
@@ -215,16 +216,18 @@ public:
   virtual bool IsLink(nsIURI** aURI) const;
 
   virtual void DestroyContent();
   virtual void SaveSubtreeState();
 
   virtual const nsAttrValue* DoGetClasses() const;
   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
 
+  nsIHTMLCollection* Children();
+
 public:
   /**
    * If there are listeners for DOMNodeInserted event, fires the event on all
    * aNodes
    */
   static void FireNodeInserted(nsIDocument* aDoc,
                                nsINode* aParent,
                                nsTArray<nsCOMPtr<nsIContent> >& aNodes);
@@ -364,18 +367,16 @@ protected:
     return static_cast<nsDOMSlots*>(GetExistingSlots());
   }
 
   friend class ::ContentUnbinder;
   /**
    * Array containing all attributes and children for this element
    */
   nsAttrAndChildArray mAttrsAndChildren;
-
-  nsContentList* GetChildrenList();
 };
 
 } // namespace dom
 } // namespace mozilla
 
 /**
  * Tearoff class to implement nsITouchEventReceiver
  */
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -46,16 +46,18 @@ class nsIURI;
 class nsNodeSupportsWeakRefTearoff;
 class nsNodeWeakReference;
 class nsXPCClassInfo;
 class nsGenericElement;
 
 namespace mozilla {
 namespace dom {
 class Element;
+class EventHandlerNonNull;
+class OnErrorEventHandlerNonNull;
 template<typename T> class Optional;
 } // namespace dom
 } // namespace mozilla
 
 namespace JS {
 class Value;
 }
 
@@ -1072,23 +1074,20 @@ public:
     GetTextContentInternal(aTextContent);
   }
   void SetTextContent(const nsAString& aTextContent,
                       mozilla::ErrorResult& aError)
   {
     SetTextContentInternal(aTextContent, aError);
   }
 
-  /**
-   * Helper methods for implementing querySelector/querySelectorAll
-   */
-  nsIContent* QuerySelector(const nsAString& aSelector,
-                            nsresult *aResult);
-  nsresult QuerySelectorAll(const nsAString& aSelector,
-                            nsIDOMNodeList **aReturn);
+  nsGenericElement* QuerySelector(const nsAString& aSelector,
+                                  mozilla::ErrorResult& aResult);
+  already_AddRefed<nsINodeList> QuerySelectorAll(const nsAString& aSelector,
+                                                 mozilla::ErrorResult& aResult);
 
   /**
    * Associate an object aData to aKey on this node. If aData is null any
    * previously registered object and UserDataHandler associated to aKey on
    * this node will be removed.
    * Should only be used to implement the DOM Level 3 UserData API.
    *
    * @param aKey the key to associate the object to
@@ -1610,25 +1609,34 @@ public:
   /* Event stuff that documents and elements share.  This needs to be
      NS_IMETHOD because some subclasses implement DOM methods with
      this exact name and signature and then the calling convention
      needs to match.
 
      Note that we include DOCUMENT_ONLY_EVENT events here so that we
      can forward all the document stuff to this implementation.
   */
-#define EVENT(name_, id_, type_, struct_)                         \
-  NS_IMETHOD GetOn##name_(JSContext *cx, JS::Value *vp);          \
+#define EVENT_HELPER(name_, handlerClass_)                            \
+  mozilla::dom::handlerClass_* GetOn##name_();                        \
+  void SetOn##name_(mozilla::dom::handlerClass_* listener,            \
+                    mozilla::ErrorResult& error);                     \
+  NS_IMETHOD GetOn##name_(JSContext *cx, JS::Value *vp);              \
   NS_IMETHOD SetOn##name_(JSContext *cx, const JS::Value &v);
+#define EVENT(name_, id_, type_, struct_)                             \
+  EVENT_HELPER(name_, EventHandlerNonNull)
 #define TOUCH_EVENT EVENT
 #define DOCUMENT_ONLY_EVENT EVENT
+#define ERROR_EVENT(name_, id_, type_, struct_)                         \
+  EVENT_HELPER(name_, OnErrorEventHandlerNonNull)
 #include "nsEventNameList.h"
+#undef ERROR_EVENT  
 #undef DOCUMENT_ONLY_EVENT
 #undef TOUCH_EVENT
 #undef EVENT  
+#undef EVENT_HELPER
 
 protected:
   static void Trace(nsINode *tmp, TraceCallback cb, void *closure);
   static bool Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb);
   static void Unlink(nsINode *tmp);
 
   nsCOMPtr<nsINodeInfo> mNodeInfo;
 
--- a/content/base/src/FragmentOrElement.cpp
+++ b/content/base/src/FragmentOrElement.cpp
@@ -447,18 +447,18 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNode3
 NS_IMETHODIMP
 nsNode3Tearoff::LookupNamespaceURI(const nsAString& aNamespacePrefix,
                                    nsAString& aNamespaceURI)
 {
   mNode->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
   return NS_OK;
 }
 
-nsContentList*
-FragmentOrElement::GetChildrenList()
+nsIHTMLCollection*
+FragmentOrElement::Children()
 {
   FragmentOrElement::nsDOMSlots *slots = DOMSlots();
 
   if (!slots->mChildrenList) {
     slots->mChildrenList = new nsContentList(this, kNameSpaceID_Wildcard, 
                                              nsGkAtoms::_asterix, nsGkAtoms::_asterix,
                                              false);
   }
--- a/content/base/src/nsContentList.h
+++ b/content/base/src/nsContentList.h
@@ -255,16 +255,17 @@ public:
                 void* aData,
                 bool aDeep = true,
                 nsIAtom* aMatchAtom = nullptr,
                 int32_t aMatchNameSpaceId = kNameSpaceID_None,
                 bool aFuncMayDependOnAttr = true);
   virtual ~nsContentList();
 
   // nsWrapperCache
+  using nsWrapperCache::GetWrapper;
   virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
                                bool *triedToWrap);
 
   // nsIDOMHTMLCollection
   NS_DECL_NSIDOMHTMLCOLLECTION
 
   // nsBaseContentList overrides
   virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -40,16 +40,17 @@
 #include "nsPIDOMWindow.h"
 #include "nsIJSContextStack.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsParserCIID.h"
 #include "nsIParser.h"
 #include "nsIFragmentContentSink.h"
 #include "nsIContentSink.h"
+#include "nsContentList.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIForm.h"
 #include "nsIFormControl.h"
 #include "nsGkAtoms.h"
 #include "imgINotificationObserver.h"
 #include "imgIRequest.h"
@@ -6293,18 +6294,16 @@ nsContentUtils::AllocClassMatchingInfo(n
   }
 
   info->mCaseTreatment =
     aRootNode->OwnerDoc()->GetCompatibilityMode() == eCompatibility_NavQuirks ?
     eIgnoreCase : eCaseMatters;
   return info;
 }
 
-// static
-
 #ifdef DEBUG
 class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
 {
 public:
   DebugWrapperTraversalCallback(void* aWrapper) : mFound(false),
                                                   mWrapper(aWrapper)
   {
     mFlags = WANT_ALL_TRACES;
--- a/content/base/src/nsDOMAttribute.h
+++ b/content/base/src/nsDOMAttribute.h
@@ -15,16 +15,17 @@
 #include "nsIDOMText.h"
 #include "nsIDOMNodeList.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsINodeInfo.h"
 #include "nsDOMAttributeMap.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsStubMutationObserver.h"
+#include "nsGenericElement.h"
 
 // Attribute helper class used to wrap up an attribute with a dom
 // object that implements nsIDOMAttr and nsIDOMNode
 class nsDOMAttribute : public nsIAttribute,
                        public nsIDOMAttr
 {
 public:
   nsDOMAttribute(nsDOMAttributeMap* aAttrMap,
--- a/content/base/src/nsDOMAttributeMap.cpp
+++ b/content/base/src/nsDOMAttributeMap.cpp
@@ -14,16 +14,18 @@
 #include "nsIDocument.h"
 #include "nsINameSpaceManager.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 #include "nsNodeInfoManager.h"
 #include "nsAttrName.h"
 #include "nsUnicharUtils.h"
 
+using namespace mozilla;
+
 //----------------------------------------------------------------------
 
 nsDOMAttributeMap::nsDOMAttributeMap(Element* aContent)
   : mContent(aContent)
 {
   // We don't add a reference to our content. If it goes away,
   // we'll be told to drop our reference
   mAttributeCache.Init();
@@ -119,51 +121,41 @@ nsDOMAttributeMap::DropAttribute(int32_t
     // Break link to map
     node->SetMap(nullptr);
 
     // Remove from cache
     mAttributeCache.Remove(attr);
   }
 }
 
-nsresult
-nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn)
+already_AddRefed<nsDOMAttribute>
+nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo)
 {
   NS_ASSERTION(aNodeInfo, "RemoveAttribute() called with aNodeInfo == nullptr!");
-  NS_ASSERTION(aReturn, "RemoveAttribute() called with aReturn == nullptr");
-
-  *aReturn = nullptr;
 
   nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
 
   nsRefPtr<nsDOMAttribute> node;
   if (!mAttributeCache.Get(attr, getter_AddRefs(node))) {
     nsAutoString value;
     // As we are removing the attribute we need to set the current value in
     // the attribute node.
     mContent->GetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), value);
     nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-    nsCOMPtr<nsIDOMNode> newAttr =
-      new nsDOMAttribute(nullptr, ni.forget(), value, true);
-    if (!newAttr) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-    newAttr.swap(*aReturn);
+    node = new nsDOMAttribute(nullptr, ni.forget(), value, true);
   }
   else {
     // Break link to map
     node->SetMap(nullptr);
 
     // Remove from cache
     mAttributeCache.Remove(attr);
-
-    node.forget(aReturn);
   }
 
-  return NS_OK;
+  return node.forget();
 }
 
 nsDOMAttribute*
 nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo, bool aNsAware)
 {
   NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nullptr!");
 
   nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
@@ -176,20 +168,18 @@ nsDOMAttributeMap::GetAttribute(nsINodeI
     mAttributeCache.Put(attr, newAttr);
     node = newAttr;
   }
 
   return node;
 }
 
 nsDOMAttribute*
-nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
+nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName)
 {
-  *aResult = NS_OK;
-
   if (mContent) {
     nsCOMPtr<nsINodeInfo> ni =
       mContent->GetExistingAttrNameFromQName(aAttrName);
     if (ni) {
       return GetAttribute(ni, false);
     }
   }
 
@@ -197,139 +187,146 @@ nsDOMAttributeMap::GetNamedItem(const ns
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName,
                                 nsIDOMNode** aAttribute)
 {
   NS_ENSURE_ARG_POINTER(aAttribute);
 
-  nsresult rv;
-  NS_IF_ADDREF(*aAttribute = GetNamedItem(aAttrName, &rv));
+  NS_IF_ADDREF(*aAttribute = GetNamedItem(aAttrName));
 
-  return rv;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn)
 {
-  return SetNamedItemInternal(aNode, aReturn, false);
+  ErrorResult rv;
+  *aReturn = SetNamedItemInternal(aNode, false, rv).get();
+  return rv.ErrorCode();
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::SetNamedItemNS(nsIDOMNode *aNode, nsIDOMNode **aReturn)
 {
-  return SetNamedItemInternal(aNode, aReturn, true);
+  ErrorResult rv;
+  *aReturn = SetNamedItemInternal(aNode, true, rv).get();
+  return rv.ErrorCode();
 }
 
-nsresult
+already_AddRefed<nsDOMAttribute>
 nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode,
-                                        nsIDOMNode **aReturn,
-                                        bool aWithNS)
+                                        bool aWithNS,
+                                        ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aNode);
-  NS_ENSURE_ARG_POINTER(aReturn);
-
-  nsresult rv = NS_OK;
-  *aReturn = nullptr;
-  nsCOMPtr<nsIDOMNode> tmpReturn;
-
   if (mContent) {
     // XXX should check same-origin between mContent and aNode however
     // nsContentUtils::CheckSameOrigin can't deal with attributenodes yet
     
     nsCOMPtr<nsIAttribute> iAttribute(do_QueryInterface(aNode));
     if (!iAttribute) {
-      return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
+      aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
+      return nullptr;
     }
 
     nsDOMAttribute *attribute = static_cast<nsDOMAttribute*>(iAttribute.get());
 
     // Check that attribute is not owned by somebody else
     nsDOMAttributeMap* owner = iAttribute->GetMap();
     if (owner) {
       if (owner != this) {
-        return NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR;
+        aError.Throw(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR);
+        return nullptr;
       }
 
       // setting a preexisting attribute is a no-op, just return the same
       // node.
-      NS_ADDREF(*aReturn = aNode);
-      
-      return NS_OK;
+      NS_ADDREF(attribute);
+      return attribute;
     }
 
+    nsresult rv;
     if (!mContent->HasSameOwnerDoc(iAttribute)) {
       nsCOMPtr<nsIDOMDocument> domDoc =
         do_QueryInterface(mContent->OwnerDoc(), &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
+      if (NS_FAILED(rv)) {
+        aError.Throw(rv);
+        return nullptr;
+      }
 
       nsCOMPtr<nsIDOMNode> adoptedNode;
       rv = domDoc->AdoptNode(aNode, getter_AddRefs(adoptedNode));
-      NS_ENSURE_SUCCESS(rv, rv);
+      if (NS_FAILED(rv)) {
+        aError.Throw(rv);
+        return nullptr;
+      }
 
       NS_ASSERTION(adoptedNode == aNode, "Uh, adopt node changed nodes?");
     }
 
     // Get nodeinfo and preexisting attribute (if it exists)
     nsAutoString name;
     nsCOMPtr<nsINodeInfo> ni;
 
+    nsRefPtr<nsDOMAttribute> attr;
     // SetNamedItemNS()
     if (aWithNS) {
       // Return existing attribute, if present
       ni = iAttribute->NodeInfo();
 
       if (mContent->HasAttr(ni->NamespaceID(), ni->NameAtom())) {
-        rv = RemoveAttribute(ni, getter_AddRefs(tmpReturn));
-        NS_ENSURE_SUCCESS(rv, rv);
+        attr = RemoveAttribute(ni);
       }
     }
     else { // SetNamedItem()
       attribute->GetName(name);
 
       // get node-info of old attribute
       ni = mContent->GetExistingAttrNameFromQName(name);
       if (ni) {
-        rv = RemoveAttribute(ni, getter_AddRefs(tmpReturn));
-        NS_ENSURE_SUCCESS(rv, rv);
+        attr = RemoveAttribute(ni);
       }
       else {
         if (mContent->IsInHTMLDocument() &&
             mContent->IsHTML()) {
           nsContentUtils::ASCIIToLower(name);
         }
 
         rv = mContent->NodeInfo()->NodeInfoManager()->
           GetNodeInfo(name, nullptr, kNameSpaceID_None,
                       nsIDOMNode::ATTRIBUTE_NODE, getter_AddRefs(ni));
-        NS_ENSURE_SUCCESS(rv, rv);
+        if (NS_FAILED(rv)) {
+          aError.Throw(rv);
+          return nullptr;
+        }
         // value is already empty
       }
     }
 
     nsAutoString value;
     attribute->GetValue(value);
 
     // Add the new attribute to the attribute map before updating
     // its value in the element. @see bug 364413.
     nsAttrKey attrkey(ni->NamespaceID(), ni->NameAtom());
     mAttributeCache.Put(attrkey, attribute);
     iAttribute->SetMap(this);
 
     rv = mContent->SetAttr(ni->NamespaceID(), ni->NameAtom(),
                            ni->GetPrefixAtom(), value, true);
     if (NS_FAILED(rv)) {
+      aError.Throw(rv);
       DropAttribute(ni->NamespaceID(), ni->NameAtom());
     }
+
+    return attr.forget();
   }
 
-  tmpReturn.swap(*aReturn); // transfers ref.
-
-  return rv;
+  return nullptr;
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
                                    nsIDOMNode** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nullptr;
@@ -401,96 +398,100 @@ nsDOMAttributeMap::GetLength(uint32_t *a
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::GetNamedItemNS(const nsAString& aNamespaceURI,
                                   const nsAString& aLocalName,
                                   nsIDOMNode** aReturn)
 {
-  return GetNamedItemNSInternal(aNamespaceURI, aLocalName, aReturn);
+  ErrorResult rv;
+  NS_IF_ADDREF(*aReturn = GetNamedItemNS(aNamespaceURI, aLocalName, rv));
+  return rv.ErrorCode();
 }
 
-nsresult
-nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI,
-                                          const nsAString& aLocalName,
-                                          nsIDOMNode** aReturn,
-                                          bool aRemove)
+nsDOMAttribute*
+nsDOMAttributeMap::GetNamedItemNS(const nsAString& aNamespaceURI,
+                                  const nsAString& aLocalName,
+                                  ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  *aReturn = nullptr;
+  nsCOMPtr<nsINodeInfo> ni = GetAttrNodeInfo(aNamespaceURI, aLocalName, aError);
+  if (!ni) {
+    return nullptr;
+  }
+
+  return GetAttribute(ni, true);
+}
 
+already_AddRefed<nsINodeInfo>
+nsDOMAttributeMap::GetAttrNodeInfo(const nsAString& aNamespaceURI,
+                                   const nsAString& aLocalName,
+                                   mozilla::ErrorResult& aError)
+{
   if (!mContent) {
-    return NS_OK;
+    return nullptr;
   }
 
   int32_t nameSpaceID = kNameSpaceID_None;
 
   if (!aNamespaceURI.IsEmpty()) {
     nameSpaceID =
       nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
     if (nameSpaceID == kNameSpaceID_Unknown) {
-      return NS_OK;
+      return nullptr;
     }
   }
 
   uint32_t i, count = mContent->GetAttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName* name = mContent->GetAttrNameAt(i);
     int32_t attrNS = name->NamespaceID();
     nsIAtom* nameAtom = name->LocalName();
 
     if (nameSpaceID == attrNS &&
         nameAtom->Equals(aLocalName)) {
       nsCOMPtr<nsINodeInfo> ni;
       ni = mContent->NodeInfo()->NodeInfoManager()->
         GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID,
                     nsIDOMNode::ATTRIBUTE_NODE);
-      NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
-
-      if (aRemove) {
-        return RemoveAttribute(ni, aReturn);
+      if (!ni) {
+        aError.Throw(NS_ERROR_OUT_OF_MEMORY);
       }
 
-      NS_ADDREF(*aReturn = GetAttribute(ni, true));
-
-      return NS_OK;
+      return ni.forget();
     }
   }
 
-  return NS_OK;
+  return nullptr;
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::RemoveNamedItemNS(const nsAString& aNamespaceURI,
                                      const nsAString& aLocalName,
                                      nsIDOMNode** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nullptr;
 
-  nsresult rv = GetNamedItemNSInternal(aNamespaceURI,
-                                       aLocalName,
-                                       aReturn,
-                                       true);
-  NS_ENSURE_SUCCESS(rv, rv);
+  ErrorResult error;
+  nsCOMPtr<nsINodeInfo> ni = GetAttrNodeInfo(aNamespaceURI, aLocalName, error);
+  if (error.Failed()) {
+    return error.ErrorCode();
+  }
 
-  if (!*aReturn) {
+  if (!ni) {
     return NS_ERROR_DOM_NOT_FOUND_ERR;
   }
 
-  nsCOMPtr<nsIAttribute> attr = do_QueryInterface(*aReturn);
-  NS_ASSERTION(attr, "attribute returned from nsDOMAttributeMap::GetNameItemNS "
-               "didn't implement nsIAttribute");
-  NS_ENSURE_TRUE(attr, NS_ERROR_UNEXPECTED);
+  nsRefPtr<nsDOMAttribute> attr = RemoveAttribute(ni);
+  nsINodeInfo *attrNi = attr->NodeInfo();
+  mContent->UnsetAttr(attrNi->NamespaceID(), attrNi->NameAtom(), true);
 
-  nsINodeInfo *ni = attr->NodeInfo();
-  mContent->UnsetAttr(ni->NamespaceID(), ni->NameAtom(), true);
-
+  attr.forget(aReturn);
   return NS_OK;
 }
 
 uint32_t
 nsDOMAttributeMap::Count() const
 {
   return mAttributeCache.Count();
 }
--- a/content/base/src/nsDOMAttributeMap.h
+++ b/content/base/src/nsDOMAttributeMap.h
@@ -10,16 +10,17 @@
 #ifndef nsDOMAttributeMap_h___
 #define nsDOMAttributeMap_h___
 
 #include "nsIDOMNamedNodeMap.h"
 #include "nsStringGlue.h"
 #include "nsRefPtrHashtable.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDOMNode.h"
+#include "mozilla/ErrorResult.h"
 
 class nsIAtom;
 class nsDOMAttribute;
 class nsINodeInfo;
 class nsIDocument;
 
 namespace mozilla {
 namespace dom {
@@ -133,17 +134,17 @@ public:
    * Enumerates over the attribute nodess in the map and calls aFunc for each
    * one. If aFunc returns PL_DHASH_STOP we'll stop enumerating at that point.
    *
    * @return The number of attribute nodes that aFunc was called for.
    */
   uint32_t Enumerate(AttrCache::EnumReadFunction aFunc, void *aUserArg) const;
 
   nsDOMAttribute* GetItemAt(uint32_t aIndex, nsresult *rv);
-  nsDOMAttribute* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
+  nsDOMAttribute* GetNamedItem(const nsAString& aAttrName);
 
   static nsDOMAttributeMap* FromSupports(nsISupports* aSupports)
   {
 #ifdef DEBUG
     {
       nsCOMPtr<nsIDOMNamedNodeMap> map_qi = do_QueryInterface(aSupports);
 
       // If this assertion fires the QI implementation for the object in
@@ -154,46 +155,52 @@ public:
     }
 #endif
 
     return static_cast<nsDOMAttributeMap*>(aSupports);
   }
 
   NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMAttributeMap)
 
+  nsDOMAttribute* GetNamedItemNS(const nsAString& aNamespaceURI,
+                                 const nsAString& aLocalName,
+                                 mozilla::ErrorResult& aError);
+
+  already_AddRefed<nsDOMAttribute> SetNamedItemNS(nsIDOMNode *aNode,
+                                                  mozilla::ErrorResult& aError)
+  {
+    return SetNamedItemInternal(aNode, true, aError);
+  }
+
   size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
 
 private:
   Element *mContent; // Weak reference
 
   /**
    * Cache of nsDOMAttributes.
    */
   AttrCache mAttributeCache;
 
   /**
    * SetNamedItem() (aWithNS = false) and SetNamedItemNS() (aWithNS =
    * true) implementation.
    */
-  nsresult SetNamedItemInternal(nsIDOMNode *aNode,
-                                nsIDOMNode **aReturn,
-                                bool aWithNS);
+  already_AddRefed<nsDOMAttribute>
+    SetNamedItemInternal(nsIDOMNode *aNode,
+                         bool aWithNS,
+                         mozilla::ErrorResult& aError);
 
-  /**
-   * GetNamedItemNS() implementation taking |aRemove| for GetAttribute(),
-   * which is used by RemoveNamedItemNS().
-   */
-  nsresult GetNamedItemNSInternal(const nsAString& aNamespaceURI,
-                                  const nsAString& aLocalName,
-                                  nsIDOMNode** aReturn,
-                                  bool aRemove = false);
+  already_AddRefed<nsINodeInfo>
+  GetAttrNodeInfo(const nsAString& aNamespaceURI,
+                  const nsAString& aLocalName,
+                  mozilla::ErrorResult& aError);
 
   nsDOMAttribute* GetAttribute(nsINodeInfo* aNodeInfo, bool aNsAware);
 
   /**
    * Remove an attribute, returns the removed node.
    */
-  nsresult RemoveAttribute(nsINodeInfo*     aNodeInfo,
-                           nsIDOMNode**     aReturn);
+  already_AddRefed<nsDOMAttribute> RemoveAttribute(nsINodeInfo* aNodeInfo);
 };
 
 
 #endif /* nsDOMAttributeMap_h___ */
--- a/content/base/src/nsDOMSettableTokenList.cpp
+++ b/content/base/src/nsDOMSettableTokenList.cpp
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Implementation of nsIDOMDOMSettableTokenList specified by HTML5.
  */
 
 #include "nsDOMSettableTokenList.h"
 #include "mozilla/dom/DOMSettableTokenListBinding.h"
+#include "nsGenericElement.h"
 
 
 nsDOMSettableTokenList::nsDOMSettableTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom)
   : nsDOMTokenList(aElement, aAttrAtom)
 {
 }
 
 nsDOMSettableTokenList::~nsDOMSettableTokenList()
--- a/content/base/src/nsDOMTokenList.cpp
+++ b/content/base/src/nsDOMTokenList.cpp
@@ -45,16 +45,25 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTok
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTokenList)
 
 void
 nsDOMTokenList::DropReference()
 {
   mElement = nullptr;
 }
 
+const nsAttrValue*
+nsDOMTokenList::GetParsedAttr()
+{
+  if (!mElement) {
+    return nullptr;
+  }
+  return mElement->GetAttrInfo(kNameSpaceID_None, mAttrAtom).mValue;
+}
+
 uint32_t
 nsDOMTokenList::Length()
 {
   const nsAttrValue* attr = GetParsedAttr();
   if (!attr) {
     return 0;
   }
 
--- a/content/base/src/nsDOMTokenList.h
+++ b/content/base/src/nsDOMTokenList.h
@@ -4,23 +4,27 @@
 
 /*
  * Implementation of nsIDOMDOMTokenList specified by HTML5.
  */
 
 #ifndef nsDOMTokenList_h___
 #define nsDOMTokenList_h___
 
-#include "nsGenericElement.h"
 #include "nsIDOMDOMTokenList.h"
+#include "nsCOMPtr.h"
+#include "nsDOMString.h"
+#include "nsWrapperCache.h"
 
 namespace mozilla {
 class ErrorResult;
 }
 class nsAttrValue;
+class nsGenericElement;
+class nsIAtom;
 
 // nsISupports must be on the primary inheritance chain 
 // because nsDOMSettableTokenList is traversed by nsGenericElement.
 class nsDOMTokenList : public nsIDOMDOMTokenList,
                        public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -29,28 +33,21 @@ public:
 
   nsDOMTokenList(nsGenericElement* aElement, nsIAtom* aAttrAtom);
 
   void DropReference();
 
   virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
                                bool *triedToWrap);
 
-  nsINode *GetParentObject()
+  nsGenericElement* GetParentObject()
   {
     return mElement;
   }
 
-  const nsAttrValue* GetParsedAttr() {
-    if (!mElement) {
-      return nullptr;
-    }
-    return mElement->GetAttrInfo(kNameSpaceID_None, mAttrAtom).mValue;
-  }
-
   uint32_t Length();
   void Item(uint32_t aIndex, nsAString& aResult)
   {
     bool found;
     IndexedGetter(aIndex, found, aResult);
     if (!found) {
       SetDOMStringToNull(aResult);
     }
@@ -63,14 +60,15 @@ public:
   void Stringify(nsAString& aResult);
 
 protected:
   virtual ~nsDOMTokenList();
 
   nsresult CheckToken(const nsAString& aStr);
   void AddInternal(const nsAttrValue* aAttr, const nsAString& aToken);
   void RemoveInternal(const nsAttrValue* aAttr, const nsAString& aToken);
+  inline const nsAttrValue* GetParsedAttr();
 
   nsGenericElement* mElement;
   nsCOMPtr<nsIAtom> mAttrAtom;
 };
 
 #endif // nsDOMTokenList_h___
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -64,16 +64,17 @@
 #include "nsIChannelEventSink.h"
 #include "imgIRequest.h"
 #include "nsIDOMDOMImplementation.h"
 #include "nsIDOMTouchEvent.h"
 #include "nsIInlineEventHandlers.h"
 #include "nsDataHashtable.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Attributes.h"
+#include "nsGenericElement.h"
 
 #define XML_DECLARATION_BITS_DECLARATION_EXISTS   (1 << 0)
 #define XML_DECLARATION_BITS_ENCODING_EXISTS      (1 << 1)
 #define XML_DECLARATION_BITS_STANDALONE_EXISTS    (1 << 2)
 #define XML_DECLARATION_BITS_STANDALONE_YES       (1 << 3)
 
 
 class nsEventListenerManager;
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -121,16 +121,17 @@
 #include "xpcpublic.h"
 #include "nsIScriptError.h"
 #include "nsLayoutStatics.h"
 #include "mozilla/Telemetry.h"
 
 #include "mozilla/CORSMode.h"
 
 #include "nsStyledElement.h"
+#include "nsXBLService.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::directionality;
 
 nsEventStates
 Element::IntrinsicState() const
 {
@@ -301,221 +302,188 @@ Element::ClearStyleStateLocks()
   nsEventStates locks = LockedStyleStates();
 
   DeleteProperty(nsGkAtoms::lockedStyleStates);
   ClearHasLockedStyleStates();
 
   NotifyStyleStateChange(locks);
 }
 
-nsIContent*
-nsGenericElement::GetFirstElementChild()
-{
-  nsAttrAndChildArray& children = mAttrsAndChildren;
-  uint32_t i, count = children.ChildCount();
-  for (i = 0; i < count; ++i) {
-    nsIContent* child = children.ChildAt(i);
-    if (child->IsElement()) {
-      return child;
-    }
-  }
-  
-  return nullptr;
-}
-
-nsIContent*
-nsGenericElement::GetLastElementChild()
+bool
+Element::GetBindingURL(nsIDocument *aDocument, css::URLValue **aResult)
 {
-  nsAttrAndChildArray& children = mAttrsAndChildren;
-  uint32_t i = children.ChildCount();
-  while (i > 0) {
-    nsIContent* child = children.ChildAt(--i);
-    if (child->IsElement()) {
-      return child;
-    }
+  // If we have a frame the frame has already loaded the binding.  And
+  // otherwise, don't do anything else here unless we're dealing with
+  // XUL or an HTML element that may have a plugin-related overlay
+  // (i.e. object, embed, or applet).
+  bool isXULorPluginElement = (IsXUL() ||
+                               IsHTML(nsGkAtoms::object) ||
+                               IsHTML(nsGkAtoms::embed) ||
+                               IsHTML(nsGkAtoms::applet));
+  nsIPresShell *shell = aDocument->GetShell();
+  if (!shell || GetPrimaryFrame() || !isXULorPluginElement) {
+    *aResult = nullptr;
+
+    return true;
   }
-  
-  return nullptr;
+
+  // Get the computed -moz-binding directly from the style context
+  nsPresContext *pctx = shell->GetPresContext();
+  NS_ENSURE_TRUE(pctx, false);
+
+  nsRefPtr<nsStyleContext> sc = pctx->StyleSet()->ResolveStyleFor(this,
+                                                                  nullptr);
+  NS_ENSURE_TRUE(sc, false);
+
+  *aResult = sc->GetStyleDisplay()->mBinding;
+
+  return true;
 }
 
-nsIContent*
-nsGenericElement::GetPreviousElementSibling()
+JSObject*
+nsGenericElement::WrapObject(JSContext *aCx, JSObject *aScope,
+                             bool *aTriedToWrap)
 {
-  nsIContent* parent = GetParent();
-  if (!parent) {
+  JSObject* obj = nsINode::WrapObject(aCx, aScope, aTriedToWrap);
+  if (!obj) {
     return nullptr;
   }
 
-  NS_ASSERTION(parent->IsElement() ||
-               parent->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT),
-               "Parent content must be an element or a doc fragment");
-
-  nsAttrAndChildArray& children =
-    static_cast<nsGenericElement*>(parent)->mAttrsAndChildren;
-  int32_t index = children.IndexOfChild(this);
-  if (index < 0) {
+  nsIDocument* doc;
+  if (HasFlag(NODE_FORCE_XBL_BINDINGS)) {
+    doc = OwnerDoc();
+  }
+  else {
+    doc = GetCurrentDoc();
+  }
+
+  if (!doc) {
+    // There's no baseclass that cares about this call so we just
+    // return here.
+    return obj;
+  }
+
+  // We must ensure that the XBL Binding is installed before we hand
+  // back this object.
+
+  if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) &&
+      doc->BindingManager()->GetBinding(this)) {
+    // There's already a binding for this element so nothing left to
+    // be done here.
+
+    // In theory we could call ExecuteAttachedHandler here when it's safe to
+    // run script if we also removed the binding from the PAQ queue, but that
+    // seems like a scary change that would mosly just add more
+    // inconsistencies.
+    return obj;
+  }
+
+  // Make sure the style context goes away _before_ we load the binding
+  // since that can destroy the relevant presshell.
+  mozilla::css::URLValue *bindingURL;
+  bool ok = GetBindingURL(doc, &bindingURL);
+  if (!ok) {
+    dom::Throw<true>(aCx, NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  uint32_t i = index;
-  while (i > 0) {
-    nsIContent* child = children.ChildAt((uint32_t)--i);
-    if (child->IsElement()) {
-      return child;
+  if (!bindingURL) {
+    // No binding, nothing left to do here.
+    return obj;
+  }
+
+  nsCOMPtr<nsIURI> uri = bindingURL->GetURI();
+  nsCOMPtr<nsIPrincipal> principal = bindingURL->mOriginPrincipal;
+
+  // We have a binding that must be installed.
+  bool dummy;
+
+  nsXBLService* xblService = nsXBLService::GetInstance();
+  if (!xblService) {
+    dom::Throw<true>(aCx, NS_ERROR_NOT_AVAILABLE);
+    return nullptr;
+  }
+
+  nsRefPtr<nsXBLBinding> binding;
+  xblService->LoadBindings(this, uri, principal, false, getter_AddRefs(binding),
+                           &dummy);
+  
+  if (binding) {
+    if (nsContentUtils::IsSafeToRunScript()) {
+      binding->ExecuteAttachedHandler();
+    }
+    else {
+      nsContentUtils::AddScriptRunner(
+        NS_NewRunnableMethod(binding, &nsXBLBinding::ExecuteAttachedHandler));
     }
   }
-  
-  return nullptr;
+
+  return obj;
 }
 
-nsIContent*
-nsGenericElement::GetNextElementSibling()
+nsGenericElement*
+nsGenericElement::GetFirstElementChild() const
 {
-  nsIContent* parent = GetParent();
-  if (!parent) {
-    return nullptr;
-  }
-
-  NS_ASSERTION(parent->IsElement() ||
-               parent->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT),
-               "Parent content must be an element or a doc fragment");
-
-  nsAttrAndChildArray& children =
-    static_cast<nsGenericElement*>(parent)->mAttrsAndChildren;
-  int32_t index = children.IndexOfChild(this);
-  if (index < 0) {
-    return nullptr;
-  }
-
-  uint32_t i, count = children.ChildCount();
-  for (i = (uint32_t)index + 1; i < count; ++i) {
-    nsIContent* child = children.ChildAt(i);
+  uint32_t i, count = mAttrsAndChildren.ChildCount();
+  for (i = 0; i < count; ++i) {
+    nsIContent* child = mAttrsAndChildren.ChildAt(i);
     if (child->IsElement()) {
-      return child;
+      return static_cast<nsGenericElement*>(child);
     }
   }
   
   return nullptr;
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetChildElementCount(uint32_t* aResult)
-{
-  *aResult = GetChildrenList()->Length(true);
-  return NS_OK;
-}
-
-// readonly attribute nsIDOMNodeList children
-NS_IMETHODIMP
-nsGenericElement::GetChildElements(nsIDOMNodeList** aResult)
-{
-  NS_ADDREF(*aResult = GetChildrenList());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetFirstElementChild(nsIDOMElement** aResult)
+nsGenericElement*
+nsGenericElement::GetLastElementChild() const
 {
-  *aResult = nullptr;
-
-  nsIContent *result = GetFirstElementChild();
-
-  return result ? CallQueryInterface(result, aResult) : NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetLastElementChild(nsIDOMElement** aResult)
-{
-  *aResult = nullptr;
-
-  nsIContent *result = GetLastElementChild();
-
-  return result ? CallQueryInterface(result, aResult) : NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetPreviousElementSibling(nsIDOMElement** aResult)
-{
-  *aResult = nullptr;
-
-  nsIContent *result = GetPreviousElementSibling();
-
-  return result ? CallQueryInterface(result, aResult) : NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetNextElementSibling(nsIDOMElement** aResult)
-{
-  *aResult = nullptr;
-
-  nsIContent *result = GetNextElementSibling();
-
-  return result ? CallQueryInterface(result, aResult) : NS_OK;
+  uint32_t i = mAttrsAndChildren.ChildCount();
+  while (i > 0) {
+    nsIContent* child = mAttrsAndChildren.ChildAt(--i);
+    if (child->IsElement()) {
+      return static_cast<nsGenericElement*>(child);
+    }
+  }
+  
+  return nullptr;
 }
 
 nsDOMTokenList*
-nsGenericElement::GetClassList(nsresult *aResult)
+nsGenericElement::ClassList()
 {
-  *aResult = NS_ERROR_OUT_OF_MEMORY;
-
   nsGenericElement::nsDOMSlots *slots = DOMSlots();
 
   if (!slots->mClassList) {
     nsCOMPtr<nsIAtom> classAttr = GetClassAttributeName();
-    if (!classAttr) {
-      *aResult = NS_OK;
-
-      return nullptr;
+    if (classAttr) {
+      slots->mClassList = new nsDOMTokenList(this, classAttr);
     }
-
-    slots->mClassList = new nsDOMTokenList(this, classAttr);
   }
 
-  *aResult = NS_OK;
-
   return slots->mClassList;
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetClassList(nsIDOMDOMTokenList** aResult)
+void
+nsGenericElement::GetClassList(nsIDOMDOMTokenList** aClassList)
 {
-  *aResult = nullptr;
-
-  nsresult rv;
-  nsIDOMDOMTokenList* list = GetClassList(&rv);
-  NS_ENSURE_TRUE(list, rv);
-
-  NS_ADDREF(*aResult = list);
-
-  return NS_OK;
+  NS_IF_ADDREF(*aClassList = ClassList());
 }
 
-NS_IMETHODIMP
-nsGenericElement::SetCapture(bool aRetargetToElement)
+already_AddRefed<nsIHTMLCollection>
+nsGenericElement::GetElementsByTagName(const nsAString& aLocalName)
 {
-  // If there is already an active capture, ignore this request. This would
-  // occur if a splitter, frame resizer, etc had already captured and we don't
-  // want to override those.
-  if (nsIPresShell::GetCapturingContent())
-    return NS_OK;
-
-  nsIPresShell::SetCapturingContent(this, CAPTURE_PREVENTDRAG |
-    (aRetargetToElement ? CAPTURE_RETARGETTOELEMENT : 0));
-
-  return NS_OK;
+  return NS_GetContentList(this, kNameSpaceID_Unknown, aLocalName);
 }
 
-NS_IMETHODIMP
-nsGenericElement::ReleaseCapture()
+void
+nsGenericElement::GetElementsByTagName(const nsAString& aLocalName,
+                                       nsIDOMHTMLCollection** aResult)
 {
-  if (nsIPresShell::GetCapturingContent() == this) {
-    nsIPresShell::SetCapturingContent(nullptr, 0);
-  }
-
-  return NS_OK;
+  *aResult = GetElementsByTagName(aLocalName).get();
 }
 
 nsIFrame*
 nsGenericElement::GetStyledFrame()
 {
   nsIFrame *frame = GetPrimaryFrame(Flush_Layout);
   return frame ? nsLayoutUtils::GetStyleFrame(frame) : nullptr;
 }
@@ -598,150 +566,71 @@ nsGenericElement::GetScrollFrame(nsIFram
     // In strict mode, the scroll info for the root element should map to the
     // the root scrollable frame.
     return frame->PresContext()->PresShell()->GetRootScrollFrameAsScrollable();
   }
 
   return nullptr;
 }
 
-int32_t
-nsGenericElement::GetScrollTop()
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  return sf ? sf->GetScrollPositionCSSPixels().y : 0;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetScrollTop(int32_t* aScrollTop)
+void
+nsGenericElement::ScrollIntoView(bool aTop)
 {
-  *aScrollTop = GetScrollTop();
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::SetScrollTop(int32_t aScrollTop)
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  if (sf) {
-    sf->ScrollToCSSPixels(nsIntPoint(sf->GetScrollPositionCSSPixels().x, aScrollTop));
+  nsIDocument *document = GetCurrentDoc();
+  if (!document) {
+    return;
+  }
+
+  // Get the presentation shell
+  nsCOMPtr<nsIPresShell> presShell = document->GetShell();
+  if (!presShell) {
+    return;
   }
-  return NS_OK;
+
+  int16_t vpercent = aTop ? nsIPresShell::SCROLL_TOP :
+    nsIPresShell::SCROLL_BOTTOM;
+
+  presShell->ScrollContentIntoView(this,
+                                   nsIPresShell::ScrollAxis(
+                                     vpercent,
+                                     nsIPresShell::SCROLL_ALWAYS),
+                                   nsIPresShell::ScrollAxis(),
+                                   nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
 }
 
 int32_t
-nsGenericElement::GetScrollLeft()
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  return sf ? sf->GetScrollPositionCSSPixels().x : 0;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetScrollLeft(int32_t* aScrollLeft)
-{
-  *aScrollLeft = GetScrollLeft();
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::SetScrollLeft(int32_t aScrollLeft)
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  if (sf) {
-    sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft, sf->GetScrollPositionCSSPixels().y));
-  }
-  return NS_OK;
-}
-
-int32_t
-nsGenericElement::GetScrollHeight()
+nsGenericElement::ScrollHeight()
 {
   if (IsSVG())
     return 0;
 
   nsIScrollableFrame* sf = GetScrollFrame();
   if (!sf) {
     return GetPaddingRectSize().height;
   }
 
   nscoord height = sf->GetScrollRange().height + sf->GetScrollPortRect().height;
   return nsPresContext::AppUnitsToIntCSSPixels(height);
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetScrollHeight(int32_t* aScrollHeight)
-{
-  *aScrollHeight = GetScrollHeight();
-
-  return NS_OK;
-}
-
 int32_t
-nsGenericElement::GetScrollWidth()
+nsGenericElement::ScrollWidth()
 {
   if (IsSVG())
     return 0;
 
   nsIScrollableFrame* sf = GetScrollFrame();
   if (!sf) {
     return GetPaddingRectSize().width;
   }
 
   nscoord width = sf->GetScrollRange().width + sf->GetScrollPortRect().width;
   return nsPresContext::AppUnitsToIntCSSPixels(width);
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetScrollWidth(int32_t *aScrollWidth)
-{
-  *aScrollWidth = GetScrollWidth();
-
-  return NS_OK;
-}
-
-int32_t
-nsGenericElement::GetScrollLeftMax()
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  if (!sf) {
-    return 0;
-  }
-
-  return nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollRange().XMost());
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetScrollLeftMax(int32_t *aScrollLeftMax)
-{
-  *aScrollLeftMax = GetScrollLeftMax();
-
-  return NS_OK;
-}
-
-int32_t
-nsGenericElement::GetScrollTopMax()
-{
-  nsIScrollableFrame* sf = GetScrollFrame();
-  if (!sf) {
-    return 0;
-  }
-
-  return nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollRange().YMost());
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetScrollTopMax(int32_t *aScrollTopMax)
-{
-  *aScrollTopMax = GetScrollTopMax();
-
-  return NS_OK;
-}
-
 nsRect
 nsGenericElement::GetClientAreaRect()
 {
   nsIFrame* styledFrame;
   nsIScrollableFrame* sf = GetScrollFrame(&styledFrame);
 
   if (sf) {
     return sf->GetScrollPortRect();
@@ -754,445 +643,354 @@ nsGenericElement::GetClientAreaRect()
     // a scroll view, see bug 180552, bug 227567.
     return styledFrame->GetPaddingRect() - styledFrame->GetPositionIgnoringScrolling();
   }
 
   // SVG nodes reach here and just return 0
   return nsRect(0, 0, 0, 0);
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetClientTop(int32_t *aClientTop)
-{
-  *aClientTop = GetClientTop();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetClientLeft(int32_t *aClientLeft)
-{
-  *aClientLeft = GetClientLeft();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetClientHeight(int32_t *aClientHeight)
+already_AddRefed<nsClientRect>
+nsGenericElement::GetBoundingClientRect()
 {
-  *aClientHeight = GetClientHeight();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetClientWidth(int32_t *aClientWidth)
-{
-  *aClientWidth = GetClientWidth();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetBoundingClientRect(nsIDOMClientRect** aResult)
-{
-  // Weak ref, since we addref it below
-  nsClientRect* rect = new nsClientRect();
-  NS_ADDREF(*aResult = rect);
+  nsRefPtr<nsClientRect> rect = new nsClientRect();
   
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
   if (!frame) {
     // display:none, perhaps? Return the empty rect
-    return NS_OK;
+    return rect.forget();
   }
 
   nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(frame,
           nsLayoutUtils::GetContainingBlockForClientRect(frame),
           nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
   rect->SetLayoutRect(r);
-  return NS_OK;
+  return rect.forget();
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetElementsByClassName(const nsAString& aClasses,
-                                         nsIDOMHTMLCollection** aReturn)
+already_AddRefed<nsClientRectList>
+nsGenericElement::GetClientRects(ErrorResult& aError)
 {
-  *aReturn = nsContentUtils::GetElementsByClassName(this, aClasses).get();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetClientRects(nsIDOMClientRectList** aResult)
-{
-  *aResult = nullptr;
-
   nsRefPtr<nsClientRectList> rectList = new nsClientRectList(this);
 
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
   if (!frame) {
     // display:none, perhaps? Return an empty list
-    *aResult = rectList.forget().get();
-    return NS_OK;
+    return rectList.forget();
   }
 
   nsLayoutUtils::RectListBuilder builder(rectList);
   nsLayoutUtils::GetAllInFlowRects(frame,
           nsLayoutUtils::GetContainingBlockForClientRect(frame), &builder,
           nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
-  if (NS_FAILED(builder.mRV))
-    return builder.mRV;
-  *aResult = rectList.forget().get();
-  return NS_OK;
+  if (NS_FAILED(builder.mRV)) {
+    aError.Throw(builder.mRV);
+    return nullptr;
+  }
+  return rectList.forget();
 }
 
 
 //----------------------------------------------------------------------
 
 
 nsGenericElement::nsGenericElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : Element(aNodeInfo)
 {
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::ELEMENT_NODE,
                     "Bad NodeType in aNodeInfo");
 
   SetIsElement();
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetTagName(nsAString& aTagName)
-{
-  aTagName = NodeName();
-  return NS_OK;
-}
-
-nsresult
-nsGenericElement::GetAttribute(const nsAString& aName,
-                               nsAString& aReturn)
+void
+nsGenericElement::GetAttribute(const nsAString& aName, nsString& aReturn)
 {
   const nsAttrValue* val =
     mAttrsAndChildren.GetAttr(aName,
                               IsHTML() && IsInHTMLDocument() ?
                                 eIgnoreCase : eCaseMatters);
   if (val) {
     val->ToString(aReturn);
   } else {
     if (IsXUL()) {
       // XXX should be SetDOMStringToNull(aReturn);
       // See bug 232598
       aReturn.Truncate();
     } else {
       SetDOMStringToNull(aReturn);
     }
   }
-
-  return NS_OK;
 }
 
-nsresult
+void
 nsGenericElement::SetAttribute(const nsAString& aName,
-                               const nsAString& aValue)
+                               const nsAString& aValue,
+                               ErrorResult& aError)
 {
   const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
 
   if (!name) {
-    nsresult rv = nsContentUtils::CheckQName(aName, false);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
-    NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
-
-    return SetAttr(kNameSpaceID_None, nameAtom, aValue, true);
+    aError = nsContentUtils::CheckQName(aName, false);
+    if (aError.Failed()) {
+      return;
+    }
+
+    nsCOMPtr<nsIAtom> nameAtom;
+    if (IsHTML() && IsInHTMLDocument()) {
+      nsAutoString lower;
+      nsresult rv = nsContentUtils::ASCIIToLower(aName, lower);
+      if (NS_SUCCEEDED(rv)) {
+        nameAtom = do_GetAtom(lower);
+      }
+    }
+    else {
+      nameAtom = do_GetAtom(aName);
+    }
+    if (!nameAtom) {
+      aError.Throw(NS_ERROR_OUT_OF_MEMORY);
+      return;
+    }
+    aError = SetAttr(kNameSpaceID_None, nameAtom, aValue, true);
+    return;
   }
 
-  return SetAttr(name->NamespaceID(), name->LocalName(), name->GetPrefix(),
-                 aValue, true);
+  aError = SetAttr(name->NamespaceID(), name->LocalName(), name->GetPrefix(),
+                   aValue, true);
+  return;
 }
 
-nsresult
-nsGenericElement::RemoveAttribute(const nsAString& aName)
+void
+nsGenericElement::RemoveAttribute(const nsAString& aName, ErrorResult& aError)
 {
   const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
 
   if (!name) {
     // If there is no canonical nsAttrName for this attribute name, then the
     // attribute does not exist and we can't get its namespace ID and
     // local name below, so we return early.
-    return NS_OK;
+    return;
   }
 
   // Hold a strong reference here so that the atom or nodeinfo doesn't go
   // away during UnsetAttr. If it did UnsetAttr would be left with a
   // dangling pointer as argument without knowing it.
   nsAttrName tmp(*name);
 
-  return UnsetAttr(name->NamespaceID(), name->LocalName(), true);
+  aError = UnsetAttr(name->NamespaceID(), name->LocalName(), true);
 }
 
-nsresult
-nsGenericElement::GetAttributeNode(const nsAString& aName,
-                                   nsIDOMAttr** aReturn)
+nsIDOMAttr*
+nsGenericElement::GetAttributeNode(const nsAString& aName)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  *aReturn = nullptr;
-
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eGetAttributeNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eGetAttributeNode);
 
   nsDOMAttributeMap* map = GetAttributes();
-  NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIDOMNode> node;
-  nsresult rv = map->GetNamedItem(aName, getter_AddRefs(node));
-
-  if (NS_SUCCEEDED(rv) && node) {
-    rv = CallQueryInterface(node, aReturn);
+  if (!map) {
+    return nullptr;
   }
 
-  return rv;
+  return map->GetNamedItem(aName);
 }
 
-nsresult
-nsGenericElement::SetAttributeNode(nsIDOMAttr* aAttribute,
-                                   nsIDOMAttr** aReturn)
+already_AddRefed<nsIDOMAttr>
+nsGenericElement::SetAttributeNode(nsIDOMAttr* aNewAttr, ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  NS_ENSURE_ARG_POINTER(aAttribute);
-
-  *aReturn = nullptr;
-
   OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNode);
 
   nsDOMAttributeMap* map = GetAttributes();
-  NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
+  if (!map) {
+    // XXX Throw?
+    return nullptr;
+  }
 
   nsCOMPtr<nsIDOMNode> returnNode;
-  nsresult rv = map->SetNamedItem(aAttribute, getter_AddRefs(returnNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (returnNode) {
-    rv = CallQueryInterface(returnNode, aReturn);
+  aError = map->SetNamedItem(aNewAttr, getter_AddRefs(returnNode));
+  if (aError.Failed()) {
+    return nullptr;
   }
 
-  return rv;
+  return static_cast<nsIDOMAttr*>(returnNode.forget().get());
 }
 
-nsresult
+already_AddRefed<nsIDOMAttr>
 nsGenericElement::RemoveAttributeNode(nsIDOMAttr* aAttribute,
-                                      nsIDOMAttr** aReturn)
+                                      ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  NS_ENSURE_ARG_POINTER(aAttribute);
-
-  *aReturn = nullptr;
-
   OwnerDoc()->WarnOnceAbout(nsIDocument::eRemoveAttributeNode);
 
   nsDOMAttributeMap* map = GetAttributes();
-  NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
+  if (!map) {
+    // XXX Throw?
+    return nullptr;
+  }
 
   nsAutoString name;
 
-  nsresult rv = aAttribute->GetName(name);
-  if (NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIDOMNode> node;
-    rv = map->RemoveNamedItem(name, getter_AddRefs(node));
-
-    if (NS_SUCCEEDED(rv) && node) {
-      rv = CallQueryInterface(node, aReturn);
-    }
+  aError = aAttribute->GetName(name);
+  if (aError.Failed()) {
+    return nullptr;
   }
 
-  return rv;
+  nsCOMPtr<nsIDOMNode> node;
+  aError = map->RemoveNamedItem(name, getter_AddRefs(node));
+  if (aError.Failed()) {
+    return nullptr;
+  }
+
+  return static_cast<nsIDOMAttr*>(node.forget().get());
 }
 
-nsresult
-nsGenericElement::GetElementsByTagName(const nsAString& aTagname,
-                                       nsIDOMHTMLCollection** aReturn)
-{
-  nsContentList *list = NS_GetContentList(this, kNameSpaceID_Unknown, 
-                                          aTagname).get();
-
-  // transfer ref to aReturn
-  *aReturn = list;
-  return NS_OK;
-}
-
-nsresult
+void
 nsGenericElement::GetAttributeNS(const nsAString& aNamespaceURI,
                                  const nsAString& aLocalName,
                                  nsAString& aReturn)
 {
   int32_t nsid =
     nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
   if (nsid == kNameSpaceID_Unknown) {
     // Unknown namespace means no attribute.
     SetDOMStringToNull(aReturn);
-    return NS_OK;
+    return;
   }
 
   nsCOMPtr<nsIAtom> name = do_GetAtom(aLocalName);
   bool hasAttr = GetAttr(nsid, name, aReturn);
   if (!hasAttr) {
     SetDOMStringToNull(aReturn);
   }
-
-  return NS_OK;
 }
 
-nsresult
+void
 nsGenericElement::SetAttributeNS(const nsAString& aNamespaceURI,
                                  const nsAString& aQualifiedName,
-                                 const nsAString& aValue)
+                                 const nsAString& aValue,
+                                 ErrorResult& aError)
 {
   nsCOMPtr<nsINodeInfo> ni;
-  nsresult rv =
+  aError =
     nsContentUtils::GetNodeInfoFromQName(aNamespaceURI, aQualifiedName,
                                          mNodeInfo->NodeInfoManager(),
                                          nsIDOMNode::ATTRIBUTE_NODE,
                                          getter_AddRefs(ni));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return SetAttr(ni->NamespaceID(), ni->NameAtom(), ni->GetPrefixAtom(),
-                 aValue, true);
+  if (aError.Failed()) {
+    return;
+  }
+
+  aError = SetAttr(ni->NamespaceID(), ni->NameAtom(), ni->GetPrefixAtom(),
+                   aValue, true);
 }
 
-nsresult
+void
 nsGenericElement::RemoveAttributeNS(const nsAString& aNamespaceURI,
-                                    const nsAString& aLocalName)
+                                    const nsAString& aLocalName,
+                                    ErrorResult& aError)
 {
   nsCOMPtr<nsIAtom> name = do_GetAtom(aLocalName);
   int32_t nsid =
     nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
   if (nsid == kNameSpaceID_Unknown) {
     // If the namespace ID is unknown, it means there can't possibly be an
     // existing attribute. We would need a known namespace ID to pass into
     // UnsetAttr, so we return early if we don't have one.
-    return NS_OK;
+    return;
   }
 
-  UnsetAttr(nsid, name, true);
-
-  return NS_OK;
+  aError = UnsetAttr(nsid, name, true);
 }
 
-nsresult
+nsIDOMAttr*
 nsGenericElement::GetAttributeNodeNS(const nsAString& aNamespaceURI,
                                      const nsAString& aLocalName,
-                                     nsIDOMAttr** aReturn)
+                                     ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  *aReturn = nullptr;
-
   OwnerDoc()->WarnOnceAbout(nsIDocument::eGetAttributeNodeNS);
 
-  return GetAttributeNodeNSInternal(aNamespaceURI, aLocalName, aReturn);
+  return GetAttributeNodeNSInternal(aNamespaceURI, aLocalName, aError);
 }
 
-nsresult
+nsIDOMAttr*
 nsGenericElement::GetAttributeNodeNSInternal(const nsAString& aNamespaceURI,
                                              const nsAString& aLocalName,
-                                             nsIDOMAttr** aReturn)
+                                             ErrorResult& aError)
 {
   nsDOMAttributeMap* map = GetAttributes();
-  NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIDOMNode> node;
-  nsresult rv = map->GetNamedItemNS(aNamespaceURI, aLocalName,
-                                    getter_AddRefs(node));
-
-  if (NS_SUCCEEDED(rv) && node) {
-    rv = CallQueryInterface(node, aReturn);
+  if (!map) {
+    return nullptr;
   }
 
-  return rv;
+  return map->GetNamedItemNS(aNamespaceURI, aLocalName, aError);
 }
 
-nsresult
+already_AddRefed<nsIDOMAttr>
 nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr,
-                                     nsIDOMAttr** aReturn)
+                                     ErrorResult& aError)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-  NS_ENSURE_ARG_POINTER(aNewAttr);
-  *aReturn = nullptr;
-
   OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNodeNS);
 
   nsDOMAttributeMap* map = GetAttributes();
-  NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIDOMNode> returnNode;
-  nsresult rv = map->SetNamedItemNS(aNewAttr, getter_AddRefs(returnNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (returnNode) {
-    rv = CallQueryInterface(returnNode, aReturn);
+  if (!map) {
+    return nullptr;
   }
 
-  return rv;
+  return map->SetNamedItemNS(aNewAttr, aError);
 }
 
-nsresult
+already_AddRefed<nsIHTMLCollection>
 nsGenericElement::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
                                          const nsAString& aLocalName,
-                                         nsIDOMHTMLCollection** aReturn)
+                                         ErrorResult& aError)
 {
   int32_t nameSpaceId = kNameSpaceID_Wildcard;
 
   if (!aNamespaceURI.EqualsLiteral("*")) {
-    nsresult rv =
+    aError =
       nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
                                                             nameSpaceId);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (aError.Failed()) {
+      return nullptr;
+    }
   }
 
   NS_ASSERTION(nameSpaceId != kNameSpaceID_Unknown, "Unexpected namespace ID!");
 
-  nsContentList *list = NS_GetContentList(this, nameSpaceId, aLocalName).get();
-
-  // transfer ref to aReturn
-  *aReturn = list;
-  return NS_OK;
+  return NS_GetContentList(this, nameSpaceId, aLocalName);
 }
 
 nsresult
-nsGenericElement::HasAttribute(const nsAString& aName, bool* aReturn)
+nsGenericElement::GetElementsByTagNameNS(const nsAString& namespaceURI,
+                                         const nsAString& localName,
+                                         nsIDOMHTMLCollection** aResult)
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-
-  const nsAttrValue* val =
-    mAttrsAndChildren.GetAttr(aName,
-                              IsHTML() && IsInHTMLDocument() ?
-                                eIgnoreCase : eCaseMatters);
-  *aReturn = (val != nullptr);
-
+  mozilla::ErrorResult rv;
+  nsCOMPtr<nsIHTMLCollection> list =
+    GetElementsByTagNameNS(namespaceURI, localName, rv);
+  if (rv.Failed()) {
+    return rv.ErrorCode();
+  }
+  list.forget(aResult);
   return NS_OK;
 }
 
-nsresult
+bool
 nsGenericElement::HasAttributeNS(const nsAString& aNamespaceURI,
-                                 const nsAString& aLocalName,
-                                 bool* aReturn)
+                                 const nsAString& aLocalName) const
 {
-  NS_ENSURE_ARG_POINTER(aReturn);
-
   int32_t nsid =
     nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
   if (nsid == kNameSpaceID_Unknown) {
     // Unknown namespace means no attr...
-
-    *aReturn = false;
-
-    return NS_OK;
+    return false;
   }
 
   nsCOMPtr<nsIAtom> name = do_GetAtom(aLocalName);
-  *aReturn = HasAttr(nsid, name);
-
-  return NS_OK;
+  return HasAttr(nsid, name);
 }
 
 static nsXBLBinding*
 GetFirstBindingWithContent(nsBindingManager* aBmgr, nsIContent* aBoundElem)
 {
   nsXBLBinding* binding = aBmgr->GetBinding(aBoundElem);
   while (binding) {
     if (binding->GetAnonymousContent()) {
@@ -1239,16 +1037,30 @@ BindNodesInInsertPoints(nsXBLBinding* aB
         }
       }
     }
   }
 
   return NS_OK;
 }
 
+already_AddRefed<nsIHTMLCollection>
+nsGenericElement::GetElementsByClassName(const nsAString& aClassNames)
+{
+  return nsContentUtils::GetElementsByClassName(this, aClassNames);
+}
+
+nsresult
+nsGenericElement::GetElementsByClassName(const nsAString& aClassNames,
+                                         nsIDOMHTMLCollection** aResult)
+{
+  *aResult = nsContentUtils::GetElementsByClassName(this, aClassNames).get();
+  return NS_OK;
+}
+
 nsresult
 nsGenericElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                              nsIContent* aBindingParent,
                              bool aCompileEventHandlers)
 {
   NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
   NS_PRECONDITION(HasSameOwnerDoc(NODE_FROM(aParent, aDocument)),
                   "Must have the same owner document");
@@ -2063,21 +1875,21 @@ nsGenericElement::SetAttrAndNotify(int32
   if (aCallAfterSetAttr) {
     rv = AfterSetAttr(aNamespaceID, aName, &aValueForAfterSetAttr, aNotify);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aFireMutation) {
     nsMutationEvent mutation(true, NS_MUTATION_ATTRMODIFIED);
 
-    nsCOMPtr<nsIDOMAttr> attrNode;
     nsAutoString ns;
     nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns);
-    GetAttributeNodeNSInternal(ns, nsDependentAtomString(aName),
-                               getter_AddRefs(attrNode));
+    ErrorResult rv;
+    nsIDOMAttr* attrNode =
+      GetAttributeNodeNSInternal(ns, nsDependentAtomString(aName), rv);
     mutation.mRelatedNode = attrNode;
 
     mutation.mAttrName = aName;
     nsAutoString newValue;
     GetAttr(aNamespaceID, aName, newValue);
     if (!newValue.IsEmpty()) {
       mutation.mNewAttrValue = do_GetAtom(newValue);
     }
@@ -2246,18 +2058,18 @@ nsGenericElement::UnsetAttr(int32_t aNam
                                          NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
                                          this);
 
   // Grab the attr node if needed before we remove it from the attr map
   nsCOMPtr<nsIDOMAttr> attrNode;
   if (hasMutationListeners) {
     nsAutoString ns;
     nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns);
-    GetAttributeNodeNSInternal(ns, nsDependentAtomString(aName),
-                               getter_AddRefs(attrNode));
+    ErrorResult rv;
+    attrNode = GetAttributeNodeNSInternal(ns, nsDependentAtomString(aName), rv);
   }
 
   // Clear binding to nsIDOMNamedNodeMap
   nsDOMSlots *slots = GetExistingDOMSlots();
   if (slots && slots->mAttributeMap) {
     slots->mAttributeMap->DropAttribute(aNameSpaceID, aName);
   }
 
@@ -2701,45 +2513,34 @@ ParseSelectorList(nsINode* aNode,
   } while (*slot);
   *aSelectorList = selectorList;
 
   return NS_OK;
 }
 
 
 bool
-nsGenericElement::MozMatchesSelector(const nsAString& aSelector, nsresult* aResult)
+nsGenericElement::MozMatchesSelector(const nsAString& aSelector,
+                                     ErrorResult& aError)
 {
   nsAutoPtr<nsCSSSelectorList> selectorList;
-  bool matches = false;
-
-  *aResult = ParseSelectorList(this, aSelector, getter_Transfers(selectorList));
-
-  if (NS_SUCCEEDED(*aResult)) {
-    OwnerDoc()->FlushPendingLinkUpdates();
-    TreeMatchContext matchingContext(false,
-                                     nsRuleWalker::eRelevantLinkUnvisited,
-                                     OwnerDoc(),
-                                     TreeMatchContext::eNeverMatchVisited);
-    matches = nsCSSRuleProcessor::SelectorListMatches(this, matchingContext,
-                                                      selectorList);
+
+  aError = ParseSelectorList(this, aSelector, getter_Transfers(selectorList));
+
+  if (aError.Failed()) {
+    return false;
   }
 
-  return matches;
-}
-
-NS_IMETHODIMP
-nsGenericElement::MozMatchesSelector(const nsAString& aSelector, bool* aReturn)
-{
-  NS_PRECONDITION(aReturn, "Null out param?");
-
-  nsresult rv;
-  *aReturn = MozMatchesSelector(aSelector, &rv);
-
-  return rv;
+  OwnerDoc()->FlushPendingLinkUpdates();
+  TreeMatchContext matchingContext(false,
+                                   nsRuleWalker::eRelevantLinkUnvisited,
+                                   OwnerDoc(),
+                                   TreeMatchContext::eNeverMatchVisited);
+  return nsCSSRuleProcessor::SelectorListMatches(this, matchingContext,
+                                                 selectorList);
 }
 
 static const nsAttrValue::EnumTable kCORSAttributeTable[] = {
   // Order matters here
   // See ParseCORSValue
   { "anonymous",       CORS_ANONYMOUS       },
   { "use-credentials", CORS_USE_CREDENTIALS },
   { 0 }
@@ -2774,47 +2575,16 @@ nsGenericElement::AttrValueToCORSMode(co
 {
   if (!aValue) {
     return CORS_NONE;
   }
 
   return CORSMode(aValue->GetEnumValue());
 }
 
-NS_IMETHODIMP
-nsGenericElement::GetOnmouseenter(JSContext* cx, JS::Value* vp)
-{
-  return nsINode::GetOnmouseenter(cx, vp);
-}
-
-NS_IMETHODIMP
-nsGenericElement::SetOnmouseenter(JSContext* cx, const JS::Value& v)
-{
-  return nsINode::SetOnmouseenter(cx, v);
-}
-
-NS_IMETHODIMP
-nsGenericElement::GetOnmouseleave(JSContext* cx, JS::Value* vp)
-{
-  return nsINode::GetOnmouseleave(cx, vp);
-}
-
-NS_IMETHODIMP
-nsGenericElement::SetOnmouseleave(JSContext* cx, const JS::Value& v)
-{
-  return nsINode::SetOnmouseleave(cx, v);
-}
-
-NS_IMETHODIMP
-nsGenericElement::MozRequestPointerLock()
-{
-  OwnerDoc()->RequestPointerLock(this);
-  return NS_OK;
-}
-
 static const char*
 GetFullScreenError(nsIDocument* aDoc)
 {
   nsCOMPtr<nsPIDOMWindow> win = aDoc->GetWindow();
   if (aDoc->NodePrincipal()->GetAppStatus() >= nsIPrincipal::APP_STATUS_INSTALLED) {
     // Request is in a web app and in the same origin as the web app.
     // Don't enforce as strict security checks for web apps, the user
     // is supposed to have trust in them. However documents cross-origin
@@ -2828,17 +2598,18 @@ GetFullScreenError(nsIDocument* aDoc)
 
   if (nsContentUtils::IsSitePermDeny(aDoc->NodePrincipal(), "fullscreen")) {
     return "FullScreenDeniedBlocked";
   }
 
   return nullptr;
 }
 
-nsresult nsGenericElement::MozRequestFullScreen()
+void
+nsGenericElement::MozRequestFullScreen()
 {
   // Only grant full-screen requests if this is called from inside a trusted
   // event handler (i.e. inside an event handler for a user initiated event).
   // This stops the full-screen from being abused similar to the popups of old,
   // and it also makes it harder for bad guys' script to go full-screen and
   // spoof the browser chrome/window and phish logins etc.
   // Note that requests for fullscreen inside a web app's origin are exempt
   // from this restriction.
@@ -2849,15 +2620,15 @@ nsresult nsGenericElement::MozRequestFul
                                     nsContentUtils::eDOM_PROPERTIES,
                                     error);
     nsRefPtr<nsAsyncDOMEvent> e =
       new nsAsyncDOMEvent(OwnerDoc(),
                           NS_LITERAL_STRING("mozfullscreenerror"),
                           true,
                           false);
     e->PostDOMEvent();
-    return NS_OK;
+    return;
   }
 
   OwnerDoc()->AsyncRequestFullScreen(this);
 
-  return NS_OK;
+  return;
 }
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -31,36 +31,48 @@
 #include "nsPresContext.h"
 #include "nsDOMClassInfoID.h" // DOMCI_DATA
 #include "nsIDOMTouchEvent.h"
 #include "nsIInlineEventHandlers.h"
 #include "mozilla/CORSMode.h"
 #include "mozilla/Attributes.h"
 #include "nsContentUtils.h"
 #include "nsINodeList.h"
+#include "mozilla/ErrorResult.h"
+#include "nsIScrollableFrame.h"
+#include "nsIDOMAttr.h"
 #include "nsISMILAttr.h"
+#include "nsClientRect.h"
+#include "nsIDOMDOMTokenList.h"
 
-class nsIDOMAttr;
 class nsIDOMEventListener;
 class nsIFrame;
 class nsIDOMNamedNodeMap;
 class nsICSSDeclaration;
 class nsIDOMCSSStyleDeclaration;
 class nsIURI;
 class nsINodeInfo;
 class nsIControllers;
 class nsEventChainVisitor;
 class nsEventListenerManager;
 class nsIScrollableFrame;
 class nsAttrValueOrString;
+class ContentUnbinder;
+class nsClientRect;
+class nsClientRectList;
+class nsIHTMLCollection;
 class nsContentList;
 class nsDOMTokenList;
-class ContentUnbinder;
 struct nsRect;
 
+already_AddRefed<nsContentList>
+NS_GetContentList(nsINode* aRootNode, 
+                  int32_t  aMatchNameSpaceId,
+                  const nsAString& aTagname);
+
 /**
  * A generic base class for DOM elements, implementing many nsIContent,
  * nsIDOMNode and nsIDOMElement methods.
  */
 class nsGenericElement : public mozilla::dom::Element
 {
 public:
   nsGenericElement(already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -193,27 +205,193 @@ public:
 
 private:
   static bool
   FindAttributeDependence(const nsIAtom* aAttribute,
                           const MappedAttributeEntry* const aMaps[],
                           uint32_t aMapCount);
 
 public:
-  // nsIDOMElement method implementation
-  NS_DECL_NSIDOMELEMENT
+  void GetTagName(nsAString& aTagName) const
+  {
+    aTagName = NodeName();
+  }
+  void GetId(nsAString& aId) const
+  {
+    GetAttr(kNameSpaceID_None, nsGkAtoms::id, aId);
+  }
+  void SetId(const nsAString& aId)
+  {
+    SetAttr(kNameSpaceID_None, nsGkAtoms::id, aId, true);
+  }
+
+  nsDOMTokenList* ClassList();
   nsDOMAttributeMap* GetAttributes()
   {
     nsDOMSlots *slots = DOMSlots();
     if (!slots->mAttributeMap) {
       slots->mAttributeMap = new nsDOMAttributeMap(this);
     }
 
     return slots->mAttributeMap;
   }
+  virtual void GetAttribute(const nsAString& aName, nsString& aReturn);
+  void GetAttributeNS(const nsAString& aNamespaceURI,
+                      const nsAString& aLocalName,
+                      nsAString& aReturn);
+  void SetAttribute(const nsAString& aName, const nsAString& aValue,
+                    mozilla::ErrorResult& aError);
+  void SetAttributeNS(const nsAString& aNamespaceURI,
+                      const nsAString& aLocalName,
+                      const nsAString& aValue,
+                      mozilla::ErrorResult& aError);
+  virtual void RemoveAttribute(const nsAString& aName,
+                               mozilla::ErrorResult& aError);
+  void RemoveAttributeNS(const nsAString& aNamespaceURI,
+                         const nsAString& aLocalName,
+                         mozilla::ErrorResult& aError);
+  virtual bool HasAttribute(const nsAString& aName) const
+  {
+    return InternalGetExistingAttrNameFromQName(aName) != nullptr;
+  }
+  bool HasAttributeNS(const nsAString& aNamespaceURI,
+                      const nsAString& aLocalName) const;
+  already_AddRefed<nsIHTMLCollection>
+    GetElementsByTagName(const nsAString& aQualifiedName);
+  already_AddRefed<nsIHTMLCollection>
+    GetElementsByTagNameNS(const nsAString& aNamespaceURI,
+                           const nsAString& aLocalName,
+                           mozilla::ErrorResult& aError);
+  already_AddRefed<nsIHTMLCollection>
+    GetElementsByClassName(const nsAString& aClassNames);
+  nsGenericElement* GetFirstElementChild() const;
+  nsGenericElement* GetLastElementChild() const;
+  nsGenericElement* GetPreviousElementSibling() const
+  {
+    nsIContent* previousSibling = GetPreviousSibling();
+    while (previousSibling) {
+      if (previousSibling->IsElement()) {
+        return static_cast<nsGenericElement*>(previousSibling);
+      }
+      previousSibling = previousSibling->GetPreviousSibling();
+    }
+
+    return nullptr;
+  }
+  nsGenericElement* GetNextElementSibling() const
+  {
+    nsIContent* nextSibling = GetNextSibling();
+    while (nextSibling) {
+      if (nextSibling->IsElement()) {
+        return static_cast<nsGenericElement*>(nextSibling);
+      }
+      nextSibling = nextSibling->GetNextSibling();
+    }
+
+    return nullptr;
+  }
+  uint32_t ChildElementCount()
+  {
+    return Children()->Length();
+  }
+  bool MozMatchesSelector(const nsAString& aSelector,
+                          mozilla::ErrorResult& aError);
+  void SetCapture(bool aRetargetToElement)
+  {
+    // If there is already an active capture, ignore this request. This would
+    // occur if a splitter, frame resizer, etc had already captured and we don't
+    // want to override those.
+    if (!nsIPresShell::GetCapturingContent()) {
+      nsIPresShell::SetCapturingContent(this, CAPTURE_PREVENTDRAG |
+        (aRetargetToElement ? CAPTURE_RETARGETTOELEMENT : 0));
+    }
+  }
+  void ReleaseCapture()
+  {
+    if (nsIPresShell::GetCapturingContent() == this) {
+      nsIPresShell::SetCapturingContent(nullptr, 0);
+    }
+  }
+  void MozRequestFullScreen();
+  void MozRequestPointerLock()
+  {
+    OwnerDoc()->RequestPointerLock(this);
+  }
+  nsIDOMAttr* GetAttributeNode(const nsAString& aName);
+  already_AddRefed<nsIDOMAttr> SetAttributeNode(nsIDOMAttr* aNewAttr,
+                                                mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMAttr> RemoveAttributeNode(nsIDOMAttr* aOldAttr,
+                                                   mozilla::ErrorResult& aError);
+  nsIDOMAttr* GetAttributeNodeNS(const nsAString& aNamespaceURI,
+                                 const nsAString& aLocalName,
+                                 mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMAttr> SetAttributeNodeNS(nsIDOMAttr* aNewAttr,
+                                                  mozilla::ErrorResult& aError);
+
+  already_AddRefed<nsClientRectList> GetClientRects(mozilla::ErrorResult& aError);
+  already_AddRefed<nsClientRect> GetBoundingClientRect();
+  void ScrollIntoView(bool aTop);
+  int32_t ScrollTop()
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    return sf ? sf->GetScrollPositionCSSPixels().y : 0;
+  }
+  void SetScrollTop(int32_t aScrollTop)
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    if (sf) {
+      sf->ScrollToCSSPixels(nsIntPoint(sf->GetScrollPositionCSSPixels().x,
+                                       aScrollTop));
+    }
+  }
+  int32_t ScrollLeft()
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    return sf ? sf->GetScrollPositionCSSPixels().x : 0;
+  }
+  void SetScrollLeft(int32_t aScrollLeft)
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    if (sf) {
+      sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft,
+                                       sf->GetScrollPositionCSSPixels().y));
+    }
+  }
+  int32_t ScrollWidth();
+  int32_t ScrollHeight();
+  int32_t ClientTop()
+  {
+    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().y);
+  }
+  int32_t ClientLeft()
+  {
+    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().x);
+  }
+  int32_t ClientWidth()
+  {
+    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().width);
+  }
+  int32_t ClientHeight()
+  {
+    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().height);
+  }
+  int32_t ScrollTopMax()
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    return sf ?
+           nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollRange().YMost()) :
+           0;
+  }
+  int32_t ScrollLeftMax()
+  {
+    nsIScrollableFrame* sf = GetScrollFrame();
+    return sf ?
+           nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollRange().XMost()) :
+           0;
+  }
 
   //----------------------------------------
 
   /**
    * Add a script event listener with the given event handler name
    * (like onclick) and with the value as JS
    * @param aEventName the event listener name
    * @param aValue the JS to attach
@@ -301,45 +479,16 @@ public:
 
     return slots ? slots->mAttributeMap.get() : nullptr;
   }
 
   virtual void RecompileScriptEventListeners()
   {
   }
 
-  int32_t GetScrollTop();
-  int32_t GetScrollLeft();
-  int32_t GetScrollHeight();
-  int32_t GetScrollWidth();
-  int32_t GetScrollLeftMax();
-  int32_t GetScrollTopMax();
-  int32_t GetClientTop()
-  {
-    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().y);
-  }
-  int32_t GetClientLeft()
-  {
-    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().x);
-  }
-  int32_t GetClientHeight()
-  {
-    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().height);
-  }
-  int32_t GetClientWidth()
-  {
-    return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().width);
-  }
-  nsIContent* GetFirstElementChild();
-  nsIContent* GetLastElementChild();
-  nsIContent* GetPreviousElementSibling();
-  nsIContent* GetNextElementSibling();
-  nsDOMTokenList* GetClassList(nsresult *aResult);
-  bool MozMatchesSelector(const nsAString& aSelector, nsresult* aResult);
-
   /**
    * Get the attr info for the given namespace ID and attribute name.  The
    * namespace ID must not be kNameSpaceID_Unknown and the name must not be
    * null.  Note that this can only return info on attributes that actually
    * live on this element (and is only virtual to handle XUL prototypes).  That
    * is, this should only be called from methods that only care about attrs
    * that effectively live in mAttrsAndChildren.
    */
@@ -362,16 +511,33 @@ public:
   static mozilla::CORSMode StringToCORSMode(const nsAString& aValue);
   
   /**
    * Return the CORS mode for a given nsAttrValue (which may be null,
    * but if not should have been parsed via ParseCORSValue).
    */
   static mozilla::CORSMode AttrValueToCORSMode(const nsAttrValue* aValue);
 
+  // These are just used to implement nsIDOMElement using
+  // NS_FORWARD_NSIDOMELEMENT_TO_GENERIC and for quickstubs.
+  void
+    GetElementsByTagName(const nsAString& aQualifiedName,
+                         nsIDOMHTMLCollection** aResult);
+  nsresult
+    GetElementsByTagNameNS(const nsAString& aNamespaceURI,
+                           const nsAString& aLocalName,
+                           nsIDOMHTMLCollection** aResult);
+  nsresult
+    GetElementsByClassName(const nsAString& aClassNames,
+                           nsIDOMHTMLCollection** aResult);
+  void GetClassList(nsIDOMDOMTokenList** aClassList);
+
+  virtual JSObject* WrapObject(JSContext *aCx, JSObject *aScope,
+                               bool *aTriedToWrap) MOZ_FINAL;
+
 protected:
   /*
    * Named-bools for use with SetAttrAndNotify to make call sites easier to
    * read.
    */
   static const bool kFireMutationEvent           = true;
   static const bool kDontFireMutationEvent       = false;
   static const bool kNotifyDocumentObservers     = true;
@@ -518,19 +684,19 @@ protected:
 
   nsIFrame* GetStyledFrame();
 
   virtual mozilla::dom::Element* GetNameSpaceElement()
   {
     return this;
   }
 
-  nsresult GetAttributeNodeNSInternal(const nsAString& aNamespaceURI,
-                                      const nsAString& aLocalName,
-                                      nsIDOMAttr** aReturn);
+  nsIDOMAttr* GetAttributeNodeNSInternal(const nsAString& aNamespaceURI,
+                                         const nsAString& aLocalName,
+                                         mozilla::ErrorResult& aError);
 
   void RegisterFreezableElement() {
     OwnerDoc()->RegisterFreezableElement(this);
   }
   void UnregisterFreezableElement() {
     OwnerDoc()->UnregisterFreezableElement(this);
   }
 
@@ -678,9 +844,304 @@ nsresult                                
     return NS_OK;                                                       \
   }                                                                     \
   NS_IMETHODIMP                                                         \
   _class::Set##_method(const nsAString& aValue)                         \
   {                                                                     \
     return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, nullptr, aValue, true); \
   }
 
+#define NS_FORWARD_NSIDOMELEMENT_TO_GENERIC                                   \
+NS_IMETHOD GetTagName(nsAString& aTagName) MOZ_FINAL                          \
+{                                                                             \
+  nsGenericElement::GetTagName(aTagName);                                     \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetClassList(nsIDOMDOMTokenList** aClassList) MOZ_FINAL            \
+{                                                                             \
+  nsGenericElement::GetClassList(aClassList);                                 \
+  return NS_OK;                                                               \
+}                                                                             \
+using nsGenericElement::GetAttribute;                                         \
+NS_IMETHOD GetAttribute(const nsAString& name, nsAString& _retval) MOZ_FINAL  \
+{                                                                             \
+  nsString attr;                                                              \
+  GetAttribute(name, attr);                                                   \
+  _retval = attr;                                                             \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetAttributeNS(const nsAString& namespaceURI,                      \
+                          const nsAString& localName,                         \
+                          nsAString& _retval) MOZ_FINAL                       \
+{                                                                             \
+  nsGenericElement::GetAttributeNS(namespaceURI, localName, _retval);         \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD SetAttribute(const nsAString& name,                                \
+                        const nsAString& value)                               \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  nsGenericElement::SetAttribute(name, value, rv);                            \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD SetAttributeNS(const nsAString& namespaceURI,                      \
+                          const nsAString& qualifiedName,                     \
+                          const nsAString& value) MOZ_FINAL                   \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  nsGenericElement::SetAttributeNS(namespaceURI, qualifiedName, value, rv);   \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+using nsGenericElement::RemoveAttribute;                                      \
+NS_IMETHOD RemoveAttribute(const nsAString& name) MOZ_FINAL                   \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  RemoveAttribute(name, rv);                                                  \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD RemoveAttributeNS(const nsAString& namespaceURI,                   \
+                             const nsAString& localName) MOZ_FINAL            \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  nsGenericElement::RemoveAttributeNS(namespaceURI, localName, rv);           \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+using nsGenericElement::HasAttribute;                                         \
+NS_IMETHOD HasAttribute(const nsAString& name,                                \
+                           bool* _retval) MOZ_FINAL                           \
+{                                                                             \
+  *_retval = HasAttribute(name);                                              \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD HasAttributeNS(const nsAString& namespaceURI,                      \
+                          const nsAString& localName,                         \
+                          bool* _retval) MOZ_FINAL                            \
+{                                                                             \
+  *_retval = nsGenericElement::HasAttributeNS(namespaceURI, localName);       \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetAttributeNode(const nsAString& name,                            \
+                            nsIDOMAttr** _retval) MOZ_FINAL                   \
+{                                                                             \
+  NS_IF_ADDREF(*_retval = nsGenericElement::GetAttributeNode(name));          \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD SetAttributeNode(nsIDOMAttr* newAttr,                              \
+                            nsIDOMAttr** _retval) MOZ_FINAL                   \
+{                                                                             \
+  if (!newAttr) {                                                             \
+    return NS_ERROR_INVALID_POINTER;                                          \
+  }                                                                           \
+  mozilla::ErrorResult rv;                                                    \
+  *_retval = nsGenericElement::SetAttributeNode(newAttr, rv).get();           \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr,                           \
+                               nsIDOMAttr** _retval) MOZ_FINAL                \
+{                                                                             \
+  if (!oldAttr) {                                                             \
+    return NS_ERROR_INVALID_POINTER;                                          \
+  }                                                                           \
+  mozilla::ErrorResult rv;                                                    \
+  *_retval = nsGenericElement::RemoveAttributeNode(oldAttr, rv).get();        \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD GetAttributeNodeNS(const nsAString& namespaceURI,                  \
+                              const nsAString& localName,                     \
+                              nsIDOMAttr** _retval) MOZ_FINAL                 \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  NS_IF_ADDREF(*_retval = nsGenericElement::GetAttributeNodeNS(namespaceURI,  \
+                                                               localName,     \
+                                                               rv));          \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* newAttr,                            \
+                              nsIDOMAttr** _retval) MOZ_FINAL                 \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  *_retval = nsGenericElement::SetAttributeNodeNS(newAttr, rv).get();         \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD GetElementsByTagName(const nsAString& name,                        \
+                                nsIDOMHTMLCollection** _retval) MOZ_FINAL     \
+{                                                                             \
+  nsGenericElement::GetElementsByTagName(name, _retval);                      \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetElementsByTagNameNS(const nsAString& namespaceURI,              \
+                                  const nsAString& localName,                 \
+                                  nsIDOMHTMLCollection** _retval) MOZ_FINAL   \
+{                                                                             \
+  return nsGenericElement::GetElementsByTagNameNS(namespaceURI, localName,    \
+                                                  _retval);                   \
+}                                                                             \
+NS_IMETHOD GetElementsByClassName(const nsAString& classes,                   \
+                                  nsIDOMHTMLCollection** _retval) MOZ_FINAL   \
+{                                                                             \
+  return nsGenericElement::GetElementsByClassName(classes, _retval);          \
+}                                                                             \
+NS_IMETHOD GetChildElements(nsIDOMNodeList** aChildElements) MOZ_FINAL        \
+{                                                                             \
+  nsIHTMLCollection* list = FragmentOrElement::Children();                    \
+  return CallQueryInterface(list, aChildElements);                            \
+}                                                                             \
+NS_IMETHOD GetFirstElementChild(nsIDOMElement** aFirstElementChild) MOZ_FINAL \
+{                                                                             \
+  nsGenericElement* element = nsGenericElement::GetFirstElementChild();       \
+  if (!element) {                                                             \
+    *aFirstElementChild = nullptr;                                            \
+    return NS_OK;                                                             \
+  }                                                                           \
+  return CallQueryInterface(element, aFirstElementChild);                     \
+}                                                                             \
+NS_IMETHOD GetLastElementChild(nsIDOMElement** aLastElementChild) MOZ_FINAL   \
+{                                                                             \
+  nsGenericElement* element = nsGenericElement::GetLastElementChild();        \
+  if (!element) {                                                             \
+    *aLastElementChild = nullptr;                                             \
+    return NS_OK;                                                             \
+  }                                                                           \
+  return CallQueryInterface(element, aLastElementChild);                      \
+}                                                                             \
+NS_IMETHOD GetPreviousElementSibling(nsIDOMElement** aPreviousElementSibling) \
+  MOZ_FINAL                                                                   \
+{                                                                             \
+  nsGenericElement* element = nsGenericElement::GetPreviousElementSibling();  \
+  if (!element) {                                                             \
+    *aPreviousElementSibling = nullptr;                                       \
+    return NS_OK;                                                             \
+  }                                                                           \
+  return CallQueryInterface(element, aPreviousElementSibling);                \
+}                                                                             \
+NS_IMETHOD GetNextElementSibling(nsIDOMElement** aNextElementSibling)         \
+  MOZ_FINAL                                                                   \
+{                                                                             \
+  nsGenericElement* element = nsGenericElement::GetNextElementSibling();      \
+  if (!element) {                                                             \
+    *aNextElementSibling = nullptr;                                           \
+    return NS_OK;                                                             \
+  }                                                                           \
+  return CallQueryInterface(element, aNextElementSibling);                    \
+}                                                                             \
+NS_IMETHOD GetChildElementCount(uint32_t* aChildElementCount) MOZ_FINAL       \
+{                                                                             \
+  *aChildElementCount = nsGenericElement::ChildElementCount();                \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetOnmouseenter(JSContext* cx, JS::Value* aOnmouseenter) MOZ_FINAL \
+{                                                                             \
+  return nsGenericElement::GetOnmouseenter(cx, aOnmouseenter);                \
+}                                                                             \
+NS_IMETHOD SetOnmouseenter(JSContext* cx,                                     \
+                           const JS::Value& aOnmouseenter) MOZ_FINAL          \
+{                                                                             \
+  return nsGenericElement::SetOnmouseenter(cx, aOnmouseenter);                \
+}                                                                             \
+NS_IMETHOD GetOnmouseleave(JSContext* cx, JS::Value* aOnmouseleave) MOZ_FINAL \
+{                                                                             \
+  return nsGenericElement::GetOnmouseleave(cx, aOnmouseleave);                \
+}                                                                             \
+NS_IMETHOD SetOnmouseleave(JSContext* cx,                                     \
+                           const JS::Value& aOnmouseleave) MOZ_FINAL          \
+{                                                                             \
+  return nsGenericElement::SetOnmouseleave(cx, aOnmouseleave);                \
+}                                                                             \
+NS_IMETHOD GetClientRects(nsIDOMClientRectList** _retval) MOZ_FINAL           \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  *_retval = nsGenericElement::GetClientRects(rv).get();                      \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD GetBoundingClientRect(nsIDOMClientRect** _retval) MOZ_FINAL        \
+{                                                                             \
+  *_retval = nsGenericElement::GetBoundingClientRect().get();                 \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollTop(int32_t* aScrollTop) MOZ_FINAL                        \
+{                                                                             \
+  *aScrollTop = nsGenericElement::ScrollTop();                                \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD SetScrollTop(int32_t aScrollTop) MOZ_FINAL                         \
+{                                                                             \
+  nsGenericElement::SetScrollTop(aScrollTop);                                 \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollLeft(int32_t* aScrollLeft) MOZ_FINAL                      \
+{                                                                             \
+  *aScrollLeft = nsGenericElement::ScrollLeft();                              \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD SetScrollLeft(int32_t aScrollLeft) MOZ_FINAL                       \
+{                                                                             \
+  nsGenericElement::SetScrollLeft(aScrollLeft);                               \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollWidth(int32_t* aScrollWidth) MOZ_FINAL                    \
+{                                                                             \
+  *aScrollWidth = nsGenericElement::ScrollWidth();                            \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollHeight(int32_t* aScrollHeight) MOZ_FINAL                  \
+{                                                                             \
+  *aScrollHeight = nsGenericElement::ScrollHeight();                          \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetClientTop(int32_t* aClientTop) MOZ_FINAL                        \
+{                                                                             \
+  *aClientTop = nsGenericElement::ClientTop();                                \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetClientLeft(int32_t* aClientLeft) MOZ_FINAL                      \
+{                                                                             \
+  *aClientLeft = nsGenericElement::ClientLeft();                              \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetClientWidth(int32_t* aClientWidth) MOZ_FINAL                    \
+{                                                                             \
+  *aClientWidth = nsGenericElement::ClientWidth();                            \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetClientHeight(int32_t* aClientHeight) MOZ_FINAL                  \
+{                                                                             \
+  *aClientHeight = nsGenericElement::ClientHeight();                          \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollLeftMax(int32_t* aScrollLeftMax) MOZ_FINAL                \
+{                                                                             \
+  *aScrollLeftMax = nsGenericElement::ScrollLeftMax();                        \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD GetScrollTopMax(int32_t* aScrollTopMax) MOZ_FINAL                  \
+{                                                                             \
+  *aScrollTopMax = nsGenericElement::ScrollTopMax();                          \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD MozMatchesSelector(const nsAString& selector,                      \
+                              bool* _retval) MOZ_FINAL                        \
+{                                                                             \
+  mozilla::ErrorResult rv;                                                    \
+  *_retval = nsGenericElement::MozMatchesSelector(selector, rv);              \
+  return rv.ErrorCode();                                                      \
+}                                                                             \
+NS_IMETHOD SetCapture(bool retargetToElement) MOZ_FINAL                       \
+{                                                                             \
+  nsGenericElement::SetCapture(retargetToElement);                            \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD ReleaseCapture(void) MOZ_FINAL                                     \
+{                                                                             \
+  nsGenericElement::ReleaseCapture();                                         \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD MozRequestFullScreen(void) MOZ_FINAL                               \
+{                                                                             \
+  nsGenericElement::MozRequestFullScreen();                                   \
+  return NS_OK;                                                               \
+}                                                                             \
+NS_IMETHOD MozRequestPointerLock(void) MOZ_FINAL                              \
+{                                                                             \
+  nsGenericElement::MozRequestPointerLock();                                  \
+  return NS_OK;                                                               \
+}
+
 #endif /* nsGenericElement_h___ */
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -2009,58 +2009,81 @@ nsINode::SizeOfExcludingThis(nsMallocSiz
   // - mSlots
   //
   // The following members are not measured:
   // - mParent, mNextSibling, mPreviousSibling, mFirstChild: because they're
   //   non-owning
   return n;
 }
 
-#define EVENT(name_, id_, type_, struct_)                                    \
+#define EVENT_HELPER(name_, handlerClass_)                                   \
   NS_IMETHODIMP nsINode::GetOn##name_(JSContext *cx, jsval *vp) {            \
-    nsEventListenerManager *elm = GetListenerManager(false);                 \
-    if (elm) {                                                               \
-      EventHandlerNonNull* h = elm->GetEventHandler(nsGkAtoms::on##name_);   \
-      if (h) {                                                               \
-        *vp = JS::ObjectValue(*h->Callable());                               \
-        return NS_OK;                                                        \
-      }                                                                      \
-    }                                                                        \
-    *vp = JSVAL_NULL;                                                        \
+    handlerClass_* h = GetOn##name_();                                       \
+    vp->setObjectOrNull(h ? h->Callable() : nullptr);                        \
     return NS_OK;                                                            \
   }                                                                          \
   NS_IMETHODIMP nsINode::SetOn##name_(JSContext *cx, const jsval &v) {       \
-    nsEventListenerManager *elm = GetListenerManager(true);                  \
-    if (!elm) {                                                              \
-      return NS_ERROR_OUT_OF_MEMORY;                                         \
-    }                                                                        \
-                                                                             \
     JSObject *obj = GetWrapper();                                            \
     if (!obj) {                                                              \
       /* Just silently do nothing */                                         \
       return NS_OK;                                                          \
     }                                                                        \
-    nsRefPtr<EventHandlerNonNull> handler;                                   \
+    nsRefPtr<handlerClass_> handler;                                         \
     JSObject *callable;                                                      \
     if (v.isObject() &&                                                      \
         JS_ObjectIsCallable(cx, callable = &v.toObject())) {                 \
       bool ok;                                                               \
-      handler = new EventHandlerNonNull(cx, obj, callable, &ok);             \
+      handler = new handlerClass_(cx, obj, callable, &ok);                   \
       if (!ok) {                                                             \
         return NS_ERROR_OUT_OF_MEMORY;                                       \
       }                                                                      \
     }                                                                        \
-    return elm->SetEventHandler(nsGkAtoms::on##name_, handler);              \
+    ErrorResult rv;                                                          \
+    SetOn##name_(handler, rv);                                               \
+    return rv.ErrorCode();                                                   \
   }
+
+#define EVENT(name_, id_, type_, struct_)                                    \
+  EventHandlerNonNull* nsINode::GetOn##name_() {                             \
+    nsEventListenerManager *elm = GetListenerManager(false);                 \
+    return elm ? elm->GetEventHandler(nsGkAtoms::on##name_) : nullptr;       \
+  }                                                                          \
+  void nsINode::SetOn##name_(EventHandlerNonNull* handler,                   \
+                             ErrorResult& error) {                           \
+    nsEventListenerManager *elm = GetListenerManager(true);                  \
+    if (elm) {                                                               \
+      error = elm->SetEventHandler(nsGkAtoms::on##name_, handler);           \
+    } else {                                                                 \
+      error.Throw(NS_ERROR_OUT_OF_MEMORY);                                   \
+    }                                                                        \
+  }                                                                          \
+  EVENT_HELPER(name_, EventHandlerNonNull)
 #define TOUCH_EVENT EVENT
 #define DOCUMENT_ONLY_EVENT EVENT
+#define ERROR_EVENT(name_, id_, type_, struct_)                              \
+  OnErrorEventHandlerNonNull* nsINode::GetOn##name_() {                      \
+    nsEventListenerManager *elm = GetListenerManager(false);                 \
+    return elm ? elm->GetOnErrorEventHandler() : nullptr;                    \
+  }                                                                          \
+  void nsINode::SetOn##name_(OnErrorEventHandlerNonNull* handler,            \
+                             ErrorResult& error) {                           \
+    nsEventListenerManager *elm = GetListenerManager(true);                  \
+    if (elm) {                                                               \
+      error = elm->SetEventHandler(handler);                                 \
+    } else {                                                                 \
+      error.Throw(NS_ERROR_OUT_OF_MEMORY);                                   \
+    }                                                                        \
+  }                                                                          \
+  EVENT_HELPER(name_, OnErrorEventHandlerNonNull)
 #include "nsEventNameList.h"
+#undef ERROR_EVENT  
 #undef DOCUMENT_ONLY_EVENT
 #undef TOUCH_EVENT
 #undef EVENT
+#undef EVENT_HELPER
 
 bool
 nsINode::Contains(const nsINode* aOther) const
 {
   if (aOther == this) {
     return true;
   }
   if (!aOther ||
@@ -2127,31 +2150,28 @@ NS_INTERFACE_MAP_END_AGGREGATED(mNode)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeSelectorTearoff)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeSelectorTearoff)
 
 NS_IMETHODIMP
 nsNodeSelectorTearoff::QuerySelector(const nsAString& aSelector,
                                      nsIDOMElement **aReturn)
 {
-  nsresult rv;
-  nsIContent* result = mNode->QuerySelector(aSelector, &rv);
-  if (!result) {
-    *aReturn = nullptr;
-    return rv;
-  }
-
-  return CallQueryInterface(result, aReturn);
+  ErrorResult rv;
+  nsIContent* result = mNode->QuerySelector(aSelector, rv);
+  return result ? CallQueryInterface(result, aReturn) : rv.ErrorCode();
 }
 
 NS_IMETHODIMP
 nsNodeSelectorTearoff::QuerySelectorAll(const nsAString& aSelector,
                                         nsIDOMNodeList **aReturn)
 {
-  return mNode->QuerySelectorAll(aSelector, aReturn);
+  ErrorResult rv;
+  *aReturn = mNode->QuerySelectorAll(aSelector, rv).get();
+  return rv.ErrorCode();
 }
 
 // NOTE: The aPresContext pointer is NOT addrefed.
 // *aSelectorList might be null even if NS_OK is returned; this
 // happens when all the selectors were pseudo-element selectors.
 static nsresult
 ParseSelectorList(nsINode* aNode,
                   const nsAString& aSelectorString,
@@ -2185,19 +2205,18 @@ ParseSelectorList(nsINode* aNode,
 
   return NS_OK;
 }
 
 // Actually find elements matching aSelectorList (which must not be
 // null) and which are descendants of aRoot and put them in aList.  If
 // onlyFirstMatch, then stop once the first one is found.
 template<bool onlyFirstMatch, class T>
-inline static nsresult FindMatchingElements(nsINode* aRoot,
-                                            const nsAString& aSelector,
-                                            T &aList)
+inline static nsresult
+FindMatchingElements(nsINode* aRoot, const nsAString& aSelector, T &aList)
 {
   nsAutoPtr<nsCSSSelectorList> selectorList;
   nsresult rv = ParseSelectorList(aRoot, aSelector,
                                   getter_Transfers(selectorList));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(selectorList, NS_OK);
 
   NS_ASSERTION(selectorList->mSelectors,
@@ -2268,45 +2287,38 @@ inline static nsresult FindMatchingEleme
 
   return NS_OK;
 }
 
 struct ElementHolder {
   ElementHolder() : mElement(nullptr) {}
   void AppendElement(Element* aElement) {
     NS_ABORT_IF_FALSE(!mElement, "Should only get one element");
-    mElement = aElement;
+    mElement = static_cast<nsGenericElement*>(aElement);
   }
-  Element* mElement;
+  nsGenericElement* mElement;
 };
 
-nsIContent*
-nsINode::QuerySelector(const nsAString& aSelector,
-                       nsresult *aResult)
+nsGenericElement*
+nsINode::QuerySelector(const nsAString& aSelector, ErrorResult& aResult)
 {
-  NS_PRECONDITION(aResult, "Null out param?");
-
   ElementHolder holder;
-  *aResult = FindMatchingElements<true>(this, aSelector, holder);
+  aResult = FindMatchingElements<true>(this, aSelector, holder);
 
   return holder.mElement;
 }
 
-/* static */
-nsresult
-nsINode::QuerySelectorAll(const nsAString& aSelector,
-                          nsIDOMNodeList **aReturn)
+already_AddRefed<nsINodeList>
+nsINode::QuerySelectorAll(const nsAString& aSelector, ErrorResult& aResult)
 {
-  NS_PRECONDITION(aReturn, "Null out param?");
+  nsRefPtr<nsSimpleContentList> contentList = new nsSimpleContentList(this);
 
-  nsSimpleContentList* contentList = new nsSimpleContentList(this);
-  NS_ENSURE_TRUE(contentList, NS_ERROR_OUT_OF_MEMORY);
-  NS_ADDREF(*aReturn = contentList);
+  aResult = FindMatchingElements<false>(this, aSelector, *contentList);
 
-  return FindMatchingElements<false>(this, aSelector, *contentList);
+  return contentList.forget();
 }
 
 JSObject*
 nsINode::WrapObject(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
 {
   // Not all nodes have been converted
   if (!IsDOMBinding()) {
     *aTriedToWrap = false;
--- a/content/html/content/public/nsHTMLAudioElement.h
+++ b/content/html/content/public/nsHTMLAudioElement.h
@@ -23,17 +23,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsHTMLMediaElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsHTMLMediaElement::)
 
   // nsIDOMHTMLMediaElement
   using nsHTMLMediaElement::GetPaused;
   NS_FORWARD_NSIDOMHTMLMEDIAELEMENT(nsHTMLMediaElement::)
 
--- a/content/html/content/public/nsHTMLCanvasElement.h
+++ b/content/html/content/public/nsHTMLCanvasElement.h
@@ -50,17 +50,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLCanvasElement
   NS_DECL_NSIDOMHTMLCANVASELEMENT
 
   // CC
--- a/content/html/content/public/nsHTMLVideoElement.h
+++ b/content/html/content/public/nsHTMLVideoElement.h
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsHTMLMediaElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsHTMLMediaElement::)
 
   // nsIDOMHTMLMediaElement
   using nsHTMLMediaElement::GetPaused;
   NS_FORWARD_NSIDOMHTMLMEDIAELEMENT(nsHTMLMediaElement::)
 
--- a/content/html/content/public/nsIHTMLCollection.h
+++ b/content/html/content/public/nsIHTMLCollection.h
@@ -61,13 +61,22 @@ public:
                         bool& found, mozilla::ErrorResult& error)
   {
     JSObject* namedItem = NamedItem(cx, name, error);
     found = !!namedItem;
     return namedItem;
   }
 
   virtual void GetSupportedNames(nsTArray<nsString>& aNames) = 0;
+
+  JSObject* GetWrapper()
+  {
+    nsWrapperCache* cache;
+    CallQueryInterface(this, &cache);
+    return cache->GetWrapper();
+  }
+  virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
+                               bool *triedToWrap) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID)
 
 #endif /* nsIHTMLCollection_h___ */
--- a/content/html/content/src/HTMLPropertiesCollection.h
+++ b/content/html/content/src/HTMLPropertiesCollection.h
@@ -14,18 +14,19 @@
 #include "nsIDOMPropertyNodeList.h"
 #include "nsCOMArray.h"
 #include "nsIMutationObserver.h"
 #include "nsStubMutationObserver.h"
 #include "nsBaseHashtable.h"
 #include "nsINodeList.h"
 #include "nsIHTMLCollection.h"
 #include "nsHashKeys.h"
-#include "nsGenericHTMLElement.h"
+#include "nsRefPtrHashtable.h"
 
+class nsGenericHTMLElement;
 class nsXPCClassInfo;
 class nsIDocument;
 class nsINode;
 
 namespace mozilla {
 namespace dom {
 
 class HTMLPropertiesCollection;
@@ -51,16 +52,17 @@ class HTMLPropertiesCollection : public 
                                  public nsWrapperCache
 {
   friend class PropertyNodeList;
   friend class PropertyStringList;
 public:
   HTMLPropertiesCollection(nsGenericHTMLElement* aRoot);
   virtual ~HTMLPropertiesCollection();
 
+  using nsWrapperCache::GetWrapper;
   virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
                                bool *triedToWrap);
 
   virtual nsGenericElement* GetElementAt(uint32_t aIndex);
 
   NS_IMETHOD NamedItem(const nsAString& aName, nsIDOMNode** aResult);
   void SetDocument(nsIDocument* aDocument);
   nsINode* GetParentObject();
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -310,46 +310,16 @@ nsGenericHTMLElement::CopyInnerTo(nsGene
     rv = aDst->SetAttr(name->NamespaceID(), name->LocalName(),
                        name->GetPrefix(), valStr, false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsGenericHTMLElement::SetAttribute(const nsAString& aName,
-                                   const nsAString& aValue)
-{
-  const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
-
-  if (!name) {
-    nsresult rv = nsContentUtils::CheckQName(aName, false);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIAtom> nameAtom;
-    if (IsInHTMLDocument()) {
-      nsAutoString lower;
-      rv = nsContentUtils::ASCIIToLower(aName, lower);
-      if (NS_SUCCEEDED(rv)) {
-        nameAtom = do_GetAtom(lower);
-      }
-    }
-    else {
-      nameAtom = do_GetAtom(aName);
-    }
-    NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
-
-    return SetAttr(kNameSpaceID_None, nameAtom, aValue, true);
-  }
-
-  return SetAttr(name->NamespaceID(), name->LocalName(), name->GetPrefix(),
-                 aValue, true);
-}
-
 already_AddRefed<nsDOMStringMap>
 nsGenericHTMLElement::Dataset()
 {
   nsDOMSlots *slots = DOMSlots();
 
   if (!slots->mDataset) {
     // mDataset is a weak reference so assignment will not AddRef.
     // AddRef is called before returning the pointer.
@@ -1571,41 +1541,21 @@ nsGenericHTMLElement::InsertAdjacentHTML
       break;
   }
   return error.ErrorCode();
 }
 
 nsresult
 nsGenericHTMLElement::ScrollIntoView(bool aTop, uint8_t optional_argc)
 {
-  nsIDocument *document = GetCurrentDoc();
-
-  if (!document) {
-    return NS_OK;
-  }
-
-  // Get the presentation shell
-  nsCOMPtr<nsIPresShell> presShell = document->GetShell();
-  if (!presShell) {
-    return NS_OK;
-  }
-
   if (!optional_argc) {
     aTop = true;
   }
 
-  int16_t vpercent = aTop ? nsIPresShell::SCROLL_TOP :
-    nsIPresShell::SCROLL_BOTTOM;
-
-  presShell->ScrollContentIntoView(this,
-                                   nsIPresShell::ScrollAxis(
-                                     vpercent,
-                                     nsIPresShell::SCROLL_ALWAYS),
-                                   nsIPresShell::ScrollAxis(),
-                                   nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
+  nsGenericElement::ScrollIntoView(aTop);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGenericHTMLElement::GetSpellcheck(bool* aSpellcheck)
 {
   NS_ENSURE_ARG_POINTER(aSpellcheck);
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -64,20 +64,16 @@ public:
    * @see nsGenericHTMLElementTearoff
    */
   nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, REFNSIID aIID,
                              void **aInstancePtr);
 
   // From nsGenericElement
   nsresult CopyInnerTo(nsGenericElement* aDest);
 
-  // Implementation for nsIDOMElement
-  NS_METHOD SetAttribute(const nsAString& aName,
-                         const nsAString& aValue);
-
   // WebIDL HTMLElement
   virtual void Click();
   virtual int32_t TabIndexDefault()
   {
     return -1;
   }
   int32_t TabIndex()
   {
--- a/content/html/content/src/nsHTMLAnchorElement.cpp
+++ b/content/html/content/src/nsHTMLAnchorElement.cpp
@@ -33,17 +33,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
   virtual bool Draggable() const MOZ_OVERRIDE;
 
   // nsIDOMHTMLAnchorElement
   NS_DECL_NSIDOMHTMLANCHORELEMENT  
--- a/content/html/content/src/nsHTMLAreaElement.cpp
+++ b/content/html/content/src/nsHTMLAreaElement.cpp
@@ -27,17 +27,17 @@ public:
 
   // DOM memory reporter participant
   NS_DECL_SIZEOF_EXCLUDING_THIS
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLAreaElement
   NS_DECL_NSIDOMHTMLAREAELEMENT
 
--- a/content/html/content/src/nsHTMLBRElement.cpp
+++ b/content/html/content/src/nsHTMLBRElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLBRElement
   NS_DECL_NSIDOMHTMLBRELEMENT    
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLBodyElement.cpp
+++ b/content/html/content/src/nsHTMLBodyElement.cpp
@@ -60,17 +60,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLBodyElement
   NS_DECL_NSIDOMHTMLBODYELEMENT
 
   // Event listener stuff; we need to declare only the ones we need to
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -61,17 +61,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLButtonElement
   NS_DECL_NSIDOMHTMLBUTTONELEMENT
 
--- a/content/html/content/src/nsHTMLDataListElement.cpp
+++ b/content/html/content/src/nsHTMLDataListElement.cpp
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLDataListElement
   NS_DECL_NSIDOMHTMLDATALISTELEMENT
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/html/content/src/nsHTMLDivElement.cpp
+++ b/content/html/content/src/nsHTMLDivElement.cpp
@@ -23,17 +23,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLDivElement
   NS_DECL_NSIDOMHTMLDIVELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLElement.cpp
+++ b/content/html/content/src/nsHTMLElement.cpp
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual void GetInnerHTML(nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
   nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const;
 
--- a/content/html/content/src/nsHTMLFieldSetElement.h
+++ b/content/html/content/src/nsHTMLFieldSetElement.h
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
 
   // nsIDOMHTMLFieldSetElement
   NS_DECL_NSIDOMHTMLFIELDSETELEMENT
 
   // nsIContent
--- a/content/html/content/src/nsHTMLFontElement.cpp
+++ b/content/html/content/src/nsHTMLFontElement.cpp
@@ -29,17 +29,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLFontElement
   NS_DECL_NSIDOMHTMLFONTELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLFormElement.cpp
+++ b/content/html/content/src/nsHTMLFormElement.cpp
@@ -2527,17 +2527,17 @@ nsFormControlList::GetElementAt(uint32_t
 JSObject*
 nsFormControlList::NamedItem(JSContext* cx, const nsAString& name,
                              mozilla::ErrorResult& error)
 {
   nsISupports *item = NamedItemInternal(name, true);
   if (!item) {
     return nullptr;
   }
-  JSObject* wrapper = GetWrapper();
+  JSObject* wrapper = nsWrapperCache::GetWrapper();
   JSAutoCompartment ac(cx, wrapper);
   JS::Value v;
   if (!mozilla::dom::WrapObject(cx, wrapper, item, &v)) {
     error.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   return &v.toObject();
 }
--- a/content/html/content/src/nsHTMLFormElement.h
+++ b/content/html/content/src/nsHTMLFormElement.h
@@ -38,17 +38,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLFormElement
   NS_DECL_NSIDOMHTMLFORMELEMENT
 
   // nsIWebProgressListener
--- a/content/html/content/src/nsHTMLFrameElement.cpp
+++ b/content/html/content/src/nsHTMLFrameElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
 
   // nsIDOMHTMLFrameElement
   NS_DECL_NSIDOMHTMLFRAMEELEMENT
 
   // nsIContent
--- a/content/html/content/src/nsHTMLFrameSetElement.h
+++ b/content/html/content/src/nsHTMLFrameSetElement.h
@@ -51,17 +51,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLFrameSetElement
   NS_DECL_NSIDOMHTMLFRAMESETELEMENT
 
   // Event listener stuff; we need to declare only the ones we need to
--- a/content/html/content/src/nsHTMLHRElement.cpp
+++ b/content/html/content/src/nsHTMLHRElement.cpp
@@ -28,17 +28,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLHRElement
   NS_DECL_NSIDOMHTMLHRELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLHeadingElement.cpp
+++ b/content/html/content/src/nsHTMLHeadingElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLHeadingElement
   NS_DECL_NSIDOMHTMLHEADINGELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLIFrameElement.h
+++ b/content/html/content/src/nsHTMLIFrameElement.h
@@ -21,17 +21,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
 
   // nsIDOMHTMLIFrameElement
   NS_DECL_NSIDOMHTMLIFRAMEELEMENT
 
   // nsIDOMGetSVGDocument
--- a/content/html/content/src/nsHTMLImageElement.h
+++ b/content/html/content/src/nsHTMLImageElement.h
@@ -22,17 +22,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual bool Draggable() const MOZ_OVERRIDE;
 
   // nsIDOMHTMLImageElement
   NS_DECL_NSIDOMHTMLIMAGEELEMENT
 
--- a/content/html/content/src/nsHTMLInputElement.h
+++ b/content/html/content/src/nsHTMLInputElement.h
@@ -69,17 +69,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual void Click() MOZ_OVERRIDE;
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
   virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
   // nsIDOMHTMLInputElement
--- a/content/html/content/src/nsHTMLLIElement.cpp
+++ b/content/html/content/src/nsHTMLLIElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLLIElement
   NS_DECL_NSIDOMHTMLLIELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLLabelElement.h
+++ b/content/html/content/src/nsHTMLLabelElement.h
@@ -23,17 +23,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLLabelElement
   NS_DECL_NSIDOMHTMLLABELELEMENT
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
--- a/content/html/content/src/nsHTMLLegendElement.h
+++ b/content/html/content/src/nsHTMLLegendElement.h
@@ -19,17 +19,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLLegendElement
   NS_DECL_NSIDOMHTMLLEGENDELEMENT
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
--- a/content/html/content/src/nsHTMLLinkElement.cpp
+++ b/content/html/content/src/nsHTMLLinkElement.cpp
@@ -44,17 +44,17 @@ public:
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLLinkElement,
                                            nsGenericHTMLElement)
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLLinkElement
   NS_DECL_NSIDOMHTMLLINKELEMENT
 
   // DOM memory reporter participant
--- a/content/html/content/src/nsHTMLMapElement.cpp
+++ b/content/html/content/src/nsHTMLMapElement.cpp
@@ -19,17 +19,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLMapElement
   NS_DECL_NSIDOMHTMLMAPELEMENT
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/html/content/src/nsHTMLMenuElement.h
+++ b/content/html/content/src/nsHTMLMenuElement.h
@@ -19,17 +19,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLMenuElement
   NS_DECL_NSIDOMHTMLMENUELEMENT
 
   // nsIHTMLMenu
--- a/content/html/content/src/nsHTMLMenuItemElement.h
+++ b/content/html/content/src/nsHTMLMenuItemElement.h
@@ -22,17 +22,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLCommandElement
   NS_DECL_NSIDOMHTMLCOMMANDELEMENT
 
   // nsIDOMHTMLMenuItemElement
--- a/content/html/content/src/nsHTMLMetaElement.cpp
+++ b/content/html/content/src/nsHTMLMetaElement.cpp
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLMetaElement
   NS_DECL_NSIDOMHTMLMETAELEMENT
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
--- a/content/html/content/src/nsHTMLMeterElement.cpp
+++ b/content/html/content/src/nsHTMLMeterElement.cpp
@@ -20,17 +20,17 @@ public:
 
   /* nsISupports */
   NS_DECL_ISUPPORTS_INHERITED
 
   /* nsIDOMNode */
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   /* nsIDOMElement */
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   /* nsIDOMHTMLElement */
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   /* nsIDOMHTMLMeterElement */
   NS_DECL_NSIDOMHTMLMETERELEMENT
 
   virtual nsEventStates IntrinsicState() const;
--- a/content/html/content/src/nsHTMLModElement.cpp
+++ b/content/html/content/src/nsHTMLModElement.cpp
@@ -18,17 +18,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLModElement
   NS_DECL_NSIDOMHTMLMODELEMENT
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/html/content/src/nsHTMLOListElement.cpp
+++ b/content/html/content/src/nsHTMLOListElement.cpp
@@ -29,17 +29,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLOListElement
   NS_DECL_NSIDOMHTMLOLISTELEMENT
 
   // nsIDOMHTMLDListElement
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -41,17 +41,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLObjectElement
   NS_DECL_NSIDOMHTMLOBJECTELEMENT
 
--- a/content/html/content/src/nsHTMLOptGroupElement.h
+++ b/content/html/content/src/nsHTMLOptGroupElement.h
@@ -18,17 +18,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLOptGroupElement
   NS_DECL_NSIDOMHTMLOPTGROUPELEMENT
 
   // nsINode
--- a/content/html/content/src/nsHTMLOptionElement.h
+++ b/content/html/content/src/nsHTMLOptionElement.h
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLOptionElement
   using nsGenericElement::SetText;
   using nsGenericElement::GetText;
   NS_DECL_NSIDOMHTMLOPTIONELEMENT
--- a/content/html/content/src/nsHTMLOutputElement.cpp
+++ b/content/html/content/src/nsHTMLOutputElement.cpp
@@ -27,17 +27,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
 
   // nsIDOMHTMLOutputElement
   NS_DECL_NSIDOMHTMLOUTPUTELEMENT
 
   // nsIFormControl
--- a/content/html/content/src/nsHTMLParagraphElement.cpp
+++ b/content/html/content/src/nsHTMLParagraphElement.cpp
@@ -26,17 +26,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLParagraphElement
   NS_DECL_NSIDOMHTMLPARAGRAPHELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLPreElement.cpp
+++ b/content/html/content/src/nsHTMLPreElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLPreElement
   NS_IMETHOD GetWidth(int32_t* aWidth);
   NS_IMETHOD SetWidth(int32_t aWidth);
 
--- a/content/html/content/src/nsHTMLProgressElement.cpp
+++ b/content/html/content/src/nsHTMLProgressElement.cpp
@@ -19,17 +19,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLProgressElement
   NS_DECL_NSIDOMHTMLPROGRESSELEMENT
 
   nsEventStates IntrinsicState() const;
--- a/content/html/content/src/nsHTMLScriptElement.cpp
+++ b/content/html/content/src/nsHTMLScriptElement.cpp
@@ -41,17 +41,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual void GetInnerHTML(nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -2181,17 +2181,17 @@ nsHTMLOptionCollection::NamedItem(const 
 JSObject*
 nsHTMLOptionCollection::NamedItem(JSContext* cx, const nsAString& name,
                                   ErrorResult& error)
 {
   nsINode *item = GetNamedItemHelper(mElements, name);
   if (!item) {
     return nullptr;
   }
-  JSObject* wrapper = GetWrapper();
+  JSObject* wrapper = nsWrapperCache::GetWrapper();
   JSAutoCompartment ac(cx, wrapper);
   JS::Value v;
   if (!mozilla::dom::WrapObject(cx, wrapper, item, item, nullptr, &v)) {
     error.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   return &v.toObject();
 }
--- a/content/html/content/src/nsHTMLSelectElement.h
+++ b/content/html/content/src/nsHTMLSelectElement.h
@@ -241,17 +241,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLSelectElement
   NS_DECL_NSIDOMHTMLSELECTELEMENT
 
--- a/content/html/content/src/nsHTMLSharedElement.cpp
+++ b/content/html/content/src/nsHTMLSharedElement.cpp
@@ -39,17 +39,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLParamElement
   NS_DECL_NSIDOMHTMLPARAMELEMENT
 
   // nsIDOMHTMLBaseElement
--- a/content/html/content/src/nsHTMLSharedObjectElement.cpp
+++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp
@@ -36,17 +36,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLAppletElement
   NS_DECL_NSIDOMHTMLAPPLETELEMENT
 
--- a/content/html/content/src/nsHTMLSourceElement.cpp
+++ b/content/html/content/src/nsHTMLSourceElement.cpp
@@ -23,17 +23,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLSourceElement
   NS_DECL_NSIDOMHTMLSOURCEELEMENT
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/html/content/src/nsHTMLSpanElement.cpp
+++ b/content/html/content/src/nsHTMLSpanElement.cpp
@@ -19,17 +19,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
--- a/content/html/content/src/nsHTMLStyleElement.cpp
+++ b/content/html/content/src/nsHTMLStyleElement.cpp
@@ -36,17 +36,17 @@ public:
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLStyleElement,
                                            nsGenericHTMLElement)
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
   virtual void GetInnerHTML(nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
--- a/content/html/content/src/nsHTMLTableCaptionElement.cpp
+++ b/content/html/content/src/nsHTMLTableCaptionElement.cpp
@@ -25,17 +25,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableCaptionElement
   NS_DECL_NSIDOMHTMLTABLECAPTIONELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTableCellElement.cpp
+++ b/content/html/content/src/nsHTMLTableCellElement.cpp
@@ -31,17 +31,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableCellElement
   NS_DECL_NSIDOMHTMLTABLECELLELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTableColElement.cpp
+++ b/content/html/content/src/nsHTMLTableColElement.cpp
@@ -29,17 +29,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableColElement
   NS_DECL_NSIDOMHTMLTABLECOLELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTableElement.cpp
+++ b/content/html/content/src/nsHTMLTableElement.cpp
@@ -255,17 +255,17 @@ TableRowsCollection::NamedItem(JSContext
       // JSObject*, but that relies on collection having a cached wrapper, which
       // we can't guarantee here.
       nsCOMPtr<nsIDOMNode> item;
       error = collection->NamedItem(name, getter_AddRefs(item));
       if (error.Failed()) {
         return nullptr;
       }
       if (item) {
-        JSObject* wrapper = GetWrapper();
+        JSObject* wrapper = nsWrapperCache::GetWrapper();
         JSAutoCompartment ac(cx, wrapper);
         JS::Value v;
         if (!mozilla::dom::WrapObject(cx, wrapper, item, &v)) {
           error.Throw(NS_ERROR_FAILURE);
           return nullptr;
         }
         return &v.toObject();
       }
--- a/content/html/content/src/nsHTMLTableElement.h
+++ b/content/html/content/src/nsHTMLTableElement.h
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableElement
   NS_DECL_NSIDOMHTMLTABLEELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTableRowElement.cpp
+++ b/content/html/content/src/nsHTMLTableRowElement.cpp
@@ -31,17 +31,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableRowElement
   NS_DECL_NSIDOMHTMLTABLEROWELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTableSectionElement.cpp
+++ b/content/html/content/src/nsHTMLTableSectionElement.cpp
@@ -30,17 +30,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTableSectionElement
   NS_DECL_NSIDOMHTMLTABLESECTIONELEMENT
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -69,17 +69,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLTextAreaElement
   NS_DECL_NSIDOMHTMLTEXTAREAELEMENT
 
--- a/content/html/content/src/nsHTMLTitleElement.cpp
+++ b/content/html/content/src/nsHTMLTitleElement.cpp
@@ -23,17 +23,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLTitleElement
   NS_DECL_NSIDOMHTMLTITLEELEMENT
 
   // nsIMutationObserver
--- a/content/html/content/src/nsHTMLUnknownElement.cpp
+++ b/content/html/content/src/nsHTMLUnknownElement.cpp
@@ -15,17 +15,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
--- a/content/mathml/content/src/nsMathMLElement.h
+++ b/content/mathml/content/src/nsMathMLElement.h
@@ -30,17 +30,17 @@ public:
   {}
 
   // Implementation of nsISupports is inherited from nsMathMLElementBase
   NS_DECL_ISUPPORTS_INHERITED
 
   // Forward implementations of parent interfaces of nsMathMLElement to 
   // our base class
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsMathMLElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                       nsIContent* aBindingParent,
                       bool aCompileEventHandlers);
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true);
 
   virtual bool ParseAttribute(int32_t aNamespaceID,
--- a/content/svg/content/src/SVGFragmentIdentifier.cpp
+++ b/content/svg/content/src/SVGFragmentIdentifier.cpp
@@ -45,17 +45,18 @@ SVGFragmentIdentifier::SaveOldPreserveAs
 
 void 
 SVGFragmentIdentifier::RestoreOldPreserveAspectRatio(nsSVGSVGElement *root)
 {
   const SVGPreserveAspectRatio *oldPARPtr = root->GetPreserveAspectRatioProperty();
   if (oldPARPtr) {
     root->mPreserveAspectRatio.SetBaseValue(*oldPARPtr, root);
   } else if (root->mPreserveAspectRatio.IsExplicitlySet()) {
-    root->RemoveAttribute(NS_LITERAL_STRING("preserveAspectRatio"));
+    mozilla::ErrorResult error;
+    root->RemoveAttribute(NS_LITERAL_STRING("preserveAspectRatio"), error);
   }
 }
 
 void 
 SVGFragmentIdentifier::SaveOldViewBox(nsSVGSVGElement *root)
 {
   if (root->mViewBox.IsExplicitlySet()) {
     root->SetViewBoxProperty(root->mViewBox.GetBaseValue());
@@ -64,17 +65,18 @@ SVGFragmentIdentifier::SaveOldViewBox(ns
 
 void 
 SVGFragmentIdentifier::RestoreOldViewBox(nsSVGSVGElement *root)
 {
   const nsSVGViewBoxRect *oldViewBoxPtr = root->GetViewBoxProperty();
   if (oldViewBoxPtr) {
     root->mViewBox.SetBaseValue(*oldViewBoxPtr, root);
   } else if (root->mViewBox.IsExplicitlySet()) {
-    root->RemoveAttribute(NS_LITERAL_STRING("viewBox"));
+    mozilla::ErrorResult error;
+    root->RemoveAttribute(NS_LITERAL_STRING("viewBox"), error);
   }
 }
 
 void 
 SVGFragmentIdentifier::SaveOldZoomAndPan(nsSVGSVGElement *root)
 {
   if (root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].IsExplicitlySet()) {
     root->SetZoomAndPanProperty(root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].GetBaseValue());
@@ -83,17 +85,18 @@ SVGFragmentIdentifier::SaveOldZoomAndPan
 
 void 
 SVGFragmentIdentifier::RestoreOldZoomAndPan(nsSVGSVGElement *root)
 {
   uint16_t oldZoomAndPan = root->GetZoomAndPanProperty();
   if (oldZoomAndPan != nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_UNKNOWN) {
     root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].SetBaseValue(oldZoomAndPan, root);
   } else if (root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].IsExplicitlySet()) {
-    root->RemoveAttribute(NS_LITERAL_STRING("zoomAndPan"));
+    mozilla::ErrorResult error;
+    root->RemoveAttribute(NS_LITERAL_STRING("zoomAndPan"), error);
   }
 }
 
 void 
 SVGFragmentIdentifier::ClearTransform(nsSVGSVGElement *root)
 {
   root->mFragmentIdentifierTransform = nullptr;
   root->InvalidateTransformNotifyFrame();
--- a/content/svg/content/src/nsSVGAElement.h
+++ b/content/svg/content/src/nsSVGAElement.h
@@ -32,17 +32,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGAELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // XXX: I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGAElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAElementBase::)
 
   // nsINode interface methods
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsILink
--- a/content/svg/content/src/nsSVGAltGlyphElement.cpp
+++ b/content/svg/content/src/nsSVGAltGlyphElement.cpp
@@ -30,17 +30,17 @@ public:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGALTGLYPHELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGAltGlyphElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAltGlyphElementBase::)
   NS_FORWARD_NSIDOMSVGTEXTCONTENTELEMENT(nsSVGAltGlyphElementBase::)
   NS_FORWARD_NSIDOMSVGTEXTPOSITIONINGELEMENT(nsSVGAltGlyphElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/svg/content/src/nsSVGAnimateElement.cpp
+++ b/content/svg/content/src/nsSVGAnimateElement.cpp
@@ -20,17 +20,17 @@ protected:
   nsSMILAnimationFunction mAnimationFunction;
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGANIMATEELEMENT
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGAnimateElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAnimateElementBase::)
   NS_FORWARD_NSIDOMSVGANIMATIONELEMENT(nsSVGAnimateElementBase::)
   
   // nsIDOMNode
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsISMILAnimationElement
   virtual nsSMILAnimationFunction& AnimationFunction();
--- a/content/svg/content/src/nsSVGAnimateMotionElement.h
+++ b/content/svg/content/src/nsSVGAnimateMotionElement.h
@@ -24,17 +24,17 @@ protected:
   mozilla::SVGMotionSMILAnimationFunction mAnimationFunction;
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGANIMATEMOTIONELEMENT
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGAnimateMotionElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAnimateMotionElementBase::)
   NS_FORWARD_NSIDOMSVGANIMATIONELEMENT(nsSVGAnimateMotionElementBase::)
 
   // nsIDOMNode specializations
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsISMILAnimationElement
   virtual nsSMILAnimationFunction& AnimationFunction();
--- a/content/svg/content/src/nsSVGAnimateTransformElement.cpp
+++ b/content/svg/content/src/nsSVGAnimateTransformElement.cpp
@@ -23,17 +23,17 @@ protected:
   nsSMILAnimationFunction mAnimationFunction;
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGANIMATETRANSFORMELEMENT
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGAnimateTransformElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAnimateTransformElementBase::)
   NS_FORWARD_NSIDOMSVGANIMATIONELEMENT(nsSVGAnimateTransformElementBase::)
 
   // nsIDOMNode specializations
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsGenericElement specializations
   bool ParseAttribute(int32_t aNamespaceID,
--- a/content/svg/content/src/nsSVGCircleElement.cpp
+++ b/content/svg/content/src/nsSVGCircleElement.cpp
@@ -25,17 +25,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGCIRCLEELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGCircleElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGCircleElementBase::)
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx);
 
--- a/content/svg/content/src/nsSVGClipPathElement.h
+++ b/content/svg/content/src/nsSVGClipPathElement.h
@@ -29,17 +29,17 @@ protected:
 public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGCLIPPATHELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGClipPathElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGClipPathElementBase::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
--- a/content/svg/content/src/nsSVGDefsElement.cpp
+++ b/content/svg/content/src/nsSVGDefsElement.cpp
@@ -25,17 +25,17 @@ protected:
 public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGDEFSELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGDefsElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGDefsElementBase::)
 
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGDescElement.cpp
+++ b/content/svg/content/src/nsSVGDescElement.cpp
@@ -20,17 +20,17 @@ protected:
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGDESCELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGDescElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGDescElementBase::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
--- a/content/svg/content/src/nsSVGEllipseElement.cpp
+++ b/content/svg/content/src/nsSVGEllipseElement.cpp
@@ -25,17 +25,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGELLIPSEELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGEllipseElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGEllipseElementBase::)
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx);
 
--- a/content/svg/content/src/nsSVGFilterElement.h
+++ b/content/svg/content/src/nsSVGFilterElement.h
@@ -36,17 +36,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGFILTERELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFilterElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFilterElementBase::)
 
   // nsIContent
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   // Invalidate users of this filter
   void Invalidate();
--- a/content/svg/content/src/nsSVGFilters.cpp
+++ b/content/svg/content/src/nsSVGFilters.cpp
@@ -352,17 +352,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Gaussian
   NS_DECL_NSIDOMSVGFEGAUSSIANBLURELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEGaussianBlurElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEGaussianBlurElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual NumberPairAttributesInfo GetNumberPairInfo();
@@ -830,17 +830,17 @@ public:
   virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
 
   // Blend
   NS_DECL_NSIDOMSVGFEBLENDELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEBlendElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEBlendElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
 
@@ -1047,17 +1047,17 @@ public:
   virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
 
   // Color Matrix
   NS_DECL_NSIDOMSVGFECOLORMATRIXELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEColorMatrixElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEColorMatrixElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual bool OperatesOnPremultipledAlpha(int32_t) { return false; }
@@ -1367,17 +1367,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Composite
   NS_DECL_NSIDOMSVGFECOMPOSITEELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFECompositeElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFECompositeElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual NumberAttributesInfo GetNumberInfo();
@@ -1678,17 +1678,17 @@ public:
   virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
 
   // Component Transfer
   NS_DECL_NSIDOMSVGFECOMPONENTTRANSFERELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEComponentTransferElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEComponentTransferElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIContent
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
@@ -2092,17 +2092,17 @@ public:
   NS_FORWARD_NSIDOMSVGCOMPONENTTRANSFERFUNCTIONELEMENT(nsSVGComponentTransferFunctionElement::)
 
   NS_DECL_NSIDOMSVGFEFUNCRELEMENT
 
   virtual int32_t GetChannel() { return 0; }
   
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGComponentTransferFunctionElement::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGComponentTransferFunctionElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
 
@@ -2139,17 +2139,17 @@ public:
   NS_FORWARD_NSIDOMSVGCOMPONENTTRANSFERFUNCTIONELEMENT(nsSVGComponentTransferFunctionElement::)
 
   NS_DECL_NSIDOMSVGFEFUNCGELEMENT
 
   virtual int32_t GetChannel() { return 1; }
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGComponentTransferFunctionElement::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGComponentTransferFunctionElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
 
@@ -2186,17 +2186,17 @@ public:
   NS_FORWARD_NSIDOMSVGCOMPONENTTRANSFERFUNCTIONELEMENT(nsSVGComponentTransferFunctionElement::)
 
   NS_DECL_NSIDOMSVGFEFUNCBELEMENT
 
   virtual int32_t GetChannel() { return 2; }
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGComponentTransferFunctionElement::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGComponentTransferFunctionElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
 
@@ -2233,17 +2233,17 @@ public:
   NS_FORWARD_NSIDOMSVGCOMPONENTTRANSFERFUNCTIONELEMENT(nsSVGComponentTransferFunctionElement::)
 
   NS_DECL_NSIDOMSVGFEFUNCAELEMENT
 
   virtual int32_t GetChannel() { return 3; }
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGComponentTransferFunctionElement::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGComponentTransferFunctionElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
 
@@ -2291,17 +2291,17 @@ public:
   virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
 
   // Merge
   NS_DECL_NSIDOMSVGFEMERGEELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEMergeElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEMergeElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIContent
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
@@ -2333,17 +2333,17 @@ public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSIDOMSVGFEMERGENODEELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEMergeNodeElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEMergeNodeElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const;
 
   const nsSVGString* In1() { return &mStringAttributes[IN1]; }
   
@@ -2528,17 +2528,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Offset
   NS_DECL_NSIDOMSVGFEOFFSETELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEOffsetElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEOffsetElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   nsIntPoint GetOffset(const nsSVGFilterInstance& aInstance);
@@ -2727,17 +2727,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Flood
   NS_DECL_NSIDOMSVGFEFLOODELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEFloodElementBase::)
   
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEFloodElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -2877,17 +2877,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Tile
   NS_DECL_NSIDOMSVGFETILEELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFETileElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFETileElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual StringAttributesInfo GetStringInfo();
@@ -3076,17 +3076,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Turbulence
   NS_DECL_NSIDOMSVGFETURBULENCEELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFETurbulenceElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFETurbulenceElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual NumberAttributesInfo GetNumberInfo();
@@ -3625,17 +3625,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Morphology
   NS_DECL_NSIDOMSVGFEMORPHOLOGYELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEMorphologyElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEMorphologyElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   void GetRXY(int32_t *aRX, int32_t *aRY, const nsSVGFilterInstance& aInstance);
@@ -3937,17 +3937,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // Color Matrix
   NS_DECL_NSIDOMSVGFECONVOLVEMATRIXELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEConvolveMatrixElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEConvolveMatrixElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual bool OperatesOnPremultipledAlpha(int32_t) {
@@ -4431,17 +4431,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGFEDISTANTLIGHTELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEDistantLightElementBase::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEDistantLightElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -4536,17 +4536,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGFEPOINTLIGHTELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEPointLightElementBase::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEPointLightElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -4648,17 +4648,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGFESPOTLIGHTELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFESpotLightElementBase::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFESpotLightElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -4815,17 +4815,16 @@ public:
   // XXX shouldn't we have ComputeTargetBBox here, since the output can
   // extend beyond the bounds of the inputs thanks to the convolution kernel?
   virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
           nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
   virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
           const nsSVGFilterInstance& aInstance);
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFELightingElementBase::)
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFELightingElementBase::)
 
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
 protected:
   virtual void
   LightPixel(const float *N, const float *L,
              nscolor color, uint8_t *targetData) = 0;
 
@@ -5195,17 +5194,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // DiffuseLighting
   NS_DECL_NSIDOMSVGFEDIFFUSELIGHTINGELEMENT
 
   NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEDiffuseLightingElementBase::)
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEDiffuseLightingElementBase::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEDiffuseLightingElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -5326,17 +5325,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // DiffuseLighting
   NS_DECL_NSIDOMSVGFESPECULARLIGHTINGELEMENT
 
   NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFESpecularLightingElementBase::)
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFESpecularLightingElementBase::)
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFESpecularLightingElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsresult Filter(nsSVGFilterInstance* aInstance,
                           const nsTArray<const Image*>& aSources,
                           const Image* aTarget,
                           const nsIntRect& aDataRect);
   virtual bool AttributeAffectsRendering(
@@ -5827,17 +5826,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   // DisplacementMap
   NS_DECL_NSIDOMSVGFEDISPLACEMENTMAPELEMENT
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEDisplacementMapElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEDisplacementMapElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   virtual bool OperatesOnSRGB(nsSVGFilterInstance* aInstance,
--- a/content/svg/content/src/nsSVGFilters.h
+++ b/content/svg/content/src/nsSVGFilters.h
@@ -247,17 +247,17 @@ public:
           const nsSVGFilterInstance& aInstance);
 
   NS_DECL_NSIDOMSVGFEIMAGEELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEImageElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGFEImageElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify);
--- a/content/svg/content/src/nsSVGForeignObjectElement.h
+++ b/content/svg/content/src/nsSVGForeignObjectElement.h
@@ -27,17 +27,17 @@ protected:
 public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGFOREIGNOBJECTELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGForeignObjectElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGForeignObjectElementBase::)
 
   // nsSVGElement specializations:
   virtual gfxMatrix PrependLocalTransformsTo(const gfxMatrix &aMatrix,
                       TransformTypes aWhich = eAllTransforms) const;
   virtual bool HasValidDimensions() const;
 
   // nsIContent interface
--- a/content/svg/content/src/nsSVGGElement.cpp
+++ b/content/svg/content/src/nsSVGGElement.cpp
@@ -25,17 +25,17 @@ protected:
 public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGGELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGGElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGGElementBase::)
 
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGGradientElement.h
+++ b/content/svg/content/src/nsSVGGradientElement.h
@@ -89,17 +89,17 @@ public:
 
   // Linear Gradient
   NS_DECL_NSIDOMSVGLINEARGRADIENTELEMENT
 
   // The Gradient Element base class implements these
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLinearGradientElementBase::)
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGLinearGradientElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
 
@@ -133,17 +133,17 @@ public:
   // Gradient Element
   NS_FORWARD_NSIDOMSVGGRADIENTELEMENT(nsSVGRadialGradientElementBase::)
 
   // Radial Gradient
   NS_DECL_NSIDOMSVGRADIALGRADIENTELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGRadialGradientElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRadialGradientElementBase::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
--- a/content/svg/content/src/nsSVGImageElement.h
+++ b/content/svg/content/src/nsSVGImageElement.h
@@ -35,17 +35,17 @@ public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGIMAGEELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGImageElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::)
 
   // nsIContent interface
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify);
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
--- a/content/svg/content/src/nsSVGLineElement.cpp
+++ b/content/svg/content/src/nsSVGLineElement.cpp
@@ -25,17 +25,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGLINEELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGLineElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
 
   // nsSVGPathGeometryElement methods:
   virtual bool IsMarkable() { return true; }
   virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
--- a/content/svg/content/src/nsSVGMarkerElement.h
+++ b/content/svg/content/src/nsSVGMarkerElement.h
@@ -87,17 +87,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGMARKERELEMENT
   NS_DECL_NSIDOMSVGFITTOVIEWBOX
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
 
   virtual bool GetAttr(int32_t aNameSpaceID, nsIAtom* aName,
                          nsAString& aResult) const;
   virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
--- a/content/svg/content/src/nsSVGMaskElement.h
+++ b/content/svg/content/src/nsSVGMaskElement.h
@@ -32,17 +32,17 @@ protected:
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 
   // Mask Element
   NS_DECL_NSIDOMSVGMASKELEMENT
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
 
   // nsIContent interface
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
--- a/content/svg/content/src/nsSVGMetadataElement.cpp
+++ b/content/svg/content/src/nsSVGMetadataElement.cpp
@@ -20,17 +20,17 @@ protected:
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGMETADATAELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
--- a/content/svg/content/src/nsSVGMpathElement.h
+++ b/content/svg/content/src/nsSVGMpathElement.h
@@ -37,17 +37,17 @@ public:
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGMpathElement,
                                            nsSVGMpathElementBase)
 
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
 
   // Forward interface implementations to base class
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGMpathElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGMpathElementBase::)
 
   // nsIContent interface
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
   virtual void UnbindFromTree(bool aDeep, bool aNullParent);
--- a/content/svg/content/src/nsSVGPathElement.h
+++ b/content/svg/content/src/nsSVGPathElement.h
@@ -32,17 +32,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGPATHELEMENT
   NS_DECL_NSIDOMSVGANIMATEDPATHDATA
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGPathElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGPathElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
--- a/content/svg/content/src/nsSVGPatternElement.h
+++ b/content/svg/content/src/nsSVGPatternElement.h
@@ -48,17 +48,17 @@ public:
 
   // URI Reference
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // FitToViewbox
   NS_DECL_NSIDOMSVGFITTOVIEWBOX
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGPolygonElement.cpp
+++ b/content/svg/content/src/nsSVGPolygonElement.cpp
@@ -21,17 +21,17 @@ protected:
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGPOLYGONELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGPolygonElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGPolygonElementBase::)
 
   // nsSVGPathGeometryElement methods:
   virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
   virtual void ConstructPath(gfxContext *aCtx);
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
--- a/content/svg/content/src/nsSVGPolylineElement.cpp
+++ b/content/svg/content/src/nsSVGPolylineElement.cpp
@@ -19,17 +19,17 @@ protected:
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGPOLYLINEELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGPolylineElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGPolylineElementBase::)
 
   // nsIContent interface
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   virtual nsXPCClassInfo* GetClassInfo();
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
 
--- a/content/svg/content/src/nsSVGRectElement.cpp
+++ b/content/svg/content/src/nsSVGRectElement.cpp
@@ -25,17 +25,17 @@ protected:
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGRECTELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGRectElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRectElementBase::)
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx);
 
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -600,24 +600,24 @@ nsSVGSVGElement::CreateSVGTransformFromM
 
 /* nsIDOMElement getElementById (in DOMString elementId); */
 NS_IMETHODIMP
 nsSVGSVGElement::GetElementById(const nsAString & elementId, nsIDOMElement **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nullptr;
 
-  nsresult rv = NS_OK;
   nsAutoString selector(NS_LITERAL_STRING("#"));
   nsStyleUtil::AppendEscapedCSSIdent(PromiseFlatString(elementId), selector);
-  nsIContent* element = QuerySelector(selector, &rv);
-  if (NS_SUCCEEDED(rv) && element) {
+  ErrorResult rv;
+  nsIContent* element = QuerySelector(selector, rv);
+  if (!rv.Failed() && element) {
     return CallQueryInterface(element, _retval);
   }
-  return rv;
+  return rv.ErrorCode();
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGFitToViewBox methods
 
 /* readonly attribute nsIDOMSVGAnimatedRect viewBox; */
 NS_IMETHODIMP
 nsSVGSVGElement::GetViewBox(nsIDOMSVGAnimatedRect * *aViewBox)
--- a/content/svg/content/src/nsSVGSVGElement.h
+++ b/content/svg/content/src/nsSVGSVGElement.h
@@ -126,17 +126,17 @@ public:
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGSVGElement, nsSVGSVGElementBase)
   NS_DECL_NSIDOMSVGSVGELEMENT
   NS_DECL_NSIDOMSVGFITTOVIEWBOX
   NS_DECL_NSIDOMSVGLOCATABLE
   NS_DECL_NSIDOMSVGZOOMANDPAN
   
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGSVGElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSVGElementBase::)
 
   /**
    * For use by zoom controls to allow currentScale, currentTranslate.x and
    * currentTranslate.y to be set by a single operation that dispatches a
    * single SVGZoom event (instead of one SVGZoom and two SVGScroll events).
    */
   NS_IMETHOD SetCurrentScaleTranslate(float s, float x, float y);
--- a/content/svg/content/src/nsSVGScriptElement.cpp
+++ b/content/svg/content/src/nsSVGScriptElement.cpp
@@ -40,17 +40,17 @@ public:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGSCRIPTELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGScriptElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGScriptElementBase::)
 
   // nsIScriptElement
   virtual void GetScriptType(nsAString& type);
   virtual void GetScriptText(nsAString& text);
   virtual void GetScriptCharset(nsAString& charset);
   virtual void FreezeUriAsyncDefer();
   virtual CORSMode GetCORSMode() const;
--- a/content/svg/content/src/nsSVGSetElement.cpp
+++ b/content/svg/content/src/nsSVGSetElement.cpp
@@ -20,17 +20,17 @@ protected:
   nsSMILSetAnimationFunction mAnimationFunction;
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGSETELEMENT
 
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGSetElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSetElementBase::)
   NS_FORWARD_NSIDOMSVGANIMATIONELEMENT(nsSVGSetElementBase::)
   
   // nsIDOMNode
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsISMILAnimationElement
   virtual nsSMILAnimationFunction& AnimationFunction();
--- a/content/svg/content/src/nsSVGStopElement.cpp
+++ b/content/svg/content/src/nsSVGStopElement.cpp
@@ -26,17 +26,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGSTOPELEMENT
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGStopElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGStopElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGStyleElement.cpp
+++ b/content/svg/content/src/nsSVGStyleElement.cpp
@@ -30,17 +30,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGSTYLEELEMENT
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGStyleElement,
                                            nsSVGStyleElementBase)
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGStyleElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGStyleElementBase::)
 
   // nsIContent
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true);
--- a/content/svg/content/src/nsSVGSwitchElement.h
+++ b/content/svg/content/src/nsSVGSwitchElement.h
@@ -31,17 +31,17 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGSwitchElement,
                                            nsSVGSwitchElementBase)
   NS_DECL_NSIDOMSVGSWITCHELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGSwitchElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSwitchElementBase::)
 
   // nsINode
   virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
                                  bool aNotify);
   virtual void RemoveChildAt(uint32_t aIndex, bool aNotify);
 
   // nsIContent
--- a/content/svg/content/src/nsSVGSymbolElement.cpp
+++ b/content/svg/content/src/nsSVGSymbolElement.cpp
@@ -30,17 +30,17 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGSYMBOLELEMENT
   NS_DECL_NSIDOMSVGFITTOVIEWBOX
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGTSpanElement.cpp
+++ b/content/svg/content/src/nsSVGTSpanElement.cpp
@@ -27,17 +27,17 @@ public:
   // interfaces:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGTSPANELEMENT
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGTSpanElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTSpanElementBase::)
   NS_FORWARD_NSIDOMSVGTEXTCONTENTELEMENT(nsSVGTSpanElementBase::)
   NS_FORWARD_NSIDOMSVGTEXTPOSITIONINGELEMENT(nsSVGTSpanElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/svg/content/src/nsSVGTextElement.cpp
+++ b/content/svg/content/src/nsSVGTextElement.cpp
@@ -52,17 +52,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGTEXTELEMENT
   NS_DECL_NSIDOMSVGTEXTPOSITIONINGELEMENT
   NS_DECL_NSIDOMSVGTEXTCONTENTELEMENT
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGTextElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTextElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
--- a/content/svg/content/src/nsSVGTextPathElement.h
+++ b/content/svg/content/src/nsSVGTextPathElement.h
@@ -41,17 +41,17 @@ public:
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGTEXTPATHELEMENT
   NS_DECL_NSIDOMSVGURIREFERENCE
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGTextPathElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTextPathElementBase::)
   NS_FORWARD_NSIDOMSVGTEXTCONTENTELEMENT(nsSVGTextPathElementBase::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
--- a/content/svg/content/src/nsSVGTitleElement.cpp
+++ b/content/svg/content/src/nsSVGTitleElement.cpp
@@ -22,17 +22,17 @@ protected:
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGTITLEELEMENT
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGTitleElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTitleElementBase::)
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
--- a/content/svg/content/src/nsSVGUnknownElement.cpp
+++ b/content/svg/content/src/nsSVGUnknownElement.cpp
@@ -19,17 +19,17 @@ protected:
   nsSVGUnknownElement(already_AddRefed<nsINodeInfo> aNodeInfo);
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGUnknownElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGUnknownElementBase::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 };
--- a/content/svg/content/src/nsSVGUseElement.h
+++ b/content/svg/content/src/nsSVGUseElement.h
@@ -58,17 +58,17 @@ public:
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
   NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
 
   // xxx I wish we could use virtual inheritance
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGUseElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGUseElementBase::)
 
   // for nsSVGUseFrame's nsIAnonymousContentCreator implementation.
   nsIContent* CreateAnonymousContent();
   nsIContent* GetAnonymousContent() const { return mClone; }
   void DestroyAnonymousContent();
 
   // nsSVGElement specializations:
--- a/content/svg/content/src/nsSVGViewElement.h
+++ b/content/svg/content/src/nsSVGViewElement.h
@@ -39,17 +39,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMSVGVIEWELEMENT
   NS_DECL_NSIDOMSVGFITTOVIEWBOX
   NS_DECL_NSIDOMSVGZOOMANDPAN
 
   // xxx If xpcom allowed virtual inheritance we wouldn't need to
   // forward here :-(
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
-  NS_FORWARD_NSIDOMELEMENT(nsSVGViewElementBase::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGViewElementBase::)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 private:
--- a/content/xml/content/src/nsXMLElement.h
+++ b/content/xml/content/src/nsXMLElement.h
@@ -20,17 +20,17 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericElement::)
+  NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsINode interface methods
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 
--- a/content/xtf/src/nsXTFElementWrapper.cpp
+++ b/content/xtf/src/nsXTFElementWrapper.cpp
@@ -27,16 +27,18 @@
 #include "nsUnicharUtils.h"
 #include "nsEventDispatcher.h"
 #include "nsIProgrammingLanguage.h"
 #include "nsIXPConnect.h"
 #include "nsXTFWeakTearoff.h"
 #include "mozAutoDocUpdate.h"
 #include "nsFocusManager.h"
 
+using namespace mozilla;
+
 nsXTFElementWrapper::nsXTFElementWrapper(already_AddRefed<nsINodeInfo> aNodeInfo,
                                          nsIXTFElement* aXTFElement)
     : nsXTFElementWrapperBase(aNodeInfo),
       mXTFElement(aXTFElement),
       mNotificationMask(0),
       mIntrinsicState(0),
       mTmpAttrName(nsGkAtoms::_asterix) // XXX this is a hack, but names
                                             // have to have a value
@@ -587,77 +589,75 @@ nsXTFElementWrapper::Clone(nsINodeInfo *
   // XXX CloneState should take |const nIDOMElement*|
   wrapper->CloneState(const_cast<nsXTFElementWrapper*>(this));
   return rv;
 }
 
 //----------------------------------------------------------------------
 // nsIDOMElement methods:
 
-NS_IMETHODIMP
-nsXTFElementWrapper::GetAttribute(const nsAString& aName, nsAString& aReturn)
+void
+nsXTFElementWrapper::GetAttribute(const nsAString& aName, nsString& aReturn)
 {
   const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
   if (name) {
     GetAttr(name->NamespaceID(), name->LocalName(), aReturn);
-    return NS_OK;
+    return;
   }
 
   // Maybe this attribute is handled by our inner element:
   if (mAttributeHandler) {
     nsresult rv = nsContentUtils::CheckQName(aName, false);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_FAILED(rv)) {
+      return; // XXX
+    }
     nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
     if (HandledByInner(nameAtom)) {
       GetAttr(kNameSpaceID_None, nameAtom, aReturn);
-      return NS_OK;
+      return;
     }
   }
   
   SetDOMStringToNull(aReturn);
-  return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXTFElementWrapper::RemoveAttribute(const nsAString& aName)
+void
+nsXTFElementWrapper::RemoveAttribute(const nsAString& aName,
+                                     ErrorResult& aError)
 {
   const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
 
   if (name) {
     nsAttrName tmp(*name);
-    return UnsetAttr(name->NamespaceID(), name->LocalName(), true);
+    aError = UnsetAttr(name->NamespaceID(), name->LocalName(), true);
+    return;
   }
 
   // Maybe this attribute is handled by our inner element:
   if (mAttributeHandler) {
     nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
-    return UnsetAttr(kNameSpaceID_None, nameAtom, true);
+    aError = UnsetAttr(kNameSpaceID_None, nameAtom, true);
   }
-
-  return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXTFElementWrapper::HasAttribute(const nsAString& aName, bool* aReturn)
+bool
+nsXTFElementWrapper::HasAttribute(const nsAString& aName) const
 {
   const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName);
   if (name) {
-    *aReturn = true;
-    return NS_OK;
+    return true;
   }
   
   // Maybe this attribute is handled by our inner element:
   if (mAttributeHandler) {
     nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
-    *aReturn = HasAttr(kNameSpaceID_None, nameAtom);
-    return NS_OK;
+    return HasAttr(kNameSpaceID_None, nameAtom);
   }
 
-  *aReturn = false;
-  return NS_OK;
+  return false;
 }
 
 
 //----------------------------------------------------------------------
 // nsIClassInfo implementation
 
 /* void getInterfaces (out uint32_t count, [array, size_is (count), retval] out nsIIDPtr array); */
 NS_IMETHODIMP 
--- a/content/xtf/src/nsXTFElementWrapper.h
+++ b/content/xtf/src/nsXTFElementWrapper.h
@@ -82,21 +82,25 @@ public:
   virtual void DoneAddingChildren(bool aHaveNotified);
 
   virtual nsIAtom *GetClassAttributeName() const;
   virtual const nsAttrValue* DoGetClasses() const;
 
   virtual void PerformAccesskey(bool aKeyCausesActivation,
                                 bool aIsTrustedEvent);
 
-  // nsIDOMElement specializations:
-  NS_IMETHOD GetAttribute(const nsAString& aName,
-                          nsAString& aReturn);
-  NS_IMETHOD RemoveAttribute(const nsAString& aName);
-  NS_IMETHOD HasAttribute(const nsAString& aName, bool* aReturn);
+  // nsGenericElement specializations:
+  using nsXMLElement::GetAttribute;
+  using nsXMLElement::RemoveAttribute;
+  using nsXMLElement::HasAttribute;
+  virtual void GetAttribute(const nsAString& aName,
+                            nsString& aReturn) MOZ_OVERRIDE;
+  virtual void RemoveAttribute(const nsAString& aName,
+                               mozilla::ErrorResult& aError) MOZ_OVERRIDE;
+  virtual bool HasAttribute(const nsAString& aName) const MOZ_OVERRIDE;
   
   // nsIClassInfo interface
   NS_DECL_NSICLASSINFO
 
   // nsIXPCScriptable interface
   NS_FORWARD_SAFE_NSIXPCSCRIPTABLE(GetBaseXPCClassInfo())
 
   // nsXPCClassInfo
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -96,16 +96,17 @@
 #include "nsReadableUtils.h"
 #include "nsIFrame.h"
 #include "nsNodeInfoManager.h"
 #include "nsXBLBinding.h"
 #include "nsEventDispatcher.h"
 #include "mozAutoDocUpdate.h"
 #include "nsIDOMXULCommandEvent.h"
 #include "nsCCUncollectableMarker.h"
+#include "nsICSSDeclaration.h"
 
 namespace css = mozilla::css;
 
 //----------------------------------------------------------------------
 
 static NS_DEFINE_CID(kXULPopupListenerCID,        NS_XULPOPUPLISTENER_CID);
 
 //----------------------------------------------------------------------
--- a/content/xul/content/src/nsXULElement.h
+++ b/content/xul/content/src/nsXULElement.h
@@ -389,17 +389,17 @@ public:
     void SetTemplateGenerated() { SetFlags(XUL_ELEMENT_TEMPLATE_GENERATED); }
     void ClearTemplateGenerated() { UnsetFlags(XUL_ELEMENT_TEMPLATE_GENERATED); }
     bool GetTemplateGenerated() { return HasFlag(XUL_ELEMENT_TEMPLATE_GENERATED); }
 
     // nsIDOMNode
     NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
     // nsIDOMElement
-    NS_FORWARD_NSIDOMELEMENT(nsGenericElement::)
+    NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
     // nsIDOMXULElement
     NS_DECL_NSIDOMXULELEMENT
 
     virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
     virtual nsEventStates IntrinsicState() const;
 
     nsresult GetFrameLoader(nsIFrameLoader** aFrameLoader);
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -8100,48 +8100,16 @@ IDBEventTargetSH::PreCreate(nsISupports 
   IDBWrapperCache *target = IDBWrapperCache::FromSupports(aNativeObj);
   JSObject *parent = target->GetParentObject();
   *aParentObj = parent ? parent : aGlobalObj;
   return NS_OK;
 }
 
 // Element helper
 
-static bool
-GetBindingURL(Element *aElement, nsIDocument *aDocument,
-              mozilla::css::URLValue **aResult)
-{
-  // If we have a frame the frame has already loaded the binding.  And
-  // otherwise, don't do anything else here unless we're dealing with
-  // XUL or an HTML element that may have a plugin-related overlay
-  // (i.e. object, embed, or applet).
-  bool isXULorPluginElement = (aElement->IsXUL() ||
-                               aElement->IsHTML(nsGkAtoms::object) ||
-                               aElement->IsHTML(nsGkAtoms::embed) ||
-                               aElement->IsHTML(nsGkAtoms::applet));
-  nsIPresShell *shell = aDocument->GetShell();
-  if (!shell || aElement->GetPrimaryFrame() || !isXULorPluginElement) {
-    *aResult = nullptr;
-
-    return true;
-  }
-
-  // Get the computed -moz-binding directly from the style context
-  nsPresContext *pctx = shell->GetPresContext();
-  NS_ENSURE_TRUE(pctx, false);
-
-  nsRefPtr<nsStyleContext> sc = pctx->StyleSet()->ResolveStyleFor(aElement,
-                                                                  nullptr);
-  NS_ENSURE_TRUE(sc, false);
-
-  *aResult = sc->GetStyleDisplay()->mBinding;
-
-  return true;
-}
-
 NS_IMETHODIMP
 nsElementSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj)
 {
   nsresult rv = nsNodeSH::PreCreate(nativeObj, cx, globalObj, parentObj);
   NS_ENSURE_SUCCESS(rv, rv);
 
   Element *element = static_cast<Element*>(nativeObj);
@@ -8167,17 +8135,17 @@ nsElementSH::PreCreate(nsISupports *nati
 
   if (element->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) &&
       doc->BindingManager()->GetBinding(element)) {
     // Don't allow slim wrappers.
     return rv == NS_SUCCESS_ALLOW_SLIM_WRAPPERS ? NS_OK : rv;
   }
 
   mozilla::css::URLValue *bindingURL;
-  bool ok = GetBindingURL(element, doc, &bindingURL);
+  bool ok = element->GetBindingURL(doc, &bindingURL);
   NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
 
   // Only allow slim wrappers if there's no binding.
   if (!bindingURL) {
     return rv;
   }
 
   element->SetFlags(NODE_ATTACH_BINDING_ON_POSTCREATE);
@@ -8232,17 +8200,17 @@ nsElementSH::PostCreate(nsIXPConnectWrap
     return NS_OK;
   }
 
   element->UnsetFlags(NODE_ATTACH_BINDING_ON_POSTCREATE);
 
   // Make sure the style context goes away _before_ we load the binding
   // since that can destroy the relevant presshell.
   mozilla::css::URLValue *bindingURL;
-  bool ok = GetBindingURL(element, doc, &bindingURL);
+  bool ok = element->GetBindingURL(doc, &bindingURL);
   NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
 
   if (!bindingURL) {
     // No binding, nothing left to do here.
     return NS_OK;
   }
 
   nsCOMPtr<nsIURI> uri = bindingURL->GetURI();
@@ -8542,17 +8510,17 @@ nsNamedNodeMapSH::GetItemAt(nsISupports 
 
 nsISupports*
 nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
                                nsWrapperCache **aCache, nsresult *aResult)
 {
   nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
 
   nsINode *attr;
-  *aCache = attr = map->GetNamedItem(aName, aResult);
+  *aCache = attr = map->GetNamedItem(aName);
   return attr;
 }
 
 // Can't be static so GetterShim will compile
 nsresult
 DocumentURIObjectGetter(JSContext *cx, JSObject *obj, jsval *vp)
 {
   // This function duplicates some of the logic in XPC_WN_HelperGetProperty
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -503,20 +503,20 @@ WrapNewBindingObject(JSContext* cx, JSOb
   //     does the right thing, but I don't see a way to do it.  :(
   // 2)  If our class doesn't claim we're nsISupports we better be
   //     reinterpret_castable to nsWrapperCache.
   const DOMClass* clasp = nullptr;
   DOMObjectSlot slot = GetDOMClass(obj, clasp);
   MOZ_ASSERT(slot != eNonDOMObject, "Totally unexpected object here");
   MOZ_ASSERT(clasp, "What happened here?");
   MOZ_ASSERT_IF(clasp->mDOMObjectIsISupports, IsISupports<T>::Value);
-  MOZ_ASSERT_IF(!clasp->mDOMObjectIsISupports,
-                reinterpret_cast<uintptr_t>(
-                  static_cast<nsWrapperCache*>(
-                    reinterpret_cast<T*>(1))) == 1);
+//  MOZ_ASSERT_IF(!clasp->mDOMObjectIsISupports,
+//                reinterpret_cast<uintptr_t>(
+//                  static_cast<nsWrapperCache*>(
+//                    reinterpret_cast<T*>(1))) == 1);
 #endif
 
   // When called via XrayWrapper, we end up here while running in the
   // chrome compartment.  But the obj we have would be created in
   // whatever the content compartment is.  So at this point we need to
   // make sure it's correctly wrapped for the compartment of |scope|.
   // cx should already be in the compartment of |scope| here.
   MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx));
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -52,17 +52,16 @@ using mozilla::DefaultXDisplay;
 #include "nsIDOMHTMLAppletElement.h"
 #include "nsAttrName.h"
 #include "nsIFocusManager.h"
 #include "nsFocusManager.h"
 #include "nsIDOMDragEvent.h"
 #include "nsIScrollableFrame.h"
 #include "nsIDocShell.h"
 #include "ImageContainer.h"
-#include "nsIDOMHTMLCollection.h"
 
 #include "nsContentCID.h"
 #include "nsWidgetsCID.h"
 static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID);
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 #ifdef XP_WIN
 #include <wtypes.h>
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -1,51 +1,186 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
- * http://www.w3.org/TR/2012/WD-dom-20120105/
+ * http://dom.spec.whatwg.org/#element and
+ * http://domparsing.spec.whatwg.org/ and
+ * http://dev.w3.org/csswg/cssom-view/ and
+ * http://www.w3.org/TR/selectors-api/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
+interface Attr;
+interface NamedNodeMap;
+
 interface Element : Node {
+/*
+  We haven't moved these from Node to Element like the spec wants.
+
+  [Throws]
   readonly attribute DOMString? namespaceURI;
   readonly attribute DOMString? prefix;
   readonly attribute DOMString localName;
+*/
   readonly attribute DOMString tagName;
 
            attribute DOMString id;
+/*
+  FIXME Bug 810677 Move className from HTMLElement to Element
            attribute DOMString className;
+*/
   readonly attribute DOMTokenList classList;
 
-  readonly attribute Attr[] attributes;
+  //readonly attribute Attr[] attributes;
   DOMString? getAttribute(DOMString name);
   DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
+  [Throws]
   void setAttribute(DOMString name, DOMString value);
+  [Throws]
   void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
+  [Throws]
   void removeAttribute(DOMString name);
+  [Throws]
   void removeAttributeNS(DOMString? namespace, DOMString localName);
   boolean hasAttribute(DOMString name);
   boolean hasAttributeNS(DOMString? namespace, DOMString localName);
 
-  NodeList getElementsByTagName(DOMString qualifiedName);
-  NodeList getElementsByTagNameNS(DOMString? namespace, DOMString localName);
-  NodeList getElementsByClassName(DOMString classNames);
+  HTMLCollection getElementsByTagName(DOMString localName);
+  [Throws]
+  HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
+  HTMLCollection getElementsByClassName(DOMString classNames);
 
   readonly attribute HTMLCollection children;
   readonly attribute Element? firstElementChild;
   readonly attribute Element? lastElementChild;
   readonly attribute Element? previousElementSibling;
   readonly attribute Element? nextElementSibling;
   readonly attribute unsigned long childElementCount;
 
   // NEW
+/*
+  FIXME We haven't implemented these yet.
+
   void prepend((Node or DOMString)... nodes);
   void append((Node or DOMString)... nodes);
   void before((Node or DOMString)... nodes);
   void after((Node or DOMString)... nodes);
   void replace((Node or DOMString)... nodes);
   void remove();
+*/
+
+  // Mozilla specific stuff
+
+  // Selectors API
+  /**
+   * Returns whether this element would be selected by the given selector
+   * string.
+   *
+   * See <http://dev.w3.org/2006/webapi/selectors-api2/#matchesselector>
+   */
+  [Throws]
+  boolean mozMatchesSelector(DOMString selector);
+
+  // Proprietary extensions
+  /**
+   * Set this during a mousedown event to grab and retarget all mouse events
+   * to this element until the mouse button is released or releaseCapture is
+   * called. If retargetToElement is true, then all events are targetted at
+   * this element. If false, events can also fire at descendants of this
+   * element.
+   * 
+   */
+  void setCapture(optional boolean retargetToElement = false);
+
+  /**
+   * If this element has captured the mouse, release the capture. If another
+   * element has captured the mouse, this method has no effect.
+   */
+  void releaseCapture();
+
+  // Mozilla extensions
+  /**
+   * Requests that this element be made the full-screen element, as per the DOM
+   * full-screen api.
+   *
+   * @see <https://wiki.mozilla.org/index.php?title=Gecko:FullScreenAPI>
+   */
+  void mozRequestFullScreen();
+
+  /**
+   * Requests that this element be made the pointer-locked element, as per the DOM
+   * pointer lock api.
+   *
+   * @see <http://dvcs.w3.org/hg/pointerlock/raw-file/default/index.html>
+   */
+  void mozRequestPointerLock();
+
+  // Obsolete methods.
+  Attr getAttributeNode(DOMString name);
+  [Throws]
+  Attr setAttributeNode(Attr newAttr);
+  [Throws]
+  Attr removeAttributeNode(Attr oldAttr);
+  [Throws]
+  Attr getAttributeNodeNS(DOMString namespaceURI, DOMString localName);
+  [Throws]
+  Attr setAttributeNodeNS(Attr newAttr);
+/*
 };
+
+// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface
+partial interface Element {
+*/
+  [Throws]
+  ClientRectList getClientRects();
+  ClientRect getBoundingClientRect();
+
+  // scrolling
+  void scrollIntoView(optional boolean top = true);
+           attribute long scrollTop;   // scroll on setting
+           attribute long scrollLeft;  // scroll on setting
+  readonly attribute long scrollWidth;
+  readonly attribute long scrollHeight;
+
+  readonly attribute long clientTop;
+  readonly attribute long clientLeft;
+  readonly attribute long clientWidth;
+  readonly attribute long clientHeight;
+
+  // Mozilla specific stuff
+  /* The maximum offset that the element can be scrolled to
+     (i.e., the value that scrollLeft/scrollTop would be clamped to if they were
+     set to arbitrarily large values. */
+  readonly attribute long scrollTopMax;
+  readonly attribute long scrollLeftMax;
+/*
+};
+
+enum insertAdjacentHTMLPosition {
+  "beforebegin",
+  "afterbegin",
+  "beforeend",
+  "afterend"
+};
+
+// http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
+partial interface Element {
+  [Throws]
+  attribute DOMString innerHTML;
+  [Throws]
+  attribute DOMString outerHTML;
+  [Throws]
+  void insertAdjacentHTML(insertAdjacentHTMLPosition position, DOMString text);
+};
+
+// http://www.w3.org/TR/selectors-api/#interface-definitions
+partial interface Element {
+*/
+  [Throws]
+  Element?  querySelector(DOMString selectors);
+  [Throws]
+  NodeList  querySelectorAll(DOMString selectors);
+};
--- a/js/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/xpconnect/src/dom_quickstubs.qsconf
@@ -650,68 +650,68 @@ customMethodCalls = {
                 'self->GetElementsByName(arg0);',
         'canFail': False
         },
     'nsIDOMStorage_Clear': {
         'code': nsIDOMStorage_Clear_customMethodCallCode
         },
     'nsIDOMElement_GetScrollTop': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetScrollTop();',
+        'code': '    int32_t result = self->ScrollTop();',
         'canFail': False
         },
     'nsIDOMElement_SetScrollTop': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_GetScrollLeft': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetScrollLeft();',
+        'code': '    int32_t result = self->ScrollLeft();',
         'canFail': False
         },
     'nsIDOMElement_SetScrollLeft': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_GetScrollHeight': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetScrollHeight();',
+        'code': '    int32_t result = self->ScrollHeight();',
         'canFail': False
         },
     'nsIDOMElement_GetScrollWidth': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetScrollWidth();',
+        'code': '    int32_t result = self->ScrollWidth();',
         'canFail': False
         },
     'nsIDOMElement_GetClientTop': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetClientTop();',
+        'code': '    int32_t result = self->ClientTop();',
         'canFail': False
         },
     'nsIDOMElement_SetClientTop': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_GetClientLeft': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetClientLeft();',
+        'code': '    int32_t result = self->ClientLeft();',
         'canFail': False
         },
     'nsIDOMElement_SetClientLeft': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_GetClientHeight': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetClientHeight();',
+        'code': '    int32_t result = self->ClientHeight();',
         'canFail': False
         },
     'nsIDOMElement_GetClientWidth': {
         'thisType': 'nsGenericElement',
-        'code': '    int32_t result = self->GetClientWidth();',
+        'code': '    int32_t result = self->ClientWidth();',
         'canFail': False
         },
     'nsIDOMElement_GetFirstElementChild': {
         'thisType': 'nsGenericElement',
         'code': '    nsIContent *result = self->GetFirstElementChild();',
         'canFail': False
         },
     'nsIDOMElement_GetLastElementChild': {
@@ -726,37 +726,45 @@ customMethodCalls = {
         },
     'nsIDOMElement_GetNextElementSibling': {
         'thisType': 'nsGenericElement',
         'code': '    nsIContent *result = self->GetNextElementSibling();',
         'canFail': False
         },
     'nsIDOMElement_GetClassList': {
         'thisType': 'nsGenericElement',
-        'code': '    nsDOMTokenList *result = self->GetClassList(&rv);'
+        'code': '    nsDOMTokenList *result = self->ClassList();',
+        'canFail': False
         },
     'nsIDOMElement_SetCapture': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_ReleaseCapture': {
         'thisType': 'nsGenericElement',
         'canFail': False
         },
     'nsIDOMElement_MozMatchesSelector': {
         'thisType': 'nsGenericElement',
-        'code': '    bool result = self->MozMatchesSelector(arg0, &rv);',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    bool result = self->MozMatchesSelector(arg0, error);\n'
+                '    rv = error.ErrorCode();'
         },
     'nsIDOMNodeSelector_QuerySelector': {
         'thisType': 'nsINode',
-        'code': '    nsIContent* result = '
-                'self->QuerySelector(arg0, &rv);'
+        'code': '    mozilla::ErrorResult error;\n'
+                '    nsIContent* result = '
+                'self->QuerySelector(arg0, error);\n'
+                '    rv = error.ErrorCode();'
         },
     'nsIDOMNodeSelector_QuerySelectorAll': {
-        'thisType': 'nsINode'
+        'thisType': 'nsINode',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    nsCOMPtr<nsINodeList> result = self->QuerySelectorAll(arg0, error);\n'
+                '    rv = error.ErrorCode();'
         },
     'nsIDOMNode_Normalize': {
         'thisType': 'nsINode',
         'canFail': False
         },
     'nsIDOMNode_GetBaseURI': {
         'thisType': 'nsINode',
         'canFail': False
@@ -952,16 +960,88 @@ customMethodCalls = {
     'nsIDOMElement_GetOnmouseleave' : {
         'thisType' : 'nsGenericElement',
         'unwrapThisFailureFatal' : False
         },
     'nsIDOMElement_SetOnmouseleave' : {
         'thisType' : 'nsGenericElement',
         'unwrapThisFailureFatal' : False
         },
+    'nsIDOMElement_RemoveAttributeNS' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    self->RemoveAttributeNS(arg0, arg1, error);\n'
+                '    rv = error.ErrorCode();'
+        },
+    'nsIDOMElement_RemoveAttribute' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    self->RemoveAttribute(arg0, error);\n'
+                '    rv = error.ErrorCode();'
+        },
+    'nsIDOMElement_GetAttribute' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    nsString result;\n'
+                '    self->GetAttribute(arg0, result);',
+        'canFail': False
+        },
+    'nsIDOMElement_GetAttributeNS' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    nsString result;\n'
+                '    self->GetAttributeNS(arg0, arg1, result);',
+        'canFail': False
+        },
+    'nsIDOMElement_SetAttribute' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    self->SetAttribute(arg0, arg1, error);\n'
+                '    rv = error.ErrorCode();'
+        },
+    'nsIDOMElement_SetAttributeNS' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    self->SetAttributeNS(arg0, arg1, arg2, error);\n'
+                '    rv = error.ErrorCode();'
+        },
+    'nsIDOMElement_HasAttribute' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    bool result = self->HasAttribute(arg0);',
+        'canFail': False
+        },
+    'nsIDOMElement_HasAttributeNS' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    bool result = self->HasAttributeNS(arg0, arg1);',
+        'canFail': False
+        },
+    'nsIDOMElement_GetElementsByTagName' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    nsCOMPtr<nsIHTMLCollection> result = self->GetElementsByTagName(arg0);',
+        'canFail': False
+        },
+    'nsIDOMElement_GetClientRects' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    mozilla::ErrorResult error;\n'
+                '    nsRefPtr<nsClientRectList> result = self->GetClientRects(error);\n'
+                '    rv = error.ErrorCode();'
+        },
+    'nsIDOMElement_GetBoundingClientRect' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    nsRefPtr<nsClientRect> result = self->GetBoundingClientRect();',
+        'canFail': False
+        },
+    'nsIDOMElement_GetChildElementCount' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    uint32_t result = self->ChildElementCount();',
+        'canFail': False
+        },
+    'nsIDOMElement_GetChildElements' : {
+        'thisType' : 'nsGenericElement',
+        'code': '    nsIHTMLCollection* result = self->Children();',
+        'canFail': False
+        },
     'nsIDOMWindow_GetOnmouseenter' : {
         'thisType' : 'nsIDOMWindow',
         'unwrapThisFailureFatal' : False
         },
     'nsIDOMWindow_SetOnmouseenter' : {
         'thisType' : 'nsIDOMWindow',
         'unwrapThisFailureFatal' : False
         },