Commit 318c9eed authored by mike@belshe.com's avatar mike@belshe.com

Add a public API for using an empty sring.

v8::String::Empty()


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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1556 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 29e3ae8d
......@@ -735,6 +735,11 @@ class V8EXPORT String : public Primitive {
int WriteAscii(char* buffer, int start = 0, int length = -1) const; // ASCII
int WriteUtf8(char* buffer, int length = -1) const; // UTF-8
/**
* A zero length string.
*/
static v8::Local<v8::String> Empty();
/**
* Returns true if the string is external
*/
......
......@@ -2472,9 +2472,17 @@ Local<External> v8::External::New(void* data) {
}
Local<String> v8::String::Empty() {
EnsureInitialized("v8::String::Empty()");
LOG_API("String::Empty()");
return Utils::ToLocal(i::Factory::empty_symbol());
}
Local<String> v8::String::New(const char* data, int length) {
EnsureInitialized("v8::String::New()");
LOG_API("String::New(char)");
if (length == 0) return Empty();
if (length == -1) length = strlen(data);
i::Handle<i::String> result =
i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length));
......@@ -2503,6 +2511,7 @@ static int TwoByteStringLength(const uint16_t* data) {
Local<String> v8::String::New(const uint16_t* data, int length) {
EnsureInitialized("v8::String::New()");
LOG_API("String::New(uint16_)");
if (length == 0) return Empty();
if (length == -1) length = TwoByteStringLength(data);
i::Handle<i::String> result =
i::Factory::NewStringFromTwoByte(i::Vector<const uint16_t>(data, length));
......
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