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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 Character, 74 Character,
75 EndOfFile, 75 EndOfFile,
76 }; 76 };
77 77
78 class Attribute { 78 class Attribute {
79 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 79 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
80 public: 80 public:
81 class Range { 81 class Range {
82 DISALLOW_NEW(); 82 DISALLOW_NEW();
83 public: 83 public:
84 static constexpr int kInvalidOffset = -1;
85
86 inline void clear()
87 {
88 #if ENABLE(ASSERT)
89 start = kInvalidOffset;
90 end = kInvalidOffset;
91 #endif
92 }
93
94 // Check Range instance that is actively being parsed.
95 inline void checkValidStart() const
96 {
97 DCHECK(start != kInvalidOffset);
Charlie Harrison 2016/07/06 13:50:37 nit: Use DCHECK_NE.
98 DCHECK_GE(start, 0);
99 }
100
101 // Check Range instance which finished parse.
102 inline void checkValid() const
103 {
104 checkValidStart();
105 DCHECK(end != kInvalidOffset);
Charlie Harrison 2016/07/06 13:50:37 ditto
106 DCHECK_GE(end, 0);
107 DCHECK_LE(start, end);
108 }
109
84 int start; 110 int start;
85 int end; 111 int end;
86 }; 112 };
87 113
88 AtomicString name() const { return AtomicString(m_name); } 114 AtomicString name() const { return AtomicString(m_name); }
89 String nameAttemptStaticStringCreation() const { return attemptStaticStr ingCreation(m_name, Likely8Bit); } 115 String nameAttemptStaticStringCreation() const { return attemptStaticStr ingCreation(m_name, Likely8Bit); }
90 const Vector<UChar, 32>& nameAsVector() const { return m_name; } 116 const Vector<UChar, 32>& nameAsVector() const { return m_name; }
91 117
92 void appendToName(UChar c) { m_name.append(c); } 118 void appendToName(UChar c) { m_name.append(c); }
93 119
(...skipping 21 matching lines...) Expand all
115 // By using an inline capacity of 256, we avoid spilling over into an malloc ed buffer 141 // By using an inline capacity of 256, we avoid spilling over into an malloc ed buffer
116 // approximately 99% of the time based on a non-scientific browse around a n umber of 142 // approximately 99% of the time based on a non-scientific browse around a n umber of
117 // popular web sites on 23 May 2013. 143 // popular web sites on 23 May 2013.
118 typedef Vector<UChar, 256> DataVector; 144 typedef Vector<UChar, 256> DataVector;
119 145
120 HTMLToken() { clear(); } 146 HTMLToken() { clear(); }
121 147
122 void clear() 148 void clear()
123 { 149 {
124 m_type = Uninitialized; 150 m_type = Uninitialized;
151 m_range.clear();
125 m_range.start = 0; 152 m_range.start = 0;
126 m_range.end = 0;
127 m_baseOffset = 0; 153 m_baseOffset = 0;
128 // Don't call Vector::clear() as that would destroy the 154 // Don't call Vector::clear() as that would destroy the
129 // alloced VectorBuffer. If the innerHTML'd content has 155 // alloced VectorBuffer. If the innerHTML'd content has
130 // two 257 character text nodes in a row, we'll needlessly 156 // two 257 character text nodes in a row, we'll needlessly
131 // thrash malloc. When we finally finish the parse the 157 // thrash malloc. When we finally finish the parse the
132 // HTMLToken will be destroyed and the VectorBuffer released. 158 // HTMLToken will be destroyed and the VectorBuffer released.
133 m_data.shrink(0); 159 m_data.shrink(0);
134 m_orAllData = 0; 160 m_orAllData = 0;
135 } 161 }
136 162
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 m_attributes.clear(); 333 m_attributes.clear();
308 334
309 m_data.appendVector(characters); 335 m_data.appendVector(characters);
310 } 336 }
311 337
312 void addNewAttribute() 338 void addNewAttribute()
313 { 339 {
314 ASSERT(m_type == StartTag || m_type == EndTag); 340 ASSERT(m_type == StartTag || m_type == EndTag);
315 m_attributes.grow(m_attributes.size() + 1); 341 m_attributes.grow(m_attributes.size() + 1);
316 m_currentAttribute = &m_attributes.last(); 342 m_currentAttribute = &m_attributes.last();
317 #if ENABLE(ASSERT) 343 m_currentAttribute->mutableNameRange().clear();
318 m_currentAttribute->mutableNameRange().start = 0; 344 m_currentAttribute->mutableValueRange().clear();
319 m_currentAttribute->mutableNameRange().end = 0;
320 m_currentAttribute->mutableValueRange().start = 0;
321 m_currentAttribute->mutableValueRange().end = 0;
322 #endif
323 } 345 }
324 346
325 void beginAttributeName(int offset) 347 void beginAttributeName(int offset)
326 { 348 {
327 m_currentAttribute->mutableNameRange().start = offset - m_baseOffset; 349 m_currentAttribute->mutableNameRange().start = offset - m_baseOffset;
350 m_currentAttribute->nameRange().checkValidStart();
328 } 351 }
329 352
330 void endAttributeName(int offset) 353 void endAttributeName(int offset)
331 { 354 {
332 int index = offset - m_baseOffset; 355 int index = offset - m_baseOffset;
333 m_currentAttribute->mutableNameRange().end = index; 356 m_currentAttribute->mutableNameRange().end = index;
357 m_currentAttribute->nameRange().checkValid();
334 m_currentAttribute->mutableValueRange().start = index; 358 m_currentAttribute->mutableValueRange().start = index;
335 m_currentAttribute->mutableValueRange().end = index; 359 m_currentAttribute->mutableValueRange().end = index;
336 } 360 }
337 361
338 void beginAttributeValue(int offset) 362 void beginAttributeValue(int offset)
339 { 363 {
364 m_currentAttribute->mutableValueRange().clear();
340 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset; 365 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset;
341 #if ENABLE(ASSERT) 366 m_currentAttribute->valueRange().checkValidStart();
342 m_currentAttribute->mutableValueRange().end = 0;
343 #endif
344 } 367 }
345 368
346 void endAttributeValue(int offset) 369 void endAttributeValue(int offset)
347 { 370 {
348 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset; 371 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset;
372 m_currentAttribute->valueRange().checkValid();
349 } 373 }
350 374
351 void appendToAttributeName(UChar character) 375 void appendToAttributeName(UChar character)
352 { 376 {
353 ASSERT(character); 377 ASSERT(character);
354 ASSERT(m_type == StartTag || m_type == EndTag); 378 ASSERT(m_type == StartTag || m_type == EndTag);
355 ASSERT(m_currentAttribute->nameRange().start); 379 m_currentAttribute->nameRange().checkValidStart();
356 m_currentAttribute->appendToName(character); 380 m_currentAttribute->appendToName(character);
357 } 381 }
358 382
359 void appendToAttributeValue(UChar character) 383 void appendToAttributeValue(UChar character)
360 { 384 {
361 ASSERT(character); 385 ASSERT(character);
362 ASSERT(m_type == StartTag || m_type == EndTag); 386 ASSERT(m_type == StartTag || m_type == EndTag);
363 ASSERT(m_currentAttribute->valueRange().start); 387 m_currentAttribute->valueRange().checkValidStart();
364 m_currentAttribute->appendToValue(character); 388 m_currentAttribute->appendToValue(character);
365 } 389 }
366 390
367 void appendToAttributeValue(size_t i, const String& value) 391 void appendToAttributeValue(size_t i, const String& value)
368 { 392 {
369 ASSERT(!value.isEmpty()); 393 ASSERT(!value.isEmpty());
370 ASSERT(m_type == StartTag || m_type == EndTag); 394 ASSERT(m_type == StartTag || m_type == EndTag);
371 m_attributes[i].appendToValue(value); 395 m_attributes[i].appendToValue(value);
372 } 396 }
373 397
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // A pointer into m_attributes used during lexing. 496 // A pointer into m_attributes used during lexing.
473 Attribute* m_currentAttribute; 497 Attribute* m_currentAttribute;
474 498
475 // For DOCTYPE 499 // For DOCTYPE
476 std::unique_ptr<DoctypeData> m_doctypeData; 500 std::unique_ptr<DoctypeData> m_doctypeData;
477 }; 501 };
478 502
479 } // namespace blink 503 } // namespace blink
480 504
481 #endif 505 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698