Add api call to determine whether a string can be externalized.

Review URL: http://codereview.chromium.org/164393

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2596299f
...@@ -901,6 +901,11 @@ class V8EXPORT String : public Primitive { ...@@ -901,6 +901,11 @@ class V8EXPORT String : public Primitive {
*/ */
bool MakeExternal(ExternalAsciiStringResource* resource); bool MakeExternal(ExternalAsciiStringResource* resource);
/**
* Returns true if this string can be made external.
*/
bool CanMakeExternal();
/** Creates an undetectable string from the supplied ascii or utf-8 data.*/ /** Creates an undetectable string from the supplied ascii or utf-8 data.*/
static Local<String> NewUndetectable(const char* data, int length = -1); static Local<String> NewUndetectable(const char* data, int length = -1);
......
...@@ -2986,7 +2986,7 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { ...@@ -2986,7 +2986,7 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
if (IsDeadCheck("v8::String::MakeExternal()")) return false; if (IsDeadCheck("v8::String::MakeExternal()")) return false;
if (this->IsExternal()) return false; // Already an external string. if (this->IsExternal()) return false; // Already an external string.
ENTER_V8; ENTER_V8;
i::Handle <i::String> obj = Utils::OpenHandle(this); i::Handle<i::String> obj = Utils::OpenHandle(this);
bool result = obj->MakeExternal(resource); bool result = obj->MakeExternal(resource);
if (result && !obj->IsSymbol()) { if (result && !obj->IsSymbol()) {
// Operation was successful and the string is not a symbol. In this case // Operation was successful and the string is not a symbol. In this case
...@@ -3022,7 +3022,7 @@ bool v8::String::MakeExternal( ...@@ -3022,7 +3022,7 @@ bool v8::String::MakeExternal(
if (IsDeadCheck("v8::String::MakeExternal()")) return false; if (IsDeadCheck("v8::String::MakeExternal()")) return false;
if (this->IsExternal()) return false; // Already an external string. if (this->IsExternal()) return false; // Already an external string.
ENTER_V8; ENTER_V8;
i::Handle <i::String> obj = Utils::OpenHandle(this); i::Handle<i::String> obj = Utils::OpenHandle(this);
bool result = obj->MakeExternal(resource); bool result = obj->MakeExternal(resource);
if (result && !obj->IsSymbol()) { if (result && !obj->IsSymbol()) {
// Operation was successful and the string is not a symbol. In this case // Operation was successful and the string is not a symbol. In this case
...@@ -3037,6 +3037,14 @@ bool v8::String::MakeExternal( ...@@ -3037,6 +3037,14 @@ bool v8::String::MakeExternal(
} }
bool v8::String::CanMakeExternal() {
if (IsDeadCheck("v8::String::CanMakeExternal()")) return false;
i::Handle<i::String> obj = Utils::OpenHandle(this);
int size = obj->Size(); // Byte size of the original string.
return (size >= i::ExternalString::kSize) && !obj->IsExternalString();
}
Local<v8::Object> v8::Object::New() { Local<v8::Object> v8::Object::New() {
EnsureInitialized("v8::Object::New()"); EnsureInitialized("v8::Object::New()");
LOG_API("Object::New"); LOG_API("Object::New");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment