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

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

Issue 12599003: Insert missing type cast in JSON.stringify. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | « no previous file | test/mjsunit/regress/regress-2570.js » ('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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 675
676 // Assert that uc16 character is not truncated down to 8 bit. 676 // Assert that uc16 character is not truncated down to 8 bit.
677 // The <uc16, char> version of this method must not be called. 677 // The <uc16, char> version of this method must not be called.
678 ASSERT(sizeof(*dest) >= sizeof(*src)); 678 ASSERT(sizeof(*dest) >= sizeof(*src));
679 679
680 for (int i = 0; i < length; i++) { 680 for (int i = 0; i < length; i++) {
681 SrcChar c = src[i]; 681 SrcChar c = src[i];
682 if (DoNotEscape(c)) { 682 if (DoNotEscape(c)) {
683 *(dest++) = static_cast<DestChar>(c); 683 *(dest++) = static_cast<DestChar>(c);
684 } else { 684 } else {
685 const char* chars = &JsonEscapeTable[c * kJsonEscapeTableEntrySize]; 685 const uint8_t* chars = reinterpret_cast<const uint8_t*>(
686 &JsonEscapeTable[c * kJsonEscapeTableEntrySize]);
686 while (*chars != '\0') *(dest++) = *(chars++); 687 while (*chars != '\0') *(dest++) = *(chars++);
687 } 688 }
688 } 689 }
689 690
690 current_index_ += static_cast<int>(dest - dest_start); 691 current_index_ += static_cast<int>(dest - dest_start);
691 } 692 }
692 693
693 694
694 template <bool is_ascii, typename Char> 695 template <bool is_ascii, typename Char>
695 void BasicJsonStringifier::SerializeString_(Handle<String> string) { 696 void BasicJsonStringifier::SerializeString_(Handle<String> string) {
(...skipping 19 matching lines...) Expand all
715 length); 716 length);
716 } 717 }
717 } else { 718 } else {
718 String* string_location = *string; 719 String* string_location = *string;
719 Vector<const Char> vector = GetCharVector<Char>(string); 720 Vector<const Char> vector = GetCharVector<Char>(string);
720 for (int i = 0; i < length; i++) { 721 for (int i = 0; i < length; i++) {
721 Char c = vector[i]; 722 Char c = vector[i];
722 if (DoNotEscape(c)) { 723 if (DoNotEscape(c)) {
723 Append_<is_ascii, Char>(c); 724 Append_<is_ascii, Char>(c);
724 } else { 725 } else {
725 Append_<is_ascii, uint8_t>( 726 Append_<is_ascii, uint8_t>(reinterpret_cast<const uint8_t*>(
726 reinterpret_cast<const uint8_t*>( 727 &JsonEscapeTable[c * kJsonEscapeTableEntrySize]));
727 &JsonEscapeTable[c * kJsonEscapeTableEntrySize]));
728 } 728 }
729 // If GC moved the string, we need to refresh the vector. 729 // If GC moved the string, we need to refresh the vector.
730 if (*string != string_location) { 730 if (*string != string_location) {
731 vector = GetCharVector<Char>(string); 731 vector = GetCharVector<Char>(string);
732 string_location = *string; 732 string_location = *string;
733 } 733 }
734 } 734 }
735 } 735 }
736 736
737 Append_<is_ascii, uint8_t>('"'); 737 Append_<is_ascii, uint8_t>('"');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 SerializeString_<false, uint8_t>(object); 782 SerializeString_<false, uint8_t>(object);
783 } else { 783 } else {
784 SerializeString_<false, uc16>(object); 784 SerializeString_<false, uc16>(object);
785 } 785 }
786 } 786 }
787 } 787 }
788 788
789 } } // namespace v8::internal 789 } } // namespace v8::internal
790 790
791 #endif // V8_JSON_STRINGIFIER_H_ 791 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2570.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698