OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
6 | 6 |
7 #include "src/parsing/scanner.h" | 7 #include "src/parsing/scanner.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
37 // Scanner | 37 // Scanner |
38 | 38 |
39 Scanner::Scanner(UnicodeCache* unicode_cache) | 39 Scanner::Scanner(UnicodeCache* unicode_cache) |
40 : unicode_cache_(unicode_cache), | 40 : unicode_cache_(unicode_cache), |
41 bookmark_c0_(kNoBookmark), | 41 bookmark_c0_(kNoBookmark), |
42 octal_pos_(Location::invalid()), | 42 octal_pos_(Location::invalid()), |
43 decimal_with_leading_zero_pos_(Location::invalid()), | 43 decimal_with_leading_zero_pos_(Location::invalid()), |
44 found_html_comment_(false), | 44 found_html_comment_(false), |
45 allow_html_comments_(false), | |
45 allow_harmony_exponentiation_operator_(false) { | 46 allow_harmony_exponentiation_operator_(false) { |
46 bookmark_current_.literal_chars = &bookmark_current_literal_; | 47 bookmark_current_.literal_chars = &bookmark_current_literal_; |
47 bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_; | 48 bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_; |
48 bookmark_next_.literal_chars = &bookmark_next_literal_; | 49 bookmark_next_.literal_chars = &bookmark_next_literal_; |
49 bookmark_next_.raw_literal_chars = &bookmark_next_raw_literal_; | 50 bookmark_next_.raw_literal_chars = &bookmark_next_raw_literal_; |
50 } | 51 } |
51 | 52 |
52 | 53 |
53 void Scanner::Initialize(Utf16CharacterStream* source) { | 54 void Scanner::Initialize(Utf16CharacterStream* source) { |
54 source_ = source; | 55 source_ = source; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 323 } |
323 | 324 |
324 // If there is an HTML comment end '-->' at the beginning of a | 325 // If there is an HTML comment end '-->' at the beginning of a |
325 // line (with only whitespace in front of it), we treat the rest | 326 // line (with only whitespace in front of it), we treat the rest |
326 // of the line as a comment. This is in line with the way | 327 // of the line as a comment. This is in line with the way |
327 // SpiderMonkey handles it. | 328 // SpiderMonkey handles it. |
328 if (c0_ == '-' && has_line_terminator_before_next_) { | 329 if (c0_ == '-' && has_line_terminator_before_next_) { |
329 Advance(); | 330 Advance(); |
330 if (c0_ == '-') { | 331 if (c0_ == '-') { |
331 Advance(); | 332 Advance(); |
332 if (c0_ == '>') { | 333 if (c0_ == '>' && !allow_html_comments_) { |
333 // Treat the rest of the line as a comment. | 334 // Treat the rest of the line as a comment. |
334 SkipSingleLineComment(); | 335 SkipSingleLineComment(); |
335 // Continue skipping white space after the comment. | 336 // Continue skipping white space after the comment. |
336 continue; | 337 continue; |
337 } | 338 } |
338 PushBack('-'); // undo Advance() | 339 PushBack('-'); // undo Advance() |
339 } | 340 } |
340 PushBack('-'); // undo Advance() | 341 PushBack('-'); // undo Advance() |
341 } | 342 } |
342 // Return whether or not we skipped any characters. | 343 // Return whether or not we skipped any characters. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 return Token::ILLEGAL; | 448 return Token::ILLEGAL; |
448 } | 449 } |
449 | 450 |
450 | 451 |
451 Token::Value Scanner::ScanHtmlComment() { | 452 Token::Value Scanner::ScanHtmlComment() { |
452 // Check for <!-- comments. | 453 // Check for <!-- comments. |
453 DCHECK(c0_ == '!'); | 454 DCHECK(c0_ == '!'); |
454 Advance(); | 455 Advance(); |
455 if (c0_ == '-') { | 456 if (c0_ == '-') { |
456 Advance(); | 457 Advance(); |
457 if (c0_ == '-') { | 458 if (c0_ == '-' && !allow_html_comments_) { |
vogelheim
2016/05/27 08:08:49
nitpick: It seems more logical to check this at th
mike3
2016/05/27 15:53:22
Maybe, but it's good taste. I was suffering from t
| |
458 found_html_comment_ = true; | 459 found_html_comment_ = true; |
459 return SkipSingleLineComment(); | 460 return SkipSingleLineComment(); |
460 } | 461 } |
461 PushBack('-'); // undo Advance() | 462 PushBack('-'); // undo Advance() |
462 } | 463 } |
463 PushBack('!'); // undo Advance() | 464 PushBack('!'); // undo Advance() |
464 DCHECK(c0_ == '!'); | 465 DCHECK(c0_ == '!'); |
465 return Token::LT; | 466 return Token::LT; |
466 } | 467 } |
467 | 468 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 } else { | 558 } else { |
558 token = Token::ADD; | 559 token = Token::ADD; |
559 } | 560 } |
560 break; | 561 break; |
561 | 562 |
562 case '-': | 563 case '-': |
563 // - -- --> -= | 564 // - -- --> -= |
564 Advance(); | 565 Advance(); |
565 if (c0_ == '-') { | 566 if (c0_ == '-') { |
566 Advance(); | 567 Advance(); |
567 if (c0_ == '>' && has_line_terminator_before_next_) { | 568 if (c0_ == '>' && has_line_terminator_before_next_ && |
569 !allow_html_comments_) { | |
568 // For compatibility with SpiderMonkey, we skip lines that | 570 // For compatibility with SpiderMonkey, we skip lines that |
569 // start with an HTML comment end '-->'. | 571 // start with an HTML comment end '-->'. |
570 token = SkipSingleLineComment(); | 572 token = SkipSingleLineComment(); |
571 } else { | 573 } else { |
572 token = Token::DEC; | 574 token = Token::DEC; |
573 } | 575 } |
574 } else if (c0_ == '=') { | 576 } else if (c0_ == '=') { |
575 token = Select(Token::ASSIGN_SUB); | 577 token = Select(Token::ASSIGN_SUB); |
576 } else { | 578 } else { |
577 token = Token::SUB; | 579 token = Token::SUB; |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1709 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1711 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1710 } | 1712 } |
1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1713 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1712 | 1714 |
1713 backing_store_.AddBlock(bytes); | 1715 backing_store_.AddBlock(bytes); |
1714 return backing_store_.EndSequence().start(); | 1716 return backing_store_.EndSequence().start(); |
1715 } | 1717 } |
1716 | 1718 |
1717 } // namespace internal | 1719 } // namespace internal |
1718 } // namespace v8 | 1720 } // namespace v8 |
OLD | NEW |