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

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: 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 inline void checkValidStart() const
dominicc (has gone to gerrit) 2016/07/05 01:08:10 I'm not sure checkValidStart and checkValidEnd are
kouhei (in TOK) 2016/07/05 03:57:14 We want two check methods: - one for checking Rang
95 {
96 DCHECK(start != kInvalidOffset);
97 }
98
99 inline void checkValidEnd() const
100 {
101 DCHECK(end != kInvalidOffset);
Yoav Weiss 2016/07/04 09:19:39 shouldn't this check that start is not negative?
kouhei (in TOK) 2016/07/05 03:57:14 Done.
102 }
103
104 inline void checkValid() const
dominicc (has gone to gerrit) 2016/07/05 01:08:10 Is there any relationship between start and end yo
105 {
106 checkValidStart();
107 checkValidEnd();
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;
328 } 350 }
329 351
330 void endAttributeName(int offset) 352 void endAttributeName(int offset)
331 { 353 {
332 int index = offset - m_baseOffset; 354 int index = offset - m_baseOffset;
333 m_currentAttribute->mutableNameRange().end = index; 355 m_currentAttribute->mutableNameRange().end = index;
334 m_currentAttribute->mutableValueRange().start = index; 356 m_currentAttribute->mutableValueRange().start = index;
335 m_currentAttribute->mutableValueRange().end = index; 357 m_currentAttribute->mutableValueRange().end = index;
336 } 358 }
337 359
338 void beginAttributeValue(int offset) 360 void beginAttributeValue(int offset)
339 { 361 {
362 m_currentAttribute->mutableValueRange().clear();
340 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset; 363 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset;
Yoav Weiss 2016/07/04 09:19:39 Alternatively, maybe DCHECK here that offset is la
341 #if ENABLE(ASSERT) 364 m_currentAttribute->valueRange().checkValidStart();
342 m_currentAttribute->mutableValueRange().end = 0;
343 #endif
344 } 365 }
345 366
346 void endAttributeValue(int offset) 367 void endAttributeValue(int offset)
347 { 368 {
348 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset; 369 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset;
349 } 370 }
350 371
351 void appendToAttributeName(UChar character) 372 void appendToAttributeName(UChar character)
352 { 373 {
353 ASSERT(character); 374 ASSERT(character);
354 ASSERT(m_type == StartTag || m_type == EndTag); 375 ASSERT(m_type == StartTag || m_type == EndTag);
355 ASSERT(m_currentAttribute->nameRange().start); 376 m_currentAttribute->nameRange().checkValidStart();
356 m_currentAttribute->appendToName(character); 377 m_currentAttribute->appendToName(character);
357 } 378 }
358 379
359 void appendToAttributeValue(UChar character) 380 void appendToAttributeValue(UChar character)
360 { 381 {
361 ASSERT(character); 382 ASSERT(character);
362 ASSERT(m_type == StartTag || m_type == EndTag); 383 ASSERT(m_type == StartTag || m_type == EndTag);
363 ASSERT(m_currentAttribute->valueRange().start); 384 m_currentAttribute->valueRange().checkValidStart();
364 m_currentAttribute->appendToValue(character); 385 m_currentAttribute->appendToValue(character);
365 } 386 }
366 387
367 void appendToAttributeValue(size_t i, const String& value) 388 void appendToAttributeValue(size_t i, const String& value)
368 { 389 {
369 ASSERT(!value.isEmpty()); 390 ASSERT(!value.isEmpty());
370 ASSERT(m_type == StartTag || m_type == EndTag); 391 ASSERT(m_type == StartTag || m_type == EndTag);
371 m_attributes[i].appendToValue(value); 392 m_attributes[i].appendToValue(value);
372 } 393 }
373 394
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // A pointer into m_attributes used during lexing. 493 // A pointer into m_attributes used during lexing.
473 Attribute* m_currentAttribute; 494 Attribute* m_currentAttribute;
474 495
475 // For DOCTYPE 496 // For DOCTYPE
476 std::unique_ptr<DoctypeData> m_doctypeData; 497 std::unique_ptr<DoctypeData> m_doctypeData;
477 }; 498 };
478 499
479 } // namespace blink 500 } // namespace blink
480 501
481 #endif 502 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698