Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 5978ed270e34d51d8a5de093310ba023d0810a55..3f5a0793b21a5e53d68070494f18e28d79c57cf2 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -5930,6 +5930,23 @@ i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
} |
+bool RedirectToExternalString(i::Isolate* isolate, |
+ i::Handle<i::String> parent, |
+ i::Handle<i::String> external) { |
+ if (parent->IsConsString()) { |
+ i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); |
+ cons->set_first(*external); |
+ cons->set_second(isolate->heap()->empty_string()); |
+ } else { |
+ ASSERT(parent->IsSlicedString()); |
+ i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent); |
+ slice->set_parent(*external); |
+ slice->set_offset(0); |
+ } |
+ return true; |
+} |
+ |
+ |
Local<String> v8::String::NewExternal( |
v8::String::ExternalStringResource* resource) { |
i::Isolate* isolate = i::Isolate::Current(); |
@@ -5958,9 +5975,23 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
return false; |
} |
CHECK(resource && resource->data()); |
- bool result = obj->MakeExternal(resource); |
- if (result && !obj->IsInternalizedString()) { |
- isolate->heap()->external_string_table()->AddString(*obj); |
+ |
+ bool result; |
+ i::Handle<i::String> external; |
+ if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
+ // We do not allow external strings in the old pointer space. Instead of |
+ // converting the string in-place, we keep the cons/sliced string and |
+ // point it to a newly-allocated external string. |
+ external = NewExternalStringHandle(isolate, resource); |
+ result = RedirectToExternalString(isolate, obj, external); |
+ } else { |
+ result = obj->MakeExternal(resource); |
+ external = obj; |
+ } |
+ |
+ ASSERT(external->IsExternalString()); |
+ if (result && !external->IsInternalizedString()) { |
+ isolate->heap()->external_string_table()->AddString(*external); |
} |
return result; |
} |
@@ -5995,9 +6026,23 @@ bool v8::String::MakeExternal( |
return false; |
} |
CHECK(resource && resource->data()); |
- bool result = obj->MakeExternal(resource); |
- if (result && !obj->IsInternalizedString()) { |
- isolate->heap()->external_string_table()->AddString(*obj); |
+ |
+ bool result; |
+ i::Handle<i::String> external; |
+ if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
+ // We do not allow external strings in the old pointer space. Instead of |
+ // converting the string in-place, we keep the cons/sliced string and |
+ // point it to a newly-allocated external string. |
+ external = NewExternalAsciiStringHandle(isolate, resource); |
+ result = RedirectToExternalString(isolate, obj, external); |
+ } else { |
+ result = obj->MakeExternal(resource); |
+ external = obj; |
+ } |
+ |
+ ASSERT(external->IsExternalString()); |
+ if (result && !external->IsInternalizedString()) { |
+ isolate->heap()->external_string_table()->AddString(*external); |
} |
return result; |
} |