Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp b/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp |
| index 51c49f89d7d6036d139a0a00db52d77c867d3385..99a34adb0a445eb91fe5fba38a57af5a20cf9dbc 100644 |
| --- a/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp |
| +++ b/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp |
| @@ -53,8 +53,8 @@ static void findBadGrammars(TextCheckerClient& client, const UChar* text, int st |
| client.checkGrammarOfString(String(text + checkLocation, checkLength), badGrammarDetails, &badGrammarLocation, &badGrammarLength); |
| if (!badGrammarLength) |
| break; |
| - ASSERT(0 <= badGrammarLocation && badGrammarLocation <= checkLength); |
| - ASSERT(0 < badGrammarLength && badGrammarLocation + badGrammarLength <= checkLength); |
| + DCHECK(0 <= badGrammarLocation && badGrammarLocation <= checkLength); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| + DCHECK(0 < badGrammarLength && badGrammarLocation + badGrammarLength <= checkLength); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| TextCheckingResult badGrammar; |
| badGrammar.decoration = TextDecorationTypeGrammar; |
| badGrammar.location = checkLocation + badGrammarLocation; |
| @@ -82,8 +82,8 @@ static void findMisspellings(TextCheckerClient& client, const UChar* text, int s |
| int misspellingLength = 0; |
| client.checkSpellingOfString(String(text + start + wordStart, wordLength), &misspellingLocation, &misspellingLength); |
| if (0 < misspellingLength) { |
| - ASSERT(0 <= misspellingLocation && misspellingLocation <= wordLength); |
| - ASSERT(0 < misspellingLength && misspellingLocation + misspellingLength <= wordLength); |
| + DCHECK(0 <= misspellingLocation && misspellingLocation <= wordLength); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| + DCHECK(0 < misspellingLength && misspellingLocation + misspellingLength <= wordLength); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| TextCheckingResult misspelling; |
| misspelling.decoration = TextDecorationTypeSpelling; |
| misspelling.location = start + wordStart + misspellingLocation; |
| @@ -142,7 +142,7 @@ TextCheckingParagraph::~TextCheckingParagraph() |
| void TextCheckingParagraph::expandRangeToNextEnd() |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| setParagraphRange(EphemeralRange(paragraphRange().startPosition(), endOfParagraph(startOfNextParagraph(createVisiblePosition(paragraphRange().startPosition()))).deepEquivalent())); |
| invalidateParagraphRangeValues(); |
| } |
| @@ -156,13 +156,13 @@ void TextCheckingParagraph::invalidateParagraphRangeValues() |
| int TextCheckingParagraph::rangeLength() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| return TextIterator::rangeLength(paragraphRange().startPosition(), paragraphRange().endPosition()); |
| } |
| EphemeralRange TextCheckingParagraph::paragraphRange() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (m_paragraphRange.isNull()) |
| m_paragraphRange = expandToParagraphBoundary(checkingRange()); |
| return m_paragraphRange; |
| @@ -175,13 +175,13 @@ void TextCheckingParagraph::setParagraphRange(const EphemeralRange& range) |
| EphemeralRange TextCheckingParagraph::subrange(int characterOffset, int characterCount) const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| return calculateCharacterSubrange(paragraphRange(), characterOffset, characterCount); |
| } |
| int TextCheckingParagraph::offsetTo(const Position& position) const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| return TextIterator::rangeLength(offsetAsRange().startPosition(), position); |
| } |
| @@ -194,7 +194,7 @@ bool TextCheckingParagraph::isEmpty() const |
| EphemeralRange TextCheckingParagraph::offsetAsRange() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (m_offsetAsRange.isNull()) |
| m_offsetAsRange = EphemeralRange(paragraphRange().startPosition(), checkingRange().startPosition()); |
| @@ -203,7 +203,7 @@ EphemeralRange TextCheckingParagraph::offsetAsRange() const |
| const String& TextCheckingParagraph::text() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (m_text.isEmpty()) |
| m_text = plainText(paragraphRange()); |
| return m_text; |
| @@ -211,7 +211,7 @@ const String& TextCheckingParagraph::text() const |
| int TextCheckingParagraph::checkingStart() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (m_checkingStart == -1) |
| m_checkingStart = TextIterator::rangeLength(offsetAsRange().startPosition(), offsetAsRange().endPosition()); |
| return m_checkingStart; |
| @@ -219,7 +219,7 @@ int TextCheckingParagraph::checkingStart() const |
| int TextCheckingParagraph::checkingEnd() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (m_checkingEnd == -1) |
| m_checkingEnd = checkingStart() + TextIterator::rangeLength(checkingRange().startPosition(), checkingRange().endPosition()); |
| return m_checkingEnd; |
| @@ -227,7 +227,7 @@ int TextCheckingParagraph::checkingEnd() const |
| int TextCheckingParagraph::checkingLength() const |
| { |
| - ASSERT(m_checkingRange.isNotNull()); |
| + DCHECK(m_checkingRange.isNotNull()); |
| if (-1 == m_checkingLength) |
| m_checkingLength = TextIterator::rangeLength(checkingRange().startPosition(), checkingRange().endPosition()); |
| return m_checkingLength; |
| @@ -265,12 +265,12 @@ String TextCheckingHelper::findFirstMisspelling(int& firstMisspellingOffset, boo |
| // 5490627 shows that there was some code path here where the String constructor below crashes. |
| // We don't know exactly what combination of bad input caused this, so we're making this much |
| // more robust against bad input on release builds. |
| - ASSERT(misspellingLength >= 0); |
| - ASSERT(misspellingLocation >= -1); |
| - ASSERT(!misspellingLength || misspellingLocation >= 0); |
| - ASSERT(misspellingLocation < length); |
| - ASSERT(misspellingLength <= length); |
| - ASSERT(misspellingLocation + misspellingLength <= length); |
| + DCHECK_GE(misspellingLength, 0); |
| + DCHECK_GE(misspellingLocation, -1); |
| + DCHECK(!misspellingLength || misspellingLocation >= 0); |
| + DCHECK_LT(misspellingLocation, length); |
| + DCHECK_LE(misspellingLength, length); |
| + DCHECK_LE(misspellingLocation + misspellingLength, length); |
| if (misspellingLocation >= 0 && misspellingLength > 0 && misspellingLocation < length && misspellingLength <= length && misspellingLocation + misspellingLength <= length) { |
| @@ -356,21 +356,21 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool& outIsSpelling, |
| for (unsigned i = 0; i < results.size(); i++) { |
| const TextCheckingResult* result = &results[i]; |
| if (result->decoration == TextDecorationTypeSpelling && result->location >= currentStartOffset && result->location + result->length <= currentEndOffset) { |
| - ASSERT(result->length > 0 && result->location >= 0); |
| + DCHECK(result->length > 0 && result->location >= 0); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| spellingLocation = result->location; |
| misspelledWord = paragraphString.substring(result->location, result->length); |
| - ASSERT(misspelledWord.length()); |
| + DCHECK(misspelledWord.length()); |
| break; |
| } |
| if (result->decoration == TextDecorationTypeGrammar && result->location < currentEndOffset && result->location + result->length > currentStartOffset) { |
| - ASSERT(result->length > 0 && result->location >= 0); |
| + DCHECK(result->length > 0 && result->location >= 0); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| // We can't stop after the first grammar result, since there might still be a spelling result after |
| // it begins but before the first detail in it, but we can stop if we find a second grammar result. |
| if (foundGrammar) |
| break; |
| for (unsigned j = 0; j < result->details.size(); j++) { |
| const GrammarDetail* detail = &result->details[j]; |
| - ASSERT(detail->length > 0 && detail->location >= 0); |
| + DCHECK(detail->length > 0 && detail->location >= 0); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| if (result->location + detail->location >= currentStartOffset && result->location + detail->location + detail->length <= currentEndOffset && (!foundGrammar || result->location + detail->location < grammarDetailLocation)) { |
| grammarDetailIndex = j; |
| grammarDetailLocation = result->location + detail->location; |
| @@ -381,7 +381,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool& outIsSpelling, |
| grammarPhraseLocation = result->location; |
| outGrammarDetail = result->details[grammarDetailIndex]; |
| badGrammarPhrase = paragraphString.substring(result->location, result->length); |
| - ASSERT(badGrammarPhrase.length()); |
| + DCHECK(badGrammarPhrase.length()); |
| } |
| } |
| } |
| @@ -425,7 +425,7 @@ int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram |
| int earliestDetailIndex = -1; |
| for (unsigned i = 0; i < grammarDetails.size(); i++) { |
| const GrammarDetail* detail = &grammarDetails[i]; |
| - ASSERT(detail->length > 0 && detail->location >= 0); |
| + DCHECK(detail->length > 0 && detail->location >= 0); |
|
yosin_UTC9
2016/04/11 04:09:11
Could you split this |DCHECK()| to two |DCHECK_XX(
|
| int detailStartOffsetInParagraph = badGrammarPhraseLocation + detail->location; |
| @@ -477,18 +477,18 @@ String TextCheckingHelper::findFirstBadGrammar(GrammarDetail& outGrammarDetail, |
| m_client->textChecker().checkGrammarOfString(paragraph.textSubstring(startOffset), grammarDetails, &badGrammarPhraseLocation, &badGrammarPhraseLength); |
| if (!badGrammarPhraseLength) { |
| - ASSERT(badGrammarPhraseLocation == -1); |
| + DCHECK_EQ(badGrammarPhraseLocation, -1); |
| return String(); |
| } |
| - ASSERT(badGrammarPhraseLocation >= 0); |
| + DCHECK_GE(badGrammarPhraseLocation, 0); |
| badGrammarPhraseLocation += startOffset; |
| // Found some bad grammar. Find the earliest detail range that starts in our search range (if any). |
| int badGrammarIndex = findFirstGrammarDetail(grammarDetails, badGrammarPhraseLocation, paragraph.checkingStart(), paragraph.checkingEnd(), markAll); |
| if (badGrammarIndex >= 0) { |
| - ASSERT(static_cast<unsigned>(badGrammarIndex) < grammarDetails.size()); |
| + DCHECK_LT(static_cast<unsigned>(badGrammarIndex), grammarDetails.size()); |
| outGrammarDetail = grammarDetails[badGrammarIndex]; |
| } |
| @@ -530,7 +530,7 @@ void TextCheckingHelper::markAllBadGrammar() |
| bool TextCheckingHelper::unifiedTextCheckerEnabled() const |
| { |
| - ASSERT(m_start.isNotNull()); |
| + DCHECK(m_start.isNotNull()); |
| Document& doc = m_start.computeContainerNode()->document(); |
| return blink::unifiedTextCheckerEnabled(doc.frame()); |
| } |