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

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

Issue 223573002: Return MaybeHandle from NewRaw???String. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/handles.h ('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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 576
577 template <typename StringType> 577 template <typename StringType>
578 inline Handle<StringType> NewRawString(Factory* factory, 578 inline Handle<StringType> NewRawString(Factory* factory,
579 int length, 579 int length,
580 PretenureFlag pretenure); 580 PretenureFlag pretenure);
581 581
582 template <> 582 template <>
583 inline Handle<SeqTwoByteString> NewRawString(Factory* factory, 583 inline Handle<SeqTwoByteString> NewRawString(Factory* factory,
584 int length, 584 int length,
585 PretenureFlag pretenure) { 585 PretenureFlag pretenure) {
586 return factory->NewRawTwoByteString(length, pretenure); 586 return factory->NewRawTwoByteString(length, pretenure).ToHandleChecked();
587 } 587 }
588 588
589 template <> 589 template <>
590 inline Handle<SeqOneByteString> NewRawString(Factory* factory, 590 inline Handle<SeqOneByteString> NewRawString(Factory* factory,
591 int length, 591 int length,
592 PretenureFlag pretenure) { 592 PretenureFlag pretenure) {
593 return factory->NewRawOneByteString(length, pretenure); 593 return factory->NewRawOneByteString(length, pretenure).ToHandleChecked();
594 } 594 }
595 595
596 596
597 // Scans the rest of a JSON string starting from position_ and writes 597 // Scans the rest of a JSON string starting from position_ and writes
598 // prefix[start..end] along with the scanned characters into a 598 // prefix[start..end] along with the scanned characters into a
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 beg_pos, 785 beg_pos,
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 =
797 ASSERT(!result.is_null()); 796 factory()->NewRawOneByteString(length, pretenure_).ToHandleChecked();
798 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); 797 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars();
799 String::WriteToFlat(*source_, dest, beg_pos, position_); 798 String::WriteToFlat(*source_, dest, beg_pos, position_);
800 799
801 ASSERT_EQ('"', c0_); 800 ASSERT_EQ('"', c0_);
802 // Advance past the last '"'. 801 // Advance past the last '"'.
803 AdvanceSkipWhitespace(); 802 AdvanceSkipWhitespace();
804 return result; 803 return result;
805 } 804 }
806 805
807 } } // namespace v8::internal 806 } } // namespace v8::internal
808 807
809 #endif // V8_JSON_PARSER_H_ 808 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698