From 2bc9672fe55727c2b1f0341b2370e7c08afd6435 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.org" Date: Tue, 11 Dec 2007 01:19:19 +0000 Subject: [PATCH] Fixing bug 407812. Don't waste time calling QI in nsNodeSH::PreCreate() and nsElementSH::PostCreate(). r+sr=jonas@sicking.cc git-svn-id: svn://10.0.0.236/trunk@240768 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDOMAttribute.cpp | 6 +++- mozilla/content/base/src/nsDocument.cpp | 6 +++- .../content/base/src/nsGenericDOMDataNode.cpp | 4 +++ mozilla/content/base/src/nsGenericElement.cpp | 4 +++ .../html/document/src/nsImageDocument.cpp | 12 ++++---- mozilla/dom/src/base/nsDOMClassInfo.cpp | 28 ++++++++++++++++--- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/mozilla/content/base/src/nsDOMAttribute.cpp b/mozilla/content/base/src/nsDOMAttribute.cpp index d01023df035..2a2e889d9b1 100644 --- a/mozilla/content/base/src/nsDOMAttribute.cpp +++ b/mozilla/content/base/src/nsDOMAttribute.cpp @@ -99,7 +99,11 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMAttribute) NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference, new nsNodeSupportsWeakRefTearoff(this)) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMAttr) + // nsNodeSH::PreCreate() depends on the identity pointer being the + // same as nsINode (which nsIAttribute inherits), so if you change + // the below line, make sure nsNodeSH::PreCreate() still does the + // right thing! + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAttribute) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Attr) NS_INTERFACE_MAP_END diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index c2fce3d4f5a..bdbaabb218a 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -896,6 +896,7 @@ nsDocument::~nsDocument() NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocument) + NS_INTERFACE_MAP_ENTRY(nsINode) NS_INTERFACE_MAP_ENTRY(nsIDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument) @@ -917,8 +918,11 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocument) NS_INTERFACE_MAP_ENTRY(nsIDOM3Document) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIRadioGroupContainer) - NS_INTERFACE_MAP_ENTRY(nsINode) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) + // nsNodeSH::PreCreate() depends on the identity pointer being the + // same as nsINode (which nsIDocument inherits), so if you change + // the below line, make sure nsNodeSH::PreCreate() still does the + // right thing! NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument) if (aIID.Equals(NS_GET_IID(nsIDOMXPathEvaluator)) || aIID.Equals(NS_GET_IID(nsIXPathEvaluatorInternal))) { diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index 1eabde52c2b..171d22daf1c 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -103,6 +103,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericDOMDataNode) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference, new nsNodeSupportsWeakRefTearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) + // nsNodeSH::PreCreate() depends on the identity pointer being the + // same as nsINode (which nsIContent inherits), so if you change the + // below line, make sure nsNodeSH::PreCreate() still does the right + // thing! NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) NS_INTERFACE_MAP_END diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index d676f7b6b00..2ee5b97a36a 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -3434,6 +3434,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericElement) nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference, new nsNodeSupportsWeakRefTearoff(this)) + // nsNodeSH::PreCreate() depends on the identity pointer being the + // same as nsINode (which nsIContent inherits), so if you change the + // below line, make sure nsNodeSH::PreCreate() still does the right + // thing! NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) NS_INTERFACE_MAP_END diff --git a/mozilla/content/html/document/src/nsImageDocument.cpp b/mozilla/content/html/document/src/nsImageDocument.cpp index 4c9199e5851..2a450e09e80 100644 --- a/mozilla/content/html/document/src/nsImageDocument.cpp +++ b/mozilla/content/html/document/src/nsImageDocument.cpp @@ -266,13 +266,11 @@ nsImageDocument::~nsImageDocument() NS_IMPL_ADDREF_INHERITED(nsImageDocument, nsMediaDocument) NS_IMPL_RELEASE_INHERITED(nsImageDocument, nsMediaDocument) -NS_INTERFACE_TABLE_HEAD(nsImageDocument) - NS_INTERFACE_TABLE4(nsImageDocument, - nsIImageDocument, - imgIDecoderObserver, - imgIContainerObserver, - nsIDOMEventListener) - NS_INTERFACE_TABLE_TO_MAP_SEGUE +NS_INTERFACE_MAP_BEGIN(nsImageDocument) + NS_INTERFACE_MAP_ENTRY(nsIImageDocument) + NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver) + NS_INTERFACE_MAP_ENTRY(imgIContainerObserver) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ImageDocument) NS_INTERFACE_MAP_END_INHERITING(nsMediaDocument) diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index 9ccd04e1507..dc1a4f63353 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -6444,9 +6444,19 @@ NS_IMETHODIMP nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj) { - nsCOMPtr node(do_QueryInterface(nativeObj)); - NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED); + nsINode *node = static_cast(nativeObj); +#ifdef DEBUG + { + nsCOMPtr node_qi(do_QueryInterface(nativeObj)); + + // If this assertion fires the QI implementation for the object in + // question doesn't use the nsINode pointer as the nsISupports + // pointer. That must be fixed, or we'll crash... + NS_ASSERTION(node_qi == node, "Uh, fix QI!"); + } +#endif + // Make sure that we get the owner document of the content node, in case // we're in document teardown. If we are, it's important to *not* use // globalObj as the nodes parent since that would give the node the @@ -6964,8 +6974,18 @@ nsElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, nsresult rv = nsNodeSH::PostCreate(wrapper, cx, obj); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr content(do_QueryWrappedNative(wrapper)); - NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED); + nsIContent *content = static_cast(wrapper->Native()); + +#ifdef DEBUG + { + nsCOMPtr content_qi(do_QueryWrappedNative(wrapper)); + + // If this assertion fires the QI implementation for the object in + // question doesn't use the nsIContent pointer as the nsISupports + // pointer. That must be fixed, or we'll crash... + NS_ASSERTION(content_qi == content, "Uh, fix QI!"); + } +#endif nsCOMPtr doc; if (content->HasFlag(NODE_FORCE_XBL_BINDINGS)) {