[runtime] Cleanup DescriptorArray interface, remove more PropertyType usages.

BUG=v8:5495

Review-Url: https://codereview.chromium.org/2633553002
Cr-Commit-Position: refs/heads/master@{#42329}
This commit is contained in:
ishell 2017-01-13 05:23:27 -08:00 committed by Commit bot
parent d4363986d7
commit 4caeb1e9eb
6 changed files with 29 additions and 85 deletions

View File

@ -4387,8 +4387,7 @@ void Genesis::TransferNamedProperties(Handle<JSObject> from,
Handle<Name> key = Handle<Name>(descs->GetKey(i));
FieldIndex index = FieldIndex::ForDescriptor(from->map(), i);
DCHECK(!descs->GetDetails(i).representation().IsDouble());
Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index),
isolate());
Handle<Object> value(from->RawFastPropertyAt(index), isolate());
JSObject::AddProperty(to, key, value, details.attributes());
} else {
DCHECK_EQ(kAccessor, details.kind());
@ -4400,8 +4399,8 @@ void Genesis::TransferNamedProperties(Handle<JSObject> from,
if (details.kind() == kData) {
HandleScope inner(isolate());
Handle<Name> key = Handle<Name>(descs->GetKey(i));
Handle<Object> constant(descs->GetConstant(i), isolate());
JSObject::AddProperty(to, key, constant, details.attributes());
Handle<Object> value(descs->GetValue(i), isolate());
JSObject::AddProperty(to, key, value, details.attributes());
} else {
DCHECK_EQ(kAccessor, details.kind());
@ -4413,10 +4412,10 @@ void Genesis::TransferNamedProperties(Handle<JSObject> from,
HandleScope inner(isolate());
DCHECK(!to->HasFastProperties());
// Add to dictionary.
Handle<Object> callbacks(descs->GetCallbacksObject(i), isolate());
Handle<Object> value(descs->GetValue(i), isolate());
PropertyDetails d(kAccessor, details.attributes(), i + 1,
PropertyCellType::kMutable);
JSObject::SetNormalizedProperty(to, key, callbacks, d);
JSObject::SetNormalizedProperty(to, key, value, d);
}
}
}

View File

@ -1741,7 +1741,7 @@ Handle<JSGlobalObject> Factory::NewJSGlobalObject(
PropertyCellType::kMutable);
Handle<Name> name(descs->GetKey(i));
Handle<PropertyCell> cell = NewPropertyCell();
cell->set_value(descs->GetCallbacksObject(i));
cell->set_value(descs->GetValue(i));
// |dictionary| already contains enough space for all properties.
USE(GlobalDictionary::Add(dictionary, name, cell, d));
}

View File

@ -3118,11 +3118,6 @@ PropertyDetails DescriptorArray::GetDetails(int descriptor_number) {
}
PropertyType DescriptorArray::GetType(int descriptor_number) {
return GetDetails(descriptor_number).type();
}
int DescriptorArray::GetFieldIndex(int descriptor_number) {
DCHECK(GetDetails(descriptor_number).location() == kField);
return GetDetails(descriptor_number).field_index();
@ -3134,47 +3129,25 @@ FieldType* DescriptorArray::GetFieldType(int descriptor_number) {
return Map::UnwrapFieldType(wrapped_type);
}
Object* DescriptorArray::GetConstant(int descriptor_number) {
return GetValue(descriptor_number);
}
Object* DescriptorArray::GetCallbacksObject(int descriptor_number) {
DCHECK(GetType(descriptor_number) == ACCESSOR_CONSTANT);
return GetValue(descriptor_number);
}
AccessorDescriptor* DescriptorArray::GetCallbacks(int descriptor_number) {
DCHECK(GetType(descriptor_number) == ACCESSOR_CONSTANT);
Foreign* p = Foreign::cast(GetCallbacksObject(descriptor_number));
return reinterpret_cast<AccessorDescriptor*>(p->foreign_address());
}
void DescriptorArray::Get(int descriptor_number, Descriptor* desc) {
desc->Init(handle(GetKey(descriptor_number), GetIsolate()),
handle(GetValue(descriptor_number), GetIsolate()),
GetDetails(descriptor_number));
}
void DescriptorArray::SetDescriptor(int descriptor_number, Descriptor* desc) {
void DescriptorArray::Set(int descriptor_number, Name* key, Object* value,
PropertyDetails details) {
// Range check.
DCHECK(descriptor_number < number_of_descriptors());
set(ToKeyIndex(descriptor_number), *desc->GetKey());
set(ToValueIndex(descriptor_number), *desc->GetValue());
set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi());
set(ToKeyIndex(descriptor_number), key);
set(ToValueIndex(descriptor_number), value);
set(ToDetailsIndex(descriptor_number), details.AsSmi());
}
void DescriptorArray::Set(int descriptor_number, Descriptor* desc) {
// Range check.
DCHECK(descriptor_number < number_of_descriptors());
set(ToKeyIndex(descriptor_number), *desc->GetKey());
set(ToValueIndex(descriptor_number), *desc->GetValue());
set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi());
Name* key = *desc->GetKey();
Object* value = *desc->GetValue();
Set(descriptor_number, key, value, desc->GetDetails());
}

View File

@ -3738,11 +3738,10 @@ void MigrateFastToSlow(Handle<JSObject> object, Handle<Map> new_map,
for (int i = 0; i < real_size; i++) {
PropertyDetails details = descs->GetDetails(i);
Handle<Name> key(descs->GetKey(i));
// TODO(ishell): Simplify the below code.
Handle<Object> value;
if (details.location() == kField) {
FieldIndex index = FieldIndex::ForDescriptor(*map, i);
if (details.kind() == kData) {
Handle<Object> value;
if (object->IsUnboxedDoubleField(index)) {
double old_value = object->RawFastDoublePropertyAt(index);
value = isolate->factory()->NewHeapNumber(old_value);
@ -3754,34 +3753,19 @@ void MigrateFastToSlow(Handle<JSObject> object, Handle<Map> new_map,
value = isolate->factory()->NewHeapNumber(old->value());
}
}
PropertyDetails d(kData, details.attributes(), i + 1,
PropertyCellType::kNoCell);
dictionary = NameDictionary::Add(dictionary, key, value, d);
} else {
DCHECK_EQ(kAccessor, details.kind());
Handle<Object> value(object->RawFastPropertyAt(index), isolate);
PropertyDetails d(kAccessor, details.attributes(), i + 1,
PropertyCellType::kNoCell);
dictionary = NameDictionary::Add(dictionary, key, value, d);
value = handle(object->RawFastPropertyAt(index), isolate);
}
} else {
DCHECK_EQ(kDescriptor, details.location());
if (details.kind() == kData) {
Handle<Object> value(descs->GetConstant(i), isolate);
PropertyDetails d(kData, details.attributes(), i + 1,
PropertyCellType::kNoCell);
dictionary = NameDictionary::Add(dictionary, key, value, d);
} else {
DCHECK_EQ(kAccessor, details.kind());
Handle<Object> value(descs->GetCallbacksObject(i), isolate);
PropertyDetails d(kAccessor, details.attributes(), i + 1,
PropertyCellType::kNoCell);
dictionary = NameDictionary::Add(dictionary, key, value, d);
}
value = handle(descs->GetValue(i), isolate);
}
DCHECK(!value.is_null());
PropertyDetails d(details.kind(), details.attributes(), i + 1,
PropertyCellType::kNoCell);
dictionary = NameDictionary::Add(dictionary, key, value, d);
}
// Copy the next enumeration index from instance descriptor.
@ -8520,7 +8504,7 @@ Object* JSObject::SlowReverseLookup(Object* value) {
} else {
DCHECK_EQ(kDescriptor, details.location());
if (details.kind() == kData) {
if (descs->GetConstant(i) == value) {
if (descs->GetValue(i) == value) {
return descs->GetKey(i);
}
}
@ -9136,9 +9120,9 @@ bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) {
} else {
DCHECK_EQ(kDescriptor, details.location());
if (details.kind() == kData) {
DCHECK(descriptors->GetConstant(descriptor) != value ||
DCHECK(descriptors->GetValue(descriptor) != value ||
value->FitsRepresentation(details.representation()));
return descriptors->GetConstant(descriptor) == value;
return descriptors->GetValue(descriptor) == value;
} else {
DCHECK_EQ(kAccessor, details.kind());
return false;
@ -9447,9 +9431,7 @@ Handle<DescriptorArray> DescriptorArray::CopyUpToAddAttributes(
details = details.CopyAddAttributes(
static_cast<PropertyAttributes>(attributes & mask));
}
Descriptor inner_desc(
handle(key), handle(value, desc->GetIsolate()), details);
descriptors->SetDescriptor(i, &inner_desc);
descriptors->Set(i, key, value, details);
}
} else {
for (int i = 0; i < size; ++i) {
@ -10112,17 +10094,11 @@ void DescriptorArray::SetEnumCache(Handle<DescriptorArray> descriptors,
}
}
void DescriptorArray::CopyFrom(int index, DescriptorArray* src) {
Object* value = src->GetValue(index);
PropertyDetails details = src->GetDetails(index);
Descriptor desc(handle(src->GetKey(index)),
handle(value, src->GetIsolate()),
details);
SetDescriptor(index, &desc);
Set(index, src->GetKey(index), src->GetValue(index), details);
}
void DescriptorArray::Sort() {
// In-place heap sort.
int len = number_of_descriptors();

View File

@ -3245,12 +3245,8 @@ class DescriptorArray: public FixedArray {
inline Object** GetDescriptorStartSlot(int descriptor_number);
inline Object** GetDescriptorEndSlot(int descriptor_number);
inline PropertyDetails GetDetails(int descriptor_number);
inline PropertyType GetType(int descriptor_number);
inline int GetFieldIndex(int descriptor_number);
inline FieldType* GetFieldType(int descriptor_number);
inline Object* GetConstant(int descriptor_number);
inline Object* GetCallbacksObject(int descriptor_number);
inline AccessorDescriptor* GetCallbacks(int descriptor_number);
inline Name* GetSortedKey(int descriptor_number);
inline int GetSortedKeyIndex(int descriptor_number);
@ -3261,6 +3257,8 @@ class DescriptorArray: public FixedArray {
// Accessor for complete descriptor.
inline void Get(int descriptor_number, Descriptor* desc);
inline void Set(int descriptor_number, Descriptor* desc);
inline void Set(int descriptor_number, Name* key, Object* value,
PropertyDetails details);
void Replace(int descriptor_number, Descriptor* descriptor);
// Append automatically sets the enumeration index. This should only be used
@ -3372,8 +3370,6 @@ class DescriptorArray: public FixedArray {
// descriptor array.
void CopyFrom(int index, DescriptorArray* src);
inline void SetDescriptor(int descriptor_number, Descriptor* desc);
// Swap first and second descriptor.
inline void SwapSortedKeys(int first, int second);

View File

@ -75,7 +75,7 @@ bool ToPropertyDescriptorFastPath(Isolate* isolate, Handle<JSReceiver> obj,
} else {
DCHECK_EQ(kDescriptor, details.location());
if (details.kind() == kData) {
value = handle(descs->GetConstant(i), isolate);
value = handle(descs->GetValue(i), isolate);
} else {
DCHECK_EQ(kAccessor, details.kind());
// Bail out to slow path.