diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index cb393a322509..7661e7e9cddd 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -265,11 +265,14 @@ nsresult mozInlineSpellWordUtil::SetPositionAndEnd(nsINode* aPositionNode, nsresult mozInlineSpellWordUtil::EnsureWords() { if (mSoftTextValid) return NS_OK; BuildSoftText(); - nsresult rv = BuildRealWords(); - if (NS_FAILED(rv)) { - mRealWords.Clear(); - return rv; + + mRealWords.Clear(); + Result realWords = BuildRealWords(); + if (realWords.isErr()) { + return realWords.unwrapErr(); } + + mRealWords = realWords.unwrap(); mSoftTextValid = true; return NS_OK; } @@ -888,19 +891,20 @@ void mozInlineSpellWordUtil::BuildSoftText() { NS_ConvertUTF16toUTF8(mSoftText).get())); } -nsresult mozInlineSpellWordUtil::BuildRealWords() { +auto mozInlineSpellWordUtil::BuildRealWords() const + -> Result { // This is pretty simple. We just have to walk mSoftText, tokenizing it // into "real words". // We do an outer traversal of words delimited by IsDOMWordSeparator, calling // SplitDOMWordAndAppendTo on each of those DOM words int32_t wordStart = -1; - mRealWords.Clear(); + RealWords realWords; for (int32_t i = 0; i < int32_t(mSoftText.Length()); ++i) { if (IsDOMWordSeparator(mSoftText.CharAt(i))) { if (wordStart >= 0) { - nsresult rv = SplitDOMWordAndAppendTo(wordStart, i, mRealWords); + nsresult rv = SplitDOMWordAndAppendTo(wordStart, i, realWords); if (NS_FAILED(rv)) { - return rv; + return Err(rv); } wordStart = -1; } @@ -912,13 +916,13 @@ nsresult mozInlineSpellWordUtil::BuildRealWords() { } if (wordStart >= 0) { nsresult rv = - SplitDOMWordAndAppendTo(wordStart, mSoftText.Length(), mRealWords); + SplitDOMWordAndAppendTo(wordStart, mSoftText.Length(), realWords); if (NS_FAILED(rv)) { - return rv; + return Err(rv); } } - return NS_OK; + return realWords; } /*********** DOM/realwords<->mSoftText mapping functions ************/ diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.h b/extensions/spellcheck/src/mozInlineSpellWordUtil.h index ef0456436fd3..7f1999e15199 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.h +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.h @@ -8,6 +8,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Maybe.h" +#include "mozilla/Result.h" #include "mozilla/dom/Document.h" #include "nsCOMPtr.h" #include "nsString.h" @@ -175,7 +176,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil { int32_t EndOffset() const { return mSoftTextOffset + mLength; } }; - nsTArray mRealWords; + using RealWords = nsTArray; + RealWords mRealWords; int32_t mNextWordIndex; bool mSoftTextValid; @@ -208,8 +210,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil { // build mSoftText and mSoftTextDOMMapping void BuildSoftText(); - // Build mRealWords array - nsresult BuildRealWords(); + + mozilla::Result BuildRealWords() const; nsresult SplitDOMWordAndAppendTo(int32_t aStart, int32_t aEnd, nsTArray& aRealWords) const;