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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index a154a4e99a3db613a6ddf555cec9a1762773fff4..3e8072264119df2cafa52accc5a3584dacec6b93 100644
--- a/src/json-stringifier.h
+++ b/src/json-stringifier.h
@@ -779,9 +779,16 @@ void BasicJsonStringifier::SerializeString_(Handle<String> string) {
length);
}
} else {
- String* string_location = *string;
- Vector<const Char> vector = GetCharVector<Char>(string);
+ String* string_location = NULL;
+ Vector<const Char> vector(NULL, 0);
for (int i = 0; i < length; i++) {
+ // If GC moved the string, we need to refresh the vector.
+ if (*string != string_location) {
+ AssertNoAllocation no_gc;
+ // This does not actually prevent the string from being relocated later.
+ vector = GetCharVector<Char>(string);
+ string_location = *string;
+ }
Char c = vector[i];
if (DoNotEscape(c)) {
Append_<is_ascii, Char>(c);
@@ -789,11 +796,6 @@ void BasicJsonStringifier::SerializeString_(Handle<String> string) {
Append_<is_ascii, uint8_t>(reinterpret_cast<const uint8_t*>(
&JsonEscapeTable[c * kJsonEscapeTableEntrySize]));
}
- // If GC moved the string, we need to refresh the vector.
- if (*string != string_location) {
- vector = GetCharVector<Char>(string);
- string_location = *string;
- }
}
}
@@ -831,17 +833,16 @@ Vector<const uc16> BasicJsonStringifier::GetCharVector(Handle<String> string) {
void BasicJsonStringifier::SerializeString(Handle<String> object) {
- FlattenString(object);
- String::FlatContent flat = object->GetFlatContent();
+ object = FlattenGetString(object);
if (is_ascii_) {
- if (flat.IsAscii()) {
+ if (object->IsOneByteRepresentation()) {
SerializeString_<true, uint8_t>(object);
} else {
ChangeEncoding();
SerializeString(object);
}
} else {
- if (flat.IsAscii()) {
+ if (object->IsOneByteRepresentation()) {
SerializeString_<false, uint8_t>(object);
} else {
SerializeString_<false, uc16>(object);
« 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