Revision: 14776
Author: [email protected]
Date: Thu May 23 06:53:49 2013
Log: Add asserts to String::GetFlatContent.
[email protected]
BUG=
Review URL: https://chromiumcodereview.appspot.com/13841012
http://code.google.com/p/v8/source/detail?r=14776
Modified:
/branches/bleeding_edge/src/json-stringifier.h
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/runtime.cc
=======================================
--- /branches/bleeding_edge/src/json-stringifier.h Wed May 8 08:02:08 2013
+++ /branches/bleeding_edge/src/json-stringifier.h Thu May 23 06:53:49 2013
@@ -773,9 +773,16 @@
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);
@@ -783,11 +790,6 @@
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;
- }
}
}
@@ -825,17 +827,16 @@
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);
=======================================
--- /branches/bleeding_edge/src/objects.cc Thu May 23 04:30:24 2013
+++ /branches/bleeding_edge/src/objects.cc Thu May 23 06:53:49 2013
@@ -7841,6 +7841,7 @@
String::FlatContent String::GetFlatContent() {
+ ASSERT(!GetHeap()->allow_allocation(false));
int length = this->length();
StringShape shape(this);
String* string = this;
@@ -8067,6 +8068,8 @@
if (str_ == NULL) return;
Handle<String> str(str_);
ASSERT(str->IsFlat());
+ AssertNoAllocation no_gc;
+ // This does not actually prevent the vector from being relocated later.
String::FlatContent content = str->GetFlatContent();
ASSERT(content.IsFlat());
is_ascii_ = content.IsAscii();
@@ -8618,6 +8621,7 @@
bool String::IsOneByteEqualTo(Vector<const uint8_t> str) {
int slen = length();
if (str.length() != slen) return false;
+ AssertNoAllocation no_gc;
FlatContent content = GetFlatContent();
if (content.IsAscii()) {
return CompareChars(content.ToOneByteVector().start(),
@@ -8633,6 +8637,7 @@
bool String::IsTwoByteEqualTo(Vector<const uc16> str) {
int slen = length();
if (str.length() != slen) return false;
+ AssertNoAllocation no_gc;
FlatContent content = GetFlatContent();
if (content.IsTwoByte()) {
return CompareChars(content.ToUC16Vector().start(), str.start(), slen)
== 0;
=======================================
--- /branches/bleeding_edge/src/runtime.cc Thu May 23 03:01:42 2013
+++ /branches/bleeding_edge/src/runtime.cc Thu May 23 06:53:49 2013
@@ -5663,11 +5663,10 @@
ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<String> string = FlattenGetString(source);
- String::FlatContent content = string->GetFlatContent();
- ASSERT(content.IsFlat());
- Handle<String> result =
- content.IsAscii() ? URIEscape::Escape<uint8_t>(isolate, source)
- : URIEscape::Escape<uc16>(isolate, source);
+ ASSERT(string->IsFlat());
+ Handle<String> result = string->IsOneByteRepresentationUnderneath()
+ ? URIEscape::Escape<uint8_t>(isolate, source)
+ : URIEscape::Escape<uc16>(isolate, source);
if (result.is_null()) return Failure::OutOfMemoryException(0x12);
return *result;
}
@@ -5678,10 +5677,10 @@
ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<String> string = FlattenGetString(source);
- String::FlatContent content = string->GetFlatContent();
- ASSERT(content.IsFlat());
- return content.IsAscii() ? *URIUnescape::Unescape<uint8_t>(isolate,
source)
- : *URIUnescape::Unescape<uc16>(isolate, source);
+ ASSERT(string->IsFlat());
+ return string->IsOneByteRepresentationUnderneath()
+ ? *URIUnescape::Unescape<uint8_t>(isolate, source)
+ : *URIUnescape::Unescape<uc16>(isolate, source);
}
@@ -6210,6 +6209,7 @@
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
elements = Handle<FixedArray>(FixedArray::cast(obj), isolate);
+ AssertNoAllocation no_gc;
String::FlatContent content = s->GetFlatContent();
if (content.IsAscii()) {
Vector<const uint8_t> chars = content.ToOneByteVector();
@@ -7076,6 +7076,7 @@
equal_prefix_result = Smi::FromInt(LESS);
}
int r;
+ AssertNoAllocation no_gc;
String::FlatContent x_content = x->GetFlatContent();
String::FlatContent y_content = y->GetFlatContent();
if (x_content.IsAscii()) {
@@ -13295,6 +13296,7 @@
ASSERT(args.length() == 2);
CONVERT_ARG_CHECKED(String, format, 0);
CONVERT_ARG_CHECKED(JSArray, elms, 1);
+ AssertNoAllocation no_gc;
String::FlatContent format_content = format->GetFlatContent();
RUNTIME_ASSERT(format_content.IsAscii());
Vector<const uint8_t> chars = format_content.ToOneByteVector();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.