| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 Advance(); | 434 Advance(); |
| 435 if (c0_ == '-' || c0_ == '+') Advance(); | 435 if (c0_ == '-' || c0_ == '+') Advance(); |
| 436 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter(); | 436 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter(); |
| 437 do { | 437 do { |
| 438 Advance(); | 438 Advance(); |
| 439 } while (c0_ >= '0' && c0_ <= '9'); | 439 } while (c0_ >= '0' && c0_ <= '9'); |
| 440 } | 440 } |
| 441 int length = position_ - beg_pos; | 441 int length = position_ - beg_pos; |
| 442 double number; | 442 double number; |
| 443 if (seq_ascii) { | 443 if (seq_ascii) { |
| 444 Vector<const char> chars(seq_source_->GetChars() + beg_pos, length); | 444 Vector<const uint8_t> chars(seq_source_->GetChars() + beg_pos, length); |
| 445 number = StringToDouble(isolate()->unicode_cache(), | 445 number = StringToDouble(isolate()->unicode_cache(), |
| 446 chars, | 446 Vector<const char>::cast(chars), |
| 447 NO_FLAGS, // Hex, octal or trailing junk. | 447 NO_FLAGS, // Hex, octal or trailing junk. |
| 448 OS::nan_value()); | 448 OS::nan_value()); |
| 449 } else { | 449 } else { |
| 450 Vector<char> buffer = Vector<char>::New(length); | 450 Vector<uint8_t> buffer = Vector<uint8_t>::New(length); |
| 451 String::WriteToFlat(*source_, buffer.start(), beg_pos, position_); | 451 String::WriteToFlat(*source_, buffer.start(), beg_pos, position_); |
| 452 Vector<const char> result = | 452 Vector<const uint8_t> result = |
| 453 Vector<const char>(reinterpret_cast<const char*>(buffer.start()), | 453 Vector<const uint8_t>(buffer.start(), length); |
| 454 length); | |
| 455 number = StringToDouble(isolate()->unicode_cache(), | 454 number = StringToDouble(isolate()->unicode_cache(), |
| 456 result, | 455 // TODO(dcarney): Convert StringToDouble to uint_t. |
| 457 NO_FLAGS, // Hex, octal or trailing junk. | 456 Vector<const char>::cast(result), |
| 458 0.0); | 457 NO_FLAGS, // Hex, octal or trailing junk. |
| 458 0.0); |
| 459 buffer.Dispose(); | 459 buffer.Dispose(); |
| 460 } | 460 } |
| 461 SkipWhitespace(); | 461 SkipWhitespace(); |
| 462 return factory()->NewNumber(number, pretenure_); | 462 return factory()->NewNumber(number, pretenure_); |
| 463 } | 463 } |
| 464 | 464 |
| 465 | 465 |
| 466 template <typename StringType> | 466 template <typename StringType> |
| 467 inline void SeqStringSet(Handle<StringType> seq_str, int i, uc32 c); | 467 inline void SeqStringSet(Handle<StringType> seq_str, int i, uc32 c); |
| 468 | 468 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // a known symbol, contains backslashes or unexpectedly reaches the end of | 620 // a known symbol, contains backslashes or unexpectedly reaches the end of |
| 621 // string, return with an empty handle. | 621 // string, return with an empty handle. |
| 622 uint32_t running_hash = isolate()->heap()->HashSeed(); | 622 uint32_t running_hash = isolate()->heap()->HashSeed(); |
| 623 int position = position_; | 623 int position = position_; |
| 624 uc32 c0 = c0_; | 624 uc32 c0 = c0_; |
| 625 do { | 625 do { |
| 626 if (c0 == '\\') { | 626 if (c0 == '\\') { |
| 627 c0_ = c0; | 627 c0_ = c0; |
| 628 int beg_pos = position_; | 628 int beg_pos = position_; |
| 629 position_ = position; | 629 position_ = position; |
| 630 return SlowScanJsonString<SeqOneByteString, char>(source_, | 630 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, |
| 631 beg_pos, | 631 beg_pos, |
| 632 position_); | 632 position_); |
| 633 } | 633 } |
| 634 if (c0 < 0x20) return Handle<String>::null(); | 634 if (c0 < 0x20) return Handle<String>::null(); |
| 635 if (static_cast<uint32_t>(c0) > | 635 if (static_cast<uint32_t>(c0) > |
| 636 unibrow::Utf16::kMaxNonSurrogateCharCode) { | 636 unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 637 running_hash = | 637 running_hash = |
| 638 StringHasher::AddCharacterCore(running_hash, | 638 StringHasher::AddCharacterCore(running_hash, |
| 639 unibrow::Utf16::LeadSurrogate(c0)); | 639 unibrow::Utf16::LeadSurrogate(c0)); |
| 640 running_hash = | 640 running_hash = |
| 641 StringHasher::AddCharacterCore(running_hash, | 641 StringHasher::AddCharacterCore(running_hash, |
| 642 unibrow::Utf16::TrailSurrogate(c0)); | 642 unibrow::Utf16::TrailSurrogate(c0)); |
| 643 } else { | 643 } else { |
| 644 running_hash = StringHasher::AddCharacterCore(running_hash, c0); | 644 running_hash = StringHasher::AddCharacterCore(running_hash, c0); |
| 645 } | 645 } |
| 646 position++; | 646 position++; |
| 647 if (position >= source_length_) return Handle<String>::null(); | 647 if (position >= source_length_) return Handle<String>::null(); |
| 648 c0 = seq_source_->SeqOneByteStringGet(position); | 648 c0 = seq_source_->SeqOneByteStringGet(position); |
| 649 } while (c0 != '"'); | 649 } while (c0 != '"'); |
| 650 int length = position - position_; | 650 int length = position - position_; |
| 651 uint32_t hash = (length <= String::kMaxHashCalcLength) | 651 uint32_t hash = (length <= String::kMaxHashCalcLength) |
| 652 ? StringHasher::GetHashCore(running_hash) : length; | 652 ? StringHasher::GetHashCore(running_hash) : length; |
| 653 Vector<const uint8_t> string_vector( | 653 Vector<const uint8_t> string_vector( |
| 654 seq_source_->GetCharsU() + position_, length); | 654 seq_source_->GetChars() + position_, length); |
| 655 SymbolTable* symbol_table = isolate()->heap()->symbol_table(); | 655 SymbolTable* symbol_table = isolate()->heap()->symbol_table(); |
| 656 uint32_t capacity = symbol_table->Capacity(); | 656 uint32_t capacity = symbol_table->Capacity(); |
| 657 uint32_t entry = SymbolTable::FirstProbe(hash, capacity); | 657 uint32_t entry = SymbolTable::FirstProbe(hash, capacity); |
| 658 uint32_t count = 1; | 658 uint32_t count = 1; |
| 659 while (true) { | 659 while (true) { |
| 660 Object* element = symbol_table->KeyAt(entry); | 660 Object* element = symbol_table->KeyAt(entry); |
| 661 if (element == isolate()->heap()->undefined_value()) { | 661 if (element == isolate()->heap()->undefined_value()) { |
| 662 // Lookup failure. | 662 // Lookup failure. |
| 663 break; | 663 break; |
| 664 } | 664 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 681 if (c0_ < 0x20) return Handle<String>::null(); | 681 if (c0_ < 0x20) return Handle<String>::null(); |
| 682 if (c0_ != '\\') { | 682 if (c0_ != '\\') { |
| 683 if (seq_ascii || c0_ <= String::kMaxOneByteCharCode) { | 683 if (seq_ascii || c0_ <= String::kMaxOneByteCharCode) { |
| 684 Advance(); | 684 Advance(); |
| 685 } else { | 685 } else { |
| 686 return SlowScanJsonString<SeqTwoByteString, uc16>(source_, | 686 return SlowScanJsonString<SeqTwoByteString, uc16>(source_, |
| 687 beg_pos, | 687 beg_pos, |
| 688 position_); | 688 position_); |
| 689 } | 689 } |
| 690 } else { | 690 } else { |
| 691 return SlowScanJsonString<SeqOneByteString, char>(source_, | 691 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, |
| 692 beg_pos, | 692 beg_pos, |
| 693 position_); | 693 position_); |
| 694 } | 694 } |
| 695 } while (c0_ != '"'); | 695 } while (c0_ != '"'); |
| 696 int length = position_ - beg_pos; | 696 int length = position_ - beg_pos; |
| 697 Handle<String> result; | 697 Handle<String> result; |
| 698 if (seq_ascii && is_symbol) { | 698 if (seq_ascii && is_symbol) { |
| 699 result = factory()->LookupOneByteSymbol(seq_source_, beg_pos, length); | 699 result = factory()->LookupOneByteSymbol(seq_source_, beg_pos, length); |
| 700 } else { | 700 } else { |
| 701 result = factory()->NewRawOneByteString(length, pretenure_); | 701 result = factory()->NewRawOneByteString(length, pretenure_); |
| 702 char* dest = SeqOneByteString::cast(*result)->GetChars(); | 702 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); |
| 703 String::WriteToFlat(*source_, dest, beg_pos, position_); | 703 String::WriteToFlat(*source_, dest, beg_pos, position_); |
| 704 } | 704 } |
| 705 ASSERT_EQ('"', c0_); | 705 ASSERT_EQ('"', c0_); |
| 706 // Advance past the last '"'. | 706 // Advance past the last '"'. |
| 707 AdvanceSkipWhitespace(); | 707 AdvanceSkipWhitespace(); |
| 708 return result; | 708 return result; |
| 709 } | 709 } |
| 710 | 710 |
| 711 } } // namespace v8::internal | 711 } } // namespace v8::internal |
| 712 | 712 |
| 713 #endif // V8_JSON_PARSER_H_ | 713 #endif // V8_JSON_PARSER_H_ |
| OLD | NEW |