Commit e0b8ab88 authored by iposva@chromium.org's avatar iposva@chromium.org

- Add String::Concat(Handle<String> left, Handle<String> right) to the V8 API.

This is the first step to address http://crbug.com/23131 by creating
a series of V8 ConsStrings as more data arrives from the server.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3066 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a6d3c162
......@@ -918,6 +918,12 @@ class V8EXPORT String : public Primitive {
/** Creates a symbol. Returns one if it exists already.*/
static Local<String> NewSymbol(const char* data, int length = -1);
/**
* Creates a new string by concatenating the left and the right strings
* passed in as parameters.
*/
static Local<String> Concat(Handle<String> left, Handle<String>right);
/**
* Creates a new external string using the data defined in the given
* resource. The resource is deleted when the external string is no
......
......@@ -2926,6 +2926,18 @@ Local<String> v8::String::New(const char* data, int length) {
}
Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
EnsureInitialized("v8::String::New()");
LOG_API("String::New(char)");
ENTER_V8;
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
i::Handle<i::String> right_string = Utils::OpenHandle(*right);
i::Handle<i::String> result = i::Factory::NewConsString(left_string,
right_string);
return Utils::ToLocal(result);
}
Local<String> v8::String::NewUndetectable(const char* data, int length) {
EnsureInitialized("v8::String::NewUndetectable()");
LOG_API("String::NewUndetectable(char)");
......
......@@ -572,6 +572,44 @@ THREADED_TEST(UsingExternalAsciiString) {
}
THREADED_TEST(StringConcat) {
{
v8::HandleScope scope;
LocalContext env;
const char* one_byte_string_1 = "function a_times_t";
const char* two_byte_string_1 = "wo_plus_b(a, b) {return ";
const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + ";
const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + ";
const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);";
Local<String> left = v8_str(one_byte_string_1);
Local<String> right = String::New(AsciiToTwoByteString(two_byte_string_1));
Local<String> source = String::Concat(left, right);
right = String::NewExternal(
new TestAsciiResource(i::StrDup(one_byte_extern_1)));
source = String::Concat(source, right);
right = String::NewExternal(
new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
source = String::Concat(source, right);
right = v8_str(one_byte_string_2);
source = String::Concat(source, right);
right = String::New(AsciiToTwoByteString(two_byte_string_2));
source = String::Concat(source, right);
right = String::NewExternal(
new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
source = String::Concat(source, right);
Local<Script> script = Script::Compile(source);
Local<Value> value = script->Run();
CHECK(value->IsNumber());
CHECK_EQ(68, value->Int32Value());
}
v8::internal::CompilationCache::Clear();
i::Heap::CollectAllGarbage(false);
i::Heap::CollectAllGarbage(false);
}
THREADED_TEST(GlobalProperties) {
v8::HandleScope scope;
LocalContext env;
......
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