Merge last green changeset on mozilla-central to mozilla-inbound
authorEd Morley <bmo@edmorley.co.uk>
Mon, 19 Sep 2011 12:27:35 +0100
changeset 77131 75086668aebb002726a7e9dd27739bf5cd8b1177
parent 77130 9ae43404500df0ed167c90ffad1348c4cc3c50d7 (current diff)
parent 77120 5319b0100025f1a5bc7c30cabde3b9a3bcbf998d (diff)
child 77132 c6d4e5bce80b58d9544405f88b2d9292a75c1ec1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
milestone9.0a1
Merge last green changeset on mozilla-central to mozilla-inbound
content/base/public/nsIPrivateDOMImplementation.h
dom/base/nsGlobalWindow.cpp
layout/generic/nsObjectFrame.cpp
layout/reftests/svg/smil/motion/animateMotion-rotate-3.svg
--- a/accessible/src/xul/Makefile.in
+++ b/accessible/src/xul/Makefile.in
@@ -67,12 +67,9 @@ CPPSRCS = \
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = \
   -I$(srcdir) \
   -I$(srcdir)/../base \
   -I$(srcdir)/../html \
-  -I$(srcdir)/../../../layout/html/base/src \
-  -I$(srcdir)/../../../layout/html/forms/src \
-  -I$(srcdir)/../../../layout/html/forms/public \
   $(NULL)
--- a/caps/src/nsSecurityManagerFactory.cpp
+++ b/caps/src/nsSecurityManagerFactory.cpp
@@ -315,22 +315,22 @@ static JSFunctionSpec PrivilegeManager_s
     { "setCanEnablePrivilege", netscape_security_setCanEnablePrivilege,
                                                                     2,0},
     { "invalidate",            netscape_security_invalidate,        1,0},
     {nsnull,nsnull,0,0}
 };
 
 /*
  * "Steal" calls to netscape.security.PrivilegeManager.enablePrivilege,
- * et. al. so that code that worked with 4.0 can still work.
+ * et al. so that code that worked with 4.0 can still work.
  */
 NS_IMETHODIMP 
 nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
 {
-    JSContext *cx = (JSContext *) aScriptContext->GetNativeContext();
+    JSContext* cx = aScriptContext->GetNativeContext();
     JSObject *global = JS_GetGlobalObject(cx);
     OBJ_TO_INNER_OBJECT(cx, global);
 
     /*
      * Find Object.prototype's class by walking up the global object's
      * prototype chain.
      */
     JSObject *obj = global;
--- a/content/base/public/nsContentCID.h
+++ b/content/base/public/nsContentCID.h
@@ -116,20 +116,16 @@
 // {09F689E0-B4DA-11d2-A68B-00104BDE6048}
 #define NS_EVENTLISTENERMANAGER_CID \
 { 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
 
 // {64F300A1-C88C-11d3-97FB-00400553EEF0}
 #define NS_XBLSERVICE_CID \
 { 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
 
-// 3a9cd622-264d-11d4-ba06-0060b0fc76dd
-#define NS_DOM_IMPLEMENTATION_CID \
-{ 0x3a9cd622, 0x264d, 0x11d4, {0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd } }
-
 // {4aef38b7-6364-4e23-a5e7-12f837fbbd9c}
 #define NS_XMLCONTENTSERIALIZER_CID \
 { 0x4aef38b7, 0x6364, 0x4e23, { 0xa5, 0xe7, 0x12, 0xf8, 0x37, 0xfb, 0xbd, 0x9c } }
 
 // {e7c2aaf5-c11a-4954-9dbf-e28edec1fd91}
 #define NS_XHTMLCONTENTSERIALIZER_CID \
 { 0xe7c2aaf5, 0xc11a, 0x4954, { 0x9d, 0xbf, 0xe2, 0x8e, 0xde, 0xc1, 0xfd, 0x91 } }
 
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1879,17 +1879,18 @@ NS_NewDocumentFragment(nsIDOMDocumentFra
 nsresult
 NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
                   const nsAString& aNamespaceURI, 
                   const nsAString& aQualifiedName, 
                   nsIDOMDocumentType* aDoctype,
                   nsIURI* aDocumentURI,
                   nsIURI* aBaseURI,
                   nsIPrincipal* aPrincipal,
-                  PRBool aLoadedAsData);
+                  PRBool aLoadedAsData,
+                  nsIScriptGlobalObject* aEventObject);
 nsresult
 NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
 
 inline nsIDocument*
 nsINode::GetOwnerDocument() const
 {
   nsIDocument* ownerDoc = GetOwnerDoc();
 
deleted file mode 100644
--- a/content/base/public/nsIPrivateDOMImplementation.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsIPrivateDOMImplementation_h__
-#define nsIPrivateDOMImplementation_h__
-
-#include "nsISupports.h"
-
-class nsIURI;
-class nsIPrincipal;
-
-/*
- * Event listener manager interface.
- */
-#define NS_IPRIVATEDOMIMPLEMENTATION_IID \
-{ /* 87c20441-8b0d-4383-a189-52fef1dd5d8a */ \
-0x87c20441, 0x8b0d, 0x4383, \
- { 0xa1, 0x89, 0x52, 0xfe, 0xf1, 0xdd, 0x5d, 0x8a } }
-
-class nsIPrivateDOMImplementation : public nsISupports {
-
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRIVATEDOMIMPLEMENTATION_IID)
-
-  NS_IMETHOD Init(nsIURI* aDocumentURI, nsIURI* aBaseURI,
-                  nsIPrincipal* aPrincipal) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIPrivateDOMImplementation,
-                              NS_IPRIVATEDOMIMPLEMENTATION_IID)
-
-nsresult
-NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult);
-
-#endif // nsIPrivateDOMImplementation_h__
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -1,12 +1,11 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * vim: set ts=2 sw=2 et tw=78:
- *
- * ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sw=2 et tw=78: */
+/* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -1281,21 +1280,20 @@ nsContentUtils::GetContextFromDocument(n
   if (!sgo) {
     // No script global, no context.
     return nsnull;
   }
 
   nsIScriptContext *scx = sgo->GetContext();
   if (!scx) {
     // No context left in the scope...
-
     return nsnull;
   }
 
-  return (JSContext *)scx->GetNativeContext();
+  return scx->GetNativeContext();
 }
 
 // static
 nsresult
 nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument,
                                    nsIDocument *aNewDocument, JSContext **aCx,
                                    JSObject **aNewScope)
 {
@@ -2554,17 +2552,17 @@ nsCxPusher::Push(nsIDOMEventTarget *aCur
     // Nothing to do here, I guess.  Have to return true so that event firing
     // will still work correctly even if there is no associated JSContext
     return PR_TRUE;
   }
 
   JSContext* cx = nsnull;
 
   if (scx) {
-    cx = static_cast<JSContext*>(scx->GetNativeContext());
+    cx = scx->GetNativeContext();
     // Bad, no JSContext from script context!
     NS_ENSURE_TRUE(cx, PR_FALSE);
   }
 
   // If there's no native context in the script context it must be
   // in the process or being torn down. We don't want to notify the
   // script context about scripts having been evaluated in such a
   // case, calling with a null cx is fine in that case.
@@ -3683,21 +3681,20 @@ nsContentUtils::CreateDocument(const nsA
                                nsIDOMDocumentType* aDoctype,
                                nsIURI* aDocumentURI, nsIURI* aBaseURI,
                                nsIPrincipal* aPrincipal,
                                nsIScriptGlobalObject* aEventObject,
                                nsIDOMDocument** aResult)
 {
   nsresult rv = NS_NewDOMDocument(aResult, aNamespaceURI, aQualifiedName,
                                   aDoctype, aDocumentURI, aBaseURI, aPrincipal,
-                                  PR_TRUE);
+                                  PR_TRUE, aEventObject);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDocument> document = do_QueryInterface(*aResult);
-  document->SetScriptHandlingObject(aEventObject);
   
   // created documents are immediately "complete" (ready to use)
   document->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
   return NS_OK;
 }
 
 /* static */
 nsresult
--- a/content/base/src/nsDOMDocumentType.cpp
+++ b/content/base/src/nsDOMDocumentType.cpp
@@ -50,44 +50,29 @@
 #include "nsIDocument.h"
 #include "nsIXPConnect.h"
 #include "nsIDOMDocument.h"
 #include "xpcpublic.h"
 
 nsresult
 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
                       nsNodeInfoManager *aNodeInfoManager,
-                      nsIPrincipal *aPrincipal,
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset)
 {
-  NS_PRECONDITION(aNodeInfoManager || aPrincipal,
-                  "Must have a principal if no nodeinfo manager.");
   NS_ENSURE_ARG_POINTER(aDocType);
   NS_ENSURE_ARG_POINTER(aName);
 
-  nsRefPtr<nsNodeInfoManager> nimgr;
-  if (aNodeInfoManager) {
-    nimgr = aNodeInfoManager;
-  }
-  else {
-    nimgr = new nsNodeInfoManager();
-    nsresult rv = nimgr->Init(nsnull);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nimgr->SetDocumentPrincipal(aPrincipal);
-  }
-
   nsCOMPtr<nsINodeInfo> ni =
-    nimgr->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nsnull,
-                       kNameSpaceID_None,
-                       nsIDOMNode::DOCUMENT_TYPE_NODE,
-                       aName);
+    aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nsnull,
+                                  kNameSpaceID_None,
+                                  nsIDOMNode::DOCUMENT_TYPE_NODE,
+                                  aName);
   NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
 
   *aDocType = new nsDOMDocumentType(ni.forget(), aPublicId, aSystemId,
                                     aInternalSubset);
   NS_ADDREF(*aDocType);
 
   return NS_OK;
 }
@@ -171,64 +156,8 @@ nsDOMDocumentType::GetInternalSubset(nsA
 nsGenericDOMDataNode*
 nsDOMDocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
 {
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   return new nsDOMDocumentType(ni.forget(), mPublicId, mSystemId,
                                mInternalSubset);
 }
 
-nsresult
-nsDOMDocumentType::BindToTree(nsIDocument *aDocument, nsIContent *aParent,
-                              nsIContent *aBindingParent,
-                              PRBool aCompileEventHandlers)
-{
-  if (!HasSameOwnerDoc(NODE_FROM(aParent, aDocument))) {
-    NS_ASSERTION(!GetOwnerDoc(), "Need to adopt or import first!");
-
-    // DocumentType nodes are the only nodes that can have a null ownerDocument
-    // according to the DOM spec, so we need to give them a new nodeinfo in that
-    // case.
-    // XXX We may want to move this to nsDOMImplementation::CreateDocument if
-    //     we want to rely on the nodeinfo and wrappers being right before
-    //     getting into ReplaceOrInsertBefore or doInsertChildAt. That would
-    //     break inserting DOMDocumentType nodes through other DOM methods
-    //     though.
-    nsNodeInfoManager *nimgr = aParent ?
-      aParent->NodeInfo()->NodeInfoManager() :
-      aDocument->NodeInfoManager();
-    nsCOMPtr<nsINodeInfo> newNodeInfo;
-    newNodeInfo = nimgr->GetNodeInfo(mNodeInfo->NameAtom(),
-                                     mNodeInfo->GetPrefixAtom(),
-                                     mNodeInfo->NamespaceID(),
-                                     nsIDOMNode::DOCUMENT_TYPE_NODE,
-                                     mNodeInfo->GetExtraName());
-    NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);
-
-    mNodeInfo.swap(newNodeInfo);
-
-    JSObject *oldScope = GetWrapper();
-    if (oldScope) {
-      nsIXPConnect *xpc = nsContentUtils::XPConnect();
-
-      JSContext *cx = nsnull;
-      JSObject *newScope = nsnull;
-      nsresult rv = nsContentUtils::GetContextAndScope(nsnull,
-                                                       nimgr->GetDocument(),
-                                                       &cx, &newScope);
-      if (cx && xpc) {
-        nsISupports *node = NS_ISUPPORTS_CAST(nsIContent*, this);
-        nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;
-        rv = xpc->ReparentWrappedNativeIfFound(cx, oldScope, newScope, node,
-                                               getter_AddRefs(oldWrapper));
-      }
-
-      if (NS_FAILED(rv)) {
-        mNodeInfo.swap(newNodeInfo);
-
-        return rv;
-      }
-    }
-  }
-
-  return nsGenericDOMDataNode::BindToTree(aDocument, aParent, aBindingParent,
-                                          aCompileEventHandlers);
-}
--- a/content/base/src/nsDOMDocumentType.h
+++ b/content/base/src/nsDOMDocumentType.h
@@ -96,32 +96,28 @@ public:
     return NS_OK;
   }
 
   // nsINode
   virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
 
   // nsIContent overrides
   virtual const nsTextFragment* GetText();
-  virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
-                              nsIContent *aBindingParent,
-                              PRBool aCompileEventHandlers);
 
   virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo,
                                               PRBool aCloneText) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 protected:
   nsString mPublicId;
   nsString mSystemId;
   nsString mInternalSubset;
 };
 
 nsresult
 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
-                      nsNodeInfoManager *aOwnerDoc,
-                      nsIPrincipal *aPrincipal,
+                      nsNodeInfoManager* aNodeInfoManager,
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset);
 
 #endif // nsDOMDocumentType_h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1316,75 +1316,63 @@ nsDOMStyleSheetSetList::GetSets(nsTArray
 
 // ==================================================================
 // =
 // ==================================================================
 
 class nsDOMImplementation : public nsIDOMDOMImplementation
 {
 public:
-  nsDOMImplementation(nsIScriptGlobalObject* aScriptObject,
+  nsDOMImplementation(nsIDocument* aOwner,
+                      nsIScriptGlobalObject* aScriptObject,
                       nsIURI* aDocumentURI,
-                      nsIURI* aBaseURI,
-                      nsIPrincipal* aPrincipal);
+                      nsIURI* aBaseURI);
   virtual ~nsDOMImplementation();
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMImplementation)
 
   // nsIDOMDOMImplementation
   NS_DECL_NSIDOMDOMIMPLEMENTATION
 
 protected:
+  nsCOMPtr<nsIDocument> mOwner;
   nsWeakPtr mScriptObject;
   nsCOMPtr<nsIURI> mDocumentURI;
   nsCOMPtr<nsIURI> mBaseURI;
-  nsCOMPtr<nsIPrincipal> mPrincipal;
 };
 
-
-nsresult
-NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult)
-{
-  *aInstancePtrResult = new nsDOMImplementation(nsnull, nsnull, nsnull, nsnull);
-  if (!*aInstancePtrResult) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  NS_ADDREF(*aInstancePtrResult);
-
-  return NS_OK;
-}
-
-nsDOMImplementation::nsDOMImplementation(nsIScriptGlobalObject* aScriptObject,
+nsDOMImplementation::nsDOMImplementation(nsIDocument* aOwner,
+                                         nsIScriptGlobalObject* aScriptObject,
                                          nsIURI* aDocumentURI,
-                                         nsIURI* aBaseURI,
-                                         nsIPrincipal* aPrincipal)
-  : mScriptObject(do_GetWeakReference(aScriptObject)),
+                                         nsIURI* aBaseURI)
+  : mOwner(aOwner),
+    mScriptObject(do_GetWeakReference(aScriptObject)),
     mDocumentURI(aDocumentURI),
-    mBaseURI(aBaseURI),
-    mPrincipal(aPrincipal)
+    mBaseURI(aBaseURI)
 {
 }
 
 nsDOMImplementation::~nsDOMImplementation()
 {
 }
 
 DOMCI_DATA(DOMImplementation, nsDOMImplementation)
 
 // QueryInterface implementation for nsDOMImplementation
-NS_INTERFACE_MAP_BEGIN(nsDOMImplementation)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMImplementation)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMImplementation)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMImplementation)
 NS_INTERFACE_MAP_END
 
-
-NS_IMPL_ADDREF(nsDOMImplementation)
-NS_IMPL_RELEASE(nsDOMImplementation)
+NS_IMPL_CYCLE_COLLECTION_1(nsDOMImplementation, mOwner)
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMImplementation)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMImplementation)
 
 
 NS_IMETHODIMP
 nsDOMImplementation::HasFeature(const nsAString& aFeature,
                                 const nsAString& aVersion,
                                 PRBool* aReturn)
 {
   return nsGenericElement::InternalIsSupported(
@@ -1394,27 +1382,29 @@ nsDOMImplementation::HasFeature(const ns
 
 NS_IMETHODIMP
 nsDOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
                                         const nsAString& aPublicId,
                                         const nsAString& aSystemId,
                                         nsIDOMDocumentType** aReturn)
 {
   *aReturn = nsnull;
+  NS_ENSURE_STATE(mOwner);
 
   nsresult rv = nsContentUtils::CheckQName(aQualifiedName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAtom> name = do_GetAtom(aQualifiedName);
   NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
 
   // Indicate that there is no internal subset (not just an empty one)
   nsAutoString voidString;
   voidString.SetIsVoid(PR_TRUE);
-  return NS_NewDOMDocumentType(aReturn, nsnull, mPrincipal, name, aPublicId,
+  return NS_NewDOMDocumentType(aReturn, mOwner->NodeInfoManager(),
+                               name, aPublicId,
                                aSystemId, voidString);
 }
 
 NS_IMETHODIMP
 nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
                                     const nsAString& aQualifiedName,
                                     nsIDOMDocumentType* aDoctype,
                                     nsIDOMDocument** aReturn)
@@ -1438,63 +1428,57 @@ nsDOMImplementation::CreateDocument(cons
       return NS_ERROR_DOM_NAMESPACE_ERR;
     }
   }
   else if (DOMStringIsNull(aQualifiedName) &&
            !DOMStringIsNull(aNamespaceURI)) {
     return NS_ERROR_DOM_NAMESPACE_ERR;
   }
 
-  if (aDoctype) {
-    nsCOMPtr<nsIDOMDocument> owner;
-    aDoctype->GetOwnerDocument(getter_AddRefs(owner));
-    if (owner) {
-      return NS_ERROR_DOM_WRONG_DOCUMENT_ERR;
-    }
-  }
-
   nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
     do_QueryReferent(mScriptObject);
   
   NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
 
   return nsContentUtils::CreateDocument(aNamespaceURI, aQualifiedName, aDoctype,
-                                        mDocumentURI, mBaseURI, mPrincipal,
+                                        mDocumentURI, mBaseURI,
+                                        mOwner->NodePrincipal(),
                                         scriptHandlingObject, aReturn);
 }
 
 NS_IMETHODIMP
 nsDOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
                                         nsIDOMDocument** aReturn)
 {
-  *aReturn = NULL;
+  *aReturn = nsnull;
+  NS_ENSURE_STATE(mOwner);
 
   nsCOMPtr<nsIDOMDocumentType> doctype;
   // Indicate that there is no internal subset (not just an empty one)
   nsAutoString voidString;
   voidString.SetIsVoid(true);
   nsresult rv = NS_NewDOMDocumentType(getter_AddRefs(doctype),
-                                      NULL, // aNodeInfoManager
-                                      mPrincipal, // aPrincipal
+                                      mOwner->NodeInfoManager(),
                                       nsGkAtoms::html, // aName
                                       EmptyString(), // aPublicId
                                       EmptyString(), // aSystemId
                                       voidString); // aInternalSubset
   NS_ENSURE_SUCCESS(rv, rv);
 
 
   nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
     do_QueryReferent(mScriptObject);
 
   NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
                                                        
   nsCOMPtr<nsIDOMDocument> document;
   rv = nsContentUtils::CreateDocument(EmptyString(), EmptyString(),
                                       doctype, mDocumentURI, mBaseURI,
-                                      mPrincipal, scriptHandlingObject,
+                                      mOwner->NodePrincipal(),
+                                      scriptHandlingObject,
                                       getter_AddRefs(document));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
 
   nsCOMPtr<nsIContent> root;
   rv = doc->CreateElem(NS_LITERAL_STRING("html"), NULL, kNameSpaceID_XHTML,
                        false, getter_AddRefs(root));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -3808,17 +3792,17 @@ nsDocument::SetScriptGlobalObject(nsIScr
 #ifdef DEBUG
     if (!mWillReparent) {
       // We really shouldn't have a wrapper here but if we do we need to make sure
       // it has the correct parent.
       JSObject *obj = GetWrapperPreserveColor();
       if (obj) {
         JSObject *newScope = aScriptGlobalObject->GetGlobalJSObject();
         nsIScriptContext *scx = aScriptGlobalObject->GetContext();
-        JSContext *cx = scx ? (JSContext *)scx->GetNativeContext() : nsnull;
+        JSContext *cx = scx ? scx->GetNativeContext() : nsnull;
         if (!cx) {
           nsContentUtils::ThreadJSContextStack()->Peek(&cx);
           if (!cx) {
             nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(&cx);
             NS_ASSERTION(cx, "Uhoh, no context, this is bad!");
           }
         }
         if (cx) {
@@ -4310,18 +4294,17 @@ nsDocument::GetImplementation(nsIDOMDOMI
   if (!mDOMImplementation) {
     nsCOMPtr<nsIURI> uri;
     NS_NewURI(getter_AddRefs(uri), "about:blank");
     NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY);
     PRBool hasHadScriptObject = PR_TRUE;
     nsIScriptGlobalObject* scriptObject =
       GetScriptHandlingObject(hasHadScriptObject);
     NS_ENSURE_STATE(scriptObject || !hasHadScriptObject);
-    mDOMImplementation = new nsDOMImplementation(scriptObject, uri, uri,
-                                                 NodePrincipal());
+    mDOMImplementation = new nsDOMImplementation(this, scriptObject, uri, uri);
     if (!mDOMImplementation) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   NS_ADDREF(*aImplementation = mDOMImplementation);
 
   return NS_OK;
@@ -4801,16 +4784,17 @@ nsDocument::ImportNode(nsIDOMNode* aImpo
   switch (nodeType) {
     case nsIDOMNode::ATTRIBUTE_NODE:
     case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
     case nsIDOMNode::ELEMENT_NODE:
     case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
     case nsIDOMNode::TEXT_NODE:
     case nsIDOMNode::CDATA_SECTION_NODE:
     case nsIDOMNode::COMMENT_NODE:
+    case nsIDOMNode::DOCUMENT_TYPE_NODE:
     {
       nsCOMPtr<nsINode> imported = do_QueryInterface(aImportedNode);
       NS_ENSURE_TRUE(imported, NS_ERROR_FAILURE);
 
       nsCOMPtr<nsIDOMNode> newNode;
       nsCOMArray<nsINode> nodesWithProperties;
       rv = nsNodeUtils::Clone(imported, aDeep, mNodeInfoManager,
                               nodesWithProperties, getter_AddRefs(newNode));
@@ -6114,16 +6098,17 @@ nsDocument::AdoptNode(nsIDOMNode *aAdopt
       break;
     }
     case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
     case nsIDOMNode::ELEMENT_NODE:
     case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
     case nsIDOMNode::TEXT_NODE:
     case nsIDOMNode::CDATA_SECTION_NODE:
     case nsIDOMNode::COMMENT_NODE:
+    case nsIDOMNode::DOCUMENT_TYPE_NODE:
     {
       // We don't want to adopt an element into its own contentDocument or into
       // a descendant contentDocument, so we check if the frameElement of this
       // document or any of its parents is the adopted node or one of its
       // descendants.
       nsIDocument *doc = this;
       do {
         nsPIDOMWindow *win = doc->GetWindow();
@@ -6146,17 +6131,16 @@ nsDocument::AdoptNode(nsIDOMNode *aAdopt
 
       break;
     }
     case nsIDOMNode::ENTITY_REFERENCE_NODE:
     {
       return NS_ERROR_NOT_IMPLEMENTED;
     }
     case nsIDOMNode::DOCUMENT_NODE:
-    case nsIDOMNode::DOCUMENT_TYPE_NODE:
     case nsIDOMNode::ENTITY_NODE:
     case nsIDOMNode::NOTATION_NODE:
     {
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
     default:
     {
       NS_WARNING("Don't know how to adopt this nodetype for adoptNode.");
@@ -6418,17 +6402,17 @@ nsDocument::IsScriptEnabled()
   NS_ENSURE_TRUE(sm, PR_FALSE);
 
   nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
   NS_ENSURE_TRUE(globalObject, PR_FALSE);
 
   nsIScriptContext *scriptContext = globalObject->GetContext();
   NS_ENSURE_TRUE(scriptContext, PR_FALSE);
 
-  JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
+  JSContext* cx = scriptContext->GetNativeContext();
   NS_ENSURE_TRUE(cx, PR_FALSE);
 
   PRBool enabled;
   nsresult rv = sm->CanExecuteScripts(cx, NodePrincipal(), &enabled);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
   return enabled;
 }
 
--- a/content/base/src/nsEventSource.cpp
+++ b/content/base/src/nsEventSource.cpp
@@ -1345,17 +1345,17 @@ nsEventSource::DispatchAllMessageEvents(
 
   // Let's play get the JSContext
   nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mOwner);
   NS_ENSURE_TRUE(sgo,);
 
   nsIScriptContext* scriptContext = sgo->GetContext();
   NS_ENSURE_TRUE(scriptContext,);
 
-  JSContext* cx = (JSContext*)scriptContext->GetNativeContext();
+  JSContext* cx = scriptContext->GetNativeContext();
   NS_ENSURE_TRUE(cx,);
 
   while (mMessagesToDispatch.GetSize() > 0) {
     nsAutoPtr<Message>
       message(static_cast<Message*>(mMessagesToDispatch.PopFront()));
 
     // Now we can turn our string into a jsval
     jsval jsData;
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -2065,17 +2065,17 @@ nsFrameLoader::EnsureMessageManager()
       mMessageManager->SetCallbackData(mRemoteBrowserShown ? this : nsnull);
     }
     return NS_OK;
   }
 
   nsIScriptContext* sctx = mOwnerContent->GetContextForEventHandlers(&rv);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(sctx);
-  JSContext* cx = static_cast<JSContext*>(sctx->GetNativeContext());
+  JSContext* cx = sctx->GetNativeContext();
   NS_ENSURE_STATE(cx);
 
   nsCOMPtr<nsIDOMChromeWindow> chromeWindow =
     do_QueryInterface(mOwnerContent->GetOwnerDoc()->GetWindow());
   NS_ENSURE_STATE(chromeWindow);
   nsCOMPtr<nsIChromeFrameMessageManager> parentManager;
   chromeWindow->GetMessageManager(getter_AddRefs(parentManager));
 
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -3589,24 +3589,18 @@ nsINode::doInsertChildAt(nsIContent* aKi
   // react to unexpected attribute changes.
   nsMutationGuard::DidMutate();
 
   // Do this before checking the child-count since this could cause mutations
   nsIDocument* doc = GetCurrentDoc();
   mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, aNotify);
 
   if (!HasSameOwnerDoc(aKid)) {
-    // DocumentType nodes are the only nodes that can have a null
-    // ownerDocument according to the DOM spec, and we need to allow
-    // inserting them w/o calling AdoptNode().
-    if (aKid->NodeType() != nsIDOMNode::DOCUMENT_TYPE_NODE ||
-        aKid->GetOwnerDoc()) {
-      rv = AdoptNodeIntoOwnerDoc(this, aKid);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
+    rv = AdoptNodeIntoOwnerDoc(this, aKid);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   PRUint32 childCount = aChildArray.ChildCount();
   NS_ENSURE_TRUE(aIndex <= childCount, NS_ERROR_ILLEGAL_VALUE);
   PRBool isAppend = (aIndex == childCount);
 
   rv = aChildArray.InsertChildAt(aKid, aIndex);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -4108,19 +4102,17 @@ nsINode::ReplaceOrInsertBefore(PRBool aR
     }
   }
 
   // Move new child over to our document if needed. Do this after removing
   // it from its parent so that AdoptNode doesn't fire DOMNodeRemoved
   // DocumentType nodes are the only nodes that can have a null
   // ownerDocument according to the DOM spec, and we need to allow
   // inserting them w/o calling AdoptNode().
-  if (!HasSameOwnerDoc(newContent) &&
-      (nodeType != nsIDOMNode::DOCUMENT_TYPE_NODE ||
-       newContent->GetOwnerDoc())) {
+  if (!HasSameOwnerDoc(newContent)) {
     res = AdoptNodeIntoOwnerDoc(this, aNewChild);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   /*
    * Check if we're inserting a document fragment. If we are, we need
    * to remove the children of the document fragment and add them
    * individually (i.e. we don't add the actual document fragment).
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -685,16 +685,18 @@ GK_ATOM(onkeydown, "onkeydown")
 GK_ATOM(onkeypress, "onkeypress")
 GK_ATOM(onkeyup, "onkeyup")
 GK_ATOM(onLoad, "onLoad")
 GK_ATOM(onload, "onload")
 GK_ATOM(onpopstate, "onpopstate")
 GK_ATOM(only, "only")               // this one is not an event
 GK_ATOM(onmessage, "onmessage")
 GK_ATOM(onmousedown, "onmousedown")
+GK_ATOM(onmouseenter, "onmouseenter")
+GK_ATOM(onmouseleave, "onmouseleave")
 GK_ATOM(onmousemove, "onmousemove")
 GK_ATOM(onmouseout, "onmouseout")
 GK_ATOM(onmouseover, "onmouseover")
 GK_ATOM(onMozMouseHittest, "onMozMouseHittest")
 GK_ATOM(onmouseup, "onmouseup")
 GK_ATOM(onMozAfterPaint, "onMozAfterPaint")
 GK_ATOM(onMozBeforePaint, "onMozBeforePaint")
 GK_ATOM(onmozfullscreenchange, "onmozfullscreenchange")
--- a/content/base/src/nsNodeInfoManager.h
+++ b/content/base/src/nsNodeInfoManager.h
@@ -134,17 +134,16 @@ public:
     return mBindingManager;
   }
 
 protected:
   friend class nsDocument;
   friend class nsXULPrototypeDocument;
   friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
                                         nsNodeInfoManager *,
-                                        nsIPrincipal *,
                                         nsIAtom *,
                                         const nsAString& ,
                                         const nsAString& ,
                                         const nsAString& );
 
   /**
    * Sets the principal of the document this nodeinfo manager belongs to.
    */
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -566,16 +566,19 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
 #ifdef MOZ_MEDIA
           if (elm->MayHaveAudioAvailableEventListener()) {
             window->SetHasAudioAvailableEventListeners();
           }
 #endif
           if (elm->MayHaveTouchEventListener()) {
             window->SetHasTouchEventListeners();
           }
+          if (elm->MayHaveMouseEnterLeaveEventListener()) {
+            window->SetHasMouseEnterLeaveEventListeners();
+          }
         }
       }
     }
 
 #ifdef MOZ_MEDIA
     if (wasRegistered && oldDoc != newDoc) {
       nsCOMPtr<nsIDOMHTMLMediaElement> domMediaElem(do_QueryInterface(aNode));
       if (domMediaElem) {
--- a/content/base/src/nsScriptLoader.cpp
+++ b/content/base/src/nsScriptLoader.cpp
@@ -905,17 +905,17 @@ nsScriptLoader::EvaluateScript(nsScriptL
                           aRequest->mLineNo, aRequest->mJSVersion, nsnull,
                           &isUndefined);
 
   // Put the old script back in case it wants to do anything else.
   mCurrentScript = oldCurrent;
 
   JSContext *cx = nsnull; // Initialize this to keep GCC happy.
   if (stid == nsIProgrammingLanguage::JAVASCRIPT) {
-    cx = (JSContext *)context->GetNativeContext();
+    cx = context->GetNativeContext();
     ::JS_BeginRequest(cx);
     NS_ASSERTION(!::JS_IsExceptionPending(cx),
                  "JS_ReportPendingException wasn't called in EvaluateString");
   }
 
   context->SetProcessingScriptTag(oldProcessingScriptTag);
 
   if (stid == nsIProgrammingLanguage::JAVASCRIPT) {
--- a/content/base/src/nsWebSocket.cpp
+++ b/content/base/src/nsWebSocket.cpp
@@ -896,17 +896,17 @@ nsWebSocket::CreateAndDispatchMessageEve
 
   // Let's play get the JSContext
   nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mOwner);
   NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
 
   nsIScriptContext* scriptContext = sgo->GetContext();
   NS_ENSURE_TRUE(scriptContext, NS_ERROR_FAILURE);
 
-  JSContext* cx = (JSContext*)scriptContext->GetNativeContext();
+  JSContext* cx = scriptContext->GetNativeContext();
   NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
 
   // Now we can turn our string into a jsval
 
   jsval jsData;
   {
     NS_ConvertUTF8toUTF16 utf16Data(aData);
     JSString* jsString;
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -501,16 +501,17 @@ include $(topsrcdir)/config/rules.mk
 		somedatas.resource \
 		somedatas.resource^headers^ \
 		delayedServerEvents.sjs \
 		test_bug664916.html \
 		test_bug666604.html \
 		test_bug675121.html \
 		file_bug675121.sjs \
 		test_bug654352.html \
+		test_bug675166.html \
 		test_bug682592.html \
 		bug682592-subframe.html \
 		bug682592-subframe-ref.html \
 		test_bug685798.html \
 		$(NULL)
 
 _CHROME_FILES =	\
 		test_bug357450.js \
--- a/content/base/test/test_bug450160.html
+++ b/content/base/test/test_bug450160.html
@@ -22,17 +22,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 function testHTMLDocuments(ids, isXHTML) {
   for (var i = 0; i < ids.length; ++i) {
     var docType1 =
       document.implementation.createDocumentType(isXHTML ? "html" : "HTML",
                                                  ids[i],
                                                  null);
     ok(docType1, "No doctype?");
-    ok(!docType1.ownerDocument, "docType shouldn't have ownerDocument!");
+    ok(docType1.ownerDocument, "docType should have ownerDocument!");
     var doc1 = document.implementation.createDocument(null, null, docType1);
     is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
     ok(!doc1.documentElement, "Document shouldn't have document element!");
     is(doc1.body, null, "Shouldn't have .body!");
     ok(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument,
        "Document should be an HTML document!");
     ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
        "Document shouldn't be an SVG document!");
@@ -59,17 +59,17 @@ function testHTMLDocuments(ids, isXHTML)
 }
 
 function testSVGDocument() {
   var docType1 =
       document.implementation.createDocumentType("svg",
                                                  "-//W3C//DTD SVG 1.1//EN",
                                                  null);
   ok(docType1, "No doctype?");
-  ok(!docType1.ownerDocument, "docType shouldn't have ownerDocument!");
+  ok(docType1.ownerDocument, "docType should have ownerDocument!");
   var doc1 = document.implementation.createDocument(null, null, docType1);
   is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
   ok(!doc1.documentElement, "Document shouldn't have document element!");
   ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
      "Document shouldn't be an HTML document!");
   ok(doc1 instanceof Components.interfaces.nsIDOMSVGDocument,
      "Document should be an SVG document!");
 
@@ -86,17 +86,17 @@ function testSVGDocument() {
   ok(doc2.rootElement, "Should have .rootElement in document");
   is(doc2.rootElement.localName, "svg", "Wrong .rootElement!");
 }
 
 function testFooBarDocument() {
   var docType1 =
       document.implementation.createDocumentType("FooBar", "FooBar", null);
   ok(docType1, "No doctype?");
-  ok(!docType1.ownerDocument, "docType shouldn't have ownerDocument!");
+  ok(docType1.ownerDocument, "docType should have ownerDocument!");
   var doc1 = document.implementation.createDocument(null, null, docType1);
   is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
   ok(!doc1.documentElement, "Document shouldn't have document element!");
   ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
      "Document shouldn't be an HTML document!");
   ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
      "Document shouldn't be an SVG document!");
 
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug675166.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=675166
+-->
+<head>
+  <title>Test for Bug 675166</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675166">Mozilla Bug 675166</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 675166 **/
+
+
+var dt = document.implementation.createDocumentType("html", null, null);
+isnot(dt.ownerDocument, null, "DocumentType should have ownerDocument");
+
+var d = document.implementation.createDocument(null, null, dt);
+is(dt.ownerDocument, d, "DocumentType shouldn't have null ownerDocument");
+
+try {
+  document.implementation.createDocument(null, null, dt);
+  ok(true, "Creating document using already bound document type shouldn't throw!");
+} catch(ex) {
+  ok(false, "Creating document using already bound document type shouldn't throw!");
+}
+
+var d2 = document.implementation.createDocument(null, null, null);
+var dt2 = document.implementation.createDocumentType("html", null, null);
+d2.appendChild(dt2);
+is(dt2.ownerDocument, d2, "DocumentType shouldn't have null ownerDocument");
+
+is(document.ownerDocument, null, "Document's ownerDocument should be null!");
+is(document.documentElement.ownerDocument, document,
+   "Element should have ownerDocument!")
+
+is(dt2.parentNode, d2, "parentNode should be document!");
+d2.removeChild(dt2);
+is(dt2.parentNode, null, "parentNode should be null!");
+
+d.adoptNode(dt2);
+d2.adoptNode(dt2);
+d2.appendChild(dt2);
+is(dt2.parentNode, d2, "parentNode should be document!");
+
+</script>
+</pre>
+</body>
+</html>
--- a/content/events/public/nsEventNameList.h
+++ b/content/events/public/nsEventNameList.h
@@ -222,16 +222,24 @@ EVENT(loadedmetadata,
 EVENT(loadstart,
       NS_LOADSTART,
       EventNameType_HTML,
       NS_EVENT_NULL)
 EVENT(mousedown,
       NS_MOUSE_BUTTON_DOWN,
       EventNameType_All,
       NS_MOUSE_EVENT)
+EVENT(mouseenter,
+      NS_MOUSEENTER,
+      EventNameType_All,
+      NS_MOUSE_EVENT)
+EVENT(mouseleave,
+      NS_MOUSELEAVE,
+      EventNameType_All,
+      NS_MOUSE_EVENT)
 EVENT(mousemove,
       NS_MOUSE_MOVE,
       EventNameType_All,
       NS_MOUSE_EVENT)
 EVENT(mouseout,
       NS_MOUSE_EXIT_SYNTH,
       EventNameType_All,
       NS_MOUSE_EVENT)
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -56,17 +56,17 @@
 #include "nsIScriptSecurityManager.h"
 #include "nsIScriptError.h"
 #include "nsDOMPopStateEvent.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 static const char* const sEventNames[] = {
-  "mousedown", "mouseup", "click", "dblclick", "mouseover",
+  "mousedown", "mouseup", "click", "dblclick", "mouseenter", "mouseleave", "mouseover",
   "mouseout", "MozMouseHittest", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
   "focus", "blur", "load", "popstate", "beforescriptexecute",
   "afterscriptexecute", "beforeunload", "unload",
   "hashchange", "readystatechange", "abort", "error",
   "submit", "reset", "change", "select", "input", "invalid", "text",
   "compositionstart", "compositionend", "popupshowing", "popupshown",
   "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
   "dragenter", "dragover", "dragexit", "dragdrop", "draggesture",
@@ -1104,16 +1104,20 @@ const char* nsDOMEvent::GetEventName(PRU
   case NS_MOUSE_BUTTON_DOWN:
     return sEventNames[eDOMEvents_mousedown];
   case NS_MOUSE_BUTTON_UP:
     return sEventNames[eDOMEvents_mouseup];
   case NS_MOUSE_CLICK:
     return sEventNames[eDOMEvents_click];
   case NS_MOUSE_DOUBLECLICK:
     return sEventNames[eDOMEvents_dblclick];
+  case NS_MOUSEENTER:
+    return sEventNames[eDOMEvents_mouseenter];
+  case NS_MOUSELEAVE:
+    return sEventNames[eDOMEvents_mouseleave];
   case NS_MOUSE_ENTER_SYNTH:
     return sEventNames[eDOMEvents_mouseover];
   case NS_MOUSE_EXIT_SYNTH:
     return sEventNames[eDOMEvents_mouseout];
   case NS_MOUSE_MOZHITTEST:
     return sEventNames[eDOMEvents_MozMouseHittest];
   case NS_MOUSE_MOVE:
     return sEventNames[eDOMEvents_mousemove];
--- a/content/events/src/nsDOMEvent.h
+++ b/content/events/src/nsDOMEvent.h
@@ -60,16 +60,18 @@ class nsDOMEvent : public nsIDOMEvent,
 public:
 
   // Note: this enum must be kept in sync with sEventNames in nsDOMEvent.cpp
   enum nsDOMEvents {
     eDOMEvents_mousedown=0,
     eDOMEvents_mouseup,
     eDOMEvents_click,
     eDOMEvents_dblclick,
+    eDOMEvents_mouseenter,
+    eDOMEvents_mouseleave,
     eDOMEvents_mouseover,
     eDOMEvents_mouseout,
     eDOMEvents_MozMouseHittest,
     eDOMEvents_mousemove,
     eDOMEvents_contextmenu,
     eDOMEvents_keydown,
     eDOMEvents_keyup,
     eDOMEvents_keypress,
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -129,16 +129,17 @@ PRUint32 nsEventListenerManager::sCreate
 
 nsEventListenerManager::nsEventListenerManager(nsISupports* aTarget) :
   mMayHavePaintEventListener(PR_FALSE),
   mMayHaveMutationListeners(PR_FALSE),
   mMayHaveCapturingListeners(PR_FALSE),
   mMayHaveSystemGroupListeners(PR_FALSE),
   mMayHaveAudioAvailableEventListener(PR_FALSE),
   mMayHaveTouchEventListener(PR_FALSE),
+  mMayHaveMouseEnterLeaveEventListener(PR_FALSE),
   mNoListenerForEvent(0),
   mTarget(aTarget)
 {
   NS_ASSERTION(aTarget, "unexpected null pointer");
 
   ++sCreatedCount;
 }
 
@@ -288,16 +289,29 @@ nsEventListenerManager::AddEventListener
               aTypeAtom == nsGkAtoms::ontouchmove ||
               aTypeAtom == nsGkAtoms::ontouchenter ||
               aTypeAtom == nsGkAtoms::ontouchleave ||
               aTypeAtom == nsGkAtoms::ontouchcancel)) {
     mMayHaveTouchEventListener = PR_TRUE;
     nsPIDOMWindow* window = GetInnerWindowForTarget();
     if (window)
       window->SetHasTouchEventListeners();
+  } else if (aTypeAtom == nsGkAtoms::onmouseenter ||
+             aTypeAtom == nsGkAtoms::onmouseleave) {
+    mMayHaveMouseEnterLeaveEventListener = PR_TRUE;
+    nsPIDOMWindow* window = GetInnerWindowForTarget();
+    if (window) {
+#ifdef DEBUG
+      nsCOMPtr<nsIDocument> d = do_QueryInterface(window->GetExtantDocument());
+      NS_WARN_IF_FALSE(!nsContentUtils::IsChromeDoc(d),
+                       "Please do not use mouseenter/leave events in chrome. "
+                       "They are slower than mouseover/out!");
+#endif
+      window->SetHasMouseEnterLeaveEventListeners();
+    }
   }
 }
 
 void
 nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, 
                                             PRUint32 aType,
                                             nsIAtom* aUserType,
                                             PRInt32 aFlags)
@@ -639,18 +653,17 @@ nsEventListenerManager::CompileEventHand
       nsIURI *uri = doc->GetDocumentURI();
       if (uri) {
         uri->GetSpec(url);
         lineNo = 1;
       }
     }
 
     nsCxPusher pusher;
-    if (aNeedsCxPush &&
-        !pusher.Push((JSContext*)context->GetNativeContext())) {
+    if (aNeedsCxPush && !pusher.Push(context->GetNativeContext())) {
       return NS_ERROR_FAILURE;
     }
 
 
     if (handlerOwner) {
       // Always let the handler owner compile the event
       // handler, as it may want to use a special
       // context or scope object.
--- a/content/events/src/nsEventListenerManager.h
+++ b/content/events/src/nsEventListenerManager.h
@@ -227,16 +227,18 @@ public:
   PRBool MayHaveAudioAvailableEventListener() { return mMayHaveAudioAvailableEventListener; }
 
   /**
    * Returns PR_TRUE if there may be a touch event listener registered,
    * PR_FALSE if there definitely isn't.
    */
   PRBool MayHaveTouchEventListener() { return mMayHaveTouchEventListener; }
 
+  PRBool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; }
+
   PRInt64 SizeOf() const;
 protected:
   nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
                               nsIDOMEventListener* aListener,
                               nsIDOMEvent* aDOMEvent,
                               nsIDOMEventTarget* aCurrentTarget,
                               PRUint32 aPhaseFlags,
                               nsCxPusher* aPusher);
@@ -297,17 +299,18 @@ protected:
   nsPIDOMWindow* GetInnerWindowForTarget();
 
   PRUint32 mMayHavePaintEventListener : 1;
   PRUint32 mMayHaveMutationListeners : 1;
   PRUint32 mMayHaveCapturingListeners : 1;
   PRUint32 mMayHaveSystemGroupListeners : 1;
   PRUint32 mMayHaveAudioAvailableEventListener : 1;
   PRUint32 mMayHaveTouchEventListener : 1;
-  PRUint32 mNoListenerForEvent : 26;
+  PRUint32 mMayHaveMouseEnterLeaveEventListener : 1;
+  PRUint32 mNoListenerForEvent : 25;
 
   nsAutoTObserverArray<nsListenerStruct, 2> mListeners;
   nsISupports*                              mTarget;  //WEAK
   nsCOMPtr<nsIAtom>                         mNoListenerForEventAtom;
 
   static PRUint32                           mInstanceCount;
   static jsid                               sAddListenerID;
 
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -3834,16 +3834,60 @@ nsEventStateManager::DispatchMouseEvent(
   }
 
   mCurrentTargetContent = nsnull;
   mCurrentTarget = previousTarget;
 
   return targetFrame;
 }
 
+class MouseEnterLeaveDispatcher
+{
+public:
+  MouseEnterLeaveDispatcher(nsEventStateManager* aESM,
+                            nsIContent* aTarget, nsIContent* aRelatedTarget,
+                            nsGUIEvent* aEvent, PRUint32 aType)
+  : mESM(aESM), mEvent(aEvent), mType(aType)
+  {
+    nsPIDOMWindow* win =
+      aTarget ? aTarget->GetOwnerDoc()->GetInnerWindow() : nsnull;
+    if (win && win->HasMouseEnterLeaveEventListeners()) {
+      mRelatedTarget = aRelatedTarget ?
+        aRelatedTarget->FindFirstNonNativeAnonymous() : nsnull;
+      nsINode* commonParent = nsnull;
+      if (aTarget && aRelatedTarget) {
+        commonParent =
+          nsContentUtils::GetCommonAncestor(aTarget, aRelatedTarget);
+      }
+      nsIContent* current = aTarget;
+      // Note, it is ok if commonParent is null!
+      while (current && current != commonParent) {
+        if (!current->IsInNativeAnonymousSubtree()) {
+          mTargets.AppendObject(current);
+        }
+        // mouseenter/leave is fired only on elements.
+        current = current->GetParent();
+      }
+    }
+  }
+
+  ~MouseEnterLeaveDispatcher()
+  {
+    for (PRInt32 i = 0; i < mTargets.Count(); ++i) {
+      mESM->DispatchMouseEvent(mEvent, mType, mTargets[i], mRelatedTarget);
+    }
+  }
+
+  nsEventStateManager*   mESM;
+  nsCOMArray<nsIContent> mTargets;
+  nsCOMPtr<nsIContent>   mRelatedTarget;
+  nsGUIEvent*            mEvent;
+  PRUint32               mType;
+};
+
 void
 nsEventStateManager::NotifyMouseOut(nsGUIEvent* aEvent, nsIContent* aMovingInto)
 {
   if (!mLastMouseOverElement)
     return;
   // Before firing mouseout, check for recursion
   if (mLastMouseOverElement == mFirstMouseOutEventElement)
     return;
@@ -3879,17 +3923,20 @@ nsEventStateManager::NotifyMouseOut(nsGU
   // Don't touch hover state if aMovingInto is non-null.  Caller will update
   // hover state itself, and we have optimizations for hover switching between
   // two nearby elements both deep in the DOM tree that would be defeated by
   // switching the hover state to null here.
   if (!aMovingInto) {
     // Unset :hover
     SetContentState(nsnull, NS_EVENT_STATE_HOVER);
   }
-  
+
+  MouseEnterLeaveDispatcher leaveDispatcher(this, mLastMouseOverElement, aMovingInto,
+                                            aEvent, NS_MOUSELEAVE);
+
   // Fire mouseout
   DispatchMouseEvent(aEvent, NS_MOUSE_EXIT_SYNTH,
                      mLastMouseOverElement, aMovingInto);
   
   mLastMouseOverFrame = nsnull;
   mLastMouseOverElement = nsnull;
   
   // Turn recursion protection back off
@@ -3927,16 +3974,19 @@ nsEventStateManager::NotifyMouseOver(nsG
   // of havoc.  Reverify and take care.
   if (mLastMouseOverElement == aContent)
     return;
 
   // Remember mLastMouseOverElement as the related content for the
   // DispatchMouseEvent() call below, since NotifyMouseOut() resets it, bug 298477.
   nsCOMPtr<nsIContent> lastMouseOverElement = mLastMouseOverElement;
 
+  MouseEnterLeaveDispatcher enterDispatcher(this, aContent, lastMouseOverElement,
+                                            aEvent, NS_MOUSEENTER);
+  
   NotifyMouseOut(aEvent, aContent);
 
   // Store the first mouseOver event we fire and don't refire mouseOver
   // to that element while the first mouseOver is still ongoing.
   mFirstMouseOverEventElement = aContent;
   
   SetContentState(aContent, NS_EVENT_STATE_HOVER);
   
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -61,16 +61,17 @@
 #include "nsContentUtils.h"
 
 class nsIPresShell;
 class nsIDocShell;
 class nsIDocShellTreeNode;
 class nsIDocShellTreeItem;
 class imgIContainer;
 class nsDOMDataTransfer;
+class MouseEnterLeaveDispatcher;
 
 namespace mozilla {
 namespace dom {
 class TabParent;
 }
 }
 
 /*
@@ -223,16 +224,18 @@ public:
   // if aContent is non-null, marks the object as active.
   static void SetActiveManager(nsEventStateManager* aNewESM,
                                nsIContent* aContent);
 
   // Sets the full-screen event state on aElement to aIsFullScreen.
   static void SetFullScreenState(mozilla::dom::Element* aElement, PRBool aIsFullScreen);
 
 protected:
+  friend class MouseEnterLeaveDispatcher;
+
   void UpdateCursor(nsPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
   /**
    * Turn a GUI mouse event into a mouse event targeted at the specified
    * content.  This returns the primary frame for the content (or null
    * if it goes away during the event).
    */
   nsIFrame* DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage,
                                nsIContent* aTargetContent,
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -66,16 +66,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug379120.html \
 		test_bug391568.xhtml \
 		test_bug402089.html \
 		test_bug405632.html \
 		test_bug409604.html \
 		test_bug412567.html \
 		test_bug426082.html \
 		test_bug427537.html \
+		test_bug432698.html \
 		test_bug443985.html \
 		test_bug447736.html \
 		test_bug450876.html \
 		test_bug456273.html \
 		test_bug457672.html \
 		test_bug428988.html \
 		bug457672.html \
 		test_draggableprop.html \
new file mode 100644
--- /dev/null
+++ b/content/events/test/test_bug432698.html
@@ -0,0 +1,190 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=432698
+-->
+<head>
+  <title>Test for Bug 432698</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=432698">Mozilla Bug 432698</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 432698 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTests);
+var outer;
+var middle;
+var inner;
+var outside;
+var container;
+var file;
+var iframe;
+var checkRelatedTarget = false;
+var expectedRelatedEnter = null;
+var expectedRelatedLeave = null;
+var mouseentercount = 0;
+var mouseleavecount = 0;
+var mouseovercount = 0;
+var mouseoutcount = 0;
+
+function sendMouseEvent(t, elem) {
+  var r = elem.getBoundingClientRect();
+  synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t});
+}
+
+function runTests() {
+  outer = document.getElementById("outertest");
+  middle = document.getElementById("middletest");
+  inner = document.getElementById("innertest");
+  outside = document.getElementById("outside");
+  container = document.getElementById("container");
+  file = document.getElementById("file");
+  iframe = document.getElementById("iframe");
+
+  // Make sure ESM thinks mouse is outside the test elements.
+  sendMouseEvent("mousemove", outside);
+
+  mouseentercount = 0;
+  mouseleavecount = 0;
+  mouseovercount = 0;
+  mouseoutcount = 0;
+  checkRelatedTarget = true;
+  expectedRelatedEnter = outside;
+  expectedRelatedLeave = inner;
+  sendMouseEvent("mousemove", inner);
+  is(mouseentercount, 3, "Unexpected mouseenter event count!");
+  is(mouseovercount, 1, "Unexpected mouseover event count!");
+  is(mouseoutcount, 0, "Unexpected mouseout event count!");
+  is(mouseleavecount, 0, "Unexpected mouseleave event count!");
+  expectedRelatedEnter = inner;
+  expectedRelatedLeave = outside;
+  sendMouseEvent("mousemove", outside);
+  is(mouseentercount, 3, "Unexpected mouseenter event count!");
+  is(mouseovercount, 1, "Unexpected mouseover event count!");
+  is(mouseoutcount, 1, "Unexpected mouseout event count!");
+  is(mouseleavecount, 3, "Unexpected mouseleave event count!");
+
+  // Event handling over native anonymous content.
+  var r = file.getBoundingClientRect();
+  expectedRelatedEnter = outside;
+  expectedRelatedLeave = file;
+  synthesizeMouse(file, r.width / 6, r.height / 2, {type: "mousemove"});
+  is(mouseentercount, 4, "Unexpected mouseenter event count!");
+  is(mouseovercount, 2, "Unexpected mouseover event count!");
+  is(mouseoutcount, 1, "Unexpected mouseout event count!");
+  is(mouseleavecount, 3, "Unexpected mouseleave event count!");
+
+  // Moving mouse over type="file" shouldn't cause mouseover/out/enter/leave events
+  synthesizeMouse(file, r.width - (r.width / 6), r.height / 2, {type: "mousemove"});
+  is(mouseentercount, 4, "Unexpected mouseenter event count!");
+  is(mouseovercount, 2, "Unexpected mouseover event count!");
+  is(mouseoutcount, 1, "Unexpected mouseout event count!");
+  is(mouseleavecount, 3, "Unexpected mouseleave event count!");
+
+  expectedRelatedEnter = file;
+  expectedRelatedLeave = outside;
+  sendMouseEvent("mousemove", outside);
+  is(mouseentercount, 4, "Unexpected mouseenter event count!");
+  is(mouseovercount, 2, "Unexpected mouseover event count!");
+  is(mouseoutcount, 2, "Unexpected mouseout event count!");
+  is(mouseleavecount, 4, "Unexpected mouseleave event count!");
+  
+  // Initialize iframe
+  iframe.contentDocument.documentElement.style.overflow = "hidden";
+  iframe.contentDocument.body.style.margin = "0px";
+  iframe.contentDocument.body.style.width = "100%";
+  iframe.contentDocument.body.style.height = "100%";
+  iframe.contentDocument.body.innerHTML =
+    "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>" +
+    "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>";
+  iframe.contentDocument.body.offsetLeft; // flush
+
+  iframe.contentDocument.body.firstChild.onmouseenter = menter;
+  iframe.contentDocument.body.firstChild.onmouseleave = mleave;
+  iframe.contentDocument.body.lastChild.onmouseenter = menter;
+  iframe.contentDocument.body.lastChild.onmouseleave = mleave;
+  r = iframe.getBoundingClientRect();
+  expectedRelatedEnter = outside;
+  expectedRelatedLeave = iframe;
+  // Move mouse inside the iframe.
+  synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "mousemove"},
+                  iframe.contentWindow);
+  synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "mousemove"},
+                  iframe.contentWindow);
+  is(mouseentercount, 7, "Unexpected mouseenter event count!");
+  expectedRelatedEnter = iframe;
+  expectedRelatedLeave = outside;
+  sendMouseEvent("mousemove", outside);
+  is(mouseleavecount, 7, "Unexpected mouseleave event count!");
+
+  SimpleTest.finish();
+}
+
+function menter(evt) {
+  ++mouseentercount;
+  evt.stopPropagation();
+  is(evt.bubbles, false, evt.type + " should not bubble!");
+  is(evt.cancelable, false, evt.type + " is not cancelable!");
+  is(evt.target, evt.currentTarget, "Wrong event target!");
+  ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
+     "Leaking nodes to another document?");
+  if (checkRelatedTarget && evt.target.ownerDocument == document) {
+    is(evt.relatedTarget, expectedRelatedEnter, "Wrong related target (mouseenter)");
+  }
+}
+
+function mleave(evt) {
+  ++mouseleavecount;
+  evt.stopPropagation();
+  is(evt.bubbles, false, evt.type + " should not bubble!");
+  is(evt.cancelable, false, evt.type + " is not cancelable!");
+  is(evt.target, evt.currentTarget, "Wrong event target!");
+  ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
+     "Leaking nodes to another document?");
+  if (checkRelatedTarget && evt.target.ownerDocument == document) {
+    is(evt.relatedTarget, expectedRelatedLeave, "Wrong related target (mouseleave)");
+  }
+}
+
+function mover(evt) {
+  ++mouseovercount;
+  evt.stopPropagation();
+}
+
+function mout(evt) {
+  ++mouseoutcount;
+  evt.stopPropagation();
+}
+
+</script>
+</pre>
+<div id="container" onmouseenter="menter(event)" onmouseleave="mleave(event)"
+                    onmouseout="mout(event)" onmouseover="mover(event)">
+  <div id="outside" onmouseout="event.stopPropagation()" onmouseover="event.stopPropagation()">foo</div>
+  <div id="outertest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
+                      onmouseout="mout(event)" onmouseover="mover(event)">
+    <div id="middletest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
+                         onmouseout="mout(event)" onmouseover="mover(event)">
+      <div id="innertest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
+                          onmouseout="mout(event)" onmouseover="mover(event)">foo</div>
+    </div>
+  </div>
+  <input type="file" id="file"
+         onmouseenter="menter(event)" onmouseleave="mleave(event)"
+         onmouseout="mout(event)" onmouseover="mover(event)">
+  <br>
+  <iframe id="iframe" width="50px" height="50px"
+          onmouseenter="menter(event)" onmouseleave="mleave(event)"
+          onmouseout="mout(event)" onmouseover="mover(event)"></iframe>
+</div>
+</body>
+</html>
--- a/content/html/content/public/nsHTMLAudioElement.h
+++ b/content/html/content/public/nsHTMLAudioElement.h
@@ -45,18 +45,17 @@
 typedef PRUint16 nsMediaNetworkState;
 typedef PRUint16 nsMediaReadyState;
 
 class nsHTMLAudioElement : public nsHTMLMediaElement,
                            public nsIDOMHTMLAudioElement,
                            public nsIJSNativeInitializer
 {
 public:
-  nsHTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                     mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
+  nsHTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLAudioElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE(nsHTMLMediaElement::)
 
--- a/content/html/content/public/nsHTMLMediaElement.h
+++ b/content/html/content/public/nsHTMLMediaElement.h
@@ -68,18 +68,17 @@ public:
   typedef mozilla::TimeDuration TimeDuration;
 
   enum CanPlayStatus {
     CANPLAY_NO,
     CANPLAY_MAYBE,
     CANPLAY_YES
   };
 
-  nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                     mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
+  nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLMediaElement();
 
   /**
    * This is used when the browser is constructing a video element to play
    * a channel that we've already started loading. The src attribute and
    * <source> children are ignored.
    * @param aChannel the channel to use
    * @param aListener returns a stream listener that should receive
--- a/content/html/content/public/nsHTMLVideoElement.h
+++ b/content/html/content/public/nsHTMLVideoElement.h
@@ -40,18 +40,17 @@
 
 #include "nsIDOMHTMLVideoElement.h"
 #include "nsHTMLMediaElement.h"
 
 class nsHTMLVideoElement : public nsHTMLMediaElement,
                            public nsIDOMHTMLVideoElement
 {
 public:
-  nsHTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                     mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
+  nsHTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLVideoElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE(nsHTMLMediaElement::)
 
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2500,17 +2500,17 @@ nsGenericHTMLFormElement::nsGenericHTMLF
   // We should add the NS_EVENT_STATE_ENABLED bit here as needed, but
   // that depends on our type, which is not initialized yet.  So we
   // have to do this in subclasses.
 }
 
 nsGenericHTMLFormElement::~nsGenericHTMLFormElement()
 {
   if (mFieldSet) {
-    static_cast<nsHTMLFieldSetElement*>(mFieldSet)->RemoveElement(this);
+    mFieldSet->RemoveElement(this);
   }
 
   // Check that this element doesn't know anything about its form at this point.
   NS_ASSERTION(!mForm, "mForm should be null at this point!");
 }
 
 NS_IMPL_QUERY_INTERFACE_INHERITED1(nsGenericHTMLFormElement,
                                    nsGenericHTMLElement,
@@ -2837,16 +2837,32 @@ nsGenericHTMLFormElement::PreHandleEvent
         break;
       }
     }
   }
 
   return nsGenericHTMLElement::PreHandleEvent(aVisitor);
 }
 
+/* virtual */
+bool
+nsGenericHTMLFormElement::IsDisabled() const
+{
+  return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled) ||
+         (mFieldSet && mFieldSet->IsDisabled());
+}
+
+void
+nsGenericHTMLFormElement::ForgetFieldSet(nsIContent* aFieldset)
+{
+  if (mFieldSet == aFieldset) {
+    mFieldSet = nsnull;
+  }
+}
+
 PRBool
 nsGenericHTMLFormElement::CanBeDisabled() const
 {
   PRInt32 type = GetType();
   // It's easier to test the types that _cannot_ be disabled
   return
     type != NS_FORM_LABEL &&
     type != NS_FORM_OBJECT &&
@@ -3087,42 +3103,40 @@ nsGenericHTMLFormElement::UpdateFormOwne
 void
 nsGenericHTMLFormElement::UpdateFieldSet(PRBool aNotify)
 {
   nsIContent* parent = nsnull;
   nsIContent* prev = nsnull;
 
   for (parent = GetParent(); parent;
        prev = parent, parent = parent->GetParent()) {
-    if (parent->IsHTML(nsGkAtoms::fieldset)) {
-      nsHTMLFieldSetElement* fieldset =
-        static_cast<nsHTMLFieldSetElement*>(parent);
-
-      if (!prev || fieldset->GetFirstLegend() != prev) {
-        if (mFieldSet == fieldset) {
-          // We already have the right fieldset;
-          return;
-        }
-
-        if (mFieldSet) {
-          static_cast<nsHTMLFieldSetElement*>(mFieldSet)->RemoveElement(this);
-        }
-        mFieldSet = fieldset;
-        fieldset->AddElement(this);
-
-        // The disabled state may have changed
-        FieldSetDisabledChanged(aNotify);
+    nsHTMLFieldSetElement* fieldset =
+      nsHTMLFieldSetElement::FromContent(parent);
+    if (fieldset &&
+        (!prev || fieldset->GetFirstLegend() != prev)) {
+      if (mFieldSet == fieldset) {
+        // We already have the right fieldset;
         return;
       }
+
+      if (mFieldSet) {
+        mFieldSet->RemoveElement(this);
+      }
+      mFieldSet = fieldset;
+      fieldset->AddElement(this);
+
+      // The disabled state may have changed
+      FieldSetDisabledChanged(aNotify);
+      return;
     }
   }
 
   // No fieldset found.
   if (mFieldSet) {
-    static_cast<nsHTMLFieldSetElement*>(mFieldSet)->RemoveElement(this);
+    mFieldSet->RemoveElement(this);
     mFieldSet = nsnull;
     // The disabled state may have changed
     FieldSetDisabledChanged(aNotify);
   }
 }
 
 void
 nsGenericHTMLFormElement::FieldSetDisabledChanged(PRBool aNotify)
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -830,16 +830,18 @@ protected:
 
 private:
   void ChangeEditableState(PRInt32 aChange);
 };
 
 
 //----------------------------------------------------------------------
 
+class nsHTMLFieldSetElement;
+
 /**
  * A helper class for form elements that can contain children
  */
 class nsGenericHTMLFormElement : public nsGenericHTMLElement,
                                  public nsIFormControl
 {
 public:
   nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -880,20 +882,17 @@ public:
                               PRBool aCompileEventHandlers);
   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
                               PRBool aNullParent = PR_TRUE);
   virtual PRUint32 GetDesiredIMEState();
   virtual nsEventStates IntrinsicState() const;
 
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
 
-  virtual bool IsDisabled() const {
-    return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled) ||
-           (mFieldSet && mFieldSet->IsDisabled());
-  }
+  virtual bool IsDisabled() const;
 
   /**
    * This callback is called by a fieldest on all its elements whenever its
    * disabled attribute is changed so the element knows its disabled state
    * might have changed.
    *
    * @note Classes redefining this method should not do any content
    * state updates themselves but should just make sure to call into
@@ -907,21 +906,17 @@ public:
 
   /**
    * This callback is called by a fieldset on all it's elements when it's being
    * destroyed. When called, the elements should check that aFieldset is there
    * first parent fieldset and null mFieldset in that case only.
    *
    * @param aFieldSet The fieldset being removed.
    */
-  void ForgetFieldSet(nsIContent* aFieldset) {
-    if (mFieldSet == aFieldset) {
-      mFieldSet = nsnull;
-    }
-  }
+  void ForgetFieldSet(nsIContent* aFieldset);
 
   /**
    * Returns if the control can be disabled.
    */
   PRBool CanBeDisabled() const;
 
   virtual PRBool IsHTMLFocusable(PRBool aWithMouse, PRBool* aIsFocusable,
                                  PRInt32* aTabIndex);
@@ -989,17 +984,17 @@ protected:
   // Get our focus state.  If this returns eInactiveWindow, it will set this
   // element as the focused element for that window.
   FocusTristate FocusState();
 
   /** The form that contains this control */
   nsHTMLFormElement* mForm;
 
   /* This is a pointer to our closest fieldset parent if any */
-  nsGenericHTMLFormElement* mFieldSet;
+  nsHTMLFieldSetElement* mFieldSet;
 };
 
 // If this flag is set on an nsGenericHTMLFormElement, that means that we have
 // added ourselves to our mForm.  It's possible to have a non-null mForm, but
 // not have this flag set.  That happens when the form is set via the content
 // sink.
 #define ADDED_TO_FORM (1 << ELEMENT_TYPE_SPECIFIC_BITS_OFFSET)
 
--- a/content/html/content/src/nsHTMLAudioElement.cpp
+++ b/content/html/content/src/nsHTMLAudioElement.cpp
@@ -85,17 +85,17 @@ NS_NewHTMLAudioElement(already_AddRefed<
     NS_ENSURE_TRUE(doc, nsnull);
 
     nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nsnull,
                                                    kNameSpaceID_XHTML,
                                                    nsIDOMNode::ELEMENT_NODE);
     NS_ENSURE_TRUE(nodeInfo, nsnull);
   }
 
-  return new nsHTMLAudioElement(nodeInfo.forget(), aFromParser);
+  return new nsHTMLAudioElement(nodeInfo.forget());
 }
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLAudioElement, nsHTMLMediaElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLAudioElement, nsHTMLMediaElement)
 
 DOMCI_NODE_DATA(HTMLAudioElement, nsHTMLAudioElement)
 
 NS_INTERFACE_TABLE_HEAD(nsHTMLAudioElement)
@@ -103,19 +103,18 @@ NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLA
                                  nsIDOMHTMLAudioElement, nsIJSNativeInitializer)
 NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAudioElement,
                                                nsHTMLMediaElement)
 NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAudioElement)
 
 NS_IMPL_ELEMENT_CLONE(nsHTMLAudioElement)
 
 
-nsHTMLAudioElement::nsHTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                                       FromParser aFromParser)
-  : nsHTMLMediaElement(aNodeInfo, aFromParser)
+nsHTMLAudioElement::nsHTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  : nsHTMLMediaElement(aNodeInfo)
 {
 }
 
 nsHTMLAudioElement::~nsHTMLAudioElement()
 {
 }
 
 NS_IMETHODIMP
--- a/content/html/content/src/nsHTMLFieldSetElement.h
+++ b/content/html/content/src/nsHTMLFieldSetElement.h
@@ -48,16 +48,25 @@ class nsHTMLFieldSetElement : public nsG
                               public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
 
   nsHTMLFieldSetElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLFieldSetElement();
 
+  /** Typesafe, non-refcounting cast from nsIContent.  Cheaper than QI. **/
+  static nsHTMLFieldSetElement* FromContent(nsIContent* aContent)
+  {
+    if (!aContent || !aContent->IsHTML(nsGkAtoms::fieldset)) {
+      return nsnull;
+    }
+    return static_cast<nsHTMLFieldSetElement*>(aContent);
+  }
+
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE(nsGenericHTMLFormElement::)
 
   // nsIDOMElement
   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -45,22 +45,18 @@
 #include "nsIPresShell.h"
 #include "nsGkAtoms.h"
 #include "nsSize.h"
 #include "nsIFrame.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsDOMError.h"
 #include "nsNodeInfoManager.h"
-#include "plbase64.h"
-#include "nsNetUtil.h"
-#include "prmem.h"
 #include "nsNetUtil.h"
 #include "nsXPCOMStrings.h"
-#include "prlock.h"
 #include "nsThreadUtils.h"
 #include "nsIThreadInternal.h"
 #include "nsContentUtils.h"
 #include "nsFrameManager.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIXPConnect.h"
 #include "jsapi.h"
 
@@ -1264,18 +1260,17 @@ NS_IMETHODIMP nsHTMLMediaElement::SetMut
     mAudioStream->SetVolume(mMuted ? 0.0 : mVolume);
   }
 
   DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
 
   return NS_OK;
 }
 
-nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                                       FromParser aFromParser)
+nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mCurrentLoadID(0),
     mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
     mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING),
     mLoadWaitStatus(NOT_WAITING),
     mVolume(1.0),
     mChannels(0),
     mRate(0),
--- a/content/html/content/src/nsHTMLVideoElement.cpp
+++ b/content/html/content/src/nsHTMLVideoElement.cpp
@@ -61,17 +61,17 @@
 #include "nsITimer.h"
 
 #include "nsEventDispatcher.h"
 #include "nsIDOMProgressEvent.h"
 #include "nsMediaError.h"
 
 using namespace mozilla::dom;
 
-NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Video)
+NS_IMPL_NS_NEW_HTML_ELEMENT(Video)
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLVideoElement, nsHTMLMediaElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLVideoElement, nsHTMLMediaElement)
 
 DOMCI_NODE_DATA(HTMLVideoElement, nsHTMLVideoElement)
 
 NS_INTERFACE_TABLE_HEAD(nsHTMLVideoElement)
   NS_HTML_CONTENT_INTERFACE_TABLE2(nsHTMLVideoElement, nsIDOMHTMLMediaElement, nsIDOMHTMLVideoElement)
@@ -95,19 +95,18 @@ NS_IMETHODIMP nsHTMLVideoElement::GetVid
 
 /* readonly attribute unsigned long videoHeight; */
 NS_IMETHODIMP nsHTMLVideoElement::GetVideoHeight(PRUint32 *aVideoHeight)
 {
   *aVideoHeight = mMediaSize.height == -1 ? 0 : mMediaSize.height;
   return NS_OK;
 }
 
-nsHTMLVideoElement::nsHTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                                       FromParser aFromParser)
-  : nsHTMLMediaElement(aNodeInfo, aFromParser)
+nsHTMLVideoElement::nsHTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  : nsHTMLMediaElement(aNodeInfo)
 {
 }
 
 nsHTMLVideoElement::~nsHTMLVideoElement()
 {
 }
 
 nsIntSize nsHTMLVideoElement::GetVideoSize(nsIntSize aDefaultSize)
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -1539,17 +1539,17 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDo
 
     globalObject = owner->GetScriptGlobalObject();
     NS_ENSURE_TRUE(globalObject, PR_TRUE);
   }
 
   nsIScriptContext *scriptContext = globalObject->GetContext();
   NS_ENSURE_TRUE(scriptContext, PR_TRUE);
 
-  JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
+  JSContext* cx = scriptContext->GetNativeContext();
   NS_ENSURE_TRUE(cx, PR_TRUE);
 
   PRBool enabled = PR_TRUE;
   nsContentUtils::GetSecurityManager()->
     CanExecuteScripts(cx, aDoc->NodePrincipal(), &enabled);
   return enabled;
 }
 
@@ -2447,17 +2447,17 @@ HTMLContentSink::AddDocTypeDecl(const ns
     if (!nameAtom) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     // Indicate that there is no internal subset (not just an empty one)
     nsAutoString voidString;
     voidString.SetIsVoid(PR_TRUE);
     rv = NS_NewDOMDocumentType(getter_AddRefs(docType),
-                               mDocument->NodeInfoManager(), nsnull, nameAtom,
+                               mDocument->NodeInfoManager(), nameAtom,
                                publicId, systemId, voidString);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (oldDocType) {
       // If we already have a doctype we replace the old one.
       nsCOMPtr<nsIDOMNode> tmpNode;
       rv = doc->ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
     } else {
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -184,37 +184,37 @@ nsSVGGraphicElement::IsEventName(nsIAtom
   return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
 }
 
 gfxMatrix
 nsSVGGraphicElement::PrependLocalTransformTo(const gfxMatrix &aMatrix) const
 {
   gfxMatrix result(aMatrix);
 
+  // animateMotion's resulting transform is supposed to apply *on top of*
+  // any transformations from the |transform| attribute. So since we're
+  // PRE-multiplying, we need to apply the animateMotion transform *first*.
+  if (mAnimateMotionTransform) {
+    result.PreMultiply(*mAnimateMotionTransform);
+  }
+
   if (mTransforms) {
     nsresult rv;
     nsCOMPtr<nsIDOMSVGTransformList> transforms;
     rv = mTransforms->GetAnimVal(getter_AddRefs(transforms));
     NS_ENSURE_SUCCESS(rv, aMatrix);
     PRUint32 count;
     transforms->GetNumberOfItems(&count);
     if (count > 0) {
       nsCOMPtr<nsIDOMSVGMatrix> matrix =
         nsSVGTransformList::GetConsolidationMatrix(transforms);
       result.PreMultiply(nsSVGUtils::ConvertSVGMatrixToThebes(matrix));
     }
   }
 
-  // <animateMotion>'s transformation is *supplemental* to the |transform|
-  // attribute and any transformations on ancestors.  So, we apply it
-  // (pre-multiply it) last.
-  if (mAnimateMotionTransform) {
-    result.PreMultiply(*mAnimateMotionTransform);
-  }
-
   return result;
 }
 
 void
 nsSVGGraphicElement::SetAnimateMotionTransform(const gfxMatrix* aMatrix)
 {
   mAnimateMotionTransform = aMatrix ? new gfxMatrix(*aMatrix) : nsnull;
   DidAnimateTransform();
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -1243,17 +1243,17 @@ nsBindingManager::GetBindingImplementati
       nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
       if (!global)
         return NS_NOINTERFACE;
 
       nsIScriptContext *context = global->GetContext();
       if (!context)
         return NS_NOINTERFACE;
 
-      JSContext* jscontext = (JSContext*)context->GetNativeContext();
+      JSContext* jscontext = context->GetNativeContext();
       if (!jscontext)
         return NS_NOINTERFACE;
 
       nsIXPConnect *xpConnect = nsContentUtils::XPConnect();
 
       nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
       xpConnect->GetWrappedNativeOfNativeObject(jscontext,
                                                 global->GetGlobalJSObject(),
--- a/content/xbl/src/nsXBLBinding.cpp
+++ b/content/xbl/src/nsXBLBinding.cpp
@@ -1057,17 +1057,17 @@ nsXBLBinding::ChangeDocument(nsIDocument
           // scope might be null if we've cycle-collected the global
           // object, since the Unlink phase of cycle collection happens
           // after JS GC finalization.  But in that case, we don't care
           // about fixing the prototype chain, since everything's going
           // away immediately.
 
           nsCOMPtr<nsIScriptContext> context = global->GetContext();
           if (context && scope) {
-            JSContext *cx = (JSContext *)context->GetNativeContext();
+            JSContext *cx = context->GetNativeContext();
  
             nsCxPusher pusher;
             pusher.Push(cx);
 
             nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
             nsIXPConnect *xpc = nsContentUtils::XPConnect();
             nsresult rv =
               xpc->GetWrappedNativeOfNativeObject(cx, scope, mBoundElement,
@@ -1390,17 +1390,17 @@ nsXBLBinding::AllowScripts()
     return PR_FALSE;
   }
 
   nsCOMPtr<nsIScriptContext> context = global->GetContext();
   if (!context) {
     return PR_FALSE;
   }
   
-  JSContext* cx = (JSContext*) context->GetNativeContext();
+  JSContext* cx = context->GetNativeContext();
 
   nsCOMPtr<nsIDocument> ourDocument =
     mPrototypeBinding->XBLDocumentInfo()->GetDocument();
   PRBool canExecute;
   nsresult rv =
     mgr->CanExecuteScripts(cx, ourDocument->NodePrincipal(), &canExecute);
   if (NS_FAILED(rv) || !canExecute) {
     return PR_FALSE;
--- a/content/xbl/src/nsXBLDocumentInfo.cpp
+++ b/content/xbl/src/nsXBLDocumentInfo.cpp
@@ -313,17 +313,17 @@ nsXBLDocGlobalObject::EnsureScriptEnviro
   nsCOMPtr<nsIScriptRuntime> scriptRuntime;
   rv = NS_GetScriptRuntimeByID(aLangID, getter_AddRefs(scriptRuntime));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIScriptContext> newCtx;
   rv = scriptRuntime->CreateContext(getter_AddRefs(newCtx));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = SetScriptContext(aLangID, newCtx);
 
-  JSContext *cx = (JSContext *)mScriptContext->GetNativeContext();
+  JSContext *cx = mScriptContext->GetNativeContext();
   JSAutoRequest ar(cx);
 
   // nsJSEnvironment set the error reporter to NS_ScriptErrorReporter so
   // we must apparently override that with our own (although it isn't clear 
   // why - see bug 339647)
   JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
 
   nsIPrincipal *principal = GetPrincipal();
@@ -367,18 +367,17 @@ JSObject *
 nsXBLDocGlobalObject::GetGlobalJSObject()
 {
   // The prototype document has its own special secret script object
   // that can be used to compile scripts and event handlers.
 
   if (!mScriptContext)
     return nsnull;
 
-  JSContext* cx = static_cast<JSContext*>
-                             (mScriptContext->GetNativeContext());
+  JSContext* cx = mScriptContext->GetNativeContext();
   if (!cx)
     return nsnull;
 
   JSObject *ret = ::JS_GetGlobalObject(cx);
   NS_ASSERTION(mJSObject == ret, "How did this magic switch happen?");
   return ret;
 }
 
--- a/content/xbl/src/nsXBLProtoImpl.cpp
+++ b/content/xbl/src/nsXBLProtoImpl.cpp
@@ -98,17 +98,17 @@ nsXBLProtoImpl::InstallImplementation(ns
   void * targetClassObject = nsnull;
   nsresult rv = InitTargetObjects(aBinding, context, aBoundElement,
                                   getter_AddRefs(holder), &targetClassObject);
   NS_ENSURE_SUCCESS(rv, rv); // kick out if we were unable to properly intialize our target objects
 
   JSObject * targetScriptObject;
   holder->GetJSObject(&targetScriptObject);
 
-  JSContext *cx = (JSContext *)context->GetNativeContext();
+  JSContext *cx = context->GetNativeContext();
 
   AutoVersionChecker avc(cx);
   
   // Walk our member list and install each one in turn.
   for (nsXBLProtoImplMember* curr = mMembers;
        curr;
        curr = curr->GetNext())
     curr->InstallMember(context, aBoundElement, targetScriptObject,
@@ -142,17 +142,17 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLP
   nsIScriptGlobalObject *sgo;
 
   if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   // Because our prototype implementation has a class, we need to build up a corresponding
   // class for the concrete implementation in the bound document.
-  JSContext* jscontext = (JSContext*)aContext->GetNativeContext();
+  JSContext* jscontext = aContext->GetNativeContext();
   JSObject* global = sgo->GetGlobalJSObject();
   nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
   jsval v;
   rv = nsContentUtils::WrapNative(jscontext, global, aBoundElement, &v,
                                   getter_AddRefs(wrapper));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // All of the above code was just obtaining the bound element's script object and its immediate
@@ -180,17 +180,17 @@ nsXBLProtoImpl::CompilePrototypeMembers(
   nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner(
       do_QueryObject(aBinding->XBLDocumentInfo()));
   nsIScriptGlobalObject* globalObject = globalOwner->GetScriptGlobalObject();
   NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
 
   nsIScriptContext *context = globalObject->GetContext();
   NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
 
-  JSContext *cx = (JSContext *)context->GetNativeContext();
+  JSContext *cx = context->GetNativeContext();
   JSObject *global = globalObject->GetGlobalJSObject();
   
 
   void* classObject;
   nsresult rv = aBinding->InitClass(mClassName, cx, global, global,
                                     &classObject);
   if (NS_FAILED(rv))
     return rv;
--- a/content/xbl/src/nsXBLProtoImplField.cpp
+++ b/content/xbl/src/nsXBLProtoImplField.cpp
@@ -112,17 +112,17 @@ nsXBLProtoImplField::InstallField(nsIScr
 
   // EvaluateStringWithValue and JS_DefineUCProperty can both trigger GC, so
   // protect |result| here.
   nsresult rv;
 
   nsCAutoString uriSpec;
   aBindingDocURI->GetSpec(uriSpec);
   
-  JSContext* cx = (JSContext*) aContext->GetNativeContext();
+  JSContext* cx = aContext->GetNativeContext();
   NS_ASSERTION(!::JS_IsExceptionPending(cx),
                "Shouldn't get here when an exception is pending!");
   
   // compile the literal string
   PRBool undefined;
   nsCOMPtr<nsIScriptContext> context = aContext;
 
   JSAutoRequest ar(cx);
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -123,17 +123,17 @@ nsresult
 nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
                                     nsIContent* aBoundElement, 
                                     void* aScriptObject,
                                     void* aTargetClassObject,
                                     const nsCString& aClassStr)
 {
   NS_PRECONDITION(IsCompiled(),
                   "Should not be installing an uncompiled method");
-  JSContext* cx = (JSContext*) aContext->GetNativeContext();
+  JSContext* cx = aContext->GetNativeContext();
 
   nsIDocument *ownerDoc = aBoundElement->GetOwnerDoc();
   nsIScriptGlobalObject *sgo;
 
   if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
@@ -289,17 +289,17 @@ nsXBLProtoImplAnonymousMethod::Execute(n
     return NS_OK;
   }
 
   nsCOMPtr<nsIScriptContext> context = global->GetContext();
   if (!context) {
     return NS_OK;
   }
   
-  JSContext* cx = (JSContext*) context->GetNativeContext();
+  JSContext* cx = context->GetNativeContext();
 
   JSObject* globalObject = global->GetGlobalJSObject();
 
   nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
   jsval v;
   nsresult rv =
     nsContentUtils::WrapNative(cx, globalObject, aBoundElement, &v,
                                getter_AddRefs(wrapper));
--- a/content/xbl/src/nsXBLProtoImplProperty.cpp
+++ b/content/xbl/src/nsXBLProtoImplProperty.cpp
@@ -150,17 +150,17 @@ nsresult
 nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
                                       nsIContent* aBoundElement, 
                                       void* aScriptObject,
                                       void* aTargetClassObject,
                                       const nsCString& aClassStr)
 {
   NS_PRECONDITION(mIsCompiled,
                   "Should not be installing an uncompiled property");
-  JSContext* cx = (JSContext*) aContext->GetNativeContext();
+  JSContext* cx = aContext->GetNativeContext();
 
   nsIDocument *ownerDoc = aBoundElement->GetOwnerDoc();
   nsIScriptGlobalObject *sgo;
 
   if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -1240,17 +1240,17 @@ nsXMLContentSink::HandleDoctypeDecl(cons
 
   NS_ASSERTION(mDocument, "Shouldn't get here from a document fragment");
 
   nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
   NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
 
   // Create a new doctype node
   nsCOMPtr<nsIDOMDocumentType> docType;
-  rv = NS_NewDOMDocumentType(getter_AddRefs(docType), mNodeInfoManager, nsnull,
+  rv = NS_NewDOMDocumentType(getter_AddRefs(docType), mNodeInfoManager,
                              name, aPublicId, aSystemId, aSubset);
   if (NS_FAILED(rv) || !docType) {
     return rv;
   }
 
   if (aCatalogData && mCSSLoader && mDocument) {
     // bug 124570 - we only expect additional agent sheets for now -- ignore
     // exit codes, error are not fatal here, just that the stylesheet won't apply
--- a/content/xml/document/src/nsXMLDocument.cpp
+++ b/content/xml/document/src/nsXMLDocument.cpp
@@ -98,17 +98,18 @@
 nsresult
 NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
                   const nsAString& aNamespaceURI, 
                   const nsAString& aQualifiedName, 
                   nsIDOMDocumentType* aDoctype,
                   nsIURI* aDocumentURI,
                   nsIURI* aBaseURI,
                   nsIPrincipal* aPrincipal,
-                  PRBool aLoadedAsData)
+                  PRBool aLoadedAsData,
+                  nsIScriptGlobalObject* aEventObject)
 {
   // Note: can't require that aDocumentURI/aBaseURI/aPrincipal be non-null,
   // since at least one caller (XMLHttpRequest) doesn't have decent args to
   // pass in.
   
   nsresult rv;
 
   *aInstancePtrResult = nsnull;
@@ -148,16 +149,18 @@ NS_NewDOMDocument(nsIDOMDocument** aInst
   } else {
     rv = NS_NewXMLDocument(getter_AddRefs(d));
   }
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  d->SetScriptHandlingObject(aEventObject);
+  
   if (isHTML) {
     nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(d);
     NS_ASSERTION(htmlDoc, "HTML Document doesn't implement nsIHTMLDocument?");
     htmlDoc->SetCompatibilityMode(eCompatibility_FullStandards);
     htmlDoc->SetIsXHTML(isXHTML);
   }
   nsDocument* doc = static_cast<nsDocument*>(d.get());
   doc->SetLoadedAsData(aLoadedAsData);
--- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp
@@ -938,17 +938,17 @@ txMozillaXMLOutput::createResultDocument
             if (!doctypeName) {
                 return NS_ERROR_OUT_OF_MEMORY;
             }
 
             // Indicate that there is no internal subset (not just an empty one)
             nsAutoString voidString;
             voidString.SetIsVoid(PR_TRUE);
             rv = NS_NewDOMDocumentType(getter_AddRefs(documentType),
-                                       mNodeInfoManager, nsnull,
+                                       mNodeInfoManager,
                                        doctypeName,
                                        mOutputFormat.mPublicId,
                                        mOutputFormat.mSystemId,
                                        voidString);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCOMPtr<nsIContent> docType = do_QueryInterface(documentType);
             rv = mDocument->AppendChildTo(docType, PR_TRUE);
--- a/content/xtf/src/Makefile.in
+++ b/content/xtf/src/Makefile.in
@@ -62,17 +62,14 @@ FORCE_STATIC_LIB = 1
 EXPORTS 	=  \
 		nsIXTFService.h  \
 		$(NULL)
 
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES += 	\
-		-I$(srcdir)/../../shared/public \
-		-I$(srcdir)/../../html/base/src \
 		-I$(srcdir)/../../xml/content/src \
-		-I$(srcdir)/../../../dom \
 		-I$(srcdir)/../../base/src \
-		-I$(srcdir)/../../../layout/html/base/src \
+		-I$(topsrcdir)/dom \
 		$(NULL)
 
 DEFINES += -D_IMPL_NS_LAYOUT
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -792,17 +792,17 @@ nsScriptEventHandlerOwnerTearoff::Compil
 
     // Compile the event handler
     PRUint32 argCount;
     const char **argNames;
     nsContentUtils::GetEventArgNames(kNameSpaceID_XUL, aName, &argCount,
                                      &argNames);
 
     nsCxPusher pusher;
-    if (!pusher.Push((JSContext*)context->GetNativeContext())) {
+    if (!pusher.Push(context->GetNativeContext())) {
       return NS_ERROR_FAILURE;
     }
 
     rv = context->CompileEventHandler(aName, argCount, argNames,
                                       aBody, aURL, aLineNo,
                                       SCRIPTVERSION_DEFAULT,  // for now?
                                       aHandler);
     if (NS_FAILED(rv)) return rv;
--- a/content/xul/document/src/nsXULPrototypeDocument.cpp
+++ b/content/xul/document/src/nsXULPrototypeDocument.cpp
@@ -723,17 +723,17 @@ nsXULPDGlobalObject::EnsureScriptEnviron
   NS_ENSURE_SUCCESS(rv, NS_OK);
 
   nsCOMPtr<nsIScriptContext> ctxNew;
   rv = languageRuntime->CreateContext(getter_AddRefs(ctxNew));
   // We have to setup a special global object.  We do this then
   // attach it as the global for this context.  Then, ::SetScriptContext
   // will re-fetch the global and set it up in our language globals array.
   {
-    JSContext *cx = (JSContext *)ctxNew->GetNativeContext();
+    JSContext *cx = ctxNew->GetNativeContext();
     JSAutoRequest ar(cx);
 
     nsIPrincipal *principal = GetPrincipal();
     JSObject *newGlob;
     JSCompartment *compartment;
 
     rv = xpc_CreateGlobalObject(cx, &gSharedGlobalClass, principal, nsnull,
                                 false, &newGlob, &compartment);
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -1415,17 +1415,17 @@ nsXULTemplateBuilder::InitHTMLTemplateRo
         return NS_ERROR_UNEXPECTED;
 
     JSObject *scope = global->GetGlobalJSObject();
 
     nsIScriptContext *context = global->GetContext();
     if (! context)
         return NS_ERROR_UNEXPECTED;
 
-    JSContext* jscontext = reinterpret_cast<JSContext*>(context->GetNativeContext());
+    JSContext* jscontext = context->GetNativeContext();
     NS_ASSERTION(context != nsnull, "no jscontext");
     if (! jscontext)
         return NS_ERROR_UNEXPECTED;
 
     JSAutoRequest ar(jscontext);
 
     jsval v;
     nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -6487,17 +6487,17 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
   JSBool ok = JS_TRUE;
   jsval exn = JSVAL_VOID;
   if (!ObjectIsNativeWrapper(cx, obj)) {
     JSAutoEnterCompartment ac;
 
     if (!my_context) {
       my_cx = cx;
     } else {
-      my_cx = (JSContext *)my_context->GetNativeContext();
+      my_cx = my_context->GetNativeContext();
 
       if (my_cx != cx) {
         if (!ac.enter(my_cx, obj)) {
           return NS_ERROR_UNEXPECTED;
         }
       }
     }
 
@@ -9335,17 +9335,17 @@ public:
       mContext(scriptContext)
   {
   }
 
   NS_IMETHOD Run()
   {
     JSContext* cx = nsnull;
     if (mContext) {
-      cx = (JSContext*)mContext->GetNativeContext();
+      cx = mContext->GetNativeContext();
     } else {
       nsCOMPtr<nsIThreadJSContextStack> stack =
         do_GetService("@mozilla.org/js/xpc/ContextStack;1");
       NS_ENSURE_TRUE(stack, NS_OK);
 
       stack->GetSafeJSContext(&cx);
       NS_ENSURE_TRUE(cx, NS_OK);
     }
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -769,17 +769,19 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTimeout, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTimeout, Release)
 
 nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow)
 : mFrameElement(nsnull), mDocShell(nsnull), mModalStateDepth(0),
   mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE),
   mIsHandlingResizeEvent(PR_FALSE), mIsInnerWindow(aOuterWindow != nsnull),
   mMayHavePaintEventListener(PR_FALSE), mMayHaveTouchEventListener(PR_FALSE),
-  mMayHaveAudioAvailableEventListener(PR_FALSE), mIsModalContentWindow(PR_FALSE),
+  mMayHaveAudioAvailableEventListener(PR_FALSE),
+  mMayHaveMouseEnterLeaveEventListener(PR_FALSE),
+  mIsModalContentWindow(PR_FALSE),
   mIsActive(PR_FALSE), mIsBackground(PR_FALSE),
   mInnerWindow(nsnull), mOuterWindow(aOuterWindow),
   // Make sure no actual window ends up with mWindowID == 0
   mWindowID(++gNextWindowID), mHasNotifiedGlobalCreated(PR_FALSE)
  {}
 
 nsPIDOMWindow::~nsPIDOMWindow() {}
 
@@ -1256,19 +1258,17 @@ nsGlobalWindow::ClearScopeWhenAllScripts
 
 void
 nsGlobalWindow::FreeInnerObjects(PRBool aClearScope)
 {
   NS_ASSERTION(IsInnerWindow(), "Don't free inner objects on an outer window");
 
   // Kill all of the workers for this window.
   nsIScriptContext *scx = GetContextInternal();
-  JSContext *cx = scx ?
-                  static_cast<JSContext*>(scx->GetNativeContext()) :
-                  nsnull;
+  JSContext *cx = scx ? scx->GetNativeContext() : nsnull;
   mozilla::dom::workers::CancelWorkersForWindow(cx, this);
 
   // Close all IndexedDB databases for this window.
   indexedDB::IndexedDatabaseManager* idbManager =
     indexedDB::IndexedDatabaseManager::Get();
   if (idbManager) {
     idbManager->AbortCloseDatabasesForWindow(this);
   }
@@ -1859,17 +1859,17 @@ nsGlobalWindow::SetNewDocument(nsIDocume
     return NS_ERROR_UNEXPECTED;
   }
 
   nsCOMPtr<nsIDocument> oldDoc(do_QueryInterface(mDocument));
 
   nsIScriptContext *scx = GetContextInternal();
   NS_ENSURE_TRUE(scx, NS_ERROR_NOT_INITIALIZED);
 
-  JSContext *cx = (JSContext *)scx->GetNativeContext();
+  JSContext *cx = scx->GetNativeContext();
 #ifndef MOZ_DISABLE_DOMCRYPTO
   // clear smartcard events, our document has gone away.
   if (mCrypto) {
     mCrypto->SetEnableSmartCardEvents(PR_FALSE);
   }
 #endif
   if (!mDocument) {
     // First document load.
@@ -2855,17 +2855,17 @@ nsGlobalWindow::SetArguments(nsIArray *a
 }
 
 nsresult
 nsGlobalWindow::DefineArgumentsProperty(nsIArray *aArguments)
 {
   JSContext *cx;
   nsIScriptContext *ctx = GetOuterWindowInternal()->mContext;
   NS_ENSURE_TRUE(aArguments && ctx &&
-                 (cx = (JSContext *)ctx->GetNativeContext()),
+                 (cx = ctx->GetNativeContext()),
                  NS_ERROR_NOT_INITIALIZED);
 
   if (mIsModalContentWindow) {
     // Modal content windows don't have an "arguments" property, they
     // have a "dialogArguments" property which is handled
     // separately. See nsWindowSH::NewResolve().
 
     return NS_OK;
@@ -6095,17 +6095,17 @@ PostMessageEvent::Run()
                     "should have been passed an outer window!");
   NS_ABORT_IF_FALSE(!mSource || mSource->IsOuterWindow(),
                     "should have been passed an outer window!");
 
   // Get the JSContext for the target window
   JSContext* cx = nsnull;
   nsIScriptContext* scriptContext = mTargetWindow->GetContext();
   if (scriptContext) {
-    cx = (JSContext*)scriptContext->GetNativeContext();
+    cx = scriptContext->GetNativeContext();
   }
 
   if (!cx) {
     // This can happen if mTargetWindow has been closed.  To avoid leaking,
     // we need to find a JSContext.
     nsIThreadJSContextStack* cxStack = nsContentUtils::ThreadJSContextStack();
     if (cxStack) {
       cxStack->GetSafeJSContext(&cx);
@@ -9799,17 +9799,17 @@ nsGlobalWindow::BuildURIfromBase(const c
 
   if (nsContentUtils::IsCallerChrome() && !chrome_win) {
     // If open() is called from chrome on a non-chrome window, we'll
     // use the context from the window on which open() is being called
     // to prevent giving chrome priveleges to new windows opened in
     // such a way. This also makes us get the appropriate base URI for
     // the below URI resolution code.
 
-    cx = (JSContext *)scx->GetNativeContext();
+    cx = scx->GetNativeContext();
   } else {
     // get the JSContext from the call stack
     nsCOMPtr<nsIThreadJSContextStack> stack(do_GetService(sJSStackContractID));
     if (stack)
       stack->Peek(&cx);
   }
 
   /* resolve the URI, which could be relative to the calling window
@@ -9902,17 +9902,17 @@ nsGlobalWindow::SaveWindowState(nsISuppo
   // Don't do anything else to this inner window! After this point, all
   // calls to SetTimeoutOrInterval will create entries in the timeout
   // list that will only run after this window has come out of the bfcache.
   // Also, while we're frozen, we won't dispatch online/offline events
   // to the page.
   inner->Freeze();
 
   // Remember the outer window's prototype.
-  JSContext *cx = (JSContext *)mContext->GetNativeContext();
+  JSContext *cx = mContext->GetNativeContext();
   JSAutoRequest req(cx);
 
   nsIXPConnect *xpc = nsContentUtils::XPConnect();
 
   nsCOMPtr<nsIClassInfo> ci =
     do_QueryInterface((nsIScriptGlobalObject *)this);
   nsCOMPtr<nsIXPConnectJSObjectHolder> proto;
   nsresult rv = xpc->GetWrappedNativePrototype(cx, mJSObject, ci,
@@ -9995,19 +9995,17 @@ nsGlobalWindow::SuspendTimeouts(PRUint32
   PRBool suspended = (mTimeoutsSuspendDepth != 0);
   mTimeoutsSuspendDepth += aIncrease;
 
   if (!suspended) {
     DisableDeviceMotionUpdates();
 
     // Suspend all of the workers for this window.
     nsIScriptContext *scx = GetContextInternal();
-    JSContext *cx = scx ?
-                    static_cast<JSContext*>(scx->GetNativeContext()) :
-                    nsnull;
+    JSContext *cx = scx ? scx->GetNativeContext() : nsnull;
     mozilla::dom::workers::SuspendWorkersForWindow(cx, this);
 
     TimeStamp now = TimeStamp::Now();
     for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
       // Set mTimeRemaining to be the time remaining for this timer.
       if (t->mWhen > now)
         t->mTimeRemaining = t->mWhen - now;
       else
@@ -10073,19 +10071,17 @@ nsGlobalWindow::ResumeTimeouts(PRBool aT
   PRBool shouldResume = (mTimeoutsSuspendDepth == 0);
   nsresult rv;
 
   if (shouldResume) {
     EnableDeviceMotionUpdates();
 
     // Resume all of the workers for this window.
     nsIScriptContext *scx = GetContextInternal();
-    JSContext *cx = scx ?
-                    static_cast<JSContext*>(scx->GetNativeContext()) :
-                    nsnull;
+    JSContext *cx = scx ? scx->GetNativeContext() : nsnull;
     mozilla::dom::workers::ResumeWorkersForWindow(cx, this);
 
     // Restore all of the timeouts, using the stored time remaining
     // (stored in timeout->mTimeRemaining).
 
     TimeStamp now = TimeStamp::Now();
 
 #ifdef DEBUG
@@ -10523,17 +10519,17 @@ nsGlobalChromeWindow::NotifyDefaultButto
 
 NS_IMETHODIMP
 nsGlobalChromeWindow::GetMessageManager(nsIChromeFrameMessageManager** aManager)
 {
   FORWARD_TO_INNER_CHROME(GetMessageManager, (aManager), NS_ERROR_FAILURE);
   if (!mMessageManager) {
     nsIScriptContext* scx = GetContextInternal();
     NS_ENSURE_STATE(scx);
-    JSContext* cx = (JSContext *)scx->GetNativeContext();
+    JSContext* cx = scx->GetNativeContext();
     NS_ENSURE_STATE(cx);
     nsCOMPtr<nsIChromeFrameMessageManager> globalMM =
       do_GetService("@mozilla.org/globalmessagemanager;1");
     mMessageManager =
       new nsFrameMessageManager(PR_TRUE,
                                 nsnull,
                                 nsnull,
                                 nsnull,
--- a/dom/base/nsIScriptContext.h
+++ b/dom/base/nsIScriptContext.h
@@ -38,16 +38,17 @@
 #ifndef nsIScriptContext_h__
 #define nsIScriptContext_h__
 
 #include "nscore.h"
 #include "nsStringGlue.h"
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
 #include "nsIProgrammingLanguage.h"
+#include "jspubtd.h"
 
 class nsIScriptGlobalObject;
 class nsIScriptSecurityManager;
 class nsIPrincipal;
 class nsIAtom;
 class nsIArray;
 class nsIVariant;
 class nsIObjectInputStream;
@@ -68,29 +69,26 @@ public:
 
   virtual nsIScriptObjectPrincipal* GetObjectPrincipal() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContextPrincipal,
                               NS_ISCRIPTCONTEXTPRINCIPAL_IID)
 
 #define NS_ISCRIPTCONTEXT_IID \
-  { 0xad76079b, 0xd408, 0x4159, \
-    {0xb7, 0x3f, 0x41, 0x08, 0x77, 0xff, 0x9b, 0x47 } }
+{ 0x827d1e82, 0x5aab, 0x4e3a, \
+  { 0x88, 0x76, 0x53, 0xf7, 0xed, 0x1e, 0x3f, 0xbe } }
 
 /* This MUST match JSVERSION_DEFAULT.  This version stuff if we don't
    know what language we have is a little silly... */
 #define SCRIPTVERSION_DEFAULT JSVERSION_DEFAULT
 
 /**
  * It is used by the application to initialize a runtime and run scripts.
  * A script runtime would implement this interface.
- * <P><I>It does have a bit too much java script information now, that
- * should be removed in a short time. Ideally this interface will be
- * language neutral</I>
  */
 class nsIScriptContext : public nsIScriptContextPrincipal
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
 
   /* Get the ID of this language. */
   virtual PRUint32 GetScriptTypeID() = 0;
@@ -287,17 +285,17 @@ public:
    *
    **/
   virtual nsIScriptGlobalObject *GetGlobalObject() = 0;
 
   /**
    * Return the native script context
    *
    **/
-  virtual void *GetNativeContext() = 0;
+  virtual JSContext* GetNativeContext() = 0;
 
   /**
    * Return the native global object for this context.
    *
    **/
   virtual void *GetNativeGlobal() = 0;
 
   /**
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -2237,17 +2237,17 @@ nsJSContext::ConnectToInner(nsIScriptGlo
   JS_SetGlobalObject(mContext, outerGlobal);
   NS_ASSERTION(JS_GetPrototype(mContext, outerGlobal) ==
                JS_GetPrototype(mContext, newInnerJSObject),
                "outer and inner globals should have the same prototype");
 
   return NS_OK;
 }
 
-void *
+JSContext*
 nsJSContext::GetNativeContext()
 {
   return mContext;
 }
 
 nsresult
 nsJSContext::InitContext()
 {
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -29,18 +29,18 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#ifndef nsJSEnvironment_h___
-#define nsJSEnvironment_h___
+#ifndef nsJSEnvironment_h
+#define nsJSEnvironment_h
 
 #include "nsIScriptContext.h"
 #include "nsIScriptRuntime.h"
 #include "nsCOMPtr.h"
 #include "jsapi.h"
 #include "nsIObserver.h"
 #include "nsIXPCScriptNotify.h"
 #include "prtime.h"
@@ -124,17 +124,17 @@ public:
                                    const char* aURL,
                                    PRUint32 aLineNo,
                                    PRUint32 aVersion,
                                    PRBool aShared,
                                    void** aFunctionObject);
 
   virtual void SetDefaultLanguageVersion(PRUint32 aVersion);
   virtual nsIScriptGlobalObject *GetGlobalObject();
-  virtual void *GetNativeContext();
+  virtual JSContext* GetNativeContext();
   virtual void *GetNativeGlobal();
   virtual nsresult CreateNativeGlobalForInner(
                                       nsIScriptGlobalObject *aGlobal,
                                       PRBool aIsChrome,
                                       nsIPrincipal *aPrincipal,
                                       void **aNativeGlobal,
                                       nsISupports **aHolder);
   virtual nsresult ConnectToInner(nsIScriptGlobalObject *aNewInner,
@@ -365,9 +365,9 @@ JSObject* NS_DOMReadStructuredClone(JSCo
                                     uint32 data, void* closure);
 
 JSBool NS_DOMWriteStructuredClone(JSContext* cx,
                                   JSStructuredCloneWriter* writer,
                                   JSObject* obj, void *closure);
 
 void NS_DOMStructuredCloneError(JSContext* cx, uint32 errorid);
 
-#endif /* nsJSEnvironment_h___ */
+#endif /* nsJSEnvironment_h */
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -75,18 +75,18 @@ class nsIDocument;
 class nsIScriptTimeoutHandler;
 struct nsTimeout;
 class nsScriptObjectHolder;
 class nsXBLPrototypeHandler;
 class nsIArray;
 class nsPIWindowRoot;
 
 #define NS_PIDOMWINDOW_IID \
-{ 0xeee816d2, 0x2f08, 0x4b34, \
-  { 0x97, 0x47, 0x5e, 0x5a, 0xcd, 0xc3, 0x56, 0xfa } }
+{ 0x8ce567b5, 0xcc8d, 0x410b, \
+  { 0xa2, 0x7b, 0x07, 0xaf, 0x31, 0xc0, 0x33, 0xb8 } }
 
 class nsPIDOMWindow : public nsIDOMWindowInternal
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOW_IID)
 
   virtual nsPIDOMWindow* GetPrivateRoot() = 0;
 
@@ -463,16 +463,34 @@ public:
    * or content in that document) has a MozAudioAvailable event listener.
    */
   void SetHasAudioAvailableEventListeners()
   {
     mMayHaveAudioAvailableEventListener = PR_TRUE;
   }
 
   /**
+   * Call this to check whether some node (this window, its document,
+   * or content in that document) has a mouseenter/leave event listener.
+   */
+  PRBool HasMouseEnterLeaveEventListeners()
+  {
+    return mMayHaveMouseEnterLeaveEventListener;
+  }
+
+  /**
+   * Call this to indicate that some node (this window, its document,
+   * or content in that document) has a mouseenter/leave event listener.
+   */
+  void SetHasMouseEnterLeaveEventListeners()
+  {
+    mMayHaveMouseEnterLeaveEventListener = PR_TRUE;
+  }  
+
+  /**
    * Initialize window.java and window.Packages.
    */
   virtual void InitJavaProperties() = 0;
 
   virtual void* GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) = 0;
   virtual void CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
                                         nsScriptObjectHolder& aHandler) = 0;
 
@@ -622,16 +640,17 @@ protected:
   PRUint32               mMutationBits;
 
   PRPackedBool           mIsDocumentLoaded;
   PRPackedBool           mIsHandlingResizeEvent;
   PRPackedBool           mIsInnerWindow;
   PRPackedBool           mMayHavePaintEventListener;
   PRPackedBool           mMayHaveTouchEventListener;
   PRPackedBool           mMayHaveAudioAvailableEventListener;
+  PRPackedBool           mMayHaveMouseEnterLeaveEventListener;
 
   // This variable is used on both inner and outer windows (and they
   // should match).
   PRPackedBool           mIsModalContentWindow;
 
   // Tracks activation state that's used for :-moz-window-inactive.
   // Only used on outer windows.
   PRPackedBool           mIsActive;
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -138,17 +138,17 @@ IDBRequest::SetDone(AsyncConnectionHelpe
 
   // If the request failed then set the error code and return.
   if (NS_FAILED(rv)) {
     mErrorCode = NS_ERROR_GET_CODE(rv);
     return NS_OK;
   }
 
   // Otherwise we need to get the result from the helper.
-  JSContext* cx = static_cast<JSContext*>(mScriptContext->GetNativeContext());
+  JSContext* cx = mScriptContext->GetNativeContext();
   NS_ASSERTION(cx, "Failed to get a context!");
 
   JSObject* global = static_cast<JSObject*>(mScriptContext->GetNativeGlobal());
   NS_ASSERTION(global, "Failed to get global object!");
 
   JSAutoRequest ar(cx);
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, global)) {
--- a/dom/interfaces/core/nsIInlineEventHandlers.idl
+++ b/dom/interfaces/core/nsIInlineEventHandlers.idl
@@ -34,17 +34,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 #include "domstubs.idl"
 
 %{ C++
 #include "jspubtd.h"
 %}
 
-[scriptable, uuid(c3cc4504-1eaf-42e9-8b1b-a3020f6d3a28)]
+[scriptable, uuid(790ad9f7-167a-4f5f-a5c1-8cfb3697104d)]
 interface nsIInlineEventHandlers : nsISupports
 {
   [implicit_jscontext] attribute jsval onabort;
   [implicit_jscontext] attribute jsval onblur;
   [implicit_jscontext] attribute jsval oncanplay;
   [implicit_jscontext] attribute jsval oncanplaythrough;
   [implicit_jscontext] attribute jsval onchange;
   [implicit_jscontext] attribute jsval onclick;
@@ -72,16 +72,18 @@ interface nsIInlineEventHandlers : nsISu
   [implicit_jscontext] attribute jsval onload;
   [implicit_jscontext] attribute jsval onloadeddata;
   [implicit_jscontext] attribute jsval onloadedmetadata;
   [implicit_jscontext] attribute jsval onloadstart;
   [implicit_jscontext] attribute jsval onmousedown;
   [implicit_jscontext] attribute jsval onmousemove;
   [implicit_jscontext] attribute jsval onmouseout;
   [implicit_jscontext] attribute jsval onmouseover;
+  [implicit_jscontext] attribute jsval onmouseenter;
+  [implicit_jscontext] attribute jsval onmouseleave;
   [implicit_jscontext] attribute jsval onmouseup;
   // Not supported yet
   // [implicit_jscontext] attribute jsval onmousewheel;
   [implicit_jscontext] attribute jsval onmozfullscreenchange;
   [implicit_jscontext] attribute jsval onpause;
   [implicit_jscontext] attribute jsval onplay;
   [implicit_jscontext] attribute jsval onplaying;
   [implicit_jscontext] attribute jsval onprogress;
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -356,17 +356,17 @@ GetJSContext(NPP npp)
 
   nsCOMPtr<nsISupports> documentContainer = doc->GetContainer();
   nsCOMPtr<nsIScriptGlobalObject> sgo(do_GetInterface(documentContainer));
   NS_ENSURE_TRUE(sgo, nsnull);
 
   nsIScriptContext *scx = sgo->GetContext();
   NS_ENSURE_TRUE(scx, nsnull);
 
-  return (JSContext *)scx->GetNativeContext();
+  return scx->GetNativeContext();
 }
 
 }
 }
 }
 
 static NPP
 LookupNPP(NPObject *npobj);
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -720,17 +720,17 @@ static JSContext *
 GetJSContextFromDoc(nsIDocument *doc)
 {
   nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
   NS_ENSURE_TRUE(sgo, nsnull);
 
   nsIScriptContext *scx = sgo->GetContext();
   NS_ENSURE_TRUE(scx, nsnull);
 
-  return (JSContext *)scx->GetNativeContext();
+  return scx->GetNativeContext();
 }
 
 static JSContext *
 GetJSContextFromNPP(NPP npp)
 {
   nsIDocument *doc = GetDocumentFromNPP(npp);
   NS_ENSURE_TRUE(doc, nsnull);
 
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -1366,17 +1366,17 @@ nsNPAPIPluginInstance::GetJSContext(JSCo
 
   if (NS_SUCCEEDED(rv) && document) {
     nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
 
     if (global) {
       nsIScriptContext *context = global->GetContext();
 
       if (context) {
-        *outContext = (JSContext*) context->GetNativeContext();
+        *outContext = context->GetNativeContext();
       }
     }
   }
 
   return rv;
 }
 
 nsresult
--- a/dom/src/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/src/jsurl/nsJSProtocolHandler.cpp
@@ -262,17 +262,17 @@ nsresult nsJSThunk::EvaluateScript(nsICh
     PRBool useSandbox =
         (aExecutionPolicy == nsIScriptChannel::EXECUTE_IN_SANDBOX);
 
     if (!useSandbox) {
         //-- Don't outside a sandbox unless the script principal subsumes the
         //   principal of the context.
         nsCOMPtr<nsIPrincipal> objectPrincipal;
         rv = securityManager->
-            GetObjectPrincipal((JSContext*)scriptContext->GetNativeContext(),
+            GetObjectPrincipal(scriptContext->GetNativeContext(),
                                globalJSObject,
                                getter_AddRefs(objectPrincipal));
         if (NS_FAILED(rv))
             return rv;
 
         PRBool subsumes;
         rv = principal->Subsumes(objectPrincipal, &subsumes);
         if (NS_FAILED(rv))
@@ -289,17 +289,17 @@ nsresult nsJSThunk::EvaluateScript(nsICh
     if (useSandbox) {
         // We were asked to use a sandbox, or the channel owner isn't allowed
         // to execute in this context.  Evaluate the javascript URL in a
         // sandbox to prevent it from accessing data it doesn't have
         // permissions to access.
 
         // First check to make sure it's OK to evaluate this script to
         // start with.  For example, script could be disabled.
-        JSContext *cx = (JSContext*)scriptContext->GetNativeContext();
+        JSContext *cx = scriptContext->GetNativeContext();
         JSAutoRequest ar(cx);
 
         PRBool ok;
         rv = securityManager->CanExecuteScripts(cx, principal, &ok);
         if (NS_FAILED(rv)) {
             return rv;
         }
 
@@ -368,17 +368,17 @@ nsresult nsJSThunk::EvaluateScript(nsICh
 
         // If there's an error on cx as a result of that call, report
         // it now -- either we're just running under the event loop,
         // so we shouldn't propagate JS exceptions out of here, or we
         // can't be sure that our caller is JS (and if it's not we'll
         // lose the error), or it might be JS that then proceeds to
         // cause an error of its own (which will also make us lose
         // this error).
-        JSContext *cx = (JSContext*)scriptContext->GetNativeContext();
+        JSContext *cx = scriptContext->GetNativeContext();
         JSAutoRequest ar(cx);
         ::JS_ReportPendingException(cx);
     }
     
     if (NS_FAILED(rv)) {
         rv = NS_ERROR_MALFORMED_URI;
     }
     else if (isUndefined) {
--- a/dom/tests/mochitest/dom-level2-core/test_createDocument03.html
+++ b/dom/tests/mochitest/dom-level2-core/test_createDocument03.html
@@ -72,16 +72,18 @@ var docName = 'createDocument03';
 
 
 /**
 * 
     The "createDocument(namespaceURI,qualifiedName,doctype)" method for a 
    DOMImplementation should raise WRONG_DOCUMENT_ERR DOMException
    if parameter doctype has been used with a different document.
    
+   The specification has changed! No exception should be thrown.
+   
    Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
    this domimplementation where doctype is the type of this document.
    Method should raise WRONG_DOCUMENT_ERR DOMException.
 
 * @author NIST
 * @author Mary Brady
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
@@ -105,21 +107,22 @@ function createDocument03() {
       docType = doc.doctype;
 
       domImpl = doc.implementation;
 
 	{
 		success = false;
 		try {
             aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
+            success = true;
         }
 		catch(ex) {
-      success = (typeof(ex.code) != 'undefined' && ex.code == 4);
+      success = false;
 		}
-		assertTrue("throw_WRONG_DOCUMENT_ERR",success);
+		//assertTrue("no_throw_WRONG_DOCUMENT_ERR",success);
 	}
 
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/createDocument03</h2>
--- a/dom/tests/mochitest/dom-level2-core/test_createDocument04.html
+++ b/dom/tests/mochitest/dom-level2-core/test_createDocument04.html
@@ -78,16 +78,18 @@ var docName = 'createDocument04';
 
 
 /**
 * 
     The "createDocument(namespaceURI,qualifiedName,doctype)" method for a 
    DOMImplementation should raise WRONG_DOCUMENT_ERR DOMException
    if parameter doctype was created from a different implementation.
    
+   The specification has changed! No exception should be thrown.
+   
    Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
    a domimplementation that is different from this domimplementation.
    Doctype is the type of this document.
    Method should raise WRONG_DOCUMENT_ERR DOMException.
 
 * @author NIST
 * @author Mary Brady
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])
@@ -118,21 +120,22 @@ function createDocument04() {
       docType = doc.doctype;
 
       domImpl = aNewDoc.implementation;
 
 	{
 		success = false;
 		try {
             aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
+            success = true;
         }
 		catch(ex) {
-      success = (typeof(ex.code) != 'undefined' && ex.code == 4);
+      success = false;
 		}
-		assertTrue("throw_WRONG_DOCUMENT_ERR",success);
+		assertTrue("no_throw_WRONG_DOCUMENT_ERR",success);
 	}
 
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/createDocument04</h2>
--- a/dom/tests/mochitest/dom-level2-core/test_documentimportnode07.html
+++ b/dom/tests/mochitest/dom-level2-core/test_documentimportnode07.html
@@ -77,16 +77,18 @@ var docName = 'documentimportnode07';
 	The importNode method imports a node from another document to this document. 
 	A NOT_SUPPORTED_ERR is raised if the type of node being imported is
 	not supported
 	
 	Using the method importNode with deep=true, try to import this Document's 
 	DocumentType object. Since DocumentType nodes cannot be imported, a 
 	NOT_SUPPORTED_ERR should be raised.
 
+	The specification has changed! No exception should be thrown.
+
 * @author IBM
 * @author Neil Delima
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode
 */
 function documentimportnode07() {
    var success;
     if(checkInitialization(builder, "documentimportnode07") != null) return;
@@ -101,21 +103,22 @@ function documentimportnode07() {
       doc = load(docRef, "doc", "staffNS");
       docType = doc.doctype;
 
       
 	{
 		success = false;
 		try {
             imported = doc.importNode(docType,true);
+            success = true;
         }
 		catch(ex) {
-      success = (typeof(ex.code) != 'undefined' && ex.code == 9);
+      success = false;
 		}
-		assertTrue("throw_NOT_SUPPORTED_ERR",success);
+		assertTrue("no_throw_NOT_SUPPORTED_ERR",success);
 	}
 
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode07</h2>
--- a/dom/tests/mochitest/dom-level2-core/test_documentimportnode08.html
+++ b/dom/tests/mochitest/dom-level2-core/test_documentimportnode08.html
@@ -76,16 +76,18 @@ var docName = 'documentimportnode08';
 * 
 	The importNode method imports a node from another document to this document. 
 	A NOT_SUPPORTED_ERR is raised if the type of node being imported is
 	not supported
 	
 	Using the method importNode with deep=true, try to import a newly created DOcumentType
 	node. Since DocumentType nodes cannot be imported, a NOT_SUPPORTED_ERR should be raised.
 
+	The specification has changed! No exception should be thrown.
+
 * @author IBM
 * @author Neil Delima
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode
 * @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=259
 */
 function documentimportnode08() {
    var success;
@@ -104,21 +106,22 @@ function documentimportnode08() {
       doc = load(docRef, "doc", "staffNS");
       domImpl = doc.implementation;
 docType = domImpl.createDocumentType("test:root",nullNS,nullNS);
       
 	{
 		success = false;
 		try {
             imported = doc.importNode(docType,true);
+            success = true;
         }
 		catch(ex) {
-      success = (typeof(ex.code) != 'undefined' && ex.code == 9);
+      success = false;
 		}
-		assertTrue("throw_NOT_SUPPORTED_ERR",success);
+		assertTrue("no_throw_NOT_SUPPORTED_ERR",success);
 	}
 
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode08</h2>
--- a/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocumenttype01.html
+++ b/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocumenttype01.html
@@ -75,16 +75,18 @@ var docName = 'domimplementationcreatedo
 * 
 	The method createDocumentType with valid values for qualifiedName, publicId and
 	systemId should create an empty DocumentType node.
 	
 	Invoke createDocument on this DOMImplementation with a valid qualifiedName and different
 	publicIds and systemIds.  Check if the the DocumentType node was created with its 
 	ownerDocument attribute set to null.
 
+	The specification has changed! ownerDocument should not be null.
+
 * @author IBM
 * @author Neil Delima
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
 */
 function domimplementationcreatedocumenttype01() {
    var success;
     if(checkInitialization(builder, "domimplementationcreatedocumenttype01") != null) return;
     var doc;
@@ -112,17 +114,17 @@ function domimplementationcreatedocument
 for(var indexN65629 = 0;indexN65629 < publicIds.length; indexN65629++) {
       publicId = publicIds[indexN65629];
       for(var indexN65633 = 0;indexN65633 < systemIds.length; indexN65633++) {
       systemId = systemIds[indexN65633];
       newDocType = domImpl.createDocumentType(qualifiedName,publicId,systemId);
       assertNotNull("domimplementationcreatedocumenttype01_newDocType",newDocType);
 ownerDocument = newDocType.ownerDocument;
 
-      assertNull("domimplementationcreatedocumenttype01_ownerDocument",ownerDocument);
+      assertNotNull("domimplementationcreatedocumenttype01_ownerDocument",ownerDocument);
     
 	}
    
 	}
    
 }
 
 </script>
--- a/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocumenttype02.html
+++ b/dom/tests/mochitest/dom-level2-core/test_domimplementationcreatedocumenttype02.html
@@ -75,16 +75,18 @@ var docName = 'domimplementationcreatedo
 * 
 	The method createDocumentType with valid values for qualifiedName, publicId and
 	systemId should create an empty DocumentType node.
 	
 	Invoke createDocument on this DOMImplementation with a different valid qualifiedNames 
 	and a valid publicId and systemId.  Check if the the DocumentType node was created 
 	with its ownerDocument attribute set to null.
 
+	The specification has changed! ownerDocument should not be null.
+
 * @author IBM
 * @author Neil Delima
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
 */
 function domimplementationcreatedocumenttype02() {
    var success;
     if(checkInitialization(builder, "domimplementationcreatedocumenttype02") != null) return;
     var doc;
@@ -118,17 +120,17 @@ function domimplementationcreatedocument
       doc = load(docRef, "doc", "staffNS");
       domImpl = doc.implementation;
 for(var indexN65655 = 0;indexN65655 < qualifiedNames.length; indexN65655++) {
       qualifiedName = qualifiedNames[indexN65655];
       newDocType = domImpl.createDocumentType(qualifiedName,publicId,systemId);
       assertNotNull("domimplementationcreatedocumenttype02_newDocType",newDocType);
 ownerDocument = newDocType.ownerDocument;
 
-      assertNull("domimplementationcreatedocumenttype02_ownerDocument",ownerDocument);
+      assertNotNull("domimplementationcreatedocumenttype02_ownerDocument",ownerDocument);
     
 	}
    
 }
 
 </script>
 </head>
 <body>
--- a/dom/tests/mochitest/dom-level2-core/test_importNode16.html
+++ b/dom/tests/mochitest/dom-level2-core/test_importNode16.html
@@ -77,16 +77,18 @@ function loadComplete() {
 var docName = 'importNode16';
 
 
 /**
 * 
     The "importNode(importedNode,deep)" method for a 
    Document should raise NOT_SUPPORTED_ERR DOMException if
    the type of node being imported is DocumentType.
+
+   The specification has changed! No exception should be thrown.
    
    Retrieve document staff.xml and get its type.
    Invoke method importNode(importedNode,deep) where importedNode
    contains the document type of the staff.xml.  
    Method should raise NOT_SUPPORT_ERR DOMException.
 
 * @author NIST
 * @author Mary Brady
@@ -115,21 +117,22 @@ function importNode16() {
       anotherDoc = load(anotherDocRef, "anotherDoc", "staffNS");
       docType = anotherDoc.doctype;
 
       
 	{
 		success = false;
 		try {
             node = doc.importNode(docType,false);
+            success = true;
         }
 		catch(ex) {
-      success = (typeof(ex.code) != 'undefined' && ex.code == 9);
+      success = false;
 		}
-		assertTrue("throw_NOT_SUPPORTED_ERR",success);
+		assertTrue("no_throw_NOT_SUPPORTED_ERR",success);
 	}
 
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/importNode16</h2>
--- a/dom/tests/mochitest/dom-level2-core/test_nodegetownerdocument01.html
+++ b/dom/tests/mochitest/dom-level2-core/test_nodegetownerdocument01.html
@@ -74,16 +74,18 @@ var docName = 'nodegetownerdocument01';
 
 /**
 * 
 	The method getOwnerDocument returns the Document object associated with this node
   
 	Create a new DocumentType node.  Since this node is not used with any Document yet
 	verify if the ownerDocument is null.
 
+	The specification has changed! ownerDocument should not be null.
+
 * @author IBM
 * @author Neil Delima
 * @see http://www.w3.org/TR/DOM-Level-2-Core/core#node-ownerDoc
 * @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=259
 */
 function nodegetownerdocument01() {
    var success;
     if(checkInitialization(builder, "nodegetownerdocument01") != null) return;
@@ -98,17 +100,17 @@ function nodegetownerdocument01() {
       if (typeof(this.doc) != 'undefined') {
         docRef = this.doc;
       }
       doc = load(docRef, "doc", "staff");
       domImpl = doc.implementation;
 docType = domImpl.createDocumentType("mydoc",nullID,nullID);
       ownerDoc = docType.ownerDocument;
 
-      assertNull("nodegetownerdocument01",ownerDoc);
+      assertNotNull("nodegetownerdocument01",ownerDoc);
     
 }
 
 </script>
 </head>
 <body>
 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodegetownerdocument01</h2>
 <p></p>
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -2171,18 +2171,17 @@ WorkerPrivateParent<Derived>::ParentJSCo
   if (!mParent) {
     AssertIsOnMainThread();
 
     if (!mScriptContext) {
       NS_ASSERTION(!mParentJSContext, "Shouldn't have a parent context!");
       return RuntimeService::AutoSafeJSContext::GetSafeContext();
     }
 
-    NS_ASSERTION(mParentJSContext ==
-                 static_cast<JSContext*>(mScriptContext->GetNativeContext()),
+    NS_ASSERTION(mParentJSContext == mScriptContext->GetNativeContext(),
                  "Native context has changed!");
   }
 
   return mParentJSContext;
 }
 
 WorkerPrivate::WorkerPrivate(JSContext* aCx, JSObject* aObject,
                              WorkerPrivate* aParent,
@@ -2284,18 +2283,17 @@ WorkerPrivate::Create(JSContext* aCx, JS
       }
 
       scriptContext = scriptGlobal->GetContext();
       if (!scriptContext) {
         JS_ReportError(aCx, "Couldn't get script context for this worker!");
         return nsnull;
       }
 
-      parentContext =
-        static_cast<JSContext*>(scriptContext->GetNativeContext());
+      parentContext = scriptContext->GetNativeContext();
 
       // If we're called from a window then we can dig out the principal and URI
       // from the document.
       document = do_QueryInterface(window->GetExtantDocument());
       if (!document) {
         JS_ReportError(aCx, "No document in this window!");
         return nsnull;
       }
--- a/embedding/components/printingui/src/os2/nsPrintingPromptService.cpp
+++ b/embedding/components/printingui/src/os2/nsPrintingPromptService.cpp
@@ -136,44 +136,38 @@ nsPrintingPromptService::ShowProgress(ns
 {
     NS_ENSURE_ARG(webProgressListener);
     NS_ENSURE_ARG(printProgressParams);
     NS_ENSURE_ARG(notifyOnOpen);
 
     *notifyOnOpen = PR_FALSE;
 
     nsPrintProgress* prtProgress = new nsPrintProgress();
-    nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
-    rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
-    NS_ENSURE_SUCCESS(rv, rv);
+    mPrintProgress = prtProgress;
+    mWebProgressListener = prtProgress;
 
-    if (printProgressParams) {
-        nsCOMPtr<nsIDOMWindow> parentDOMIntl = parent;
+    nsCOMPtr<nsIPrintProgressParams> prtProgressParams = new nsPrintProgressParams();
+      
+    nsCOMPtr<nsIDOMWindow> parentWindow = parent;
 
-        if (mWatcher && !parentDOMIntl) {
-            mWatcher->GetActiveWindow(getter_AddRefs(parentDOMIntl));
-        }
-
-        if (parentDOMIntl) {
-            mPrintProgress->OpenProgressDialog(parentDOMIntl,
-                                               isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
-                                               *printProgressParams, openDialogObserver, notifyOnOpen);
-        }
+    if (mWatcher && !parentWindow) {
+        mWatcher->GetActiveWindow(getter_AddRefs(parentWindow));
     }
 
-    *webProgressListener = static_cast<nsIWebProgressListener*>(this);
-    NS_ADDREF(*webProgressListener);
+    if (parentWindow) {
+        mPrintProgress->OpenProgressDialog(parentWindow,
+                                           isForPrinting ? kPrintProgressDialogURL : kPrtPrvProgressDialogURL,
+                                           prtProgressParams, openDialogObserver, notifyOnOpen);
+    }
 
-    return rv;
+    prtProgressParams.forget(printProgressParams);
+    nsCOMPtr<nsIWebProgressListener> myWebProgressListener = this;
+    myWebProgressListener.forget(webProgressListener);
+
+    return NS_OK;
 }
 
 /* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
 NS_IMETHODIMP 
 nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, nsIObserver *aObs)
 {
     NS_ENSURE_ARG(printSettings);
 
--- a/embedding/components/printingui/src/unixshared/nsPrintingPromptService.cpp
+++ b/embedding/components/printingui/src/unixshared/nsPrintingPromptService.cpp
@@ -139,44 +139,37 @@ nsPrintingPromptService::ShowProgress(ns
 {
     NS_ENSURE_ARG(webProgressListener);
     NS_ENSURE_ARG(printProgressParams);
     NS_ENSURE_ARG(notifyOnOpen);
 
     *notifyOnOpen = PR_FALSE;
 
     nsPrintProgress* prtProgress = new nsPrintProgress(printSettings);
-    nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
-    NS_ENSURE_SUCCESS(rv, rv);
+    mPrintProgress = prtProgress;
+    mWebProgressListener = prtProgress;
 
-    rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
-    rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsIPrintProgressParams> prtProgressParams = new nsPrintProgressParams();
 
-    if (printProgressParams) {
-        nsCOMPtr<nsIDOMWindow> parentDOMIntl = parent;
+    nsCOMPtr<nsIDOMWindow> parentWindow = parent;
 
-        if (mWatcher && !parentDOMIntl) {
-            mWatcher->GetActiveWindow(getter_AddRefs(parentDOMIntl));
-        }
-
-        if (parentDOMIntl) {
-            mPrintProgress->OpenProgressDialog(parentDOMIntl,
-                                               isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
-                                               *printProgressParams, openDialogObserver, notifyOnOpen);
-        }
+    if (mWatcher && !parentWindow) {
+        mWatcher->GetActiveWindow(getter_AddRefs(parentWindow));
     }
 
-    *webProgressListener = static_cast<nsIWebProgressListener*>(this);
-    NS_ADDREF(*webProgressListener);
+    if (parentWindow) {
+        mPrintProgress->OpenProgressDialog(parentWindow,
+                                           isForPrinting ? kPrintProgressDialogURL : kPrtPrvProgressDialogURL,
+                                           prtProgressParams, openDialogObserver, notifyOnOpen);
+    }
 
-    return rv;
+    prtProgressParams.forget(printProgressParams);
+    NS_ADDREF(*webProgressListener = this);
+
+    return NS_OK;
 }
 
 /* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
 NS_IMETHODIMP 
 nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, nsIObserver *aObs)
 {
     NS_ENSURE_ARG(printSettings);
 
--- a/embedding/components/printingui/src/win/nsPrintingPromptService.cpp
+++ b/embedding/components/printingui/src/win/nsPrintingPromptService.cpp
@@ -204,52 +204,44 @@ nsPrintingPromptService::ShowProgress(ns
                                       nsIPrintProgressParams** printProgressParams,
                                       PRBool*                  notifyOnOpen)
 {
     NS_ENSURE_ARG(webProgressListener);
     NS_ENSURE_ARG(printProgressParams);
     NS_ENSURE_ARG(notifyOnOpen);
 
     *notifyOnOpen = PR_FALSE;
-    if (mPrintProgress) 
-    {
+    if (mPrintProgress) {
         *webProgressListener = nsnull;
         *printProgressParams = nsnull;
         return NS_ERROR_FAILURE;
     }
 
     nsPrintProgress* prtProgress = new nsPrintProgress();
-    nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
-    NS_ENSURE_SUCCESS(rv, rv);
+    mPrintProgress = prtProgress;
+    mWebProgressListener = prtProgress;
 
-    rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
-    rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsIPrintProgressParams> prtProgressParams = new nsPrintProgressParams();
 
-    if (printProgressParams) {
-        nsCOMPtr<nsIDOMWindow> parentDOMIntl = parent;
+    nsCOMPtr<nsIDOMWindow> parentWindow = parent;
 
-        if (mWatcher && !parentDOMIntl) {
-            mWatcher->GetActiveWindow(getter_AddRefs(parentDOMIntl));
-        }
-
-        if (parentDOMIntl) {
-            mPrintProgress->OpenProgressDialog(parentDOMIntl,
-                                               isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
-                                               *printProgressParams, openDialogObserver, notifyOnOpen);
-        }
+    if (mWatcher && !parentWindow) {
+        mWatcher->GetActiveWindow(getter_AddRefs(parentWindow));
     }
 
-    *webProgressListener = static_cast<nsIWebProgressListener*>(this);
-    NS_ADDREF(*webProgressListener);
+    if (parentWindow) {
+        mPrintProgress->OpenProgressDialog(parentWindow,
+                                           isForPrinting ? kPrintProgressDialogURL : kPrtPrvProgressDialogURL,
+                                           prtProgressParams, openDialogObserver, notifyOnOpen);
+    }
 
-    return rv;
+    prtProgressParams.forget(printProgressParams);
+    NS_ADDREF(*webProgressListener = this);
+
+    return NS_OK;
 }
 
 /* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
 NS_IMETHODIMP 
 nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, nsIObserver *aObs)
 {
     NS_ENSURE_ARG(printSettings);
 
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -2111,17 +2111,17 @@ nsWindowWatcher::GetJSContextFromWindow(
 {
   JSContext *cx = 0;
 
   if (aWindow) {
     nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow));
     if (sgo) {
       nsIScriptContext *scx = sgo->GetContext();
       if (scx)
-        cx = (JSContext *) scx->GetNativeContext();
+        cx = scx->GetNativeContext();
     }
     /* (off-topic note:) the nsIScriptContext can be retrieved by
     nsCOMPtr<nsIScriptContext> scx;
     nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scx));
     */
   }
 
   return cx;
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -264,19 +264,16 @@ static NS_DEFINE_CID(kWindowCommandTable
 
 nsresult
 NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 nsresult
 NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 #endif
 
-nsresult
-NS_NewDOMImplementation(nsIDOMDOMImplementation**);
-
 static void Shutdown();
 
 #ifdef MOZ_XTF
 #include "nsIXTFService.h"
 #include "nsIXMLContentBuilder.h"
 #endif
 
 #include "nsGeolocation.h"
@@ -505,17 +502,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMView
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDeepTreeWalker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inFlasher)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inCSSValueSearch)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMUtils)
 
 MAKE_CTOR(CreateNameSpaceManager,         nsINameSpaceManager,         NS_GetNameSpaceManager)
 MAKE_CTOR(CreateDocumentViewer,           nsIDocumentViewer,           NS_NewDocumentViewer)
 MAKE_CTOR(CreateHTMLDocument,             nsIDocument,                 NS_NewHTMLDocument)
-MAKE_CTOR(CreateDOMImplementation,        nsIDOMDOMImplementation,     NS_NewDOMImplementation)
 MAKE_CTOR(CreateXMLDocument,              nsIDocument,                 NS_NewXMLDocument)
 MAKE_CTOR(CreateSVGDocument,              nsIDocument,                 NS_NewSVGDocument)
 MAKE_CTOR(CreateImageDocument,            nsIDocument,                 NS_NewImageDocument)
 MAKE_CTOR(CreateDOMSelection,             nsISelection,                NS_NewDomSelection)
 MAKE_CTOR(CreateRange,                    nsIDOMRange,                 NS_NewRange)
 MAKE_CTOR(CreateRangeUtils,               nsIRangeUtils,               NS_NewRangeUtils)
 MAKE_CTOR(CreateContentIterator,          nsIContentIterator,          NS_NewContentIterator)
 MAKE_CTOR(CreatePreContentIterator,       nsIContentIterator,          NS_NewPreContentIterator)
@@ -741,17 +737,16 @@ NS_DEFINE_NAMED_CID(IN_DOMVIEW_CID);
 #endif
 NS_DEFINE_NAMED_CID(IN_DEEPTREEWALKER_CID);
 NS_DEFINE_NAMED_CID(IN_FLASHER_CID);
 NS_DEFINE_NAMED_CID(IN_CSSVALUESEARCH_CID);
 NS_DEFINE_NAMED_CID(IN_DOMUTILS_CID);
 NS_DEFINE_NAMED_CID(NS_NAMESPACEMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_DOCUMENT_VIEWER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLDOCUMENT_CID);
-NS_DEFINE_NAMED_CID(NS_DOM_IMPLEMENTATION_CID);
 NS_DEFINE_NAMED_CID(NS_XMLDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_SVGDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_IMAGEDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_DOMSELECTION_CID);
 NS_DEFINE_NAMED_CID(NS_RANGE_CID);
 NS_DEFINE_NAMED_CID(NS_RANGEUTILS_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENTITERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_PRECONTENTITERATOR_CID);
@@ -876,17 +871,16 @@ static const mozilla::Module::CIDEntry k
 #endif
   { &kIN_DEEPTREEWALKER_CID, false, NULL, inDeepTreeWalkerConstructor },
   { &kIN_FLASHER_CID, false, NULL, inFlasherConstructor },
   { &kIN_CSSVALUESEARCH_CID, false, NULL, inCSSValueSearchConstructor },
   { &kIN_DOMUTILS_CID, false, NULL, inDOMUtilsConstructor },
   { &kNS_NAMESPACEMANAGER_CID, false, NULL, CreateNameSpaceManager },
   { &kNS_DOCUMENT_VIEWER_CID, false, NULL, CreateDocumentViewer },
   { &kNS_HTMLDOCUMENT_CID, false, NULL, CreateHTMLDocument },
-  { &kNS_DOM_IMPLEMENTATION_CID, false, NULL, CreateDOMImplementation },
   { &kNS_XMLDOCUMENT_CID, false, NULL, CreateXMLDocument },
   { &kNS_SVGDOCUMENT_CID, false, NULL, CreateSVGDocument },
   { &kNS_IMAGEDOCUMENT_CID, false, NULL, CreateImageDocument },
   { &kNS_DOMSELECTION_CID, false, NULL, CreateDOMSelection },
   { &kNS_RANGE_CID, false, NULL, CreateRange },
   { &kNS_RANGEUTILS_CID, false, NULL, CreateRangeUtils },
   { &kNS_CONTENTITERATOR_CID, false, NULL, CreateContentIterator },
   { &kNS_PRECONTENTITERATOR_CID, false, NULL, CreatePreContentIterator },
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1054,17 +1054,16 @@ public:
 private:
   PRInt16 mSelectionValue;
 };
 
 void nsDisplaySelectionOverlay::Paint(nsDisplayListBuilder* aBuilder,
                                       nsRenderingContext* aCtx)
 {
   LookAndFeel::ColorID colorID;
-  nsresult result;
   if (mSelectionValue == nsISelectionController::SELECTION_ON) {
     colorID = LookAndFeel::eColorID_TextSelectBackground;
   } else if (mSelectionValue == nsISelectionController::SELECTION_ATTENTION) {
     colorID = LookAndFeel::eColorID_TextSelectBackgroundAttention;
   } else {
     colorID = LookAndFeel::eColorID_TextSelectBackgroundDisabled;
   }
 
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -2538,17 +2538,17 @@ nsObjectFrame::NotifyContentObjectWrappe
   nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
   if (!sgo)
     return;
 
   nsIScriptContext *scx = sgo->GetContext();
   if (!scx)
     return;
 
-  JSContext *cx = (JSContext *)scx->GetNativeContext();
+  JSContext *cx = scx->GetNativeContext();
 
   nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
   nsContentUtils::XPConnect()->
     GetWrappedNativeOfNativeObject(cx, sgo->GetGlobalJSObject(), mContent,
                                    NS_GET_IID(nsISupports),
                                    getter_AddRefs(wrapper));
 
   if (!wrapper) {
deleted file mode 100644
--- a/layout/reftests/svg/smil/motion/animateMotion-rotate-3.svg
+++ /dev/null
@@ -1,30 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg"
-     xmlns:xlink="http://www.w3.org/1999/xlink"
-     class="reftest-wait">
-  <!-- Tests for "rotate" interacting with the transform attribute. -->
-  <script xlink:href="../smil-util.js" type="text/javascript"/>
-  <script type="text/javascript">
-    function doTest() {
-      setTimeAndSnapshot(1, false);
-    }
-    window.addEventListener("MozReftestInvalidate", doTest, false);
-  </script>
-
-  <!-- Big green background to match lime.svg -->
-  <rect height="100%" width="100%" fill="lime"/>
-
-  <!-- A "shadow" rect (should be covered up by green rect). The only difference
-       between this rect and the other one is that this rect has the
-       |transform| attr set on its <g> parent instead of on it directly. -->
-  <g transform="translate(0, 50)">
-    <rect width="50" height="50" fill="red">
-     <animateMotion begin="0s" dur="1s" fill="freeze" rotate="90"
-                    path="M50 0 h50"/>
-    </rect>
-  </g>
-
-  <rect width="50" height="50" fill="lime" transform="translate(0, 50)">
-    <animateMotion begin="0s" dur="1s" fill="freeze" rotate="90"
-                   path="M50 0 h50"/>
-  </rect>
-</svg>
--- a/layout/reftests/svg/smil/motion/reftest.list
+++ b/layout/reftests/svg/smil/motion/reftest.list
@@ -3,17 +3,16 @@
 
 == animateMotion-by-1.svg      lime.svg
 == animateMotion-from-to-1.svg lime.svg
 == animateMotion-indefinite-to-1.svg lime.svg
 == animateMotion-indefinite-to-2.svg lime.svg
 == animateMotion-rotate-1a.svg lime.svg
 == animateMotion-rotate-1b.svg lime.svg
 == animateMotion-rotate-2.svg  lime.svg
-== animateMotion-rotate-3.svg  lime.svg
 == animateMotion-to-overridden-1.svg lime.svg
 == animateMotion-values-linear-1.svg animateMotion-values-linear-1-ref.svg
 == animateMotion-values-paced-1a.svg animateMotion-values-paced-1-ref.svg
 == animateMotion-values-paced-1b.svg animateMotion-values-paced-1-ref.svg
 
 # Tests involving <mpath> sub-element
 == animateMotion-mpath-pathLength-1.svg lime.svg
 == animateMotion-mpath-targetChange-1.svg lime.svg
--- a/parser/html/nsHtml5TreeOpExecutor.cpp
+++ b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -625,17 +625,17 @@ nsHtml5TreeOpExecutor::IsScriptEnabled()
   if (!globalObject) {
     nsCOMPtr<nsIScriptGlobalObjectOwner> owner = do_GetInterface(mDocShell);
     NS_ENSURE_TRUE(owner, PR_TRUE);
     globalObject = owner->GetScriptGlobalObject();
     NS_ENSURE_TRUE(globalObject, PR_TRUE);
   }
   nsIScriptContext *scriptContext = globalObject->GetContext();
   NS_ENSURE_TRUE(scriptContext, PR_TRUE);
-  JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
+  JSContext* cx = scriptContext->GetNativeContext();
   NS_ENSURE_TRUE(cx, PR_TRUE);
   PRBool enabled = PR_TRUE;
   nsContentUtils::GetSecurityManager()->
     CanExecuteScripts(cx, mDocument->NodePrincipal(), &enabled);
   return enabled;
 }
 
 void
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -587,17 +587,16 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       
       // Adapted from nsXMLContentSink
       // Create a new doctype node
       nsCOMPtr<nsIDOMDocumentType> docType;
       nsAutoString voidString;
       voidString.SetIsVoid(PR_TRUE);
       NS_NewDOMDocumentType(getter_AddRefs(docType),
                             aBuilder->GetNodeInfoManager(),
-                            nsnull,
                             name,
                             publicId,
                             systemId,
                             voidString);
       NS_ASSERTION(docType, "Doctype creation failed.");
       nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
       return AppendToDocument(asContent, aBuilder);
     }
--- a/toolkit/toolkit-makefiles.sh
+++ b/toolkit/toolkit-makefiles.sh
@@ -261,17 +261,16 @@ MAKEFILES_content="
   content/xbl/builtin/unix/Makefile
   content/xslt/Makefile
   content/xslt/public/Makefile
   content/xslt/src/Makefile
   content/xslt/src/base/Makefile
   content/xslt/src/xml/Makefile
   content/xslt/src/xpath/Makefile
   content/xslt/src/xslt/Makefile
-  content/xslt/src/main/Makefile
 "
 
 MAKEFILES_layout="
   layout/Makefile
   layout/base/Makefile
   layout/base/tests/Makefile
   layout/build/Makefile
   layout/forms/Makefile
@@ -677,17 +676,16 @@ MAKEFILES_jsctypes="
 
 MAKEFILES_jsreflect="
   toolkit/components/reflect/Makefile
 "
 
 MAKEFILES_jsductwork="
   js/ductwork/Makefile
   js/ductwork/debugger/Makefile
-  js/ductwork/debugger/tests/Makefile
 "
 
 MAKEFILES_libpr0n="
   modules/libpr0n/Makefile
   modules/libpr0n/build/Makefile
   modules/libpr0n/public/Makefile
   modules/libpr0n/src/Makefile
   modules/libpr0n/decoders/Makefile
--- a/widget/public/nsGUIEvent.h
+++ b/widget/public/nsGUIEvent.h
@@ -257,16 +257,18 @@ class nsHashKey;
 #define NS_MOUSE_ENTER                  (NS_MOUSE_MESSAGE_START + 22)
 #define NS_MOUSE_EXIT                   (NS_MOUSE_MESSAGE_START + 23)
 #define NS_MOUSE_DOUBLECLICK            (NS_MOUSE_MESSAGE_START + 24)
 #define NS_MOUSE_CLICK                  (NS_MOUSE_MESSAGE_START + 27)
 #define NS_MOUSE_ACTIVATE               (NS_MOUSE_MESSAGE_START + 30)
 #define NS_MOUSE_ENTER_SYNTH            (NS_MOUSE_MESSAGE_START + 31)
 #define NS_MOUSE_EXIT_SYNTH             (NS_MOUSE_MESSAGE_START + 32)
 #define NS_MOUSE_MOZHITTEST             (NS_MOUSE_MESSAGE_START + 33)
+#define NS_MOUSEENTER                   (NS_MOUSE_MESSAGE_START + 34)
+#define NS_MOUSELEAVE                   (NS_MOUSE_MESSAGE_START + 35)
 
 #define NS_CONTEXTMENU_MESSAGE_START    500
 #define NS_CONTEXTMENU                  (NS_CONTEXTMENU_MESSAGE_START)
 
 #define NS_SCROLLBAR_MESSAGE_START      1000
 #define NS_SCROLLBAR_POS                (NS_SCROLLBAR_MESSAGE_START)
 #define NS_SCROLLBAR_PAGE_NEXT          (NS_SCROLLBAR_MESSAGE_START + 1)
 #define NS_SCROLLBAR_PAGE_PREV          (NS_SCROLLBAR_MESSAGE_START + 2)
@@ -873,35 +875,53 @@ public:
 
 protected:
   nsMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w,
                PRUint8 structType, reasonType aReason)
     : nsMouseEvent_base(isTrusted, msg, w, structType),
       acceptActivation(PR_FALSE), ignoreRootScrollFrame(PR_FALSE),
       reason(aReason), context(eNormal), exit(eChild), clickCount(0)
   {
-    if (msg == NS_MOUSE_MOVE) {
-      flags |= NS_EVENT_FLAG_CANT_CANCEL;
+    switch (msg) {
+      case NS_MOUSE_MOVE:
+        flags |= NS_EVENT_FLAG_CANT_CANCEL;
+        break;
+      case NS_MOUSEENTER:
+      case NS_MOUSELEAVE:
+        flags |= (NS_EVENT_FLAG_CANT_CANCEL & NS_EVENT_FLAG_CANT_BUBBLE);
+        break;
+      default:
+        break;
     }
   }
 
 public:
 
   nsMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w,
                reasonType aReason, contextType aContext = eNormal)
     : nsMouseEvent_base(isTrusted, msg, w, NS_MOUSE_EVENT),
       acceptActivation(PR_FALSE), ignoreRootScrollFrame(PR_FALSE),
       reason(aReason), context(aContext), exit(eChild), clickCount(0)
   {
-    if (msg == NS_MOUSE_MOVE) {
-      flags |= NS_EVENT_FLAG_CANT_CANCEL;
-    } else if (msg == NS_CONTEXTMENU) {
-      button = (context == eNormal) ? eRightButton : eLeftButton;
+    switch (msg) {
+      case NS_MOUSE_MOVE:
+        flags |= NS_EVENT_FLAG_CANT_CANCEL;
+        break;
+      case NS_MOUSEENTER:
+      case NS_MOUSELEAVE:
+        flags |= (NS_EVENT_FLAG_CANT_CANCEL | NS_EVENT_FLAG_CANT_BUBBLE);
+        break;
+      case NS_CONTEXTMENU:
+        button = (context == eNormal) ? eRightButton : eLeftButton;
+        break;
+      default:
+        break;
     }
   }
+
 #ifdef NS_DEBUG
   ~nsMouseEvent() {
     NS_WARN_IF_FALSE(message != NS_CONTEXTMENU ||
                      button ==
                        ((context == eNormal) ? eRightButton : eLeftButton),
                      "Wrong button set to NS_CONTEXTMENU event?");
   }
 #endif
--- a/xpfe/appshell/src/nsAppShellService.cpp
+++ b/xpfe/appshell/src/nsAppShellService.cpp
@@ -446,17 +446,17 @@ nsAppShellService::GetHiddenWindowAndJSC
                 sgo = do_QueryInterface( hiddenDOMWindow );
                 if (!sgo) { rv = NS_ERROR_FAILURE; break; }
 
                 // 4. Get script context from that.
                 nsIScriptContext *scriptContext = sgo->GetContext();
                 if (!scriptContext) { rv = NS_ERROR_FAILURE; break; }
 
                 // 5. Get JSContext from the script context.
-                JSContext *jsContext = (JSContext*)scriptContext->GetNativeContext();
+                JSContext *jsContext = scriptContext->GetNativeContext();
                 if (!jsContext) { rv = NS_ERROR_FAILURE; break; }
 
                 // Now, give results to caller.
                 *aWindow    = hiddenDOMWindow.get();
                 NS_IF_ADDREF( *aWindow );
                 *aJSContext = jsContext;
             } while (0);
         } else {
--- a/xpfe/components/directory/nsDirectoryViewer.cpp
+++ b/xpfe/components/directory/nsDirectoryViewer.cpp
@@ -193,18 +193,17 @@ nsHTTPIndex::OnFTPControlLog(PRBool serv
     NS_ENSURE_TRUE(mRequestor, NS_OK);
 
     nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));
     NS_ENSURE_TRUE(scriptGlobal, NS_OK);
 
     nsIScriptContext *context = scriptGlobal->GetContext();
     NS_ENSURE_TRUE(context, NS_OK);
 
-    JSContext* cx = reinterpret_cast<JSContext*>
-                                    (context->GetNativeContext());
+    JSContext* cx = context->GetNativeContext();
     NS_ENSURE_TRUE(cx, NS_OK);
 
     JSObject* global = JS_GetGlobalObject(cx);
     NS_ENSURE_TRUE(global, NS_OK);
 
     jsval params[2];
 
     nsString unicodeMsg;
@@ -271,18 +270,17 @@ nsHTTPIndex::OnStartRequest(nsIRequest *
 
     // Now get the content viewer container's script object.
     nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));
     NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_FAILURE);
 
     nsIScriptContext *context = scriptGlobal->GetContext();
     NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
 
-    JSContext* cx = reinterpret_cast<JSContext*>
-                                    (context->GetNativeContext());
+    JSContext* cx = context->GetNativeContext();
     JSObject* global = JS_GetGlobalObject(cx);
 
     // Using XPConnect, wrap the HTTP index object...
     static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
     nsCOMPtr<nsIXPConnect> xpc(do_GetService(kXPConnectCID, &rv));
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
--- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp
+++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp
@@ -739,17 +739,17 @@ nsresult InitInstallTriggerGlobalClass(J
 
 
 
 //
 // InstallTriggerGlobal class initialization
 //
 nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype)
 {
-  JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
+  JSContext *jscontext = aContext->GetNativeContext();
   JSObject *proto = nsnull;
   JSObject *constructor = nsnull;
   JSObject *global = JS_GetGlobalObject(jscontext);
   jsval vp;
 
   if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) ||
       !JSVAL_IS_OBJECT(vp) ||
       ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
@@ -784,17 +784,17 @@ NS_NewScriptInstallTriggerGlobal(nsIScri
                                  void **aReturn)
 {
   NS_PRECONDITION(nsnull != aContext && nsnull != aSupports &&
                   nsnull != aReturn,
                   "null argument to NS_NewScriptInstallTriggerGlobal");
 
   JSObject *proto;
   JSObject *parent = nsnull;
-  JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
+  JSContext *jscontext = aContext->GetNativeContext();
   nsresult result = NS_OK;
   nsIDOMInstallTriggerGlobal *installTriggerGlobal;
 
   nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(aParent));
 
   if (owner) {
     if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
       return NS_ERROR_FAILURE;