Chromium Code Reviews| 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); |
| } |