From d0ca5b8b57ad966c14bd5fb3b60e4b33b1767cfb Mon Sep 17 00:00:00 2001 From: "brettw%gmail.com" Date: Tue, 8 Aug 2006 16:57:50 +0000 Subject: [PATCH] Bug 347819 r=bryner Change assersions hit in normal usage to non-assertions & return failure git-svn-id: svn://10.0.0.236/trunk@206842 18797224-902f-48f8-a5cc-f745e15eee43 --- .../spellcheck/src/mozInlineSpellChecker.cpp | 19 ++++++++++++------- .../spellcheck/src/mozInlineSpellChecker.h | 3 ++- .../spellcheck/src/mozInlineSpellWordUtil.cpp | 5 ++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.cpp index e9890741ca6..b09733d0f89 100644 --- a/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -1060,17 +1060,15 @@ mozInlineSpellChecker::SpellCheckBetweenNodes(nsIDOMNode *aStartNode, // for these cases. nsresult -mozInlineSpellChecker::SkipSpellCheckForNode(nsIDOMNode *aNode, +mozInlineSpellChecker::SkipSpellCheckForNode(nsIEditor* aEditor, + nsIDOMNode *aNode, PRBool *checkSpelling) { *checkSpelling = PR_TRUE; NS_ENSURE_ARG_POINTER(aNode); - nsCOMPtr editor (do_QueryReferent(mEditor)); - NS_ENSURE_TRUE(editor, NS_ERROR_NULL_POINTER); - PRUint32 flags; - editor->GetFlags(&flags); + aEditor->GetFlags(&flags); if (flags & nsIPlaintextEditor::eEditorMailMask) { nsCOMPtr parent; @@ -1238,6 +1236,12 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil, PRInt32 beginOffset, endOffset; *aDoneChecking = PR_TRUE; + // get the editor for SkipSpellCheckForNode, this may fail in reasonable + // circumstances since the editor could have gone away + nsCOMPtr editor (do_QueryReferent(mEditor)); + if (! editor) + return NS_ERROR_FAILURE; + PRBool iscollapsed; nsresult rv = aStatus->mRange->GetCollapsed(&iscollapsed); NS_ENSURE_SUCCESS(rv, rv); @@ -1320,7 +1324,8 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil, // some nodes we don't spellcheck PRBool checkSpelling; - SkipSpellCheckForNode(beginNode, &checkSpelling); + rv = SkipSpellCheckForNode(editor, beginNode, &checkSpelling); + NS_ENSURE_SUCCESS(rv, rv); if (!checkSpelling) continue; @@ -1390,7 +1395,7 @@ mozInlineSpellChecker::ResumeCheck(mozInlineSpellStatus* aStatus) mozInlineSpellWordUtil wordUtil; nsresult rv = wordUtil.Init(mEditor); if (NS_FAILED(rv)) - return NS_OK; // editor doesn't like us + return NS_OK; // editor doesn't like us, don't assert nsCOMPtr spellCheckSelection; rv = GetSpellCheckSelection(getter_AddRefs(spellCheckSelection)); diff --git a/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.h b/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.h index fd17885f215..1e4c2b00072 100644 --- a/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.h +++ b/mozilla/extensions/spellcheck/src/mozInlineSpellChecker.h @@ -252,7 +252,8 @@ public: // examines the dom node in question and returns true if the inline spell // checker should skip the node (i.e. the text is inside of a block quote // or an e-mail signature...) - nsresult SkipSpellCheckForNode(nsIDOMNode *aNode, PRBool * aCheckSpelling); + nsresult SkipSpellCheckForNode(nsIEditor* aEditor, + nsIDOMNode *aNode, PRBool * aCheckSpelling); nsresult SpellCheckAfterChange(nsIDOMNode* aCursorNode, PRInt32 aCursorOffset, nsIDOMNode* aPreviousNode, PRInt32 aPreviousOffset, diff --git a/mozilla/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/mozilla/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index 543453f5381..0f448c7beed 100644 --- a/mozilla/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/mozilla/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -87,8 +87,11 @@ mozInlineSpellWordUtil::Init(nsWeakPtr aWeakEditor) { nsresult rv; + // getting the editor can fail commonly because the editor was detached, so + // don't assert nsCOMPtr editor = do_QueryReferent(aWeakEditor, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) + return rv; nsCOMPtr domDoc; rv = editor->GetDocument(getter_AddRefs(domDoc));