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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "src/scanner.h" | 9 #include "src/scanner.h" |
| 10 | 10 |
| 11 #include "include/v8stdint.h" | 11 #include "include/v8stdint.h" |
| 12 #include "src/char-predicates-inl.h" | 12 #include "src/char-predicates-inl.h" |
| 13 #include "src/conversions-inl.h" | 13 #include "src/conversions-inl.h" |
| 14 #include "src/list-inl.h" | 14 #include "src/list-inl.h" |
| 15 #include "src/v8.h" | 15 #include "src/v8.h" |
| 16 #include "src/parser.h" | 16 #include "src/parser.h" |
| 17 | 17 |
| 18 namespace v8 { | 18 namespace v8 { |
| 19 namespace internal { | 19 namespace internal { |
| 20 | 20 |
| 21 | |
| 22 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { | |
| 23 if (is_one_byte()) { | |
| 24 return isolate->factory()->InternalizeOneByteString(one_byte_literal()); | |
| 25 } | |
| 26 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); | |
| 27 } | |
| 28 | |
| 29 | |
| 21 // ---------------------------------------------------------------------------- | 30 // ---------------------------------------------------------------------------- |
| 22 // Scanner | 31 // Scanner |
| 23 | 32 |
| 24 Scanner::Scanner(UnicodeCache* unicode_cache) | 33 Scanner::Scanner(UnicodeCache* unicode_cache) |
| 25 : unicode_cache_(unicode_cache), | 34 : unicode_cache_(unicode_cache), |
| 26 octal_pos_(Location::invalid()), | 35 octal_pos_(Location::invalid()), |
| 27 harmony_scoping_(false), | 36 harmony_scoping_(false), |
| 28 harmony_modules_(false), | 37 harmony_modules_(false), |
| 29 harmony_numeric_literals_(false) { } | 38 harmony_numeric_literals_(false) { } |
| 30 | 39 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 // stream of input elements for the syntactic grammar (see | 296 // stream of input elements for the syntactic grammar (see |
| 288 // ECMA-262, section 7.4). | 297 // ECMA-262, section 7.4). |
| 289 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | 298 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { |
| 290 Advance(); | 299 Advance(); |
| 291 } | 300 } |
| 292 | 301 |
| 293 return Token::WHITESPACE; | 302 return Token::WHITESPACE; |
| 294 } | 303 } |
| 295 | 304 |
| 296 | 305 |
| 306 Token::Value Scanner::SkipMagicComment() { | |
| 307 Advance(); | |
| 308 TryToParseMagicComment(); | |
| 309 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | |
| 310 Advance(); | |
| 311 } | |
| 312 | |
| 313 return Token::WHITESPACE; | |
| 314 } | |
| 315 | |
| 316 | |
| 317 void Scanner::TryToParseMagicComment() { | |
| 318 // Magic comments are of the form \s*name\s*=\s*value\s*.* and this function | |
|
yurys
2014/06/10 09:28:47
We might need to allow only single whitespace betw
| |
| 319 // will just return if it cannot parse a magic comment. | |
| 320 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { | |
| 321 Advance(); | |
| 322 } | |
| 323 if (c0_ < 0 || unicode_cache_->IsLineTerminator(c0_)) return; | |
| 324 LiteralBuffer name; | |
| 325 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_) && | |
| 326 c0_ != '=') { | |
| 327 name.AddChar(c0_); | |
| 328 Advance(); | |
| 329 } | |
| 330 if (!name.is_one_byte()) return; | |
| 331 Vector<const uint8_t> name_literal = name.one_byte_literal(); | |
| 332 LiteralBuffer* value; | |
| 333 if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceURL"))) { | |
| 334 value = &source_url_; | |
| 335 } else if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceMappingURL"))) { | |
|
yurys
2014/06/10 09:28:47
Since we add support for sourceMappingURL we need
marja
2014/06/10 13:46:09
Done.
| |
| 336 value = &source_mapping_url_; | |
| 337 } else { | |
| 338 return; | |
| 339 } | |
| 340 value->Reset(); | |
| 341 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { | |
| 342 Advance(); | |
| 343 } | |
| 344 if (c0_ != '=') | |
| 345 return; | |
| 346 Advance(); | |
| 347 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { | |
| 348 Advance(); | |
| 349 } | |
| 350 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_)) { | |
| 351 value->AddChar(c0_); | |
| 352 Advance(); | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 | |
| 297 Token::Value Scanner::SkipMultiLineComment() { | 357 Token::Value Scanner::SkipMultiLineComment() { |
| 298 ASSERT(c0_ == '*'); | 358 ASSERT(c0_ == '*'); |
| 299 Advance(); | 359 Advance(); |
| 300 | 360 |
| 301 while (c0_ >= 0) { | 361 while (c0_ >= 0) { |
| 302 uc32 ch = c0_; | 362 uc32 ch = c0_; |
| 303 Advance(); | 363 Advance(); |
| 304 if (unicode_cache_->IsLineTerminator(ch)) { | 364 if (unicode_cache_->IsLineTerminator(ch)) { |
| 305 // Following ECMA-262, section 7.4, a comment containing | 365 // Following ECMA-262, section 7.4, a comment containing |
| 306 // a newline will make the comment count as a line-terminator. | 366 // a newline will make the comment count as a line-terminator. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 | 511 |
| 452 case '%': | 512 case '%': |
| 453 // % %= | 513 // % %= |
| 454 token = Select('=', Token::ASSIGN_MOD, Token::MOD); | 514 token = Select('=', Token::ASSIGN_MOD, Token::MOD); |
| 455 break; | 515 break; |
| 456 | 516 |
| 457 case '/': | 517 case '/': |
| 458 // / // /* /= | 518 // / // /* /= |
| 459 Advance(); | 519 Advance(); |
| 460 if (c0_ == '/') { | 520 if (c0_ == '/') { |
| 461 token = SkipSingleLineComment(); | 521 Advance(); |
| 522 if (c0_ == '@' || c0_ == '#') { | |
| 523 Advance(); | |
| 524 token = SkipMagicComment(); | |
| 525 } else { | |
| 526 PushBack(c0_); | |
| 527 token = SkipSingleLineComment(); | |
| 528 } | |
| 462 } else if (c0_ == '*') { | 529 } else if (c0_ == '*') { |
| 463 token = SkipMultiLineComment(); | 530 token = SkipMultiLineComment(); |
| 464 } else if (c0_ == '=') { | 531 } else if (c0_ == '=') { |
| 465 token = Select(Token::ASSIGN_DIV); | 532 token = Select(Token::ASSIGN_DIV); |
| 466 } else { | 533 } else { |
| 467 token = Token::DIV; | 534 token = Token::DIV; |
| 468 } | 535 } |
| 469 break; | 536 break; |
| 470 | 537 |
| 471 case '&': | 538 case '&': |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 return isolate->factory()->NewStringFromOneByte( | 1166 return isolate->factory()->NewStringFromOneByte( |
| 1100 next_literal_one_byte_string(), tenured).ToHandleChecked(); | 1167 next_literal_one_byte_string(), tenured).ToHandleChecked(); |
| 1101 } else { | 1168 } else { |
| 1102 return isolate->factory()->NewStringFromTwoByte( | 1169 return isolate->factory()->NewStringFromTwoByte( |
| 1103 next_literal_two_byte_string(), tenured).ToHandleChecked(); | 1170 next_literal_two_byte_string(), tenured).ToHandleChecked(); |
| 1104 } | 1171 } |
| 1105 } | 1172 } |
| 1106 | 1173 |
| 1107 | 1174 |
| 1108 Handle<String> Scanner::AllocateInternalizedString(Isolate* isolate) { | 1175 Handle<String> Scanner::AllocateInternalizedString(Isolate* isolate) { |
| 1109 if (is_literal_one_byte()) { | 1176 return current_.literal_chars->Internalize(isolate); |
| 1110 return isolate->factory()->InternalizeOneByteString( | |
| 1111 literal_one_byte_string()); | |
| 1112 } else { | |
| 1113 return isolate->factory()->InternalizeTwoByteString( | |
| 1114 literal_two_byte_string()); | |
| 1115 } | |
| 1116 } | 1177 } |
| 1117 | 1178 |
| 1118 | 1179 |
| 1119 double Scanner::DoubleValue() { | 1180 double Scanner::DoubleValue() { |
| 1120 ASSERT(is_literal_one_byte()); | 1181 ASSERT(is_literal_one_byte()); |
| 1121 return StringToDouble( | 1182 return StringToDouble( |
| 1122 unicode_cache_, | 1183 unicode_cache_, |
| 1123 literal_one_byte_string(), | 1184 literal_one_byte_string(), |
| 1124 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | 1185 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); |
| 1125 } | 1186 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 } | 1332 } |
| 1272 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1333 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1273 } | 1334 } |
| 1274 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1335 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1275 | 1336 |
| 1276 backing_store_.AddBlock(bytes); | 1337 backing_store_.AddBlock(bytes); |
| 1277 return backing_store_.EndSequence().start(); | 1338 return backing_store_.EndSequence().start(); |
| 1278 } | 1339 } |
| 1279 | 1340 |
| 1280 } } // namespace v8::internal | 1341 } } // namespace v8::internal |
| OLD | NEW |