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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // sequential string of type StringType. | 599 // sequential string of type StringType. |
600 template <bool seq_ascii> | 600 template <bool seq_ascii> |
601 template <typename StringType, typename SinkChar> | 601 template <typename StringType, typename SinkChar> |
602 Handle<String> JsonParser<seq_ascii>::SlowScanJsonString( | 602 Handle<String> JsonParser<seq_ascii>::SlowScanJsonString( |
603 Handle<String> prefix, int start, int end) { | 603 Handle<String> prefix, int start, int end) { |
604 int count = end - start; | 604 int count = end - start; |
605 int max_length = count + source_length_ - position_; | 605 int max_length = count + source_length_ - position_; |
606 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); | 606 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); |
607 Handle<StringType> seq_string = | 607 Handle<StringType> seq_string = |
608 NewRawString<StringType>(factory(), length, pretenure_); | 608 NewRawString<StringType>(factory(), length, pretenure_); |
| 609 ASSERT(!seq_string.is_null()); |
609 // Copy prefix into seq_str. | 610 // Copy prefix into seq_str. |
610 SinkChar* dest = seq_string->GetChars(); | 611 SinkChar* dest = seq_string->GetChars(); |
611 String::WriteToFlat(*prefix, dest, start, end); | 612 String::WriteToFlat(*prefix, dest, start, end); |
612 | 613 |
613 while (c0_ != '"') { | 614 while (c0_ != '"') { |
614 // Check for control character (0x00-0x1f) or unterminated string (<0). | 615 // Check for control character (0x00-0x1f) or unterminated string (<0). |
615 if (c0_ < 0x20) return Handle<String>::null(); | 616 if (c0_ < 0x20) return Handle<String>::null(); |
616 if (count >= length) { | 617 if (count >= length) { |
617 // We need to create a longer sequential string for the result. | 618 // We need to create a longer sequential string for the result. |
618 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count); | 619 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 position_); | 787 position_); |
787 } | 788 } |
788 } else { | 789 } else { |
789 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, | 790 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, |
790 beg_pos, | 791 beg_pos, |
791 position_); | 792 position_); |
792 } | 793 } |
793 } while (c0_ != '"'); | 794 } while (c0_ != '"'); |
794 int length = position_ - beg_pos; | 795 int length = position_ - beg_pos; |
795 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_); | 796 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_); |
| 797 ASSERT(!result.is_null()); |
796 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); | 798 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); |
797 String::WriteToFlat(*source_, dest, beg_pos, position_); | 799 String::WriteToFlat(*source_, dest, beg_pos, position_); |
798 | 800 |
799 ASSERT_EQ('"', c0_); | 801 ASSERT_EQ('"', c0_); |
800 // Advance past the last '"'. | 802 // Advance past the last '"'. |
801 AdvanceSkipWhitespace(); | 803 AdvanceSkipWhitespace(); |
802 return result; | 804 return result; |
803 } | 805 } |
804 | 806 |
805 } } // namespace v8::internal | 807 } } // namespace v8::internal |
806 | 808 |
807 #endif // V8_JSON_PARSER_H_ | 809 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |