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

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

Issue 2510873005: A decimal integer literal with a leading 0 is now an error in strict mode. (Closed)
Patch Set: Created 4 years, 1 month 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool Scanner::BookmarkScope::HasBeenApplied() { 71 bool Scanner::BookmarkScope::HasBeenApplied() {
72 return bookmark_ == kBookmarkWasApplied; 72 return bookmark_ == kBookmarkWasApplied;
73 } 73 }
74 74
75 // ---------------------------------------------------------------------------- 75 // ----------------------------------------------------------------------------
76 // Scanner 76 // Scanner
77 77
78 Scanner::Scanner(UnicodeCache* unicode_cache) 78 Scanner::Scanner(UnicodeCache* unicode_cache)
79 : unicode_cache_(unicode_cache), 79 : unicode_cache_(unicode_cache),
80 octal_pos_(Location::invalid()), 80 octal_pos_(Location::invalid()),
81 decimal_with_leading_zero_pos_(Location::invalid()), 81 octal_message_(MessageTemplate::kNone),
82 found_html_comment_(false) { 82 found_html_comment_(false) {}
83 }
84
85 83
86 void Scanner::Initialize(Utf16CharacterStream* source) { 84 void Scanner::Initialize(Utf16CharacterStream* source) {
87 source_ = source; 85 source_ = source;
88 // Need to capture identifiers in order to recognize "get" and "set" 86 // Need to capture identifiers in order to recognize "get" and "set"
89 // in object literals. 87 // in object literals.
90 Init(); 88 Init();
91 // Skip initial whitespace allowing HTML comment ends just like 89 // Skip initial whitespace allowing HTML comment ends just like
92 // after a newline and scan first token. 90 // after a newline and scan first token.
93 has_line_terminator_before_next_ = true; 91 has_line_terminator_before_next_ = true;
94 SkipWhiteSpace(); 92 SkipWhiteSpace();
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 x = nx; 908 x = nx;
911 Advance<capture_raw>(); 909 Advance<capture_raw>();
912 } 910 }
913 // Anything except '\0' is an octal escape sequence, illegal in strict mode. 911 // Anything except '\0' is an octal escape sequence, illegal in strict mode.
914 // Remember the position of octal escape sequences so that an error 912 // Remember the position of octal escape sequences so that an error
915 // can be reported later (in strict mode). 913 // can be reported later (in strict mode).
916 // We don't report the error immediately, because the octal escape can 914 // We don't report the error immediately, because the octal escape can
917 // occur before the "use strict" directive. 915 // occur before the "use strict" directive.
918 if (c != '0' || i > 0) { 916 if (c != '0' || i > 0) {
919 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); 917 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
918 octal_message_ = MessageTemplate::kStrictOctalEscape;
920 } 919 }
921 return x; 920 return x;
922 } 921 }
923 922
924 923
925 Token::Value Scanner::ScanString() { 924 Token::Value Scanner::ScanString() {
926 uc32 quote = c0_; 925 uc32 quote = c0_;
927 Advance<false, false>(); // consume quote 926 Advance<false, false>(); // consume quote
928 927
929 LiteralScope literal(this); 928 LiteralScope literal(this);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 kind = IMPLICIT_OCTAL; 1122 kind = IMPLICIT_OCTAL;
1124 while (true) { 1123 while (true) {
1125 if (c0_ == '8' || c0_ == '9') { 1124 if (c0_ == '8' || c0_ == '9') {
1126 at_start = false; 1125 at_start = false;
1127 kind = DECIMAL_WITH_LEADING_ZERO; 1126 kind = DECIMAL_WITH_LEADING_ZERO;
1128 break; 1127 break;
1129 } 1128 }
1130 if (c0_ < '0' || '7' < c0_) { 1129 if (c0_ < '0' || '7' < c0_) {
1131 // Octal literal finished. 1130 // Octal literal finished.
1132 octal_pos_ = Location(start_pos, source_pos()); 1131 octal_pos_ = Location(start_pos, source_pos());
1132 octal_message_ = MessageTemplate::kStrictOctalLiteral;
1133 break; 1133 break;
1134 } 1134 }
1135 AddLiteralCharAdvance(); 1135 AddLiteralCharAdvance();
1136 } 1136 }
1137 } else if (c0_ == '8' || c0_ == '9') { 1137 } else if (c0_ == '8' || c0_ == '9') {
1138 kind = DECIMAL_WITH_LEADING_ZERO; 1138 kind = DECIMAL_WITH_LEADING_ZERO;
1139 } 1139 }
1140 } 1140 }
1141 1141
1142 // Parse decimal digits and allow trailing fractional part. 1142 // Parse decimal digits and allow trailing fractional part.
1143 if (kind == DECIMAL || kind == DECIMAL_WITH_LEADING_ZERO) { 1143 if (kind == DECIMAL || kind == DECIMAL_WITH_LEADING_ZERO) {
1144 if (at_start) { 1144 if (at_start) {
1145 uint64_t value = 0; 1145 uint64_t value = 0;
1146 while (IsDecimalDigit(c0_)) { 1146 while (IsDecimalDigit(c0_)) {
1147 value = 10 * value + (c0_ - '0'); 1147 value = 10 * value + (c0_ - '0');
1148 1148
1149 uc32 first_char = c0_; 1149 uc32 first_char = c0_;
1150 Advance<false, false>(); 1150 Advance<false, false>();
1151 AddLiteralChar(first_char); 1151 AddLiteralChar(first_char);
1152 } 1152 }
1153 1153
1154 if (next_.literal_chars->one_byte_literal().length() <= 10 && 1154 if (next_.literal_chars->one_byte_literal().length() <= 10 &&
1155 value <= Smi::kMaxValue && c0_ != '.' && c0_ != 'e' && c0_ != 'E') { 1155 value <= Smi::kMaxValue && c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
1156 next_.smi_value_ = static_cast<uint32_t>(value); 1156 next_.smi_value_ = static_cast<uint32_t>(value);
1157 literal.Complete(); 1157 literal.Complete();
1158 HandleLeadSurrogate(); 1158 HandleLeadSurrogate();
1159 1159
1160 if (kind == DECIMAL_WITH_LEADING_ZERO) 1160 if (kind == DECIMAL_WITH_LEADING_ZERO) {
1161 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos()); 1161 octal_pos_ = Location(start_pos, source_pos());
1162 octal_message_ = MessageTemplate::kStrictOctalLiteral;
1163 }
1162 return Token::SMI; 1164 return Token::SMI;
1163 } 1165 }
1164 HandleLeadSurrogate(); 1166 HandleLeadSurrogate();
1165 } 1167 }
1166 1168
1167 ScanDecimalDigits(); // optional 1169 ScanDecimalDigits(); // optional
1168 if (c0_ == '.') { 1170 if (c0_ == '.') {
1169 AddLiteralCharAdvance(); 1171 AddLiteralCharAdvance();
1170 ScanDecimalDigits(); // optional 1172 ScanDecimalDigits(); // optional
1171 } 1173 }
(...skipping 19 matching lines...) Expand all
1191 // The source character immediately following a numeric literal must 1193 // The source character immediately following a numeric literal must
1192 // not be an identifier start or a decimal digit; see ECMA-262 1194 // not be an identifier start or a decimal digit; see ECMA-262
1193 // section 7.8.3, page 17 (note that we read only one decimal digit 1195 // section 7.8.3, page 17 (note that we read only one decimal digit
1194 // if the value is 0). 1196 // if the value is 0).
1195 if (IsDecimalDigit(c0_) || 1197 if (IsDecimalDigit(c0_) ||
1196 (c0_ != kEndOfInput && unicode_cache_->IsIdentifierStart(c0_))) 1198 (c0_ != kEndOfInput && unicode_cache_->IsIdentifierStart(c0_)))
1197 return Token::ILLEGAL; 1199 return Token::ILLEGAL;
1198 1200
1199 literal.Complete(); 1201 literal.Complete();
1200 1202
1201 if (kind == DECIMAL_WITH_LEADING_ZERO) 1203 if (kind == DECIMAL_WITH_LEADING_ZERO) {
1202 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos()); 1204 octal_pos_ = Location(start_pos, source_pos());
1205 octal_message_ = MessageTemplate::kStrictOctalLiteral;
1206 }
1203 return Token::NUMBER; 1207 return Token::NUMBER;
1204 } 1208 }
1205 1209
1206 1210
1207 uc32 Scanner::ScanIdentifierUnicodeEscape() { 1211 uc32 Scanner::ScanIdentifierUnicodeEscape() {
1208 Advance(); 1212 Advance();
1209 if (c0_ != 'u') return -1; 1213 if (c0_ != 'u') return -1;
1210 Advance(); 1214 Advance();
1211 return ScanUnicodeEscape<false>(); 1215 return ScanUnicodeEscape<false>();
1212 } 1216 }
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 // 2, reset the source to the desired position, 1640 // 2, reset the source to the desired position,
1637 source_->Seek(position); 1641 source_->Seek(position);
1638 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). 1642 // 3, re-scan, by scanning the look-ahead char + 1 token (next_).
1639 c0_ = source_->Advance(); 1643 c0_ = source_->Advance();
1640 Next(); 1644 Next();
1641 DCHECK_EQ(next_.location.beg_pos, position); 1645 DCHECK_EQ(next_.location.beg_pos, position);
1642 } 1646 }
1643 1647
1644 } // namespace internal 1648 } // namespace internal
1645 } // namespace v8 1649 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698