Back out fixes for bug 560462 to fix orange.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 11 May 2010 19:20:03 +0200
changeset 42156 d67ddb92a98c53fd5d41515030ce2ff799e62334
parent 42155 c2dac370c16dc545a1cd262aecd39b1b7089eec9
child 42157 d4dbc269d83baf806e7c8bb0aa4ce65ce7acf966
child 46846 22343803fc8448a8e06d3ccdc1602315e4e99bb1
push id13205
push userpvanderbeken@mozilla.com
push dateTue, 11 May 2010 17:59:39 +0000
treeherdermozilla-central@d67ddb92a98c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs560462
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Back out fixes for bug 560462 to fix orange.
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
content/xul/document/src/nsXULDocument.cpp
content/xul/document/src/nsXULDocument.h
dom/base/nsDOMClassInfoID.h
js/src/xpconnect/src/Makefile.in
js/src/xpconnect/src/dom_quickstubs.qsconf
js/src/xpconnect/src/nsDOMQS.h
js/src/xpconnect/src/qsgen.py
js/src/xpconnect/src/xpcquickstubs.h
layout/style/nsStyleSet.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -187,18 +187,16 @@ static NS_DEFINE_CID(kDOMEventGroupCID, 
 #ifdef MOZ_SMIL
 #include "nsSMILAnimationController.h"
 #include "imgIContainer.h"
 #include "nsSVGUtils.h"
 #endif // MOZ_SMIL
 
 // FOR CSP (autogenerated by xpidl)
 #include "nsIContentSecurityPolicy.h"
-#include "nsHTMLStyleSheet.h"
-#include "nsHTMLCSSStyleSheet.h"
 
 #include "mozilla/dom/Link.h"
 using namespace mozilla::dom;
 
 
 /* Keeps track of whether or not CSP is enabled */
 static PRBool gCSPEnabled = PR_TRUE;
 
@@ -3911,57 +3909,36 @@ nsDocument::GetElementByIdInternal(nsIAt
     // entry again, adding if necessary (the adding may be necessary in case
     // the flush actually deleted entries).
     entry = mIdentifierMap.PutEntry(aID);
   }
   
   return entry;
 }
 
-Element*
-nsDocument::GetElementById(const nsAString& aElementId, nsresult *aResult)
-{
+NS_IMETHODIMP
+nsDocument::GetElementById(const nsAString& aElementId,
+                           nsIDOMElement** aReturn)
+{
+  NS_ENSURE_ARG_POINTER(aReturn);
+  *aReturn = nsnull;
+
   nsCOMPtr<nsIAtom> idAtom(do_GetAtom(aElementId));
-  if (!idAtom) {
-    *aResult = NS_ERROR_OUT_OF_MEMORY;
-
-    return nsnull;
-  }
-
-  if (!CheckGetElementByIdArg(idAtom)) {
-    *aResult = NS_OK;
-
-    return nsnull;
-  }
+  NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
+  if (!CheckGetElementByIdArg(idAtom))
+    return NS_OK;
 
   nsIdentifierMapEntry *entry = GetElementByIdInternal(idAtom);
-  if (!entry) {
-    *aResult = NS_ERROR_OUT_OF_MEMORY;
-
-    return nsnull;
-  }
-
-  *aResult = NS_OK;
-
-  return entry->GetIdElement();
-}
-
-NS_IMETHODIMP
-nsDocument::GetElementById(const nsAString& aId, nsIDOMElement** aReturn)
-{
-  nsresult rv;
-  Element *content = GetElementById(aId, &rv);
-  if (content) {
-    rv = CallQueryInterface(content, aReturn);
-  }
-  else {
-    *aReturn = nsnull;
-  }
-
-  return rv;
+  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
+
+  Element *e = entry->GetIdElement();
+  if (!e)
+    return NS_OK;
+
+  return CallQueryInterface(e, aReturn);
 }
 
 nsIContent*
 nsDocument::AddIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
                                 void* aData)
 {
   if (!CheckGetElementByIdArg(aID))
     return nsnull;
@@ -4403,75 +4380,53 @@ nsDocument::CreateEntityReference(const 
                                   nsIDOMEntityReference** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
 
   *aReturn = nsnull;
   return NS_OK;
 }
 
-already_AddRefed<nsContentList>
-nsDocument::GetElementsByTagName(const nsAString& aTagname)
-{
-  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aTagname);
-  if (IsHTML()) {
-    nsAutoString tmp(aTagname);
-    ToLowerCase(tmp); // HTML elements are lower case internally.
-    nameAtom = do_GetAtom(tmp);
-  }
-  else {
-    nameAtom = do_GetAtom(aTagname);
-  }
-  NS_ENSURE_TRUE(nameAtom, nsnull);
-
-  return NS_GetContentList(this, nameAtom, kNameSpaceID_Unknown);
-}
-
 NS_IMETHODIMP
 nsDocument::GetElementsByTagName(const nsAString& aTagname,
                                  nsIDOMNodeList** aReturn)
 {
-  nsRefPtr<nsContentList> list = GetElementsByTagName(aTagname);
+  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aTagname);
+  NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
+
+  nsContentList *list = NS_GetContentList(this, nameAtom, kNameSpaceID_Unknown).get();
   NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
 
   // transfer ref to aReturn
-  *aReturn = list.forget().get();
+  *aReturn = list;
   return NS_OK;
 }
 
-already_AddRefed<nsContentList>
+NS_IMETHODIMP
 nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
-                                   const nsAString& aLocalName)
+                                   const nsAString& aLocalName,
+                                   nsIDOMNodeList** aReturn)
 {
   PRInt32 nameSpaceId = kNameSpaceID_Wildcard;
 
   if (!aNamespaceURI.EqualsLiteral("*")) {
     nsresult rv =
       nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
                                                             nameSpaceId);
-    NS_ENSURE_SUCCESS(rv, nsnull);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
-  NS_ENSURE_TRUE(nameAtom, nsnull);
-
-  return NS_GetContentList(this, nameAtom, nameSpaceId);
-}
-
-NS_IMETHODIMP
-nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
-                                   const nsAString& aLocalName,
-                                   nsIDOMNodeList** aReturn)
-{
-  nsRefPtr<nsContentList> list = GetElementsByTagNameNS(aNamespaceURI,
-                                                        aLocalName);
+  NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
+
+  nsContentList *list = NS_GetContentList(this, nameAtom, nameSpaceId).get();
   NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
 
   // transfer ref to aReturn
-  *aReturn = list.forget().get();
+  *aReturn = list;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::GetAsync(PRBool *aAsync)
 {
   NS_ERROR("nsDocument::GetAsync() should be overriden by subclass!");
 
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -90,17 +90,23 @@
 #include "nsTObserverArray.h"
 #include "nsStubMutationObserver.h"
 #include "nsIChannel.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsContentList.h"
 #include "nsGkAtoms.h"
 #include "nsIApplicationCache.h"
 #include "nsIApplicationCacheContainer.h"
+
+// Put these here so all document impls get them automatically
+#include "nsHTMLStyleSheet.h"
+#include "nsHTMLCSSStyleSheet.h"
+
 #include "nsStyleSet.h"
+#include "nsXMLEventsManager.h"
 #include "pldhash.h"
 #include "nsAttrAndChildArray.h"
 #include "nsDOMAttributeMap.h"
 #include "nsContentUtils.h"
 #include "nsThreadUtils.h"
 #include "nsIDocumentViewer.h"
 #include "nsIDOMXPathNSResolver.h"
 #include "nsIInterfaceRequestor.h"
@@ -124,19 +130,16 @@ class nsIOutputStream;
 class nsDocument;
 class nsIDTD;
 class nsIRadioVisitor;
 class nsIFormControl;
 struct nsRadioGroupStruct;
 class nsOnloadBlocker;
 class nsUnblockOnloadEvent;
 class nsChildContentList;
-class nsXMLEventsManager;
-class nsHTMLStyleSheet;
-class nsHTMLCSSStyleSheet;
 
 /**
  * Right now our identifier map entries contain information for 'name'
  * and 'id' mappings of a given string. This is so that
  * nsHTMLDocument::ResolveName only has to do one hash lookup instead
  * of two. It's not clear whether this still matters for performance.
  * 
  * We also store the document.all result list here. This is mainly so that
@@ -922,25 +925,16 @@ public:
 
   virtual PRInt32 GetDocumentState();
 
   virtual void RegisterFileDataUri(nsACString& aUri);
 
   // Only BlockOnload should call this!
   void AsyncBlockOnload();
 
-  already_AddRefed<nsContentList>
-    GetElementsByTagName(const nsAString& aTagName);
-  already_AddRefed<nsContentList>
-    GetElementsByTagNameNS(const nsAString& aNamespaceURI,
-                           const nsAString& aLocalName);
-
-  virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId,
-                                                nsresult *aResult);
-
 protected:
   friend class nsNodeUtils;
   void RegisterNamedItems(nsIContent *aContent);
   void UnregisterNamedItems(nsIContent *aContent);
   void UpdateNameTableEntry(mozilla::dom::Element *aElement);
   void UpdateIdTableEntry(mozilla::dom::Element *aElement);
   void RemoveFromNameTable(mozilla::dom::Element *aElement);
   void RemoveFromIdTable(mozilla::dom::Element *aElement);
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1384,17 +1384,21 @@ nsHTMLDocument::CreateTextNode(const nsA
 {
   return nsDocument::CreateTextNode(aData, aReturn);
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname,
                                      nsIDOMNodeList** aReturn)
 {
-  return nsDocument::GetElementsByTagName(aTagname, aReturn);
+  nsAutoString tmp(aTagname);
+  if (IsHTML()) {
+    ToLowerCase(tmp); // HTML elements are lower case internally.
+  }
+  return nsDocument::GetElementsByTagName(tmp, aReturn);
 }
 
 // nsIDOM3Document interface implementation
 NS_IMETHODIMP
 nsHTMLDocument::GetXmlEncoding(nsAString& aXmlEncoding)
 {
   if (!IsHTML()) {
     return nsDocument::GetXmlEncoding(aXmlEncoding);
@@ -1572,58 +1576,47 @@ nsHTMLDocument::GetURL(nsAString& aURL)
     mDocumentURI->GetSpec(str);
   }
 
   CopyUTF8toUTF16(str, aURL);
 
   return NS_OK;
 }
 
-nsIContent*
-nsHTMLDocument::GetBody(nsresult *aResult)
+NS_IMETHODIMP
+nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
 {
+  *aBody = nsnull;
+
   Element* body = GetBodyElement();
 
-  *aResult = NS_OK;
-
   if (body) {
     // There is a body element, return that as the body.
-    return body;
+    return CallQueryInterface(body, aBody);
   }
 
   // The document is most likely a frameset document so look for the
   // outer most frameset element
-  nsRefPtr<nsContentList> nodeList;
-
-  if (IsHTML()) {
-    nodeList = nsDocument::GetElementsByTagName(NS_LITERAL_STRING("frameset"));
-  } else {
-    nodeList =
-      nsDocument::GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"),
-                             NS_LITERAL_STRING("frameset"));
-  }
-
-  if (!nodeList) {
-    *aResult = NS_ERROR_OUT_OF_MEMORY;
-
-    return nsnull;
-  }
-
-  return nodeList->GetNodeAt(0);
-}
-
-NS_IMETHODIMP
-nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
-{
-  *aBody = nsnull;
+  nsCOMPtr<nsIDOMNodeList> nodeList;
 
   nsresult rv;
-  nsIContent *body = GetBody(&rv);
-
-  return body ? CallQueryInterface(body, aBody) : rv;
+  if (IsHTML()) {
+    rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
+                              getter_AddRefs(nodeList));
+  } else {
+    rv = GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"),
+                                NS_LITERAL_STRING("frameset"),
+                                getter_AddRefs(nodeList));
+  }
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIDOMNode> node;
+  nodeList->Item(0, getter_AddRefs(node));
+
+  return node ? CallQueryInterface(node, aBody) : NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
 {
   nsCOMPtr<nsIContent> newBody = do_QueryInterface(aBody);
   Element* root = GetRootElement();
 
@@ -2289,21 +2282,28 @@ nsHTMLDocument::MatchNameAttribute(nsICo
     aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
                           *elementName, eCaseMatters);
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetElementsByName(const nsAString& aElementName,
                                   nsIDOMNodeList** aReturn)
 {
-  nsRefPtr<nsContentList> list = GetElementsByName(aElementName);
-  NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
+  nsString* elementNameData = new nsString(aElementName);
+  NS_ENSURE_TRUE(elementNameData, NS_ERROR_OUT_OF_MEMORY);
+  nsContentList* elements =
+    NS_GetFuncStringContentList(this,
+                                MatchNameAttribute,
+                                nsContentUtils::DestroyMatchString,
+                                elementNameData,
+                                *elementNameData).get();
+  NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);
 
   // Transfer ownership
-  list.forget(aReturn);
+  *aReturn = elements;
 
   return NS_OK;
 }
 
 void
 nsHTMLDocument::ScriptLoading(nsIScriptElement *aScript)
 {
   if (mWriteState == eNotWriting) {
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -155,27 +155,16 @@ public:
   NS_IMETHOD Open(void);
   NS_IMETHOD Close(void);
   NS_IMETHOD Write(const nsAString & text);
   NS_IMETHOD Writeln(const nsAString & text);
   NS_IMETHOD GetElementsByName(const nsAString & elementName,
                                nsIDOMNodeList **_retval);
   virtual nsresult GetDocumentAllResult(const nsAString& aID,
                                         nsISupports** aResult);
-  nsIContent *GetBody(nsresult *aResult);
-  already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
-  {
-    nsString* elementNameData = new nsString(aName);
-
-    return NS_GetFuncStringContentList(this,
-                                       MatchNameAttribute,
-                                       nsContentUtils::DestroyMatchString,
-                                       elementNameData,
-                                       *elementNameData);
-  }
 
   // nsIDOMNSHTMLDocument interface
   NS_DECL_NSIDOMNSHTMLDOCUMENT
 
   virtual nsresult ResolveName(const nsAString& aName,
                                nsIDOMHTMLFormElement *aForm,
                                nsISupports **aResult);
 
@@ -234,22 +223,16 @@ public:
   }
 
   virtual nsresult SetEditingState(EditingState aState);
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   virtual NS_HIDDEN_(void) RemovedFromDocShell();
 
-  virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId,
-                                                nsresult *aResult)
-  {
-    return nsDocument::GetElementById(aElementId, aResult);
-  }
-
 protected:
   nsresult GetBodySize(PRInt32* aWidth,
                        PRInt32* aHeight);
 
   nsresult PrePopulateIdentifierMap();
 
   nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
 
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -182,42 +182,42 @@ struct BroadcasterMapEntry : public PLDH
     nsSmallVoidArray mListeners;   // [OWNING] of BroadcastListener objects
 };
 
 struct BroadcastListener {
     nsWeakPtr mListener;
     nsCOMPtr<nsIAtom> mAttribute;
 };
 
-Element*
-nsRefMapEntry::GetFirstElement()
+nsIContent*
+nsRefMapEntry::GetFirstContent()
 {
-    return static_cast<Element*>(mRefContentList.SafeElementAt(0));
+    return static_cast<nsIContent*>(mRefContentList.SafeElementAt(0));
 }
 
 void
 nsRefMapEntry::AppendAll(nsCOMArray<nsIContent>* aElements)
 {
     for (PRInt32 i = 0; i < mRefContentList.Count(); ++i) {
         aElements->AppendObject(static_cast<nsIContent*>(mRefContentList[i]));
     }
 }
 
 PRBool
-nsRefMapEntry::AddElement(Element* aElement)
+nsRefMapEntry::AddContent(nsIContent* aContent)
 {
-    if (mRefContentList.IndexOf(aElement) >= 0)
+    if (mRefContentList.IndexOf(aContent) >= 0)
         return PR_TRUE;
-    return mRefContentList.AppendElement(aElement);
+    return mRefContentList.AppendElement(aContent);
 }
 
 PRBool
-nsRefMapEntry::RemoveElement(Element* aElement)
+nsRefMapEntry::RemoveContent(nsIContent* aContent)
 {
-    mRefContentList.RemoveElement(aElement);
+    mRefContentList.RemoveElement(aContent);
     return mRefContentList.Count() == 0;
 }
 
 //----------------------------------------------------------------------
 //
 // ctors & dtors
 //
 
@@ -973,17 +973,17 @@ nsXULDocument::AttributeWillChange(nsIDo
 {
     NS_ABORT_IF_FALSE(aContent, "Null content!");
     NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
 
     // XXXbz check aNameSpaceID, dammit!
     // See if we need to update our ref map.
     if (aAttribute == nsGkAtoms::ref ||
         (aAttribute == nsGkAtoms::id && !aContent->GetIDAttributeName())) {
-        RemoveElementFromRefMap(aContent->AsElement());
+        RemoveElementFromRefMap(aContent);
     }
     
     nsXMLDocument::AttributeWillChange(aDocument, aContent, aNameSpaceID,
                                        aAttribute, aModType);
 }
 
 void
 nsXULDocument::AttributeChanged(nsIDocument* aDocument,
@@ -1318,17 +1318,17 @@ nsXULDocument::Persist(const nsAString& 
     // If we're currently reading persisted attributes out of the
     // localstore, _don't_ re-enter and try to set them again!
     if (mApplyingPersistedAttrs)
         return NS_OK;
 
     nsresult rv;
 
     nsCOMPtr<nsIDOMElement> domelement;
-    rv = nsDocument::GetElementById(aID, getter_AddRefs(domelement));
+    rv = GetElementById(aID, getter_AddRefs(domelement));
     if (NS_FAILED(rv)) return rv;
 
     if (! domelement)
         return NS_OK;
 
     nsCOMPtr<nsIContent> element = do_QueryInterface(domelement);
     NS_ASSERTION(element != nsnull, "null ptr");
     if (! element)
@@ -1655,44 +1655,43 @@ nsXULDocument::SetTooltipNode(nsIDOMNode
 NS_IMETHODIMP
 nsXULDocument::GetCommandDispatcher(nsIDOMXULCommandDispatcher** aTracker)
 {
     *aTracker = mCommandDispatcher;
     NS_IF_ADDREF(*aTracker);
     return NS_OK;
 }
 
-Element*
-nsXULDocument::GetElementById(const nsAString& aId, nsresult *aResult)
+NS_IMETHODIMP
+nsXULDocument::GetElementById(const nsAString& aId,
+                              nsIDOMElement** aReturn)
 {
-    nsCOMPtr<nsIAtom> atom(do_GetAtom(aId));
-    if (!atom) {
-        *aResult = NS_ERROR_OUT_OF_MEMORY;
-
-        return nsnull;
-    }
-
-    *aResult = NS_OK;
+    NS_ENSURE_ARG_POINTER(aReturn);
+    *aReturn = nsnull;
+
+    nsCOMPtr<nsIAtom> atom = do_GetAtom(aId);
+    if (!atom)
+        return NS_ERROR_OUT_OF_MEMORY;
 
     if (!CheckGetElementByIdArg(atom))
-        return nsnull;
+        return NS_OK;
 
     nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(atom);
     if (entry) {
         Element* element = entry->GetIdElement();
         if (element)
-            return element;
+            return CallQueryInterface(element, aReturn);
     }
     nsRefMapEntry* refEntry = mRefMap.GetEntry(atom);
     if (refEntry) {
-        NS_ASSERTION(refEntry->GetFirstElement(),
+        NS_ASSERTION(refEntry->GetFirstContent(),
                      "nsRefMapEntries should have nonempty content lists");
-        return refEntry->GetFirstElement();
+        return CallQueryInterface(refEntry->GetFirstContent(), aReturn);
     }
-    return nsnull;
+    return NS_OK;
 }
 
 nsresult
 nsXULDocument::AddElementToDocumentPre(Element* aElement)
 {
     // Do a bunch of work that's necessary when an element gets added
     // to the XUL Document.
     nsresult rv;
@@ -1894,59 +1893,59 @@ nsXULDocument::GetTemplateBuilderFor(nsI
     }
     else
         *aResult = nsnull;
 
     return NS_OK;
 }
 
 static void
-GetRefMapAttribute(Element* aElement, nsAutoString* aValue)
+GetRefMapAttribute(nsIContent* aElement, nsAutoString* aValue)
 {
     aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::ref, *aValue);
     if (aValue->IsEmpty() && !aElement->GetIDAttributeName()) {
         aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::id, *aValue);
     }
 }
 
 nsresult
-nsXULDocument::AddElementToRefMap(Element* aElement)
+nsXULDocument::AddElementToRefMap(nsIContent* aElement)
 {
     // Look at the element's 'ref' attribute, and if set,
     // add an entry in the resource-to-element map to the element.
     nsAutoString value;
     GetRefMapAttribute(aElement, &value);
     if (!value.IsEmpty()) {
         nsCOMPtr<nsIAtom> atom = do_GetAtom(value);
         if (!atom)
             return NS_ERROR_OUT_OF_MEMORY;
         nsRefMapEntry *entry = mRefMap.PutEntry(atom);
         if (!entry)
             return NS_ERROR_OUT_OF_MEMORY;
-        if (!entry->AddElement(aElement))
+        if (!entry->AddContent(aElement))
             return NS_ERROR_OUT_OF_MEMORY;
     }
 
     return NS_OK;
 }
 
 void
-nsXULDocument::RemoveElementFromRefMap(Element* aElement)
+nsXULDocument::RemoveElementFromRefMap(nsIContent* aElement)
 {
     // Remove the element from the resource-to-element map.
     nsAutoString value;
     GetRefMapAttribute(aElement, &value);
     if (!value.IsEmpty()) {
         nsCOMPtr<nsIAtom> atom = do_GetAtom(value);
         if (!atom)
             return;
         nsRefMapEntry *entry = mRefMap.GetEntry(atom);
         if (!entry)
             return;
-        if (entry->RemoveElement(aElement)) {
+        if (entry->RemoveContent(aElement)) {
             mRefMap.RemoveEntry(atom);
         }
     }
 }
 
 //----------------------------------------------------------------------
 //
 // nsIDOMNode interface
--- a/content/xul/document/src/nsXULDocument.h
+++ b/content/xul/document/src/nsXULDocument.h
@@ -85,27 +85,27 @@ public:
   {
   }
   nsRefMapEntry(const nsRefMapEntry& aOther) :
     nsISupportsHashKey(GetKey())
   {
     NS_ERROR("Should never be called");
   }
 
-  mozilla::dom::Element* GetFirstElement();
+  nsIContent* GetFirstContent();
   void AppendAll(nsCOMArray<nsIContent>* aElements);
   /**
-   * @return true if aElement was added, false if we failed due to OOM
+   * @return true if aContent was added, false if we failed due to OOM
    */
-  PRBool AddElement(mozilla::dom::Element* aElement);
+  PRBool AddContent(nsIContent* aContent);
   /**
-   * @return true if aElement was removed and it was the last content for
+   * @return true if aContent was removed and it was the last content for
    * this ref, so this entry should be removed from the map
    */
-  PRBool RemoveElement(mozilla::dom::Element* aElement);
+  PRBool RemoveContent(nsIContent* aContent);
 
 private:
   nsSmallVoidArray mRefContentList;
 };
 
 /**
  * The XUL document class
  */
@@ -160,23 +160,19 @@ public:
     NS_IMETHOD GetTemplateBuilderFor(nsIContent* aContent,
                                      nsIXULTemplateBuilder** aResult);
     NS_IMETHOD OnPrototypeLoadDone(PRBool aResumeWalk);
     PRBool OnDocumentParserError();
 
     // nsIDOMNode interface overrides
     NS_IMETHOD CloneNode(PRBool deep, nsIDOMNode **_retval);
 
-    // nsDocument interface overrides
-    NS_IMETHOD GetElementById(const nsAString& aId, nsIDOMElement** aReturn)
-    {
-        return nsDocument::GetElementById(aId, aReturn);
-    }
-    virtual mozilla::dom::Element* GetElementById(const nsAString & elementId,
-                                                  nsresult *aResult);
+    // nsIDOMDocument interface overrides
+    NS_IMETHOD GetElementById(const nsAString & elementId,
+                              nsIDOMElement **_retval); 
 
     // nsIDOMXULDocument interface
     NS_DECL_NSIDOMXULDOCUMENT
 
     // nsIDOMNSDocument
     NS_IMETHOD GetContentType(nsAString& aContentType);
 
     // nsICSSLoaderObserver
@@ -206,19 +202,19 @@ protected:
     // Implementation methods
     friend nsresult
     NS_NewXULDocument(nsIXULDocument** aResult);
 
     nsresult Init(void);
     nsresult StartLayout(void);
 
     nsresult
-    AddElementToRefMap(mozilla::dom::Element* aElement);
+    AddElementToRefMap(nsIContent* aElement);
     void
-    RemoveElementFromRefMap(mozilla::dom::Element* aElement);
+    RemoveElementFromRefMap(nsIContent* aElement);
 
     nsresult GetViewportSize(PRInt32* aWidth, PRInt32* aHeight);
 
     nsresult PrepareToLoad(nsISupports* aContainer,
                            const char* aCommand,
                            nsIChannel* aChannel,
                            nsILoadGroup* aLoadGroup,
                            nsIParser** aResult);
--- a/dom/base/nsDOMClassInfoID.h
+++ b/dom/base/nsDOMClassInfoID.h
@@ -69,30 +69,26 @@ enum nsDOMClassInfoID {
  * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and
  * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES.
  *
  * WARNING: Be very careful when adding interfaces to this list. Every object
  *          that implements one of these interfaces must be directly castable
  *          to that interface from the *canonical* nsISupports!
  */
 #define DOMCI_CASTABLE_INTERFACES(_extra)                                     \
-DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra)                         \
-DOMCI_CASTABLE_INTERFACE(nsIContent, nsIContent, 1, _extra)                   \
-DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 2, _extra)                 \
-DOMCI_CASTABLE_INTERFACE(nsINodeList, nsINodeList, 3, _extra)                 \
-DOMCI_CASTABLE_INTERFACE(nsICSSDeclaration, nsICSSDeclaration, 4, _extra)     \
-DOMCI_CASTABLE_INTERFACE(nsGenericTextNode, nsGenericTextNode, 5, _extra)     \
-DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 6, _extra)                  \
-DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsGenericHTMLElement, 7,       \
-                         _extra)                                              \
-DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 8, _extra)
+DOMCI_CASTABLE_INTERFACE(nsINode, 0, _extra)                                  \
+DOMCI_CASTABLE_INTERFACE(nsIContent, 1, _extra)                               \
+DOMCI_CASTABLE_INTERFACE(nsIDocument, 2, _extra)                              \
+DOMCI_CASTABLE_INTERFACE(nsINodeList, 3, _extra)                              \
+DOMCI_CASTABLE_INTERFACE(nsICSSDeclaration, 4, _extra)                        \
+DOMCI_CASTABLE_INTERFACE(nsGenericTextNode, 5, _extra)
 
 // Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES
 // have been declared.
-#define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface;
+#define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2) class _interface;
 DOMCI_CASTABLE_INTERFACES(unused)
 #undef DOMCI_CASTABLE_INTERFACE
 
 #ifdef _IMPL_NS_LAYOUT
 
 #define DOMCI_CLASS(_dom_class)                                               \
   extern const PRUint32 kDOMClassInfo_##_dom_class##_interfaces;
 
@@ -134,17 +130,17 @@ template <typename Interface> struct DOM
   (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) ==        \
    sizeof(DOMCI_CastableTo<_interface>::true_type))
 
 #endif
 
 /**
  * Here we calculate the bitmap for a given class.
  */
-#define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class)             \
+#define DOMCI_CASTABLE_INTERFACE(_interface, _bit, _class)                    \
   (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) +
 
 #define DOMCI_DATA(_dom_class, _class)                                        \
 const PRUint32 kDOMClassInfo_##_dom_class##_interfaces =                      \
   DOMCI_CASTABLE_INTERFACES(_class)                                           \
   0;
 
 class nsIClassInfo;
--- a/js/src/xpconnect/src/Makefile.in
+++ b/js/src/xpconnect/src/Makefile.in
@@ -116,19 +116,16 @@ endif
 include $(topsrcdir)/config/config.mk
 
 LOCAL_INCLUDES = \
 		-I$(srcdir)/../loader \
 		-I$(topsrcdir)/js/src \
 		-I$(topsrcdir)/js/src/nanojit \
 		-I$(topsrcdir)/caps/include \
 		-I$(topsrcdir)/content/base/src \
-		-I$(topsrcdir)/content/html/content/src \
-		-I$(topsrcdir)/content/html/document/src \
-		-I$(topsrcdir)/layout/style \
 		$(NULL)
 
 EXTRA_DSO_LDOPTS += \
 		$(MOZ_COMPONENT_LIBS) \
 		$(MOZ_JS_LIBS) \
 		$(NULL)
 
 ifdef MOZ_JSLOADER
--- a/js/src/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/src/xpconnect/src/dom_quickstubs.qsconf
@@ -136,25 +136,28 @@ members = [
     'nsIDOMNode.replaceChild',
     'nsIDOMNode.localName',
     'nsIDOMNode.lastChild',
     'nsIDOMNode.ownerDocument',
     'nsIDOMNode.parentNode',
     'nsIDOMNode.removeChild',
     'nsIDOMNode.hasAttributes',
     'nsIDOMNode.attributes',
-    'nsIDOMNodeList.*',
+    'nsIDOMNodeList.item',
+    'nsIDOMNodeList.length',
     'nsIDOMNodeSelector.querySelector',
     'nsIDOMNodeSelector.querySelectorAll',
     'nsIDOMText.splitText',
     'nsIDOM3Document.documentURI',
     'nsIDOM3Document.adoptNode',
     'nsIDOM3Document.renameNode',
     'nsIDOM3Node.*',
-    'nsIDOMDOMStringList.*',
+    'nsIDOMDOMStringList.item',
+    'nsIDOMDOMStringList.length',
+    'nsIDOMDOMStringList.contains',
     'nsIDOMDOMTokenList.*',
     'nsIDOMDOMSettableTokenList.*',
     'nsIDOMNameList.getName',
     'nsIDOMNameList.contains',
     'nsIDOMNameList.containsNS',
     'nsIDOMNameList.length',
     'nsIDOMNameList.getNamespaceURI',
     'nsIDOMNSDocument.getElementsByClassName',
@@ -175,27 +178,30 @@ members = [
     'nsIDOMNSElement.scrollWidth',
     'nsIDOMNSElement.clientLeft',
     'nsIDOMNSElement.clientHeight',
     'nsIDOMNSElement.clientWidth',
     'nsIDOMNSElement.clientTop',
     'nsIDOMNSElement.mozMatchesSelector',
 
     # dom/interfaces/css
-    'nsIDOMElementCSSInlineStyle.*',
+    'nsIDOMElementCSSInlineStyle.style',
     'nsIDOMCSS2Properties.*',
     'nsIDOMNSCSS2Properties.*',
-    'nsIDOMRect.*',
+    'nsIDOMRect.top',
+    'nsIDOMRect.right',
+    'nsIDOMRect.left',
+    'nsIDOMRect.bottom',
     'nsIDOMViewCSS.getComputedStyle',
 
     # dom/interfaces/events
     'nsIDOMEventTarget.dispatchEvent',
     'nsIDOMEventTarget.removeEventListener',
     'nsIDOMNSEventTarget.addEventListener',
-    'nsIDOMDocumentEvent.*',
+    'nsIDOMDocumentEvent.createEvent',
 
     'nsIDOMEvent.*',
     'nsIDOMMouseEvent.*',
     'nsIDOMKeyEvent.*',
     'nsIDOMMutationEvent.*',
     'nsIDOMDragEvent.*',
     'nsIDOMScrollAreaEvent.*',
     'nsIDOMNotifyPaintEvent.*',
@@ -490,21 +496,18 @@ irregularFilenames = {
     }
 
 customIncludes = [
     'nsINode.h',
     'nsIContent.h',
     'nsIDocument.h',
     'nsINodeList.h',
     'nsCSSPropertiesQS.h',
-    'nsDocument.h',
     'nsGenericDOMDataNode.h',
     'nsGenericElement.h',
-    'nsGenericHTMLElement.h',
-    'nsHTMLDocument.h',
     'nsDOMQS.h',
     ]
 
 customQuickStubs = [
     'CustomQS_WebGL.h',
     'CustomQS_Canvas2D.h'
     ]
 
@@ -618,62 +621,43 @@ customMethodCalls = {
         },
     'nsIDOMNode_AppendChild': {
         'thisType': 'nsINode',
         'arg0Type': 'nsINode',
         'code': '    nsINode *result = self->AppendChild(arg0, &rv);\n'
                 '    if(NS_FAILED(rv))\n'
                 '        result = nsnull;'
         },
-    'nsIDOMNode_GetNodeType': {
-        'thisType': 'nsINode',
-        'canFail': False
-        },
     'nsIDOMNodeList_Item': {
         'thisType': 'nsINodeList',
         'code': '    nsINode *result = self->GetNodeAt(arg0);',
         'canFail': False
         },
-    'nsIDOMNodeList_GetLength': {
-        'thisType': 'nsINodeList'
-        },
-    'nsIDOMHTMLDocument_': {
-        'thisType': 'nsHTMLDocument'
-        },
     'nsIDOMHTMLDocument_Write': {
-        'thisType': 'nsHTMLDocument',
         'code': nsIDOMHTMLDocument_Write_customMethodCallCode % 'Write'
         },
     'nsIDOMHTMLDocument_Writeln': {
-        'thisType': 'nsHTMLDocument',
         'code': nsIDOMHTMLDocument_Write_customMethodCallCode % 'Writeln'
         },
-    'nsIDOMHTMLDocument_GetBody': {
-        'thisType': 'nsHTMLDocument',
-        'code': '    nsIContent *result = self->GetBody(&rv);'
-        },
-    'nsIDOMHTMLDocument_GetElementsByName': {
-        'thisType': 'nsHTMLDocument',
-        'code': '    nsRefPtr<nsContentList> result = '
-                'self->GetElementsByName(arg0);',
-        'canFail': False
-        },
-    'nsIDOMNSHTMLDocument_': {
-        'thisType': 'nsHTMLDocument'
-        },
     'nsIDOMStorage_Clear': {
         'code': nsIDOMStorage_Clear_customMethodCallCode
         },
     'nsIDOMCanvasRenderingContext2D_StrokeStyle': { 'skipgen': True },
     'nsIDOMCanvasRenderingContext2D_StrokeStyle': { 'skipgen': True },
     'nsIDOMCanvasRenderingContext2D_FillStyle': { 'skipgen': True },
     'nsIDOMCanvasRenderingContext2D_FillStyle': { 'skipgen': True },
     'nsIDOMCSS2Properties_': CSS2Properties_,
     'nsIDOMNSCSS2Properties_': CSS2Properties_,
-    'nsIDOMNSElement_': {
+    'nsIDOMNSElement_GetClientRects': {
+        'thisType': 'nsGenericElement'
+        },
+    'nsIDOMNSElement_GetBoundingClientRect': {
+        'thisType': 'nsGenericElement'
+        },
+    'nsIDOMNSElement_GetElementsByClassName': {
         'thisType': 'nsGenericElement'
         },
     'nsIDOMNSElement_GetScrollWidth': {
         'thisType': 'nsGenericElement',
         'code': '    PRInt32 result = self->GetScrollWidth();',
         'canFail': False
         },
     'nsIDOMNSElement_GetClientTop': {
@@ -704,55 +688,55 @@ customMethodCalls = {
         'code': '    PRInt32 result = self->GetClientWidth();',
         'canFail': False
         },
     'nsIDOMNSElement_MozMatchesSelector': {
         'thisType': 'nsGenericElement',
         'code': '    PRBool result = self->MozMatchesSelector(arg0);',
         'canFail': False
         },
-    'nsIDOM3Text_': {
-        'thisType': 'nsGenericTextNode'
-        },
     'nsIDOM3Text_IsElementContentWhitespace': {
         'thisType': 'nsGenericTextNode',
         'code': '    PRBool result = self->IsElementContentWhitespace();',
         'canFail': False
         },
     'nsIDOM3Text_ReplaceWholeText': {
         'thisType': 'nsGenericTextNode',
         'code': '    nsIContent* result = '
                 'self->ReplaceWholeText(PromiseFlatString(arg0), &rv);'
         },
+    'nsIDOM3Text_WholeText': {
+        'thisType': 'nsGenericTextNode'
+        },
     'nsIDOMNodeSelector_QuerySelector': {
         'thisType': 'nsINode',
         'code': '    nsIContent* result = '
                 'nsGenericElement::doQuerySelector(self, arg0, &rv);'
         },
     'nsIDOMNodeSelector_QuerySelectorAll': {
         'thisType': 'nsINode',
         'code': '    nsCOMPtr<nsIDOMNodeList> result;\n'
                 '    rv = nsGenericElement::doQuerySelectorAll(self, '
                 'arg0, getter_AddRefs(result));'
         },
-    'nsIDOM3Node_': {
-        'thisType': 'nsINode'
-        },
     'nsIDOM3Node_GetBaseURI': {
         'thisType': 'nsINode',
         'canFail': False
         },
     'nsIDOM3Node_CompareDocumentPosition': {
         'thisType': 'nsINode',
         'arg0Type': 'nsINode'
         },
     'nsIDOM3Node_GetTextContent': {
         'thisType': 'nsINode',
         'canFail': False
         },
+    'nsIDOM3Node_SetTextContent': {
+        'thisType': 'nsINode'
+        },
     'nsIDOM3Node_IsSameNode': {
         'thisType': 'nsINode',
         'arg0Type': 'nsINode',
         'code': '    PRBool result = self->IsSameNode(arg0);',
         'canFail': False
         },
     'nsIDOM3Node_LookupPrefix': {
         'thisType': 'nsINode',
@@ -768,51 +752,26 @@ customMethodCalls = {
         'canFail': False
         },
     'nsIDOM3Node_IsEqualNode': {
         'thisType': 'nsINode',
         'arg0Type': 'nsINode',
         'code': '    PRBool result = self->IsEqualNode(arg0);',
         'canFail': False
         },
+    'nsIDOM3Node_GetFeature': {
+        'thisType': 'nsINode'
+        },
     'nsIDOM3Node_GetUserData': {
         'thisType': 'nsINode',
         'code': '    nsIVariant *result = self->GetUserData(arg0);',
         'canFail': False
         },
-    'nsIDOMNSHTMLElement_': {
-        'thisType': 'nsGenericHTMLElement'
-        },
-    'nsIDOMDocument_': {
-        'thisType': 'nsDocument'
-        },
-    'nsIDOMDocument_GetElementById': {
-        'thisType': 'nsDocument',
-        'code': '    mozilla::dom::Element *result = self->GetElementById(arg0, &rv);'
-        },
-    'nsIDOMDocument_GetElementsByTagName': {
-        'thisType': 'nsDocument',
-        'code': '    nsRefPtr<nsContentList> result ='
-                'self->GetElementsByTagName(arg0);',
-        'canFail': False
-        },
-    'nsIDOMDocument_GetElementsByTagNameNS': {
-        'thisType': 'nsDocument',
-        'code': '    nsRefPtr<nsContentList> result ='
-                'self->GetElementsByTagNameNS(arg0, arg1);',
-        'canFail': False
-        },
-    'nsIDOMNSDocument_': {
-        'thisType': 'nsDocument'
-        },
-    'nsIDOM3Document_': {
-        'thisType': 'nsDocument'
-        },
-    'nsIDOMElement_': {
-        'thisType': 'nsGenericElement'
+    'nsIDOM3Node_SetUserData': {
+        'thisType': 'nsINode'
         },
     # WebGL
     'nsICanvasRenderingContextWebGL_BufferData': CUSTOM_QS,
     'nsICanvasRenderingContextWebGL_BufferSubData': CUSTOM_QS,
     'nsICanvasRenderingContextWebGL_TexImage2D': CUSTOM_QS,
     'nsICanvasRenderingContextWebGL_TexSubImage2D': CUSTOM_QS,
     'nsICanvasRenderingContextWebGL_Uniform1iv': CUSTOM_QS_TN,
     'nsICanvasRenderingContextWebGL_Uniform2iv': CUSTOM_QS_TN,
--- a/js/src/xpconnect/src/nsDOMQS.h
+++ b/js/src/xpconnect/src/nsDOMQS.h
@@ -34,55 +34,55 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsDOMQS_h__
 #define nsDOMQS_h__
 
 #include "nsDOMClassInfoID.h"
 
-#define DEFINE_UNWRAP_CAST(_interface, _base, _bit)                           \
+#define DEFINE_UNWRAP_CAST(_interface, _bit)                                  \
 NS_SPECIALIZE_TEMPLATE                                                        \
 inline JSBool                                                                 \
 xpc_qsUnwrapThis<_interface>(JSContext *cx,                                   \
                              JSObject *obj,                                   \
                              JSObject *callee,                                \
                              _interface **ppThis,                             \
                              nsISupports **pThisRef,                          \
                              jsval *pThisVal,                                 \
                              XPCLazyCallContext *lccx)                        \
 {                                                                             \
     nsresult rv;                                                              \
     nsISupports *native = castNativeFromWrapper(cx, obj, callee, _bit,        \
                                                 pThisRef, pThisVal, lccx,     \
                                                 &rv);                         \
     if(!native)                                                               \
         return xpc_qsThrow(cx, rv);                                           \
-    *ppThis = static_cast<_interface*>(static_cast<_base*>(native));          \
+    *ppThis = static_cast<_interface*>(native);                               \
     return JS_TRUE;                                                           \
 }                                                                             \
                                                                               \
 NS_SPECIALIZE_TEMPLATE                                                        \
 inline nsresult                                                               \
 xpc_qsUnwrapArg<_interface>(JSContext *cx,                                    \
                             jsval v,                                          \
                             _interface **ppArg,                               \
                             nsISupports **ppArgRef,                           \
                             jsval *vp)                                        \
 {                                                                             \
     nsresult rv;                                                              \
     nsISupports *native = castNativeArgFromWrapper(cx, v, _bit, ppArgRef, vp, \
                                                    &rv);                      \
     if(NS_SUCCEEDED(rv))                                                      \
-        *ppArg = static_cast<_interface*>(static_cast<_base*>(native));       \
+        *ppArg = static_cast<_interface*>(native);                            \
     return rv;                                                                \
 }
 
-#define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _extra)             \
-  DEFINE_UNWRAP_CAST(_interface, _base, _bit)
+#define DOMCI_CASTABLE_INTERFACE(_interface, _bit, _extra)                    \
+  DEFINE_UNWRAP_CAST(_interface, _bit)
 
 DOMCI_CASTABLE_INTERFACES(unused)
 
 #undef DOMCI_CASTABLE_INTERFACE
 
 // Ideally we'd just add nsGenericElement to the castable interfaces, but for
 // now nsDocumentFragment inherits from nsGenericElement (even though it's not
 // an Element) so we have to special-case nsGenericElement and use
@@ -134,15 +134,9 @@ xpc_qsUnwrapArg<nsGenericElement>(JSCont
     nsIContent *content;
     jsval val;
     nsresult rv = xpc_qsUnwrapArg<nsIContent>(cx, v, &content, ppArgRef, &val);
     if(NS_SUCCEEDED(rv) && !castToElement(content, val, ppArg, vp))
         rv = NS_ERROR_XPC_BAD_CONVERT_JS;
     return rv;
 }
 
-inline nsISupports*
-ToSupports(nsContentList *p)
-{
-    return static_cast<nsINodeList*>(p);
-}
-
 #endif /* nsDOMQS_h__ */
--- a/js/src/xpconnect/src/qsgen.py
+++ b/js/src/xpconnect/src/qsgen.py
@@ -675,19 +675,19 @@ def writeResultConv(f, type, jsvalPtr, j
             return
         # else fall through; this type isn't supported yet
     elif isInterfaceType(type):
         if isVariantType(type):
             f.write("    return xpc_qsVariantToJsval(lccx, result, %s);\n"
                     % jsvalPtr)
             return
         else:
-            f.write("    return xpc_qsXPCOMObjectToJsval(lccx, "
-                    "ToSupports(result), xpc_qsGetWrapperCache(result), "
-                    "&NS_GET_IID(%s), &interfaces[k_%s], %s);\n"
+            f.write("    return xpc_qsXPCOMObjectToJsval(lccx, result, "
+                    "xpc_qsGetWrapperCache(result), &NS_GET_IID(%s), "
+                    "&interfaces[k_%s], %s);\n"
                     % (type.name, type.name, jsvalPtr))
             return
 
     warn("Unable to convert result of type %s" % type.name)
     f.write("    !; // TODO - Convert `result` to jsval, store in `%s`.\n"
             % jsvalRef)
     f.write("    return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n")
 
@@ -737,26 +737,16 @@ def writeQuickStub(f, customMethodCalls,
         # JSFastNative.
         signature += "%s(JSContext *cx, uintN argc,%s jsval *vp)\n"
 
     customMethodCall = customMethodCalls.get(stubName, None)
 
     if customMethodCall is None:
         customMethodCall = customMethodCalls.get(member.iface.name + '_', None)
         if customMethodCall is not None:
-            if isMethod:
-                code = customMethodCall.get('code', None)
-            elif isGetter:
-                code = customMethodCall.get('getter_code', None)
-            else:
-                code = customMethodCall.get('setter_code', None)
-        else:
-            code = None
-
-        if code is not None:
             templateName = member.iface.name
             if isGetter:
                 templateName += '_Get'
             elif isSetter:
                 templateName += '_Set'
 
             # Generate the code for the stub, calling the template function
             # that's shared between the stubs. The stubs can't have additional
@@ -780,19 +770,25 @@ def writeQuickStub(f, customMethodCalls,
             # real stubs, but only generate the stub once. Otherwise, just write
             # out the call to the template function and return.
             templateGenerated = templateName + '_generated'
             if templateGenerated in customMethodCall:
                 f.write(callTemplate)
                 return
             customMethodCall[templateGenerated] = True
 
+            if isMethod:
+                code = customMethodCall['code']
+            elif isGetter:
+                code = customMethodCall['getter_code']
+            else:
+                code = customMethodCall['setter_code']
             stubName = templateName
         else:
-            callTemplate = ""
+            code = None
     else:
         callTemplate = ""
         code = customMethodCall.get('code', None)
 
     # Function prolog.
 
     # Only template functions can have additional arguments.
     if customMethodCall is None or not 'additionalArguments' in customMethodCall:
@@ -902,18 +898,17 @@ def writeQuickStub(f, customMethodCalls,
     if code is not None:
         f.write("%s\n" % code)
 
     if code is None or (isGetter and callTemplate is ""):
         debugGetter = code is not None
         if debugGetter:
             f.write("#ifdef DEBUG\n")
             f.write("    nsresult debug_rv;\n")
-            f.write("    nsCOMPtr<%s> debug_self;\n"
-                    "    CallQueryInterface(self, getter_AddRefs(debug_self));\n"
+            f.write("    nsCOMPtr<%s> debug_self = do_QueryInterface(self);\n"
                     % member.iface.name);
             prefix = 'debug_'
         else:
             prefix = ''
 
         resultname = prefix + 'result'
         selfname = prefix + 'self'
         nsresultname = prefix + 'rv'
@@ -1196,20 +1191,20 @@ def writeTraceableResultConv(f, type):
             f.write(substitute(template, values))
             return
         # else fall through; this type isn't supported yet
     elif isInterfaceType(type):
         if isVariantType(type):
             f.write("    JSBool ok = xpc_qsVariantToJsval(lccx, result, "
                     "&vp.array[0]);\n")
         else:
-            f.write("    JSBool ok = xpc_qsXPCOMObjectToJsval(lccx, "
-                    "ToSupports(result), xpc_qsGetWrapperCache(result), "
-                    "&NS_GET_IID(%s), &interfaces[k_%s], &vp.array[0]);\n"
-                    % (type.name, type.name))
+            f.write("    JSBool ok = xpc_qsXPCOMObjectToJsval(lccx, result, "
+                    "xpc_qsGetWrapperCache(result), &NS_GET_IID(%s), "
+                    "&interfaces[k_%s], &vp.array[0]);"
+                    "\n" % (type.name, type.name))
         f.write("    if (!ok) {\n");
         writeFailure(f, getTraceInfoDefaultReturn(type), 2)
         f.write("    return vp.array[0];\n")
         return
 
     warn("Unable to convert result of type %s" % typeName)
     f.write("    !; // TODO - Convert `result` to jsval, store in rval.\n")
     f.write("    return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n")
@@ -1221,22 +1216,16 @@ def writeTraceableQuickStub(f, customMet
         'type': getTraceInfoReturnType(member.realtype) + "_FAIL",
         'params': ["CONTEXT", "THIS"]
         }
 
     haveCcx = memberNeedsCcx(member)
 
     customMethodCall = customMethodCalls.get(stubName, None)
 
-    if customMethodCall is None:
-        customMethodCall = customMethodCalls.get(member.iface.name + '_', None)
-        if customMethodCall is not None:
-            # We don't support traceable templated quickstubs yet
-            assert not 'code' in customMethodCall
-
     if customMethodCall is not None and customMethodCall.get('skipgen', False):
         return
 
     # Write the function
     f.write("static %sFASTCALL\n" % getTraceReturnType(member.realtype))
     f.write("%s(JSContext *cx, JSObject *obj" % (stubName + "_tn"))
     # This code MUST match the arguments length check in addStubMember
     if memberNeedsCallee(member):
--- a/js/src/xpconnect/src/xpcquickstubs.h
+++ b/js/src/xpconnect/src/xpcquickstubs.h
@@ -555,22 +555,16 @@ xpc_qsXPCOMObjectToJsval(XPCLazyCallCont
 /**
  * Convert a variant to jsval. Return JS_TRUE on success.
  */
 JSBool
 xpc_qsVariantToJsval(XPCLazyCallContext &ccx,
                      nsIVariant *p,
                      jsval *rval);
 
-inline nsISupports*
-ToSupports(nsISupports *p)
-{
-    return p;
-}
-
 #ifdef DEBUG
 void
 xpc_qsAssertContextOK(JSContext *cx);
 
 inline PRBool
 xpc_qsSameResult(nsISupports *result1, nsISupports *result2)
 {
     return SameCOMIdentity(result1, result2);
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -384,27 +384,24 @@ class nsStyleSet
 
   unsigned mInShutdown : 1;
   unsigned mAuthorStyleDisabled: 1;
   unsigned mInReconstruct : 1;
   unsigned mDirty : 8;  // one dirty bit is used per sheet type
 
 };
 
-#ifdef _IMPL_NS_LAYOUT
 inline
 void nsRuleNode::AddRef()
 {
   if (mRefCnt++ == 0 && !IsRoot()) {
     mPresContext->StyleSet()->RuleNodeInUse();
   }
 }
 
 inline
 void nsRuleNode::Release()
 {
   if (--mRefCnt == 0 && !IsRoot()) {
     mPresContext->StyleSet()->RuleNodeUnused();
   }
 }
 #endif
-
-#endif