2014-12-10 15:18:44 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "src/compilation-cache.h"
|
|
|
|
#include "src/execution.h"
|
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/global-handles.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Helper functions.
|
|
|
|
//
|
|
|
|
|
2014-12-16 13:22:23 +00:00
|
|
|
static void CheckPropertyDetailsFieldsConsistency(PropertyType type,
|
|
|
|
PropertyKind kind,
|
|
|
|
PropertyLocation location) {
|
|
|
|
int type_value = PropertyDetails::TypeField::encode(type);
|
|
|
|
int kind_location_value = PropertyDetails::KindField::encode(kind) |
|
|
|
|
PropertyDetails::LocationField::encode(location);
|
|
|
|
CHECK_EQ(type_value, kind_location_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(PropertyDetailsFieldsConsistency) {
|
2015-01-19 17:49:13 +00:00
|
|
|
CheckPropertyDetailsFieldsConsistency(DATA, kData, kField);
|
|
|
|
CheckPropertyDetailsFieldsConsistency(DATA_CONSTANT, kData, kDescriptor);
|
|
|
|
CheckPropertyDetailsFieldsConsistency(ACCESSOR, kAccessor, kField);
|
|
|
|
CheckPropertyDetailsFieldsConsistency(ACCESSOR_CONSTANT, kAccessor,
|
|
|
|
kDescriptor);
|
2014-12-16 13:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-10 15:18:44 +00:00
|
|
|
TEST(TransitionArray_SimpleFieldTransitions) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
Handle<String> name1 = factory->InternalizeUtf8String("foo");
|
|
|
|
Handle<String> name2 = factory->InternalizeUtf8String("bar");
|
|
|
|
PropertyAttributes attributes = NONE;
|
|
|
|
|
|
|
|
Handle<Map> map0 = Map::Create(isolate, 0);
|
|
|
|
Handle<Map> map1 =
|
2016-01-26 15:03:40 +00:00
|
|
|
Map::CopyWithField(map0, name1, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
Handle<Map> map2 =
|
2016-01-26 15:03:40 +00:00
|
|
|
Map::CopyWithField(map0, name2, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
|
|
|
|
#endif
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArray_FullFieldTransitions) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
Handle<String> name1 = factory->InternalizeUtf8String("foo");
|
|
|
|
Handle<String> name2 = factory->InternalizeUtf8String("bar");
|
|
|
|
PropertyAttributes attributes = NONE;
|
|
|
|
|
|
|
|
Handle<Map> map0 = Map::Create(isolate, 0);
|
|
|
|
Handle<Map> map1 =
|
2016-01-26 15:03:40 +00:00
|
|
|
Map::CopyWithField(map0, name1, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
Handle<Map> map2 =
|
2016-01-26 15:03:40 +00:00
|
|
|
Map::CopyWithField(map0, name2, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
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));
|
|
|
|
}
|
2015-03-05 20:41:47 +00:00
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
|
|
|
|
#endif
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArray_DifferentFieldNames) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
const int PROPS_COUNT = 10;
|
|
|
|
Handle<String> names[PROPS_COUNT];
|
|
|
|
Handle<Map> maps[PROPS_COUNT];
|
|
|
|
PropertyAttributes attributes = NONE;
|
|
|
|
|
|
|
|
Handle<Map> map0 = Map::Create(isolate, 0);
|
2015-03-06 14:08:33 +00:00
|
|
|
CHECK(map0->raw_transitions()->IsSmi());
|
2014-12-10 15:18:44 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < PROPS_COUNT; i++) {
|
|
|
|
EmbeddedVector<char, 64> buffer;
|
|
|
|
SNPrintF(buffer, "prop%d", i);
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String(buffer.start());
|
2016-01-26 15:03:40 +00:00
|
|
|
Handle<Map> map = Map::CopyWithField(
|
|
|
|
map0, name, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
names[i] = name;
|
|
|
|
maps[i] = map;
|
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < PROPS_COUNT; i++) {
|
2015-03-06 14:08:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
|
|
|
|
#endif
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArray_SameFieldNamesDifferentAttributesSimple) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
Handle<Map> map0 = Map::Create(isolate, 0);
|
2015-03-06 14:08:33 +00:00
|
|
|
CHECK(map0->raw_transitions()->IsSmi());
|
2014-12-10 15:18:44 +00:00
|
|
|
|
|
|
|
const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
|
|
|
|
STATIC_ASSERT(ATTRS_COUNT == 8);
|
|
|
|
Handle<Map> attr_maps[ATTRS_COUNT];
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("foo");
|
|
|
|
|
|
|
|
// Add transitions for same field name but different attributes.
|
|
|
|
for (int i = 0; i < ATTRS_COUNT; i++) {
|
|
|
|
PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
|
|
|
|
|
2016-01-26 15:03:40 +00:00
|
|
|
Handle<Map> map = Map::CopyWithField(
|
|
|
|
map0, name, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
attr_maps[i] = map;
|
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that transitions for |name| field are valid.
|
|
|
|
for (int i = 0; i < ATTRS_COUNT; i++) {
|
|
|
|
PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
|
2015-03-06 14:08:33 +00:00
|
|
|
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));
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
|
|
|
|
#endif
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArray_SameFieldNamesDifferentAttributes) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
const int PROPS_COUNT = 10;
|
|
|
|
Handle<String> names[PROPS_COUNT];
|
|
|
|
Handle<Map> maps[PROPS_COUNT];
|
|
|
|
|
|
|
|
Handle<Map> map0 = Map::Create(isolate, 0);
|
2015-03-06 14:08:33 +00:00
|
|
|
CHECK(map0->raw_transitions()->IsSmi());
|
2014-12-10 15:18:44 +00:00
|
|
|
|
|
|
|
// Some number of fields.
|
|
|
|
for (int i = 0; i < PROPS_COUNT; i++) {
|
|
|
|
EmbeddedVector<char, 64> buffer;
|
|
|
|
SNPrintF(buffer, "prop%d", i);
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String(buffer.start());
|
|
|
|
Handle<Map> map =
|
2016-01-26 15:03:40 +00:00
|
|
|
Map::CopyWithField(map0, name, handle(FieldType::Any(), isolate), NONE,
|
|
|
|
Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
names[i] = name;
|
|
|
|
maps[i] = map;
|
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
|
|
|
|
STATIC_ASSERT(ATTRS_COUNT == 8);
|
|
|
|
Handle<Map> attr_maps[ATTRS_COUNT];
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("foo");
|
|
|
|
|
|
|
|
// Add transitions for same field name but different attributes.
|
|
|
|
for (int i = 0; i < ATTRS_COUNT; i++) {
|
|
|
|
PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
|
|
|
|
|
2016-01-26 15:03:40 +00:00
|
|
|
Handle<Map> map = Map::CopyWithField(
|
|
|
|
map0, name, handle(FieldType::Any(), isolate),
|
|
|
|
attributes, Representation::Tagged(), OMIT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
2014-12-10 15:18:44 +00:00
|
|
|
attr_maps[i] = map;
|
|
|
|
|
2015-03-06 14:08:33 +00:00
|
|
|
TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that transitions for |name| field are valid.
|
|
|
|
for (int i = 0; i < ATTRS_COUNT; i++) {
|
2015-03-06 14:08:33 +00:00
|
|
|
PropertyAttributes attr = static_cast<PropertyAttributes>(i);
|
|
|
|
CHECK_EQ(*attr_maps[i],
|
|
|
|
TransitionArray::SearchTransition(*map0, kData, *name, attr));
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that info about the other fields still valid.
|
2015-03-06 14:08:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
|
|
|
|
#endif
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|