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

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

Issue 2665513002: [parser] Lift template literal invalid escape restriction (Closed)
Patch Set: rebase harder Created 3 years, 10 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 // 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 case '2': // fall through 941 case '2': // fall through
942 case '3': // fall through 942 case '3': // fall through
943 case '4': // fall through 943 case '4': // fall through
944 case '5': // fall through 944 case '5': // fall through
945 case '6': // fall through 945 case '6': // fall through
946 case '7': 946 case '7':
947 c = ScanOctalEscape<capture_raw>(c, 2); 947 c = ScanOctalEscape<capture_raw>(c, 2);
948 break; 948 break;
949 } 949 }
950 950
951 // According to ECMA-262, section 7.8.4, characters not covered by the 951 // Other escaped characters are interpreted as their non-escaped version.
952 // above cases should be illegal, but they are commonly handled as
953 // non-escaped characters by JS VMs.
954 AddLiteralChar(c); 952 AddLiteralChar(c);
955 return true; 953 return true;
956 } 954 }
957 955
958 956
959 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of
960 // ECMA-262. Other JS VMs support them.
961 template <bool capture_raw> 957 template <bool capture_raw>
962 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { 958 uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
963 uc32 x = c - '0'; 959 uc32 x = c - '0';
964 int i = 0; 960 int i = 0;
965 for (; i < length; i++) { 961 for (; i < length; i++) {
966 int d = c0_ - '0'; 962 int d = c0_ - '0';
967 if (d < 0 || d > 7) break; 963 if (d < 0 || d > 7) break;
968 int nx = x * 8 + d; 964 int nx = x * 8 + d;
969 if (nx >= 256) break; 965 if (nx >= 256) break;
970 x = nx; 966 x = nx;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 uc32 lastChar = c0_; 1058 uc32 lastChar = c0_;
1063 Advance<capture_raw>(); 1059 Advance<capture_raw>();
1064 if (lastChar == '\r') { 1060 if (lastChar == '\r') {
1065 ReduceRawLiteralLength(1); // Remove \r 1061 ReduceRawLiteralLength(1); // Remove \r
1066 if (c0_ == '\n') { 1062 if (c0_ == '\n') {
1067 Advance<capture_raw>(); // Adds \n 1063 Advance<capture_raw>(); // Adds \n
1068 } else { 1064 } else {
1069 AddRawLiteralChar('\n'); 1065 AddRawLiteralChar('\n');
1070 } 1066 }
1071 } 1067 }
1072 } else if (!ScanEscape<capture_raw, in_template_literal>()) { 1068 } else {
1073 return Token::ILLEGAL; 1069 // For templates, invalid escape sequence checking is handled in the
1070 // parser.
1071 ScanEscape<capture_raw, in_template_literal>();
1074 } 1072 }
1075 } else if (c < 0) { 1073 } else if (c < 0) {
1076 // Unterminated template literal 1074 // Unterminated template literal
1077 PushBack(c); 1075 PushBack(c);
1078 break; 1076 break;
1079 } else { 1077 } else {
1080 // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A. 1078 // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A.
1081 // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence 1079 // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence
1082 // consisting of the CV 0x000A. 1080 // consisting of the CV 0x000A.
1083 if (c == '\r') { 1081 if (c == '\r') {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 // 2, reset the source to the desired position, 1687 // 2, reset the source to the desired position,
1690 source_->Seek(position); 1688 source_->Seek(position);
1691 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). 1689 // 3, re-scan, by scanning the look-ahead char + 1 token (next_).
1692 c0_ = source_->Advance(); 1690 c0_ = source_->Advance();
1693 Next(); 1691 Next();
1694 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position)); 1692 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position));
1695 } 1693 }
1696 1694
1697 } // namespace internal 1695 } // namespace internal
1698 } // namespace v8 1696 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698