Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLToken.h

Issue 2121703002: Change HTMLTokenizer::Attribute::Range.start initial invalid value from 0 -> -1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update check Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/parser/HTMLToken.h
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLToken.h b/third_party/WebKit/Source/core/html/parser/HTMLToken.h
index 679a187e1d1a14bdd36a685985f7846369b99ad0..3f0d7637b4582d308426a33e0a32ee115c88fb7c 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLToken.h
+++ b/third_party/WebKit/Source/core/html/parser/HTMLToken.h
@@ -81,6 +81,32 @@ public:
class Range {
DISALLOW_NEW();
public:
+ static constexpr int kInvalidOffset = -1;
+
+ inline void clear()
+ {
+#if ENABLE(ASSERT)
+ start = kInvalidOffset;
+ end = kInvalidOffset;
+#endif
+ }
+
+ // Check Range instance that is actively being parsed.
+ inline void checkValidStart() const
+ {
+ DCHECK(start != kInvalidOffset);
Charlie Harrison 2016/07/06 13:50:37 nit: Use DCHECK_NE.
+ DCHECK_GE(start, 0);
+ }
+
+ // Check Range instance which finished parse.
+ inline void checkValid() const
+ {
+ checkValidStart();
+ DCHECK(end != kInvalidOffset);
Charlie Harrison 2016/07/06 13:50:37 ditto
+ DCHECK_GE(end, 0);
+ DCHECK_LE(start, end);
+ }
+
int start;
int end;
};
@@ -122,8 +148,8 @@ public:
void clear()
{
m_type = Uninitialized;
+ m_range.clear();
m_range.start = 0;
- m_range.end = 0;
m_baseOffset = 0;
// Don't call Vector::clear() as that would destroy the
// alloced VectorBuffer. If the innerHTML'd content has
@@ -314,45 +340,43 @@ public:
ASSERT(m_type == StartTag || m_type == EndTag);
m_attributes.grow(m_attributes.size() + 1);
m_currentAttribute = &m_attributes.last();
-#if ENABLE(ASSERT)
- m_currentAttribute->mutableNameRange().start = 0;
- m_currentAttribute->mutableNameRange().end = 0;
- m_currentAttribute->mutableValueRange().start = 0;
- m_currentAttribute->mutableValueRange().end = 0;
-#endif
+ m_currentAttribute->mutableNameRange().clear();
+ m_currentAttribute->mutableValueRange().clear();
}
void beginAttributeName(int offset)
{
m_currentAttribute->mutableNameRange().start = offset - m_baseOffset;
+ m_currentAttribute->nameRange().checkValidStart();
}
void endAttributeName(int offset)
{
int index = offset - m_baseOffset;
m_currentAttribute->mutableNameRange().end = index;
+ m_currentAttribute->nameRange().checkValid();
m_currentAttribute->mutableValueRange().start = index;
m_currentAttribute->mutableValueRange().end = index;
}
void beginAttributeValue(int offset)
{
+ m_currentAttribute->mutableValueRange().clear();
m_currentAttribute->mutableValueRange().start = offset - m_baseOffset;
-#if ENABLE(ASSERT)
- m_currentAttribute->mutableValueRange().end = 0;
-#endif
+ m_currentAttribute->valueRange().checkValidStart();
}
void endAttributeValue(int offset)
{
m_currentAttribute->mutableValueRange().end = offset - m_baseOffset;
+ m_currentAttribute->valueRange().checkValid();
}
void appendToAttributeName(UChar character)
{
ASSERT(character);
ASSERT(m_type == StartTag || m_type == EndTag);
- ASSERT(m_currentAttribute->nameRange().start);
+ m_currentAttribute->nameRange().checkValidStart();
m_currentAttribute->appendToName(character);
}
@@ -360,7 +384,7 @@ public:
{
ASSERT(character);
ASSERT(m_type == StartTag || m_type == EndTag);
- ASSERT(m_currentAttribute->valueRange().start);
+ m_currentAttribute->valueRange().checkValidStart();
m_currentAttribute->appendToValue(character);
}

Powered by Google App Engine
This is Rietveld 408576698