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

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

Issue 13841012: Add asserts to String::GetFlatContent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | « no previous file | src/objects.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 vector.start(), 772 vector.start(),
773 SeqOneByteString::cast(*current_part_)->GetChars() + current_index_, 773 SeqOneByteString::cast(*current_part_)->GetChars() + current_index_,
774 length); 774 length);
775 } else { 775 } else {
776 current_index_ += SerializeStringUnchecked_( 776 current_index_ += SerializeStringUnchecked_(
777 vector.start(), 777 vector.start(),
778 SeqTwoByteString::cast(*current_part_)->GetChars() + current_index_, 778 SeqTwoByteString::cast(*current_part_)->GetChars() + current_index_,
779 length); 779 length);
780 } 780 }
781 } else { 781 } else {
782 String* string_location = *string; 782 String* string_location = NULL;
783 Vector<const Char> vector = GetCharVector<Char>(string); 783 Vector<const Char> vector(NULL, 0);
784 for (int i = 0; i < length; i++) { 784 for (int i = 0; i < length; i++) {
785 // If GC moved the string, we need to refresh the vector.
786 if (*string != string_location) {
787 AssertNoAllocation no_gc;
788 // This does not actually prevent the string from being relocated later.
789 vector = GetCharVector<Char>(string);
790 string_location = *string;
791 }
785 Char c = vector[i]; 792 Char c = vector[i];
786 if (DoNotEscape(c)) { 793 if (DoNotEscape(c)) {
787 Append_<is_ascii, Char>(c); 794 Append_<is_ascii, Char>(c);
788 } else { 795 } else {
789 Append_<is_ascii, uint8_t>(reinterpret_cast<const uint8_t*>( 796 Append_<is_ascii, uint8_t>(reinterpret_cast<const uint8_t*>(
790 &JsonEscapeTable[c * kJsonEscapeTableEntrySize])); 797 &JsonEscapeTable[c * kJsonEscapeTableEntrySize]));
791 } 798 }
792 // If GC moved the string, we need to refresh the vector.
793 if (*string != string_location) {
794 vector = GetCharVector<Char>(string);
795 string_location = *string;
796 }
797 } 799 }
798 } 800 }
799 801
800 Append_<is_ascii, uint8_t>('"'); 802 Append_<is_ascii, uint8_t>('"');
801 } 803 }
802 804
803 805
804 template <> 806 template <>
805 bool BasicJsonStringifier::DoNotEscape(uint8_t c) { 807 bool BasicJsonStringifier::DoNotEscape(uint8_t c) {
806 return c >= '#' && c <= '~' && c != '\\'; 808 return c >= '#' && c <= '~' && c != '\\';
(...skipping 17 matching lines...) Expand all
824 826
825 template <> 827 template <>
826 Vector<const uc16> BasicJsonStringifier::GetCharVector(Handle<String> string) { 828 Vector<const uc16> BasicJsonStringifier::GetCharVector(Handle<String> string) {
827 String::FlatContent flat = string->GetFlatContent(); 829 String::FlatContent flat = string->GetFlatContent();
828 ASSERT(flat.IsTwoByte()); 830 ASSERT(flat.IsTwoByte());
829 return flat.ToUC16Vector(); 831 return flat.ToUC16Vector();
830 } 832 }
831 833
832 834
833 void BasicJsonStringifier::SerializeString(Handle<String> object) { 835 void BasicJsonStringifier::SerializeString(Handle<String> object) {
834 FlattenString(object); 836 object = FlattenGetString(object);
835 String::FlatContent flat = object->GetFlatContent();
836 if (is_ascii_) { 837 if (is_ascii_) {
837 if (flat.IsAscii()) { 838 if (object->IsOneByteRepresentation()) {
838 SerializeString_<true, uint8_t>(object); 839 SerializeString_<true, uint8_t>(object);
839 } else { 840 } else {
840 ChangeEncoding(); 841 ChangeEncoding();
841 SerializeString(object); 842 SerializeString(object);
842 } 843 }
843 } else { 844 } else {
844 if (flat.IsAscii()) { 845 if (object->IsOneByteRepresentation()) {
845 SerializeString_<false, uint8_t>(object); 846 SerializeString_<false, uint8_t>(object);
846 } else { 847 } else {
847 SerializeString_<false, uc16>(object); 848 SerializeString_<false, uc16>(object);
848 } 849 }
849 } 850 }
850 } 851 }
851 852
852 } } // namespace v8::internal 853 } } // namespace v8::internal
853 854
854 #endif // V8_JSON_STRINGIFIER_H_ 855 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698