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

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: Created 4 years, 7 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 module_(false),
adamk 2016/05/25 20:43:02 Please call this "allow_html_comments_" instead.
mike3 2016/05/25 21:10:13 Acknowledged.
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
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_ == '>' && !module_) {
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
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_ == '-' && !module_) {
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
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_ && !module_) {
568 // For compatibility with SpiderMonkey, we skip lines that 569 // For compatibility with SpiderMonkey, we skip lines that
569 // start with an HTML comment end '-->'. 570 // start with an HTML comment end '-->'.
570 token = SkipSingleLineComment(); 571 token = SkipSingleLineComment();
571 } else { 572 } else {
572 token = Token::DEC; 573 token = Token::DEC;
573 } 574 }
574 } else if (c0_ == '=') { 575 } else if (c0_ == '=') {
575 token = Select(Token::ASSIGN_SUB); 576 token = Select(Token::ASSIGN_SUB);
576 } else { 577 } else {
577 token = Token::SUB; 578 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)); 1710 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1710 } 1711 }
1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1712 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1712 1713
1713 backing_store_.AddBlock(bytes); 1714 backing_store_.AddBlock(bytes);
1714 return backing_store_.EndSequence().start(); 1715 return backing_store_.EndSequence().start();
1715 } 1716 }
1716 1717
1717 } // namespace internal 1718 } // namespace internal
1718 } // namespace v8 1719 } // 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