Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1410)

Unified Diff: test/cctest/test-strings.cc

Issue 16337005: Deprecate FACTORY helper macro. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-serialize.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 2889172f5a625e9ccfea54cf72a113e4d2dc6633..c45303ebccd89aa9c51a8b35fddf60e9ef4ef591 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -136,7 +136,9 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
RandomNumberGenerator* rng) {
// A list of pointers that we don't have any interest in cleaning up.
// If they are reachable from a root then leak detection won't complain.
- Zone* zone = Isolate::Current()->runtime_zone();
+ Isolate* isolate = Isolate::Current();
+ Factory* factory = isolate->factory();
+ Zone* zone = isolate->runtime_zone();
for (int i = 0; i < bb_length; i++) {
int len = rng->next(16);
int slice_head_chars = 0;
@@ -168,7 +170,7 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
buf[j] = rng->next(0x10000);
}
building_blocks[i] =
- FACTORY->NewStringFromTwoByte(Vector<const uc16>(buf, len));
+ factory->NewStringFromTwoByte(Vector<const uc16>(buf, len));
for (int j = 0; j < len; j++) {
CHECK_EQ(buf[j], building_blocks[i]->Get(j));
}
@@ -180,7 +182,7 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
buf[j] = rng->next(0x80);
}
building_blocks[i] =
- FACTORY->NewStringFromAscii(Vector<const char>(buf, len));
+ factory->NewStringFromAscii(Vector<const char>(buf, len));
for (int j = 0; j < len; j++) {
CHECK_EQ(buf[j], building_blocks[i]->Get(j));
}
@@ -192,7 +194,7 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
buf[j] = rng->next(0x10000);
}
Resource* resource = new(zone) Resource(Vector<const uc16>(buf, len));
- building_blocks[i] = FACTORY->NewExternalStringFromTwoByte(resource);
+ building_blocks[i] = factory->NewExternalStringFromTwoByte(resource);
for (int j = 0; j < len; j++) {
CHECK_EQ(buf[j], building_blocks[i]->Get(j));
}
@@ -205,7 +207,7 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
}
AsciiResource* resource =
new(zone) AsciiResource(Vector<const char>(buf, len));
- building_blocks[i] = FACTORY->NewExternalStringFromAscii(resource);
+ building_blocks[i] = factory->NewExternalStringFromAscii(resource);
for (int j = 0; j < len; j++) {
CHECK_EQ(buf[j], building_blocks[i]->Get(j));
}
@@ -213,7 +215,7 @@ static void InitializeBuildingBlocks(Handle<String>* building_blocks,
}
}
for (int j = slice_depth; j > 0; j--) {
- building_blocks[i] = FACTORY->NewSubString(
+ building_blocks[i] = factory->NewSubString(
building_blocks[i],
slice_head_chars,
building_blocks[i]->length() - slice_tail_chars);
@@ -400,6 +402,7 @@ void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) {
static Handle<String> ConstructRandomString(ConsStringGenerationData* data,
unsigned max_recursion) {
+ Factory* factory = Isolate::Current()->factory();
// Compute termination characteristics.
bool terminate = false;
bool flat = data->rng_.next(data->empty_leaf_threshold_);
@@ -446,7 +449,7 @@ static Handle<String> ConstructRandomString(ConsStringGenerationData* data,
left = ConstructRandomString(data, max_recursion - 1);
}
// Build the cons string.
- Handle<String> root = FACTORY->NewConsString(left, right);
+ Handle<String> root = factory->NewConsString(left, right);
CHECK(root->IsConsString() && !root->IsFlat());
// Special work needed for flat string.
if (flat) {
@@ -461,11 +464,12 @@ static Handle<String> ConstructRandomString(ConsStringGenerationData* data,
static Handle<String> ConstructLeft(
ConsStringGenerationData* data,
int depth) {
- Handle<String> answer = FACTORY->NewStringFromAscii(CStrVector(""));
+ Factory* factory = Isolate::Current()->factory();
+ Handle<String> answer = factory->NewStringFromAscii(CStrVector(""));
data->stats_.leaves_++;
for (int i = 0; i < depth; i++) {
Handle<String> block = data->block(i);
- Handle<String> next = FACTORY->NewConsString(answer, block);
+ Handle<String> next = factory->NewConsString(answer, block);
if (next->IsConsString()) data->stats_.leaves_++;
data->stats_.chars_ += block->length();
answer = next;
@@ -478,11 +482,12 @@ static Handle<String> ConstructLeft(
static Handle<String> ConstructRight(
ConsStringGenerationData* data,
int depth) {
- Handle<String> answer = FACTORY->NewStringFromAscii(CStrVector(""));
+ Factory* factory = Isolate::Current()->factory();
+ Handle<String> answer = factory->NewStringFromAscii(CStrVector(""));
data->stats_.leaves_++;
for (int i = depth - 1; i >= 0; i--) {
Handle<String> block = data->block(i);
- Handle<String> next = FACTORY->NewConsString(block, answer);
+ Handle<String> next = factory->NewConsString(block, answer);
if (next->IsConsString()) data->stats_.leaves_++;
data->stats_.chars_ += block->length();
answer = next;
@@ -496,6 +501,7 @@ static Handle<String> ConstructBalancedHelper(
ConsStringGenerationData* data,
int from,
int to) {
+ Factory* factory = Isolate::Current()->factory();
CHECK(to > from);
if (to - from == 1) {
data->stats_.chars_ += data->block(from)->length();
@@ -504,7 +510,7 @@ static Handle<String> ConstructBalancedHelper(
if (to - from == 2) {
data->stats_.chars_ += data->block(from)->length();
data->stats_.chars_ += data->block(from+1)->length();
- return FACTORY->NewConsString(data->block(from), data->block(from+1));
+ return factory->NewConsString(data->block(from), data->block(from+1));
}
Handle<String> part1 =
ConstructBalancedHelper(data, from, from + ((to - from) / 2));
@@ -512,7 +518,7 @@ static Handle<String> ConstructBalancedHelper(
ConstructBalancedHelper(data, from + ((to - from) / 2), to);
if (part1->IsConsString()) data->stats_.left_traversals_++;
if (part2->IsConsString()) data->stats_.right_traversals_++;
- return FACTORY->NewConsString(part1, part2);
+ return factory->NewConsString(part1, part2);
}
@@ -690,6 +696,7 @@ static const int kCharacterStreamNonRandomCases = 8;
static Handle<String> BuildEdgeCaseConsString(
int test_case, ConsStringGenerationData* data) {
+ Factory* factory = Isolate::Current()->factory();
data->Reset();
switch (test_case) {
case 0:
@@ -707,7 +714,7 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.chars_ += data->block(0)->length();
data->stats_.chars_ += data->block(1)->length();
data->stats_.leaves_ += 2;
- return FACTORY->NewConsString(data->block(0), data->block(1));
+ return factory->NewConsString(data->block(0), data->block(1));
case 6:
// Simple flattened tree.
data->stats_.chars_ += data->block(0)->length();
@@ -716,7 +723,7 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.empty_leaves_ += 1;
{
Handle<String> string =
- FACTORY->NewConsString(data->block(0), data->block(1));
+ factory->NewConsString(data->block(0), data->block(1));
FlattenString(string);
return string;
}
@@ -730,9 +737,9 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.left_traversals_ += 1;
{
Handle<String> left =
- FACTORY->NewConsString(data->block(0), data->block(1));
+ factory->NewConsString(data->block(0), data->block(1));
FlattenString(left);
- return FACTORY->NewConsString(left, data->block(2));
+ return factory->NewConsString(left, data->block(2));
}
case 8:
// Left node and right node flattened.
@@ -746,12 +753,12 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.right_traversals_ += 1;
{
Handle<String> left =
- FACTORY->NewConsString(data->block(0), data->block(1));
+ factory->NewConsString(data->block(0), data->block(1));
FlattenString(left);
Handle<String> right =
- FACTORY->NewConsString(data->block(2), data->block(2));
+ factory->NewConsString(data->block(2), data->block(2));
FlattenString(right);
- return FACTORY->NewConsString(left, right);
+ return factory->NewConsString(left, right);
}
}
UNREACHABLE();
@@ -852,6 +859,7 @@ static const int DEEP_ASCII_DEPTH = 100000;
TEST(DeepAscii) {
printf("TestDeepAscii\n");
CcTest::InitializeVM();
+ Factory* factory = Isolate::Current()->factory();
v8::HandleScope scope(CcTest::isolate());
char* foo = NewArray<char>(DEEP_ASCII_DEPTH);
@@ -859,12 +867,12 @@ TEST(DeepAscii) {
foo[i] = "foo "[i % 4];
}
Handle<String> string =
- FACTORY->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH));
- Handle<String> foo_string = FACTORY->NewStringFromAscii(CStrVector("foo"));
+ factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH));
+ Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo"));
for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) {
- string = FACTORY->NewConsString(string, foo_string);
+ string = factory->NewConsString(string, foo_string);
}
- Handle<String> flat_string = FACTORY->NewConsString(string, foo_string);
+ Handle<String> flat_string = factory->NewConsString(string, foo_string);
FlattenString(flat_string);
for (int i = 0; i < 500; i++) {
@@ -1059,13 +1067,14 @@ TEST(CachedHashOverflow) {
TEST(SliceFromCons) {
FLAG_string_slices = true;
CcTest::InitializeVM();
+ Factory* factory = Isolate::Current()->factory();
v8::HandleScope scope(CcTest::isolate());
Handle<String> string =
- FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
- Handle<String> parent = FACTORY->NewConsString(string, string);
+ factory->NewStringFromAscii(CStrVector("parentparentparent"));
+ Handle<String> parent = factory->NewConsString(string, string);
CHECK(parent->IsConsString());
CHECK(!parent->IsFlat());
- Handle<String> slice = FACTORY->NewSubString(parent, 1, 25);
+ Handle<String> slice = factory->NewSubString(parent, 1, 25);
// After slicing, the original string becomes a flat cons.
CHECK(parent->IsFlat());
CHECK(slice->IsSlicedString());
@@ -1093,12 +1102,13 @@ class AsciiVectorResource : public v8::String::ExternalAsciiStringResource {
TEST(SliceFromExternal) {
FLAG_string_slices = true;
CcTest::InitializeVM();
+ Factory* factory = Isolate::Current()->factory();
v8::HandleScope scope(CcTest::isolate());
AsciiVectorResource resource(
i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26));
- Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource);
+ Handle<String> string = factory->NewExternalStringFromAscii(&resource);
CHECK(string->IsExternalString());
- Handle<String> slice = FACTORY->NewSubString(string, 1, 25);
+ Handle<String> slice = factory->NewSubString(string, 1, 25);
CHECK(slice->IsSlicedString());
CHECK(string->IsExternalString());
CHECK_EQ(SlicedString::cast(*slice)->parent(), *string);
@@ -1112,6 +1122,7 @@ TEST(TrivialSlice) {
// actually creates a new string (it should not).
FLAG_string_slices = true;
CcTest::InitializeVM();
+ Factory* factory = Isolate::Current()->factory();
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> result;
Handle<String> string;
@@ -1126,7 +1137,7 @@ TEST(TrivialSlice) {
string = v8::Utils::OpenHandle(v8::String::Cast(*result));
CHECK(!string->IsSlicedString());
- string = FACTORY->NewSubString(string, 0, 26);
+ string = factory->NewSubString(string, 0, 26);
CHECK(!string->IsSlicedString());
result = CompileRun(crosscheck);
CHECK(result->IsString());
« no previous file with comments | « test/cctest/test-serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698