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

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

Issue 2751483005: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/html/parser/ (Closed)
Patch Set: rebase Created 3 years, 9 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // thrash malloc. When we finally finish the parse the 159 // thrash malloc. When we finally finish the parse the
160 // HTMLToken will be destroyed and the VectorBuffer released. 160 // HTMLToken will be destroyed and the VectorBuffer released.
161 m_data.shrink(0); 161 m_data.shrink(0);
162 m_orAllData = 0; 162 m_orAllData = 0;
163 } 163 }
164 164
165 bool isUninitialized() { return m_type == Uninitialized; } 165 bool isUninitialized() { return m_type == Uninitialized; }
166 TokenType type() const { return m_type; } 166 TokenType type() const { return m_type; }
167 167
168 void makeEndOfFile() { 168 void makeEndOfFile() {
169 ASSERT(m_type == Uninitialized); 169 DCHECK_EQ(m_type, Uninitialized);
170 m_type = EndOfFile; 170 m_type = EndOfFile;
171 } 171 }
172 172
173 // Range and offset methods exposed for HTMLSourceTracker and 173 // Range and offset methods exposed for HTMLSourceTracker and
174 // HTMLViewSourceParser. 174 // HTMLViewSourceParser.
175 int startIndex() const { return m_range.start; } 175 int startIndex() const { return m_range.start; }
176 int endIndex() const { return m_range.end; } 176 int endIndex() const { return m_range.end; }
177 177
178 void setBaseOffset(int offset) { m_baseOffset = offset; } 178 void setBaseOffset(int offset) { m_baseOffset = offset; }
179 179
180 void end(int endOffset) { m_range.end = endOffset - m_baseOffset; } 180 void end(int endOffset) { m_range.end = endOffset - m_baseOffset; }
181 181
182 const DataVector& data() const { 182 const DataVector& data() const {
183 ASSERT(m_type == Character || m_type == Comment || m_type == StartTag || 183 DCHECK(m_type == Character || m_type == Comment || m_type == StartTag ||
184 m_type == EndTag); 184 m_type == EndTag);
185 return m_data; 185 return m_data;
186 } 186 }
187 187
188 bool isAll8BitData() const { return (m_orAllData <= 0xff); } 188 bool isAll8BitData() const { return (m_orAllData <= 0xff); }
189 189
190 const DataVector& name() const { 190 const DataVector& name() const {
191 ASSERT(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE); 191 DCHECK(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE);
192 return m_data; 192 return m_data;
193 } 193 }
194 194
195 void appendToName(UChar character) { 195 void appendToName(UChar character) {
196 ASSERT(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE); 196 DCHECK(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE);
197 ASSERT(character); 197 DCHECK(character);
198 m_data.push_back(character); 198 m_data.push_back(character);
199 m_orAllData |= character; 199 m_orAllData |= character;
200 } 200 }
201 201
202 /* DOCTYPE Tokens */ 202 /* DOCTYPE Tokens */
203 203
204 bool forceQuirks() const { 204 bool forceQuirks() const {
205 ASSERT(m_type == DOCTYPE); 205 DCHECK_EQ(m_type, DOCTYPE);
206 return m_doctypeData->m_forceQuirks; 206 return m_doctypeData->m_forceQuirks;
207 } 207 }
208 208
209 void setForceQuirks() { 209 void setForceQuirks() {
210 ASSERT(m_type == DOCTYPE); 210 DCHECK_EQ(m_type, DOCTYPE);
211 m_doctypeData->m_forceQuirks = true; 211 m_doctypeData->m_forceQuirks = true;
212 } 212 }
213 213
214 void beginDOCTYPE() { 214 void beginDOCTYPE() {
215 ASSERT(m_type == Uninitialized); 215 DCHECK_EQ(m_type, Uninitialized);
216 m_type = DOCTYPE; 216 m_type = DOCTYPE;
217 m_doctypeData = WTF::wrapUnique(new DoctypeData); 217 m_doctypeData = WTF::wrapUnique(new DoctypeData);
218 } 218 }
219 219
220 void beginDOCTYPE(UChar character) { 220 void beginDOCTYPE(UChar character) {
221 ASSERT(character); 221 DCHECK(character);
222 beginDOCTYPE(); 222 beginDOCTYPE();
223 m_data.push_back(character); 223 m_data.push_back(character);
224 m_orAllData |= character; 224 m_orAllData |= character;
225 } 225 }
226 226
227 // FIXME: Distinguish between a missing public identifer and an empty one. 227 // FIXME: Distinguish between a missing public identifer and an empty one.
228 const WTF::Vector<UChar>& publicIdentifier() const { 228 const WTF::Vector<UChar>& publicIdentifier() const {
229 ASSERT(m_type == DOCTYPE); 229 DCHECK_EQ(m_type, DOCTYPE);
230 return m_doctypeData->m_publicIdentifier; 230 return m_doctypeData->m_publicIdentifier;
231 } 231 }
232 232
233 // FIXME: Distinguish between a missing system identifer and an empty one. 233 // FIXME: Distinguish between a missing system identifer and an empty one.
234 const WTF::Vector<UChar>& systemIdentifier() const { 234 const WTF::Vector<UChar>& systemIdentifier() const {
235 ASSERT(m_type == DOCTYPE); 235 DCHECK_EQ(m_type, DOCTYPE);
236 return m_doctypeData->m_systemIdentifier; 236 return m_doctypeData->m_systemIdentifier;
237 } 237 }
238 238
239 void setPublicIdentifierToEmptyString() { 239 void setPublicIdentifierToEmptyString() {
240 ASSERT(m_type == DOCTYPE); 240 DCHECK_EQ(m_type, DOCTYPE);
241 m_doctypeData->m_hasPublicIdentifier = true; 241 m_doctypeData->m_hasPublicIdentifier = true;
242 m_doctypeData->m_publicIdentifier.clear(); 242 m_doctypeData->m_publicIdentifier.clear();
243 } 243 }
244 244
245 void setSystemIdentifierToEmptyString() { 245 void setSystemIdentifierToEmptyString() {
246 ASSERT(m_type == DOCTYPE); 246 DCHECK_EQ(m_type, DOCTYPE);
247 m_doctypeData->m_hasSystemIdentifier = true; 247 m_doctypeData->m_hasSystemIdentifier = true;
248 m_doctypeData->m_systemIdentifier.clear(); 248 m_doctypeData->m_systemIdentifier.clear();
249 } 249 }
250 250
251 void appendToPublicIdentifier(UChar character) { 251 void appendToPublicIdentifier(UChar character) {
252 ASSERT(character); 252 DCHECK(character);
253 ASSERT(m_type == DOCTYPE); 253 DCHECK_EQ(m_type, DOCTYPE);
254 ASSERT(m_doctypeData->m_hasPublicIdentifier); 254 DCHECK(m_doctypeData->m_hasPublicIdentifier);
255 m_doctypeData->m_publicIdentifier.push_back(character); 255 m_doctypeData->m_publicIdentifier.push_back(character);
256 } 256 }
257 257
258 void appendToSystemIdentifier(UChar character) { 258 void appendToSystemIdentifier(UChar character) {
259 ASSERT(character); 259 DCHECK(character);
260 ASSERT(m_type == DOCTYPE); 260 DCHECK_EQ(m_type, DOCTYPE);
261 ASSERT(m_doctypeData->m_hasSystemIdentifier); 261 DCHECK(m_doctypeData->m_hasSystemIdentifier);
262 m_doctypeData->m_systemIdentifier.push_back(character); 262 m_doctypeData->m_systemIdentifier.push_back(character);
263 } 263 }
264 264
265 std::unique_ptr<DoctypeData> releaseDoctypeData() { 265 std::unique_ptr<DoctypeData> releaseDoctypeData() {
266 return std::move(m_doctypeData); 266 return std::move(m_doctypeData);
267 } 267 }
268 268
269 /* Start/End Tag Tokens */ 269 /* Start/End Tag Tokens */
270 270
271 bool selfClosing() const { 271 bool selfClosing() const {
272 ASSERT(m_type == StartTag || m_type == EndTag); 272 DCHECK(m_type == StartTag || m_type == EndTag);
273 return m_selfClosing; 273 return m_selfClosing;
274 } 274 }
275 275
276 void setSelfClosing() { 276 void setSelfClosing() {
277 ASSERT(m_type == StartTag || m_type == EndTag); 277 DCHECK(m_type == StartTag || m_type == EndTag);
278 m_selfClosing = true; 278 m_selfClosing = true;
279 } 279 }
280 280
281 void beginStartTag(UChar character) { 281 void beginStartTag(UChar character) {
282 ASSERT(character); 282 DCHECK(character);
283 ASSERT(m_type == Uninitialized); 283 DCHECK_EQ(m_type, Uninitialized);
284 m_type = StartTag; 284 m_type = StartTag;
285 m_selfClosing = false; 285 m_selfClosing = false;
286 m_currentAttribute = 0; 286 m_currentAttribute = 0;
287 m_attributes.clear(); 287 m_attributes.clear();
288 288
289 m_data.push_back(character); 289 m_data.push_back(character);
290 m_orAllData |= character; 290 m_orAllData |= character;
291 } 291 }
292 292
293 void beginEndTag(LChar character) { 293 void beginEndTag(LChar character) {
294 ASSERT(m_type == Uninitialized); 294 DCHECK_EQ(m_type, Uninitialized);
295 m_type = EndTag; 295 m_type = EndTag;
296 m_selfClosing = false; 296 m_selfClosing = false;
297 m_currentAttribute = 0; 297 m_currentAttribute = 0;
298 m_attributes.clear(); 298 m_attributes.clear();
299 299
300 m_data.push_back(character); 300 m_data.push_back(character);
301 } 301 }
302 302
303 void beginEndTag(const Vector<LChar, 32>& characters) { 303 void beginEndTag(const Vector<LChar, 32>& characters) {
304 ASSERT(m_type == Uninitialized); 304 DCHECK_EQ(m_type, Uninitialized);
305 m_type = EndTag; 305 m_type = EndTag;
306 m_selfClosing = false; 306 m_selfClosing = false;
307 m_currentAttribute = 0; 307 m_currentAttribute = 0;
308 m_attributes.clear(); 308 m_attributes.clear();
309 309
310 m_data.appendVector(characters); 310 m_data.appendVector(characters);
311 } 311 }
312 312
313 void addNewAttribute() { 313 void addNewAttribute() {
314 ASSERT(m_type == StartTag || m_type == EndTag); 314 DCHECK(m_type == StartTag || m_type == EndTag);
315 m_attributes.grow(m_attributes.size() + 1); 315 m_attributes.grow(m_attributes.size() + 1);
316 m_currentAttribute = &m_attributes.back(); 316 m_currentAttribute = &m_attributes.back();
317 m_currentAttribute->mutableNameRange().clear(); 317 m_currentAttribute->mutableNameRange().clear();
318 m_currentAttribute->mutableValueRange().clear(); 318 m_currentAttribute->mutableValueRange().clear();
319 } 319 }
320 320
321 void beginAttributeName(int offset) { 321 void beginAttributeName(int offset) {
322 m_currentAttribute->mutableNameRange().start = offset - m_baseOffset; 322 m_currentAttribute->mutableNameRange().start = offset - m_baseOffset;
323 m_currentAttribute->nameRange().checkValidStart(); 323 m_currentAttribute->nameRange().checkValidStart();
324 } 324 }
(...skipping 11 matching lines...) Expand all
336 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset; 336 m_currentAttribute->mutableValueRange().start = offset - m_baseOffset;
337 m_currentAttribute->valueRange().checkValidStart(); 337 m_currentAttribute->valueRange().checkValidStart();
338 } 338 }
339 339
340 void endAttributeValue(int offset) { 340 void endAttributeValue(int offset) {
341 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset; 341 m_currentAttribute->mutableValueRange().end = offset - m_baseOffset;
342 m_currentAttribute->valueRange().checkValid(); 342 m_currentAttribute->valueRange().checkValid();
343 } 343 }
344 344
345 void appendToAttributeName(UChar character) { 345 void appendToAttributeName(UChar character) {
346 ASSERT(character); 346 DCHECK(character);
347 ASSERT(m_type == StartTag || m_type == EndTag); 347 DCHECK(m_type == StartTag || m_type == EndTag);
348 m_currentAttribute->nameRange().checkValidStart(); 348 m_currentAttribute->nameRange().checkValidStart();
349 m_currentAttribute->appendToName(character); 349 m_currentAttribute->appendToName(character);
350 } 350 }
351 351
352 void appendToAttributeValue(UChar character) { 352 void appendToAttributeValue(UChar character) {
353 ASSERT(character); 353 DCHECK(character);
354 ASSERT(m_type == StartTag || m_type == EndTag); 354 DCHECK(m_type == StartTag || m_type == EndTag);
355 m_currentAttribute->valueRange().checkValidStart(); 355 m_currentAttribute->valueRange().checkValidStart();
356 m_currentAttribute->appendToValue(character); 356 m_currentAttribute->appendToValue(character);
357 } 357 }
358 358
359 void appendToAttributeValue(size_t i, const String& value) { 359 void appendToAttributeValue(size_t i, const String& value) {
360 ASSERT(!value.isEmpty()); 360 DCHECK(!value.isEmpty());
361 ASSERT(m_type == StartTag || m_type == EndTag); 361 DCHECK(m_type == StartTag || m_type == EndTag);
362 m_attributes[i].appendToValue(value); 362 m_attributes[i].appendToValue(value);
363 } 363 }
364 364
365 const AttributeList& attributes() const { 365 const AttributeList& attributes() const {
366 ASSERT(m_type == StartTag || m_type == EndTag); 366 DCHECK(m_type == StartTag || m_type == EndTag);
367 return m_attributes; 367 return m_attributes;
368 } 368 }
369 369
370 const Attribute* getAttributeItem(const QualifiedName& name) const { 370 const Attribute* getAttributeItem(const QualifiedName& name) const {
371 for (unsigned i = 0; i < m_attributes.size(); ++i) { 371 for (unsigned i = 0; i < m_attributes.size(); ++i) {
372 if (m_attributes.at(i).name() == name.localName()) 372 if (m_attributes.at(i).name() == name.localName())
373 return &m_attributes.at(i); 373 return &m_attributes.at(i);
374 } 374 }
375 return 0; 375 return 0;
376 } 376 }
377 377
378 // Used by the XSSAuditor to nuke XSS-laden attributes. 378 // Used by the XSSAuditor to nuke XSS-laden attributes.
379 void eraseValueOfAttribute(size_t i) { 379 void eraseValueOfAttribute(size_t i) {
380 ASSERT(m_type == StartTag || m_type == EndTag); 380 DCHECK(m_type == StartTag || m_type == EndTag);
381 m_attributes[i].clearValue(); 381 m_attributes[i].clearValue();
382 } 382 }
383 383
384 /* Character Tokens */ 384 /* Character Tokens */
385 385
386 // Starting a character token works slightly differently than starting 386 // Starting a character token works slightly differently than starting
387 // other types of tokens because we want to save a per-character branch. 387 // other types of tokens because we want to save a per-character branch.
388 void ensureIsCharacterToken() { 388 void ensureIsCharacterToken() {
389 ASSERT(m_type == Uninitialized || m_type == Character); 389 DCHECK(m_type == Uninitialized || m_type == Character);
390 m_type = Character; 390 m_type = Character;
391 } 391 }
392 392
393 const DataVector& characters() const { 393 const DataVector& characters() const {
394 ASSERT(m_type == Character); 394 DCHECK_EQ(m_type, Character);
395 return m_data; 395 return m_data;
396 } 396 }
397 397
398 void appendToCharacter(char character) { 398 void appendToCharacter(char character) {
399 ASSERT(m_type == Character); 399 DCHECK_EQ(m_type, Character);
400 m_data.push_back(character); 400 m_data.push_back(character);
401 } 401 }
402 402
403 void appendToCharacter(UChar character) { 403 void appendToCharacter(UChar character) {
404 ASSERT(m_type == Character); 404 DCHECK_EQ(m_type, Character);
405 m_data.push_back(character); 405 m_data.push_back(character);
406 m_orAllData |= character; 406 m_orAllData |= character;
407 } 407 }
408 408
409 void appendToCharacter(const Vector<LChar, 32>& characters) { 409 void appendToCharacter(const Vector<LChar, 32>& characters) {
410 ASSERT(m_type == Character); 410 DCHECK_EQ(m_type, Character);
411 m_data.appendVector(characters); 411 m_data.appendVector(characters);
412 } 412 }
413 413
414 /* Comment Tokens */ 414 /* Comment Tokens */
415 415
416 const DataVector& comment() const { 416 const DataVector& comment() const {
417 ASSERT(m_type == Comment); 417 DCHECK_EQ(m_type, Comment);
418 return m_data; 418 return m_data;
419 } 419 }
420 420
421 void beginComment() { 421 void beginComment() {
422 ASSERT(m_type == Uninitialized); 422 DCHECK_EQ(m_type, Uninitialized);
423 m_type = Comment; 423 m_type = Comment;
424 } 424 }
425 425
426 void appendToComment(UChar character) { 426 void appendToComment(UChar character) {
427 ASSERT(character); 427 DCHECK(character);
428 ASSERT(m_type == Comment); 428 DCHECK_EQ(m_type, Comment);
429 m_data.push_back(character); 429 m_data.push_back(character);
430 m_orAllData |= character; 430 m_orAllData |= character;
431 } 431 }
432 432
433 // Only for XSSAuditor 433 // Only for XSSAuditor
434 void eraseCharacters() { 434 void eraseCharacters() {
435 ASSERT(m_type == Character); 435 DCHECK_EQ(m_type, Character);
436 m_data.clear(); 436 m_data.clear();
437 m_orAllData = 0; 437 m_orAllData = 0;
438 } 438 }
439 439
440 private: 440 private:
441 TokenType m_type; 441 TokenType m_type;
442 Attribute::Range m_range; // Always starts at zero. 442 Attribute::Range m_range; // Always starts at zero.
443 int m_baseOffset; 443 int m_baseOffset;
444 DataVector m_data; 444 DataVector m_data;
445 UChar m_orAllData; 445 UChar m_orAllData;
446 446
447 // For StartTag and EndTag 447 // For StartTag and EndTag
448 bool m_selfClosing; 448 bool m_selfClosing;
449 AttributeList m_attributes; 449 AttributeList m_attributes;
450 450
451 // A pointer into m_attributes used during lexing. 451 // A pointer into m_attributes used during lexing.
452 Attribute* m_currentAttribute; 452 Attribute* m_currentAttribute;
453 453
454 // For DOCTYPE 454 // For DOCTYPE
455 std::unique_ptr<DoctypeData> m_doctypeData; 455 std::unique_ptr<DoctypeData> m_doctypeData;
456 }; 456 };
457 457
458 #ifndef NDEBUG 458 #ifndef NDEBUG
459 const char* toString(HTMLToken::TokenType); 459 const char* toString(HTMLToken::TokenType);
460 #endif 460 #endif
461 461
462 } // namespace blink 462 } // namespace blink
463 463
464 #endif 464 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLStackItem.h ('k') | third_party/WebKit/Source/core/html/parser/HTMLTokenizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698