Bug 539683 - defunct object methods should return CO_E_OBJNOTCONNECTED, patch=tbsaunde, surkov, r=surkov, tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 09 Apr 2012 23:45:47 +0900
changeset 91249 74670610b9194aab1c5422a4cdcc00e7f255ccab
parent 91248 bf132b7a5a9d839643f832f9e0996e6d0e3e6def
child 91250 575db34e12396ab28b333a9d3df2d3dd9ca13530
push id22433
push usereakhgari@mozilla.com
push dateTue, 10 Apr 2012 15:11:59 +0000
treeherdermozilla-central@3fa30b0edd15 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov, tbsaunde
bugs539683
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 539683 - defunct object methods should return CO_E_OBJNOTCONNECTED, patch=tbsaunde, surkov, r=surkov, tbsaunde
accessible/src/msaa/CAccessibleComponent.cpp
accessible/src/msaa/CAccessibleEditableText.cpp
accessible/src/msaa/CAccessibleHyperlink.cpp
accessible/src/msaa/CAccessibleHypertext.cpp
accessible/src/msaa/CAccessibleText.cpp
accessible/src/msaa/ia2AccessibleAction.cpp
accessible/src/msaa/nsAccessibleWrap.cpp
accessible/src/msaa/nsApplicationAccessibleWrap.cpp
--- a/accessible/src/msaa/CAccessibleComponent.cpp
+++ b/accessible/src/msaa/CAccessibleComponent.cpp
@@ -75,18 +75,18 @@ CAccessibleComponent::QueryInterface(REF
 STDMETHODIMP
 CAccessibleComponent::get_locationInParent(long *aX, long *aY)
 {
 __try {
   *aX = 0;
   *aY = 0;
 
   nsRefPtr<nsAccessible> acc(do_QueryObject(this));
-  if (!acc)
-    return E_FAIL;
+  if (acc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   // If the object is not on any screen the returned position is (0,0).
   PRUint64 state = acc->State();
   if (state & states::INVISIBLE)
     return S_OK;
 
   PRInt32 x = 0, y = 0, width = 0, height = 0;
   nsresult rv = acc->GetBounds(&x, &y, &width, &height);
@@ -123,17 +123,17 @@ CAccessibleComponent::get_locationInPare
 }
 
 STDMETHODIMP
 CAccessibleComponent::get_foreground(IA2Color* aForeground)
 {
 __try {
   nsRefPtr<nsAccessible> acc(do_QueryObject(this));
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsIFrame* frame = acc->GetFrame();
   if (frame)
     *aForeground = frame->GetStyleColor()->mColor;
 
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
@@ -142,17 +142,17 @@ CAccessibleComponent::get_foreground(IA2
 }
 
 STDMETHODIMP
 CAccessibleComponent::get_background(IA2Color* aBackground)
 {
 __try {
   nsRefPtr<nsAccessible> acc(do_QueryObject(this));
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsIFrame* frame = acc->GetFrame();
   if (frame)
     *aBackground = frame->GetStyleBackground()->mBackgroundColor;
 
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
--- a/accessible/src/msaa/CAccessibleEditableText.cpp
+++ b/accessible/src/msaa/CAccessibleEditableText.cpp
@@ -35,30 +35,22 @@
  * 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 ***** */
 
 #include "CAccessibleEditableText.h"
 
-#include "nsIAccessibleEditableText.h"
 #include "AccessibleEditableText_i.c"
-#include "nsAccessNodeWrap.h"
+#include "nsHyperTextAccessible.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
-#define GET_NSIACCESSIBLEEDITABLETEXT \
-nsCOMPtr<nsIAccessibleEditableText> textAcc(do_QueryObject(this));\
-NS_ASSERTION(textAcc,\
-             "Subclass of CAccessibleEditableText doesn't implement nsIAccessibleEditableText");\
-if (!textAcc)\
-  return E_FAIL;\
-
 // IUnknown
 
 STDMETHODIMP
 CAccessibleEditableText::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleEditableText == iid) {
@@ -74,86 +66,98 @@ CAccessibleEditableText::QueryInterface(
 }
 
 // IAccessibleEditableText
 
 STDMETHODIMP
 CAccessibleEditableText::copyText(long aStartOffset, long aEndOffset)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->CopyText(aStartOffset, aEndOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleEditableText::deleteText(long aStartOffset, long aEndOffset)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->DeleteText(aStartOffset, aEndOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleEditableText::insertText(long aOffset, BSTR *aText)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint32 length = ::SysStringLen(*aText);
   nsAutoString text(*aText, length);
 
   nsresult rv = textAcc->InsertText(text, aOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleEditableText::cutText(long aStartOffset, long aEndOffset)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->CutText(aStartOffset, aEndOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleEditableText::pasteText(long aOffset)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->PasteText(aOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleEditableText::replaceText(long aStartOffset, long aEndOffset,
                                      BSTR *aText)
 {
 __try {
-  GET_NSIACCESSIBLEEDITABLETEXT
+  nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->DeleteText(aStartOffset, aEndOffset);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   PRUint32 length = ::SysStringLen(*aText);
   nsAutoString text(*aText, length);
 
--- a/accessible/src/msaa/CAccessibleHyperlink.cpp
+++ b/accessible/src/msaa/CAccessibleHyperlink.cpp
@@ -71,22 +71,25 @@ CAccessibleHyperlink::QueryInterface(REF
 
 STDMETHODIMP
 CAccessibleHyperlink::get_anchor(long aIndex, VARIANT *aAnchor)
 {
 __try {
   VariantInit(aAnchor);
 
   nsRefPtr<nsAccessible> thisObj = do_QueryObject(this);
-  if (thisObj->IsDefunct() || !thisObj->IsLink())
-    return E_FAIL;
+  if (thisObj->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
     return E_INVALIDARG;
 
+  if (!thisObj->IsLink())
+    return S_FALSE;
+
   nsAccessibleWrap* anchor =
     static_cast<nsAccessibleWrap*>(thisObj->AnchorAt(aIndex));
   if (!anchor)
     return S_FALSE;
 
   void* instancePtr = NULL;
   HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr);
   if (FAILED(result))
@@ -103,22 +106,25 @@ CAccessibleHyperlink::get_anchor(long aI
 
 STDMETHODIMP
 CAccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT *aAnchorTarget)
 {
 __try {
   VariantInit(aAnchorTarget);
 
   nsRefPtr<nsAccessible> thisObj = do_QueryObject(this);
-  if (thisObj->IsDefunct() || !thisObj->IsLink())
-    return E_FAIL;
+  if (thisObj->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
     return E_INVALIDARG;
 
+  if (!thisObj->IsLink())
+    return S_FALSE;
+
   nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex);
   if (!uri)
     return S_FALSE;
 
   nsCAutoString prePath;
   nsresult rv = uri->GetPrePath(prePath);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
@@ -143,52 +149,61 @@ CAccessibleHyperlink::get_anchorTarget(l
 
 STDMETHODIMP
 CAccessibleHyperlink::get_startIndex(long *aIndex)
 {
 __try {
   *aIndex = 0;
 
   nsRefPtr<nsAccessible> thisObj = do_QueryObject(this);
-  if (thisObj->IsDefunct() || !thisObj->IsLink())
-    return E_FAIL;
+  if (thisObj->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  if (!thisObj->IsLink())
+    return S_FALSE;
 
   *aIndex = thisObj->StartOffset();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleHyperlink::get_endIndex(long *aIndex)
 {
 __try {
   *aIndex = 0;
 
   nsRefPtr<nsAccessible> thisObj = do_QueryObject(this);
-  if (thisObj->IsDefunct() || !thisObj->IsLink())
-    return E_FAIL;
+  if (thisObj->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  if (!thisObj->IsLink())
+    return S_FALSE;
 
   *aIndex = thisObj->EndOffset();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleHyperlink::get_valid(boolean *aValid)
 {
 __try {
   *aValid = false;
 
   nsRefPtr<nsAccessible> thisObj = do_QueryObject(this);
-  if (thisObj->IsDefunct() || !thisObj->IsLink())
-    return E_FAIL;
+  if (thisObj->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  if (!thisObj->IsLink())
+    return S_FALSE;
 
   *aValid = thisObj->IsLinkValid();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
--- a/accessible/src/msaa/CAccessibleHypertext.cpp
+++ b/accessible/src/msaa/CAccessibleHypertext.cpp
@@ -67,36 +67,36 @@ CAccessibleHypertext::QueryInterface(REF
 
 STDMETHODIMP
 CAccessibleHypertext::get_nHyperlinks(long *aHyperlinkCount)
 {
 __try {
   *aHyperlinkCount = 0;
 
   nsRefPtr<nsHyperTextAccessible> hyperText = do_QueryObject(this);
-  if (!hyperText)
-    return E_FAIL;
+  if (hyperText->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   *aHyperlinkCount = hyperText->GetLinkCount();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleHypertext::get_hyperlink(long aLinkIndex,
                                     IAccessibleHyperlink **aHyperlink)
 {
 __try {
   *aHyperlink = NULL;
 
   nsRefPtr<nsHyperTextAccessible> hyperText = do_QueryObject(this);
-  if (!hyperText)
-    return E_FAIL;
+  if (hyperText->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsAccessible* hyperLink = hyperText->GetLinkAt(aLinkIndex);
   nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryObject(hyperLink));
   if (!winAccessNode)
     return E_FAIL;
 
   void *instancePtr = NULL;
   nsresult rv =  winAccessNode->QueryNativeInterface(IID_IAccessibleHyperlink,
@@ -113,18 +113,18 @@ CAccessibleHypertext::get_hyperlink(long
 
 STDMETHODIMP
 CAccessibleHypertext::get_hyperlinkIndex(long aCharIndex, long *aHyperlinkIndex)
 {
 __try {
   *aHyperlinkIndex = 0;
 
   nsRefPtr<nsHyperTextAccessible> hyperAcc(do_QueryObject(this));
-  if (!hyperAcc)
-    return E_FAIL;
+  if (hyperAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   *aHyperlinkIndex = hyperAcc->GetLinkIndexAtOffset(aCharIndex);
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
--- a/accessible/src/msaa/CAccessibleText.cpp
+++ b/accessible/src/msaa/CAccessibleText.cpp
@@ -69,16 +69,19 @@ CAccessibleText::QueryInterface(REFIID i
 
 // IAccessibleText
 
 STDMETHODIMP
 CAccessibleText::addSelection(long aStartOffset, long aEndOffset)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsresult rv = textAcc->AddSelection(aStartOffset, aEndOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
@@ -89,16 +92,18 @@ CAccessibleText::get_attributes(long aOf
   if (!aStartOffset || !aEndOffset || !aTextAttributes)
     return E_INVALIDARG;
 
   *aStartOffset = 0;
   *aEndOffset = 0;
   *aTextAttributes = NULL;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRInt32 startOffset = 0, endOffset = 0;
   nsCOMPtr<nsIPersistentProperties> attributes;
   nsresult rv = textAcc->GetTextAttributes(true, aOffset,
                                            &startOffset, &endOffset,
                                            getter_AddRefs(attributes));
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
@@ -119,16 +124,18 @@ CAccessibleText::get_attributes(long aOf
 
 STDMETHODIMP
 CAccessibleText::get_caretOffset(long *aOffset)
 {
 __try {
   *aOffset = -1;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRInt32 offset = 0;
   nsresult rv = textAcc->GetCaretOffset(&offset);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   *aOffset = offset;
   return offset != -1 ? S_OK : S_FALSE;
@@ -145,16 +152,18 @@ CAccessibleText::get_characterExtents(lo
 {
 __try {
   *aX = 0;
   *aY = 0;
   *aWidth = 0;
   *aHeight = 0;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint32 geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
     nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
     nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
 
   PRInt32 x = 0, y =0, width = 0, height = 0;
   nsresult rv = textAcc->GetCharacterExtents (aOffset, &x, &y, &width, &height,
                                               geckoCoordType);
@@ -174,17 +183,17 @@ CAccessibleText::get_characterExtents(lo
 STDMETHODIMP
 CAccessibleText::get_nSelections(long *aNSelections)
 {
 __try {
   *aNSelections = 0;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
   if (textAcc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   PRInt32 selCount = 0;
   nsresult rv = textAcc->GetSelectionCount(&selCount);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   *aNSelections = selCount;
   return S_OK;
@@ -197,16 +206,18 @@ STDMETHODIMP
 CAccessibleText::get_offsetAtPoint(long aX, long aY,
                                    enum IA2CoordinateType aCoordType,
                                    long *aOffset)
 {
 __try {
   *aOffset = 0;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint32 geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
     nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
     nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
 
   PRInt32 offset = 0;
   nsresult rv = textAcc->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
   if (NS_FAILED(rv))
@@ -223,16 +234,18 @@ STDMETHODIMP
 CAccessibleText::get_selection(long aSelectionIndex, long *aStartOffset,
                                long *aEndOffset)
 {
 __try {
   *aStartOffset = 0;
   *aEndOffset = 0;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRInt32 startOffset = 0, endOffset = 0;
   nsresult rv = textAcc->GetSelectionBounds(aSelectionIndex,
                                             &startOffset, &endOffset);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   *aStartOffset = startOffset;
@@ -245,16 +258,18 @@ CAccessibleText::get_selection(long aSel
 
 STDMETHODIMP
 CAccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR *aText)
 {
 __try {
   *aText = NULL;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsAutoString text;
   nsresult rv = textAcc->GetText(aStartOffset, aEndOffset, text);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (text.IsEmpty())
     return S_FALSE;
@@ -274,17 +289,17 @@ CAccessibleText::get_textBeforeOffset(lo
 {
 __try {
   *aStartOffset = 0;
   *aEndOffset = 0;
   *aText = NULL;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
   if (textAcc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = NS_OK;
   nsAutoString text;
   PRInt32 startOffset = 0, endOffset = 0;
 
   if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
     startOffset = 0;
     endOffset = textAcc->CharacterCount();
@@ -321,17 +336,17 @@ CAccessibleText::get_textAfterOffset(lon
 {
 __try {
   *aStartOffset = 0;
   *aEndOffset = 0;
   *aText = NULL;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
   if (textAcc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = NS_OK;
   nsAutoString text;
   PRInt32 startOffset = 0, endOffset = 0;
 
   if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
     startOffset = 0;
     endOffset = textAcc->CharacterCount();
@@ -368,17 +383,17 @@ CAccessibleText::get_textAtOffset(long a
 {
 __try {
   *aStartOffset = 0;
   *aEndOffset = 0;
   *aText = NULL;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
   if (textAcc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = NS_OK;
   nsAutoString text;
   PRInt32 startOffset = 0, endOffset = 0;
 
   if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
     startOffset = 0;
     endOffset = textAcc->CharacterCount();
@@ -407,43 +422,49 @@ CAccessibleText::get_textAtOffset(long a
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleText::removeSelection(long aSelectionIndex)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->RemoveSelection(aSelectionIndex);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleText::setCaretOffset(long aOffset)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->SetCaretOffset(aOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleText::setSelection(long aSelectionIndex, long aStartOffset,
                               long aEndOffset)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->SetSelectionBounds(aSelectionIndex,
                                             aStartOffset, aEndOffset);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
@@ -451,46 +472,50 @@ CAccessibleText::setSelection(long aSele
 STDMETHODIMP
 CAccessibleText::get_nCharacters(long *aNCharacters)
 {
 __try {
   *aNCharacters = 0;
 
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
   if (textAcc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   *aNCharacters  = textAcc->CharacterCount();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleText::scrollSubstringTo(long aStartIndex, long aEndIndex,
                                    enum IA2ScrollType aScrollType)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsresult rv = textAcc->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex,
                                         enum IA2CoordinateType aCoordType,
                                         long aX, long aY)
 {
 __try {
   nsRefPtr<nsHyperTextAccessible> textAcc(do_QueryObject(this));
+  if (textAcc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint32 geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
     nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
     nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
 
   nsresult rv = textAcc->ScrollSubstringToPoint(aStartIndex, aEndIndex,
                                                 geckoCoordType, aX, aY);
   return GetHRESULT(rv);
--- a/accessible/src/msaa/ia2AccessibleAction.cpp
+++ b/accessible/src/msaa/ia2AccessibleAction.cpp
@@ -68,32 +68,32 @@ ia2AccessibleAction::nActions(long* aAct
 __try {
   if (!aActionCount)
     return E_INVALIDARG;
 
   *aActionCount = 0;
 
   nsAccessibleWrap* acc = static_cast<nsAccessibleWrap*>(this);
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   *aActionCount = acc->ActionCount();
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 ia2AccessibleAction::doAction(long aActionIndex)
 {
 __try {
   nsAccessibleWrap* acc = static_cast<nsAccessibleWrap*>(this);
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint8 index = static_cast<PRUint8>(aActionIndex);
   nsresult rv = acc->DoAction(index);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
@@ -101,17 +101,17 @@ ia2AccessibleAction::doAction(long aActi
 STDMETHODIMP
 ia2AccessibleAction::get_description(long aActionIndex, BSTR *aDescription)
 {
 __try {
   *aDescription = NULL;
 
   nsAccessibleWrap* acc = static_cast<nsAccessibleWrap*>(this);
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsAutoString description;
   PRUint8 index = static_cast<PRUint8>(aActionIndex);
   nsresult rv = acc->GetActionDescription(index, description);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (description.IsEmpty())
@@ -139,17 +139,17 @@ ia2AccessibleAction::get_keyBinding(long
     return E_INVALIDARG;
   *aNumBinding = 0;
 
   if (aActionIndex != 0 || aNumMaxBinding < 1)
     return E_INVALIDARG;
 
   nsAccessibleWrap* acc = static_cast<nsAccessibleWrap*>(this);
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   // Expose keyboard shortcut if it's not exposed via MSAA keyboard shortcut.
   KeyBinding keyBinding = acc->AccessKey();
   if (keyBinding.IsEmpty())
     return S_FALSE;
 
   keyBinding = acc->KeyboardShortcut();
   if (keyBinding.IsEmpty())
@@ -178,17 +178,17 @@ ia2AccessibleAction::get_keyBinding(long
 STDMETHODIMP
 ia2AccessibleAction::get_name(long aActionIndex, BSTR *aName)
 {
 __try {
   *aName = NULL;
 
   nsAccessibleWrap* acc = static_cast<nsAccessibleWrap*>(this);
   if (acc->IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsAutoString name;
   PRUint8 index = static_cast<PRUint8>(aActionIndex);
   nsresult rv = acc->GetActionName(index, name);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (name.IsEmpty())
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -163,17 +163,17 @@ STDMETHODIMP nsAccessibleWrap::QueryInte
 //-----------------------------------------------------
 
 STDMETHODIMP nsAccessibleWrap::get_accParent( IDispatch __RPC_FAR *__RPC_FAR *ppdispParent)
 {
 __try {
   *ppdispParent = NULL;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsRefPtr<nsDocAccessible> doc(do_QueryObject(this));
   if (doc) {
     // Return window system accessible object for root document and tab document
     // accessibles.
     if (!doc->ParentDocument() ||
         nsWinUtils::IsWindowEmulationStarted() &&
         nsCoreUtils::IsTabDocument(doc->GetDocumentNode())) {
@@ -205,17 +205,17 @@ STDMETHODIMP nsAccessibleWrap::get_accCh
 {
 __try {
   if (!pcountChildren)
     return E_INVALIDARG;
 
   *pcountChildren = 0;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   if (nsAccUtils::MustPrune(this))
     return S_OK;
 
   *pcountChildren = GetChildCount();
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
 
   return S_OK;
@@ -223,41 +223,54 @@ STDMETHODIMP nsAccessibleWrap::get_accCh
 
 STDMETHODIMP nsAccessibleWrap::get_accChild(
       /* [in] */ VARIANT varChild,
       /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispChild)
 {
 __try {
   *ppdispChild = NULL;
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   // IAccessible::accChild is used to return this accessible or child accessible
   // at the given index or to get an accessible by child ID in the case of
   // document accessible (it's handled by overriden GetXPAccessibleFor method
   // on the document accessible). The getting an accessible by child ID is used
   // by AccessibleObjectFromEvent() called by AT when AT handles our MSAA event.
   nsAccessible* child = GetXPAccessibleFor(varChild);
-  if (child)
-    *ppdispChild = NativeAccessible(child);
+  if (!child)
+    return E_INVALIDARG;
+
+  if (child->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  *ppdispChild = NativeAccessible(child);
 
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
 
-  return (*ppdispChild)? S_OK: E_INVALIDARG;
+  return S_OK;
 }
 
 STDMETHODIMP nsAccessibleWrap::get_accName(
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ BSTR __RPC_FAR *pszName)
 {
 __try {
   *pszName = NULL;
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
+
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
   if (!xpAccessible)
-    return E_FAIL;
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString name;
   nsresult rv = xpAccessible->GetName(name);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   // The name was not provided, e.g. no alt attribute for an image. A screen
   // reader may choose to invent its own accessible name, e.g. from an image src
   // attribute. Refer to NS_OK_EMPTY_NAME return value.
@@ -276,19 +289,25 @@ STDMETHODIMP nsAccessibleWrap::get_accNa
 
 STDMETHODIMP nsAccessibleWrap::get_accValue(
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ BSTR __RPC_FAR *pszValue)
 {
 __try {
   *pszValue = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
-  if (!xpAccessible || xpAccessible->IsDefunct())
-    return E_FAIL;
+  if (!xpAccessible)
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   if (xpAccessible->NativeRole() == roles::PASSWORD_TEXT)
     return E_ACCESSDENIED;
 
   nsAutoString value;
   xpAccessible->Value(value);
 
   // See bug 438784: need to expose URL on doc's value attribute. For this,
@@ -307,19 +326,25 @@ STDMETHODIMP nsAccessibleWrap::get_accVa
 
 STDMETHODIMP
 nsAccessibleWrap::get_accDescription(VARIANT varChild,
                                      BSTR __RPC_FAR *pszDescription)
 {
 __try {
   *pszDescription = NULL;
 
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
-  if (!xpAccessible || xpAccessible->IsDefunct())
-    return E_FAIL;
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
+  if (!xpAccessible)
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   nsAutoString description;
   xpAccessible->Description(description);
 
   *pszDescription = ::SysAllocStringLen(description.get(),
                                         description.Length());
   return *pszDescription ? S_OK : E_OUTOFMEMORY;
 
@@ -330,21 +355,24 @@ nsAccessibleWrap::get_accDescription(VAR
 STDMETHODIMP nsAccessibleWrap::get_accRole(
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ VARIANT __RPC_FAR *pvarRole)
 {
 __try {
   VariantInit(pvarRole);
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
   if (!xpAccessible)
-    return E_FAIL;
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
 #ifdef DEBUG_A11Y
   NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(xpAccessible),
                "Does not support nsIAccessibleText when it should");
 #endif
 
   roles::Role role = xpAccessible->Role();
   PRUint32 msaaRole = gWindowsRoleMap[role].msaaRole;
@@ -407,19 +435,25 @@ STDMETHODIMP nsAccessibleWrap::get_accSt
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ VARIANT __RPC_FAR *pvarState)
 {
 __try {
   VariantInit(pvarState);
   pvarState->vt = VT_I4;
   pvarState->lVal = 0;
 
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
   if (!xpAccessible)
-    return E_FAIL;
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   // MSAA only has 31 states and the lowest 31 bits of our state bit mask
   // are the same states as MSAA.
   // Note: we map the following Gecko states to different MSAA states:
   //   REQUIRED -> ALERT_LOW
   //   ALERT -> ALERT_MEDIUM
   //   INVALID -> ALERT_HIGH
   //   CHECKABLE -> MARQUEED
@@ -464,19 +498,25 @@ STDMETHODIMP nsAccessibleWrap::get_accKe
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ BSTR __RPC_FAR *pszKeyboardShortcut)
 {
 __try {
   if (!pszKeyboardShortcut)
     return E_INVALIDARG;
   *pszKeyboardShortcut = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAccessible* acc = GetXPAccessibleFor(varChild);
-  if (!acc || acc->IsDefunct())
-    return E_FAIL;
+  if (!acc)
+    return E_INVALIDARG;
+
+  if (acc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   KeyBinding keyBinding = acc->AccessKey();
   if (keyBinding.IsEmpty())
     keyBinding = acc->KeyboardShortcut();
 
   nsAutoString shortcut;
   keyBinding.ToString(shortcut);
 
@@ -493,17 +533,17 @@ STDMETHODIMP nsAccessibleWrap::get_accFo
   // VT_EMPTY:    None. This object does not have the keyboard focus itself
   //              and does not contain a child that has the keyboard focus.
   // VT_I4:       lVal is CHILDID_SELF. The object itself has the keyboard focus.
   // VT_I4:       lVal contains the child ID of the child element with the keyboard focus.
   // VT_DISPATCH: pdispVal member is the address of the IDispatch interface
   //              for the child object with the keyboard focus.
 __try {
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   VariantInit(pvarChild);
 
   // Return the current IAccessible child that has focus
   nsAccessible* focusedAccessible = FocusedChild();
   if (focusedAccessible == this) {
     pvarChild->vt = VT_I4;
     pvarChild->lVal = CHILDID_SELF;
@@ -667,16 +707,19 @@ AccessibleEnumerator::Skip(unsigned long
   *  - the object is not the type that can have children selected
   */
 STDMETHODIMP nsAccessibleWrap::get_accSelection(VARIANT __RPC_FAR *pvarChildren)
 {
 __try {
   VariantInit(pvarChildren);
   pvarChildren->vt = VT_EMPTY;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   if (IsSelect()) {
     nsCOMPtr<nsIArray> selectedItems = SelectedItems();
     if (selectedItems) {
       // 1) Create and initialize the enumeration
       nsRefPtr<AccessibleEnumerator> pEnum =
         new AccessibleEnumerator(selectedItems);
 
       // 2) Put the enumerator in the VARIANT
@@ -691,39 +734,54 @@ STDMETHODIMP nsAccessibleWrap::get_accSe
 }
 
 STDMETHODIMP nsAccessibleWrap::get_accDefaultAction(
       /* [optional][in] */ VARIANT varChild,
       /* [retval][out] */ BSTR __RPC_FAR *pszDefaultAction)
 {
 __try {
   *pszDefaultAction = NULL;
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
-  if (xpAccessible) {
-    nsAutoString defaultAction;
-    if (NS_FAILED(xpAccessible->GetActionName(0, defaultAction)))
-      return E_FAIL;
+
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
+  if (!xpAccessible)
+    return E_INVALIDARG;
 
-    *pszDefaultAction = ::SysAllocStringLen(defaultAction.get(),
-                                            defaultAction.Length());
-    return *pszDefaultAction ? S_OK : E_OUTOFMEMORY;
-  }
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAutoString defaultAction;
+  if (NS_FAILED(xpAccessible->GetActionName(0, defaultAction)))
+    return E_FAIL;
+
+  *pszDefaultAction = ::SysAllocStringLen(defaultAction.get(),
+                                          defaultAction.Length());
+  return *pszDefaultAction ? S_OK : E_OUTOFMEMORY;
 
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP nsAccessibleWrap::accSelect(
       /* [in] */ long flagsSelect,
       /* [optional][in] */ VARIANT varChild)
 {
 __try {
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   // currently only handle focus and selection
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
-  NS_ENSURE_TRUE(xpAccessible, E_FAIL);
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
+  if (!xpAccessible)
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   if (flagsSelect & (SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION|SELFLAG_REMOVESELECTION))
   {
     if (flagsSelect & SELFLAG_TAKEFOCUS)
       xpAccessible->TakeFocus();
 
     if (flagsSelect & SELFLAG_TAKESELECTION)
       xpAccessible->TakeSelection();
@@ -747,46 +805,59 @@ STDMETHODIMP nsAccessibleWrap::accSelect
 STDMETHODIMP nsAccessibleWrap::accLocation(
       /* [out] */ long __RPC_FAR *pxLeft,
       /* [out] */ long __RPC_FAR *pyTop,
       /* [out] */ long __RPC_FAR *pcxWidth,
       /* [out] */ long __RPC_FAR *pcyHeight,
       /* [optional][in] */ VARIANT varChild)
 {
 __try {
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
-  if (xpAccessible) {
-    PRInt32 x, y, width, height;
-    if (NS_FAILED(xpAccessible->GetBounds(&x, &y, &width, &height)))
-      return E_FAIL;
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
+  if (!xpAccessible)
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
-    *pxLeft = x;
-    *pyTop = y;
-    *pcxWidth = width;
-    *pcyHeight = height;
-    return S_OK;
-  }
+  PRInt32 x, y, width, height;
+  if (NS_FAILED(xpAccessible->GetBounds(&x, &y, &width, &height)))
+    return E_FAIL;
+
+  *pxLeft = x;
+  *pyTop = y;
+  *pcxWidth = width;
+  *pcyHeight = height;
+  return S_OK;
+
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
 
   return E_FAIL;
 }
 
 STDMETHODIMP nsAccessibleWrap::accNavigate(
       /* [in] */ long navDir,
       /* [optional][in] */ VARIANT varStart,
       /* [retval][out] */ VARIANT __RPC_FAR *pvarEndUpAt)
 {
 __try {
   if (!pvarEndUpAt)
     return E_INVALIDARG;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAccessible* accessible = GetXPAccessibleFor(varStart);
-  if (!accessible || accessible->IsDefunct())
-    return E_FAIL;
+  if (!accessible)
+    return E_INVALIDARG;
+
+  if (accessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
 
   VariantInit(pvarEndUpAt);
 
   nsAccessible* navAccessible = nsnull;
   PRUint32 xpRelation = 0;
 
   switch(navDir) {
     case NAVDIR_FIRSTCHILD:
@@ -881,18 +952,19 @@ STDMETHODIMP nsAccessibleWrap::accNaviga
 
 STDMETHODIMP nsAccessibleWrap::accHitTest(
       /* [in] */ long xLeft,
       /* [in] */ long yTop,
       /* [retval][out] */ VARIANT __RPC_FAR *pvarChild)
 {
 __try {
   VariantInit(pvarChild);
+
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   nsAccessible* accessible = ChildAtPoint(xLeft, yTop, eDirectChild);
 
   // if we got a child
   if (accessible) {
     // if the child is us
     if (accessible == this) {
       pvarChild->vt = VT_I4;
@@ -910,22 +982,30 @@ STDMETHODIMP nsAccessibleWrap::accHitTes
 
   return S_OK;
 }
 
 STDMETHODIMP nsAccessibleWrap::accDoDefaultAction(
       /* [optional][in] */ VARIANT varChild)
 {
 __try {
-  nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
-  if (!xpAccessible || FAILED(xpAccessible->DoAction(0))) {
-    return E_FAIL;
-  }
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  nsAccessible* xpAccessible = GetXPAccessibleFor(varChild);
+  if (!xpAccessible)
+    return E_INVALIDARG;
+
+  if (xpAccessible->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  return GetHRESULT(xpAccessible->DoAction(0));
+
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
-  return S_OK;
+  return E_FAIL;
 }
 
 STDMETHODIMP nsAccessibleWrap::put_accName(
       /* [optional][in] */ VARIANT varChild,
       /* [in] */ BSTR szName)
 {
   return E_NOTIMPL;
 }
@@ -1030,17 +1110,17 @@ nsAccessibleWrap::get_nRelations(long *a
 {
 __try {
   if (!aNRelations)
     return E_INVALIDARG;
 
   *aNRelations = 0;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   for (PRUint32 relType = nsIAccessibleRelation::RELATION_FIRST;
        relType <= nsIAccessibleRelation::RELATION_LAST; relType++) {
     Relation rel = RelationByType(relType);
     if (rel.Next())
       (*aNRelations)++;
   }
   return S_OK;
@@ -1054,17 +1134,17 @@ nsAccessibleWrap::get_relation(long aRel
 {
 __try {
   if (!aRelation)
     return E_INVALIDARG;
 
   *aRelation = NULL;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   PRUint32 relIdx = 0;
   for (PRUint32 relType = nsIAccessibleRelation::RELATION_FIRST;
        relType <= nsIAccessibleRelation::RELATION_LAST; relType++) {
     Relation rel = RelationByType(relType);
     nsRefPtr<ia2AccessibleRelation> ia2Relation =
       new ia2AccessibleRelation(relType, &rel);
     if (ia2Relation->HasTargets()) {
@@ -1089,17 +1169,17 @@ nsAccessibleWrap::get_relations(long aMa
 {
 __try {
   if (!aRelation || !aNRelations)
     return E_INVALIDARG;
 
   *aNRelations = 0;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   for (PRUint32 relType = nsIAccessibleRelation::RELATION_FIRST;
        relType <= nsIAccessibleRelation::RELATION_LAST &&
        *aNRelations < aMaxRelations; relType++) {
     Relation rel = RelationByType(relType);
     nsRefPtr<ia2AccessibleRelation> ia2Rel =
       new ia2AccessibleRelation(relType, &rel);
     if (ia2Rel->HasTargets()) {
@@ -1115,17 +1195,17 @@ nsAccessibleWrap::get_relations(long aMa
 
 STDMETHODIMP
 nsAccessibleWrap::role(long *aRole)
 {
 __try {
   *aRole = 0;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   NS_ASSERTION(gWindowsRoleMap[roles::LAST_ENTRY].ia2Role == ROLE_WINDOWS_LAST_ENTRY,
                "MSAA role map skewed");
 
   roles::Role role = Role();
   *aRole = gWindowsRoleMap[role].ia2Role;
 
   // Special case, if there is a ROLE_ROW inside of a ROLE_TREE_TABLE, then call
@@ -1141,28 +1221,34 @@ nsAccessibleWrap::role(long *aRole)
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::scrollTo(enum IA2ScrollType aScrollType)
 {
 __try {
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAccessNode::ScrollTo(aScrollType);
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::scrollToPoint(enum IA2CoordinateType aCoordType,
                                 long aX, long aY)
 {
 __try {
+  if (IsDefunct())
+      return CO_E_OBJNOTCONNECTED;
+
   PRUint32 geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
     nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
     nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
 
   nsresult rv = ScrollToPoint(geckoCoordType, aX, aY);
   return GetHRESULT(rv);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
@@ -1170,16 +1256,19 @@ nsAccessibleWrap::scrollToPoint(enum IA2
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_groupPosition(long *aGroupLevel,
                                     long *aSimilarItemsInGroup,
                                     long *aPositionInGroup)
 {
 __try {
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   PRInt32 groupLevel = 0;
   PRInt32 similarItemsInGroup = 0;
   PRInt32 positionInGroup = 0;
 
   nsresult rv = GroupPosition(&groupLevel, &similarItemsInGroup,
                               &positionInGroup);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
@@ -1201,16 +1290,19 @@ nsAccessibleWrap::get_groupPosition(long
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_states(AccessibleStates *aStates)
 {
 __try {
   *aStates = 0;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   // XXX: bug 344674 should come with better approach that we have here.
 
   PRUint64 state = State();
 
   if (state & states::INVALID)
     *aStates |= IA2_STATE_INVALID_ENTRY;
   if (state & states::REQUIRED)
     *aStates |= IA2_STATE_REQUIRED;
@@ -1323,17 +1415,17 @@ nsAccessibleWrap::get_uniqueID(long *uni
 
 STDMETHODIMP
 nsAccessibleWrap::get_windowHandle(HWND *aWindowHandle)
 {
 __try {
   *aWindowHandle = 0;
 
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   *aWindowHandle = GetHWNDFor(this);
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
@@ -1341,17 +1433,17 @@ STDMETHODIMP
 nsAccessibleWrap::get_indexInParent(long *aIndexInParent)
 {
 __try {
   if (!aIndexInParent)
     return E_INVALIDARG;
 
   *aIndexInParent = -1;
   if (IsDefunct())
-    return E_FAIL;
+    return CO_E_OBJNOTCONNECTED;
 
   *aIndexInParent = IndexInParent();
   if (*aIndexInParent == -1)
     return S_FALSE;
 
   return S_OK;
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
@@ -1361,16 +1453,19 @@ STDMETHODIMP
 nsAccessibleWrap::get_locale(IA2Locale *aLocale)
 {
 __try {
   // Language codes consist of a primary code and a possibly empty series of
   // subcodes: language-code = primary-code ( "-" subcode )*
   // Two-letter primary codes are reserved for [ISO639] language abbreviations.
   // Any two-letter subcode is understood to be a [ISO3166] country code.
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString lang;
   Language(lang);
 
   // If primary code consists from two letters then expose it as language.
   PRInt32 offset = lang.FindChar('-', 0);
   if (offset == -1) {
     if (lang.Length() == 2) {
       aLocale->language = ::SysAllocString(lang.get());
@@ -1404,16 +1499,19 @@ nsAccessibleWrap::get_locale(IA2Locale *
 STDMETHODIMP
 nsAccessibleWrap::get_attributes(BSTR *aAttributes)
 {
   // The format is name:value;name:value; with \ for escaping these
   // characters ":;=,\".
 __try {
   *aAttributes = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsCOMPtr<nsIPersistentProperties> attributes;
   nsresult rv = GetAttributes(getter_AddRefs(attributes));
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   return ConvertToIA2Attributes(attributes, aAttributes);
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
--- a/accessible/src/msaa/nsApplicationAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsApplicationAccessibleWrap.cpp
@@ -97,16 +97,19 @@ nsApplicationAccessibleWrap::QueryInterf
 // IAccessibleApplication
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_appName(BSTR *aName)
 {
 __try {
   *aName = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString name;
   nsresult rv = GetAppName(name);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (name.IsEmpty())
     return S_FALSE;
 
@@ -118,16 +121,19 @@ nsApplicationAccessibleWrap::get_appName
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_appVersion(BSTR *aVersion)
 {
 __try {
   *aVersion = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString version;
   nsresult rv = GetAppVersion(version);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (version.IsEmpty())
     return S_FALSE;
 
@@ -137,16 +143,19 @@ nsApplicationAccessibleWrap::get_appVers
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_toolkitName(BSTR *aName)
 {
 __try {
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString name;
   nsresult rv = GetPlatformName(name);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (name.IsEmpty())
     return S_FALSE;
 
@@ -158,16 +167,19 @@ nsApplicationAccessibleWrap::get_toolkit
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_toolkitVersion(BSTR *aVersion)
 {
 __try {
   *aVersion = NULL;
 
+  if (IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
   nsAutoString version;
   nsresult rv = GetPlatformVersion(version);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   if (version.IsEmpty())
     return S_FALSE;