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

Side by Side Diff: src/parsing/scanner.cc

Issue 2009963002: [modules] Disable HTML-like comments Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Unify behavior for optimized and non-optimized executions Created 4 years, 6 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
« no previous file with comments | « src/parsing/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_(true),
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 void Scanner::Initialize(Utf16CharacterStream* source,
53 void Scanner::Initialize(Utf16CharacterStream* source) { 54 bool allow_html_comments) {
54 source_ = source; 55 source_ = source;
55 // Need to capture identifiers in order to recognize "get" and "set" 56 // Need to capture identifiers in order to recognize "get" and "set"
56 // in object literals. 57 // in object literals.
57 Init(); 58 Init();
58 // Skip initial whitespace allowing HTML comment ends just like 59 // Skip initial whitespace allowing HTML comment ends just like
59 // after a newline and scan first token. 60 // after a newline and scan first token.
60 has_line_terminator_before_next_ = true; 61 has_line_terminator_before_next_ = true;
62 allow_html_comments_ = allow_html_comments;
61 SkipWhiteSpace(); 63 SkipWhiteSpace();
62 Scan(); 64 Scan();
63 } 65 }
64 66
65 template <bool capture_raw, bool unicode> 67 template <bool capture_raw, bool unicode>
66 uc32 Scanner::ScanHexNumber(int expected_length) { 68 uc32 Scanner::ScanHexNumber(int expected_length) {
67 DCHECK(expected_length <= 4); // prevent overflow 69 DCHECK(expected_length <= 4); // prevent overflow
68 70
69 int begin = source_pos() - 2; 71 int begin = source_pos() - 2;
70 uc32 x = 0; 72 uc32 x = 0;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 !IsLittleEndianByteOrderMark(c0_)) { 320 !IsLittleEndianByteOrderMark(c0_)) {
319 break; 321 break;
320 } 322 }
321 Advance(); 323 Advance();
322 } 324 }
323 325
324 // If there is an HTML comment end '-->' at the beginning of a 326 // 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 327 // 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 328 // of the line as a comment. This is in line with the way
327 // SpiderMonkey handles it. 329 // SpiderMonkey handles it.
328 if (c0_ == '-' && has_line_terminator_before_next_) { 330 if (c0_ == '-' && has_line_terminator_before_next_ &&
331 allow_html_comments_) {
329 Advance(); 332 Advance();
330 if (c0_ == '-') { 333 if (c0_ == '-') {
331 Advance(); 334 Advance();
332 if (c0_ == '>') { 335 if (c0_ == '>') {
333 // Treat the rest of the line as a comment. 336 // Treat the rest of the line as a comment.
334 SkipSingleLineComment(); 337 SkipSingleLineComment();
335 // Continue skipping white space after the comment. 338 // Continue skipping white space after the comment.
336 continue; 339 continue;
337 } 340 }
338 PushBack('-'); // undo Advance() 341 PushBack('-'); // undo Advance()
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 token = ScanString(); 494 token = ScanString();
492 break; 495 break;
493 496
494 case '<': 497 case '<':
495 // < <= << <<= <!-- 498 // < <= << <<= <!--
496 Advance(); 499 Advance();
497 if (c0_ == '=') { 500 if (c0_ == '=') {
498 token = Select(Token::LTE); 501 token = Select(Token::LTE);
499 } else if (c0_ == '<') { 502 } else if (c0_ == '<') {
500 token = Select('=', Token::ASSIGN_SHL, Token::SHL); 503 token = Select('=', Token::ASSIGN_SHL, Token::SHL);
501 } else if (c0_ == '!') { 504 } else if (c0_ == '!' && allow_html_comments_) {
502 token = ScanHtmlComment(); 505 token = ScanHtmlComment();
503 } else { 506 } else {
504 token = Token::LT; 507 token = Token::LT;
505 } 508 }
506 break; 509 break;
507 510
508 case '>': 511 case '>':
509 // > >= >> >>= >>> >>>= 512 // > >= >> >>= >>> >>>=
510 Advance(); 513 Advance();
511 if (c0_ == '=') { 514 if (c0_ == '=') {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } else { 560 } else {
558 token = Token::ADD; 561 token = Token::ADD;
559 } 562 }
560 break; 563 break;
561 564
562 case '-': 565 case '-':
563 // - -- --> -= 566 // - -- --> -=
564 Advance(); 567 Advance();
565 if (c0_ == '-') { 568 if (c0_ == '-') {
566 Advance(); 569 Advance();
567 if (c0_ == '>' && has_line_terminator_before_next_) { 570 if (c0_ == '>' && has_line_terminator_before_next_ &&
571 allow_html_comments_) {
568 // For compatibility with SpiderMonkey, we skip lines that 572 // For compatibility with SpiderMonkey, we skip lines that
569 // start with an HTML comment end '-->'. 573 // start with an HTML comment end '-->'.
570 token = SkipSingleLineComment(); 574 token = SkipSingleLineComment();
571 } else { 575 } else {
572 token = Token::DEC; 576 token = Token::DEC;
573 } 577 }
574 } else if (c0_ == '=') { 578 } else if (c0_ == '=') {
575 token = Select(Token::ASSIGN_SUB); 579 token = Select(Token::ASSIGN_SUB);
576 } else { 580 } else {
577 token = Token::SUB; 581 token = Token::SUB;
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1713 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1710 } 1714 }
1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1715 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1712 1716
1713 backing_store_.AddBlock(bytes); 1717 backing_store_.AddBlock(bytes);
1714 return backing_store_.EndSequence().start(); 1718 return backing_store_.EndSequence().start();
1715 } 1719 }
1716 1720
1717 } // namespace internal 1721 } // namespace internal
1718 } // namespace v8 1722 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698