Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 1e4d4a4c14d8550301f5ff09b9ed6a3b0c9e6fff..560db37a8708b1750b6edbd55efc7959a798f5e4 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -678,6 +678,9 @@ Object* String::SlowTryFlatten(PretenureFlag pretenure) { |
bool String::MakeExternal(v8::String::ExternalStringResource* resource) { |
+ // Externalizing twice leaks the external resouce, so it's |
+ // prohibited by the API. |
+ ASSERT(!this->IsExternalString()); |
#ifdef DEBUG |
if (FLAG_enable_slow_asserts) { |
// Assert that the resource and the string are equivalent. |
@@ -697,13 +700,16 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { |
return false; |
} |
ASSERT(size >= ExternalString::kSize); |
+ bool is_ascii = this->IsAsciiRepresentation(); |
bool is_symbol = this->IsSymbol(); |
int length = this->length(); |
int hash_field = this->hash_field(); |
// Morph the object to an external string by adjusting the map and |
// reinitializing the fields. |
- this->set_map(Heap::external_string_map()); |
+ this->set_map(is_ascii ? |
+ Heap::external_string_with_ascii_data_map() : |
+ Heap::external_string_map()); |
ExternalTwoByteString* self = ExternalTwoByteString::cast(this); |
self->set_length(length); |
self->set_hash_field(hash_field); |
@@ -713,7 +719,9 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { |
if (is_symbol) { |
self->Hash(); // Force regeneration of the hash value. |
// Now morph this external string into a external symbol. |
- this->set_map(Heap::external_symbol_map()); |
+ this->set_map(is_ascii ? |
+ Heap::external_symbol_with_ascii_data_map() : |
+ Heap::external_symbol_map()); |
} |
// Fill the remainder of the string with dead wood. |