Index: test/cctest/test-transitions.cc |
diff --git a/test/cctest/test-transitions.cc b/test/cctest/test-transitions.cc |
index 800c2a0e4436950798df310c1f2d7fa4eaf6e1f7..59c9f74c96dbdb41ef34ccb1b55e634936fcf522 100644 |
--- a/test/cctest/test-transitions.cc |
+++ b/test/cctest/test-transitions.cc |
@@ -19,6 +19,16 @@ |
// |
// Helper functions. |
// |
+ |
+static void ConnectTransition(Handle<Map> parent, |
+ Handle<TransitionArray> transitions, |
+ Handle<Map> child) { |
+ if (!parent->HasTransitionArray() || *transitions != parent->transitions()) { |
+ parent->set_transitions(*transitions); |
+ } |
+ child->SetBackPointer(*parent); |
+} |
+ |
static void CheckPropertyDetailsFieldsConsistency(PropertyType type, |
PropertyKind kind, |
@@ -59,32 +69,34 @@ |
attributes, Representation::Tagged(), |
OMIT_TRANSITION).ToHandleChecked(); |
- CHECK(map0->raw_transitions()->IsSmi()); |
- |
- TransitionArray::Insert(map0, name1, map1, SIMPLE_PROPERTY_TRANSITION); |
- CHECK(TransitionArray::IsSimpleTransition(map0->raw_transitions())); |
- CHECK_EQ(*map1, |
- TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); |
- CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions())); |
- CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0)); |
- CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0)); |
- |
- TransitionArray::Insert(map0, name2, map2, SIMPLE_PROPERTY_TRANSITION); |
- CHECK(TransitionArray::IsFullTransitionArray(map0->raw_transitions())); |
- |
- CHECK_EQ(*map1, |
- TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); |
- CHECK_EQ(*map2, |
- TransitionArray::SearchTransition(*map0, kData, *name2, attributes)); |
- CHECK_EQ(2, TransitionArray::NumberOfTransitions(map0->raw_transitions())); |
- for (int i = 0; i < 2; i++) { |
- Name* key = TransitionArray::GetKey(map0->raw_transitions(), i); |
- Map* target = TransitionArray::GetTarget(map0->raw_transitions(), i); |
- CHECK((key == *name1 && target == *map1) || |
- (key == *name2 && target == *map2)); |
- } |
- |
- DCHECK(TransitionArray::IsSortedNoDuplicates(*map0)); |
+ CHECK(!map0->HasTransitionArray()); |
+ Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0); |
+ CHECK(transitions->IsFullTransitionArray()); |
+ |
+ int transition; |
+ transitions = |
+ transitions->Insert(map0, name1, map1, SIMPLE_PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map1); |
+ CHECK(transitions->IsSimpleTransition()); |
+ transition = transitions->Search(kData, *name1, attributes); |
+ CHECK_EQ(TransitionArray::kSimpleTransitionIndex, transition); |
+ CHECK_EQ(*name1, transitions->GetKey(transition)); |
+ CHECK_EQ(*map1, transitions->GetTarget(transition)); |
+ |
+ transitions = |
+ transitions->Insert(map0, name2, map2, SIMPLE_PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map2); |
+ CHECK(transitions->IsFullTransitionArray()); |
+ |
+ transition = transitions->Search(kData, *name1, attributes); |
+ CHECK_EQ(*name1, transitions->GetKey(transition)); |
+ CHECK_EQ(*map1, transitions->GetTarget(transition)); |
+ |
+ transition = transitions->Search(kData, *name2, attributes); |
+ CHECK_EQ(*name2, transitions->GetKey(transition)); |
+ CHECK_EQ(*map2, transitions->GetTarget(transition)); |
+ |
+ DCHECK(transitions->IsSortedNoDuplicates()); |
} |
@@ -108,32 +120,31 @@ |
attributes, Representation::Tagged(), |
OMIT_TRANSITION).ToHandleChecked(); |
- CHECK(map0->raw_transitions()->IsSmi()); |
- |
- TransitionArray::Insert(map0, name1, map1, PROPERTY_TRANSITION); |
- CHECK(TransitionArray::IsFullTransitionArray(map0->raw_transitions())); |
- CHECK_EQ(*map1, |
- TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); |
- CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions())); |
- CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0)); |
- CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0)); |
- |
- TransitionArray::Insert(map0, name2, map2, PROPERTY_TRANSITION); |
- CHECK(TransitionArray::IsFullTransitionArray(map0->raw_transitions())); |
- |
- CHECK_EQ(*map1, |
- TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); |
- CHECK_EQ(*map2, |
- TransitionArray::SearchTransition(*map0, kData, *name2, attributes)); |
- CHECK_EQ(2, TransitionArray::NumberOfTransitions(map0->raw_transitions())); |
- for (int i = 0; i < 2; i++) { |
- Name* key = TransitionArray::GetKey(map0->raw_transitions(), i); |
- Map* target = TransitionArray::GetTarget(map0->raw_transitions(), i); |
- CHECK((key == *name1 && target == *map1) || |
- (key == *name2 && target == *map2)); |
- } |
- |
- DCHECK(TransitionArray::IsSortedNoDuplicates(*map0)); |
+ CHECK(!map0->HasTransitionArray()); |
+ Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0); |
+ CHECK(transitions->IsFullTransitionArray()); |
+ |
+ int transition; |
+ transitions = transitions->Insert(map0, name1, map1, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map1); |
+ CHECK(transitions->IsFullTransitionArray()); |
+ transition = transitions->Search(kData, *name1, attributes); |
+ CHECK_EQ(*name1, transitions->GetKey(transition)); |
+ CHECK_EQ(*map1, transitions->GetTarget(transition)); |
+ |
+ transitions = transitions->Insert(map0, name2, map2, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map2); |
+ CHECK(transitions->IsFullTransitionArray()); |
+ |
+ transition = transitions->Search(kData, *name1, attributes); |
+ CHECK_EQ(*name1, transitions->GetKey(transition)); |
+ CHECK_EQ(*map1, transitions->GetTarget(transition)); |
+ |
+ transition = transitions->Search(kData, *name2, attributes); |
+ CHECK_EQ(*name2, transitions->GetKey(transition)); |
+ CHECK_EQ(*map2, transitions->GetTarget(transition)); |
+ |
+ DCHECK(transitions->IsSortedNoDuplicates()); |
} |
@@ -149,7 +160,9 @@ |
PropertyAttributes attributes = NONE; |
Handle<Map> map0 = Map::Create(isolate, 0); |
- CHECK(map0->raw_transitions()->IsSmi()); |
+ CHECK(!map0->HasTransitionArray()); |
+ Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0); |
+ CHECK(transitions->IsFullTransitionArray()); |
for (int i = 0; i < PROPS_COUNT; i++) { |
EmbeddedVector<char, 64> buffer; |
@@ -162,25 +175,17 @@ |
names[i] = name; |
maps[i] = map; |
- TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); |
+ transitions = transitions->Insert(map0, name, map, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map); |
} |
for (int i = 0; i < PROPS_COUNT; i++) { |
- CHECK_EQ(*maps[i], TransitionArray::SearchTransition( |
- *map0, kData, *names[i], attributes)); |
- } |
- for (int i = 0; i < PROPS_COUNT; i++) { |
- Name* key = TransitionArray::GetKey(map0->raw_transitions(), i); |
- Map* target = TransitionArray::GetTarget(map0->raw_transitions(), i); |
- for (int j = 0; j < PROPS_COUNT; j++) { |
- if (*names[i] == key) { |
- CHECK_EQ(*maps[i], target); |
- break; |
- } |
- } |
- } |
- |
- DCHECK(TransitionArray::IsSortedNoDuplicates(*map0)); |
+ int transition = transitions->Search(kData, *names[i], attributes); |
+ CHECK_EQ(*names[i], transitions->GetKey(transition)); |
+ CHECK_EQ(*maps[i], transitions->GetTarget(transition)); |
+ } |
+ |
+ DCHECK(transitions->IsSortedNoDuplicates()); |
} |
@@ -191,7 +196,9 @@ |
Factory* factory = isolate->factory(); |
Handle<Map> map0 = Map::Create(isolate, 0); |
- CHECK(map0->raw_transitions()->IsSmi()); |
+ CHECK(!map0->HasTransitionArray()); |
+ Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0); |
+ CHECK(transitions->IsFullTransitionArray()); |
const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1; |
STATIC_ASSERT(ATTRS_COUNT == 8); |
@@ -208,20 +215,20 @@ |
OMIT_TRANSITION).ToHandleChecked(); |
attr_maps[i] = map; |
- TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); |
+ transitions = transitions->Insert(map0, name, map, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map); |
} |
// Ensure that transitions for |name| field are valid. |
for (int i = 0; i < ATTRS_COUNT; i++) { |
PropertyAttributes attributes = static_cast<PropertyAttributes>(i); |
- CHECK_EQ(*attr_maps[i], TransitionArray::SearchTransition( |
- *map0, kData, *name, attributes)); |
- // All transitions use the same key, so this check doesn't need to |
- // care about ordering. |
- CHECK_EQ(*name, TransitionArray::GetKey(map0->raw_transitions(), i)); |
- } |
- |
- DCHECK(TransitionArray::IsSortedNoDuplicates(*map0)); |
+ |
+ int transition = transitions->Search(kData, *name, attributes); |
+ CHECK_EQ(*name, transitions->GetKey(transition)); |
+ CHECK_EQ(*attr_maps[i], transitions->GetTarget(transition)); |
+ } |
+ |
+ DCHECK(transitions->IsSortedNoDuplicates()); |
} |
@@ -236,7 +243,9 @@ |
Handle<Map> maps[PROPS_COUNT]; |
Handle<Map> map0 = Map::Create(isolate, 0); |
- CHECK(map0->raw_transitions()->IsSmi()); |
+ CHECK(!map0->HasTransitionArray()); |
+ Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0); |
+ CHECK(transitions->IsFullTransitionArray()); |
// Some number of fields. |
for (int i = 0; i < PROPS_COUNT; i++) { |
@@ -250,7 +259,8 @@ |
names[i] = name; |
maps[i] = map; |
- TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); |
+ transitions = transitions->Insert(map0, name, map, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map); |
} |
const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1; |
@@ -268,36 +278,25 @@ |
OMIT_TRANSITION).ToHandleChecked(); |
attr_maps[i] = map; |
- TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); |
+ transitions = transitions->Insert(map0, name, map, PROPERTY_TRANSITION); |
+ ConnectTransition(map0, transitions, map); |
} |
// Ensure that transitions for |name| field are valid. |
for (int i = 0; i < ATTRS_COUNT; i++) { |
- PropertyAttributes attr = static_cast<PropertyAttributes>(i); |
- CHECK_EQ(*attr_maps[i], |
- TransitionArray::SearchTransition(*map0, kData, *name, attr)); |
+ PropertyAttributes attributes = static_cast<PropertyAttributes>(i); |
+ |
+ int transition = transitions->Search(kData, *name, attributes); |
+ CHECK_EQ(*name, transitions->GetKey(transition)); |
+ CHECK_EQ(*attr_maps[i], transitions->GetTarget(transition)); |
} |
// Ensure that info about the other fields still valid. |
- CHECK_EQ(PROPS_COUNT + ATTRS_COUNT, |
- TransitionArray::NumberOfTransitions(map0->raw_transitions())); |
- for (int i = 0; i < PROPS_COUNT + ATTRS_COUNT; i++) { |
- Name* key = TransitionArray::GetKey(map0->raw_transitions(), i); |
- Map* target = TransitionArray::GetTarget(map0->raw_transitions(), i); |
- if (key == *name) { |
- // Attributes transition. |
- PropertyAttributes attributes = |
- target->GetLastDescriptorDetails().attributes(); |
- CHECK_EQ(*attr_maps[static_cast<int>(attributes)], target); |
- } else { |
- for (int j = 0; j < PROPS_COUNT; j++) { |
- if (*names[j] == key) { |
- CHECK_EQ(*maps[j], target); |
- break; |
- } |
- } |
- } |
- } |
- |
- DCHECK(TransitionArray::IsSortedNoDuplicates(*map0)); |
-} |
+ for (int i = 0; i < PROPS_COUNT; i++) { |
+ int transition = transitions->Search(kData, *names[i], NONE); |
+ CHECK_EQ(*names[i], transitions->GetKey(transition)); |
+ CHECK_EQ(*maps[i], transitions->GetTarget(transition)); |
+ } |
+ |
+ DCHECK(transitions->IsSortedNoDuplicates()); |
+} |