Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 // occur before the "use strict" directive. | 783 // occur before the "use strict" directive. |
| 784 if (c != '0' || i > 0) { | 784 if (c != '0' || i > 0) { |
| 785 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); | 785 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); |
| 786 } | 786 } |
| 787 return x; | 787 return x; |
| 788 } | 788 } |
| 789 | 789 |
| 790 | 790 |
| 791 Token::Value Scanner::ScanString() { | 791 Token::Value Scanner::ScanString() { |
| 792 uc32 quote = c0_; | 792 uc32 quote = c0_; |
| 793 Advance(); // consume quote | 793 Advance<false, false>(); // consume quote |
| 794 | 794 |
| 795 LiteralScope literal(this); | 795 LiteralScope literal(this); |
| 796 while (true) { | |
| 797 if (c0_ > 127) { | |
|
marja
2015/03/04 08:52:51
I was briefly confused by the 127. Why so restrict
| |
| 798 HandleLeadSurrogate(); | |
| 799 break; | |
| 800 } | |
| 801 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL; | |
| 802 if (c0_ == quote) { | |
| 803 literal.Complete(); | |
| 804 Advance<false, false>(); | |
| 805 return Token::STRING; | |
| 806 } | |
| 807 uc32 c = c0_; | |
| 808 if (c == '\\') break; | |
| 809 Advance<false, false>(); | |
| 810 AddLiteralChar(c); | |
| 811 } | |
| 812 | |
| 796 while (c0_ != quote && c0_ >= 0 | 813 while (c0_ != quote && c0_ >= 0 |
| 797 && !unicode_cache_->IsLineTerminator(c0_)) { | 814 && !unicode_cache_->IsLineTerminator(c0_)) { |
| 798 uc32 c = c0_; | 815 uc32 c = c0_; |
| 799 Advance(); | 816 Advance(); |
| 800 if (c == '\\') { | 817 if (c == '\\') { |
| 801 if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL; | 818 if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL; |
| 802 } else { | 819 } else { |
| 803 AddLiteralChar(c); | 820 AddLiteralChar(c); |
| 804 } | 821 } |
| 805 } | 822 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 | 1003 |
| 987 uc32 first_char = c0_; | 1004 uc32 first_char = c0_; |
| 988 Advance<false, false>(); | 1005 Advance<false, false>(); |
| 989 AddLiteralChar(first_char); | 1006 AddLiteralChar(first_char); |
| 990 } | 1007 } |
| 991 | 1008 |
| 992 if (next_.literal_chars->one_byte_literal().length() < 10 && | 1009 if (next_.literal_chars->one_byte_literal().length() < 10 && |
| 993 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { | 1010 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { |
| 994 smi_value_ = value; | 1011 smi_value_ = value; |
| 995 literal.Complete(); | 1012 literal.Complete(); |
| 996 HandleLeadSurrugate(); | 1013 HandleLeadSurrogate(); |
| 997 | 1014 |
| 998 return Token::SMI; | 1015 return Token::SMI; |
| 999 } | 1016 } |
| 1000 HandleLeadSurrugate(); | 1017 HandleLeadSurrogate(); |
| 1001 } | 1018 } |
| 1002 | 1019 |
| 1003 ScanDecimalDigits(); // optional | 1020 ScanDecimalDigits(); // optional |
| 1004 if (c0_ == '.') { | 1021 if (c0_ == '.') { |
| 1005 AddLiteralCharAdvance(); | 1022 AddLiteralCharAdvance(); |
| 1006 ScanDecimalDigits(); // optional | 1023 ScanDecimalDigits(); // optional |
| 1007 } | 1024 } |
| 1008 } | 1025 } |
| 1009 } | 1026 } |
| 1010 | 1027 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 } | 1240 } |
| 1224 } else if (c0_ <= 127 && c0_ != '\\') { | 1241 } else if (c0_ <= 127 && c0_ != '\\') { |
| 1225 // Only a-z+: could be a keyword or identifier. | 1242 // Only a-z+: could be a keyword or identifier. |
| 1226 literal.Complete(); | 1243 literal.Complete(); |
| 1227 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); | 1244 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
| 1228 return KeywordOrIdentifierToken(chars.start(), chars.length(), | 1245 return KeywordOrIdentifierToken(chars.start(), chars.length(), |
| 1229 harmony_scoping_, harmony_modules_, | 1246 harmony_scoping_, harmony_modules_, |
| 1230 harmony_classes_); | 1247 harmony_classes_); |
| 1231 } | 1248 } |
| 1232 | 1249 |
| 1233 HandleLeadSurrugate(); | 1250 HandleLeadSurrogate(); |
| 1234 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { | 1251 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { |
| 1235 do { | 1252 do { |
| 1236 uc32 first_char = c0_; | 1253 uc32 first_char = c0_; |
| 1237 Advance<false, false>(); | 1254 Advance<false, false>(); |
| 1238 AddLiteralChar(first_char); | 1255 AddLiteralChar(first_char); |
| 1239 } while (IsAsciiIdentifier(c0_)); | 1256 } while (IsAsciiIdentifier(c0_)); |
| 1240 | 1257 |
| 1241 if (c0_ <= 127 && c0_ != '\\') { | 1258 if (c0_ <= 127 && c0_ != '\\') { |
| 1242 literal.Complete(); | 1259 literal.Complete(); |
| 1243 return Token::IDENTIFIER; | 1260 return Token::IDENTIFIER; |
| 1244 } | 1261 } |
| 1245 | 1262 |
| 1246 HandleLeadSurrugate(); | 1263 HandleLeadSurrogate(); |
| 1247 } else if (c0_ == '\\') { | 1264 } else if (c0_ == '\\') { |
| 1248 // Scan identifier start character. | 1265 // Scan identifier start character. |
| 1249 uc32 c = ScanIdentifierUnicodeEscape(); | 1266 uc32 c = ScanIdentifierUnicodeEscape(); |
| 1250 // Only allow legal identifier start characters. | 1267 // Only allow legal identifier start characters. |
| 1251 if (c < 0 || | 1268 if (c < 0 || |
| 1252 c == '\\' || // No recursive escapes. | 1269 c == '\\' || // No recursive escapes. |
| 1253 !unicode_cache_->IsIdentifierStart(c)) { | 1270 !unicode_cache_->IsIdentifierStart(c)) { |
| 1254 return Token::ILLEGAL; | 1271 return Token::ILLEGAL; |
| 1255 } | 1272 } |
| 1256 AddLiteralChar(c); | 1273 AddLiteralChar(c); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1554 } | 1571 } |
| 1555 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1572 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1556 } | 1573 } |
| 1557 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1574 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1558 | 1575 |
| 1559 backing_store_.AddBlock(bytes); | 1576 backing_store_.AddBlock(bytes); |
| 1560 return backing_store_.EndSequence().start(); | 1577 return backing_store_.EndSequence().start(); |
| 1561 } | 1578 } |
| 1562 | 1579 |
| 1563 } } // namespace v8::internal | 1580 } } // namespace v8::internal |
| OLD | NEW |