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

Side by Side Diff: src/json-parser.h

Issue 210143002: Revert "No longer OOM on invalid string length." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
610 // Copy prefix into seq_str. 609 // Copy prefix into seq_str.
611 SinkChar* dest = seq_string->GetChars(); 610 SinkChar* dest = seq_string->GetChars();
612 String::WriteToFlat(*prefix, dest, start, end); 611 String::WriteToFlat(*prefix, dest, start, end);
613 612
614 while (c0_ != '"') { 613 while (c0_ != '"') {
615 // Check for control character (0x00-0x1f) or unterminated string (<0). 614 // Check for control character (0x00-0x1f) or unterminated string (<0).
616 if (c0_ < 0x20) return Handle<String>::null(); 615 if (c0_ < 0x20) return Handle<String>::null();
617 if (count >= length) { 616 if (count >= length) {
618 // We need to create a longer sequential string for the result. 617 // We need to create a longer sequential string for the result.
619 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count); 618 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 position_); 786 position_);
788 } 787 }
789 } else { 788 } else {
790 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, 789 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_,
791 beg_pos, 790 beg_pos,
792 position_); 791 position_);
793 } 792 }
794 } while (c0_ != '"'); 793 } while (c0_ != '"');
795 int length = position_ - beg_pos; 794 int length = position_ - beg_pos;
796 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_); 795 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_);
797 ASSERT(!result.is_null());
798 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); 796 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars();
799 String::WriteToFlat(*source_, dest, beg_pos, position_); 797 String::WriteToFlat(*source_, dest, beg_pos, position_);
800 798
801 ASSERT_EQ('"', c0_); 799 ASSERT_EQ('"', c0_);
802 // Advance past the last '"'. 800 // Advance past the last '"'.
803 AdvanceSkipWhitespace(); 801 AdvanceSkipWhitespace();
804 return result; 802 return result;
805 } 803 }
806 804
807 } } // namespace v8::internal 805 } } // namespace v8::internal
808 806
809 #endif // V8_JSON_PARSER_H_ 807 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698