Commit 77751e93 authored by verwaest's avatar verwaest Committed by Commit bot

[runtime] Avoid prefix PrepareForDataProperty in TransitionToDataProperty

BUG=

Review URL: https://codereview.chromium.org/1700903002

Cr-Commit-Position: refs/heads/master@{#34018}
parent 2f8e3352
...@@ -3164,8 +3164,14 @@ void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map, ...@@ -3164,8 +3164,14 @@ void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map,
// respective prototypes. // respective prototypes.
UpdatePrototypeUserRegistration(old_map, new_map, new_map->GetIsolate()); UpdatePrototypeUserRegistration(old_map, new_map, new_map->GetIsolate());
if (object->HasFastProperties()) { if (old_map->is_dictionary_map()) {
if (!new_map->is_dictionary_map()) { // For slow-to-fast migrations JSObject::MigrateSlowToFast()
// must be used instead.
CHECK(new_map->is_dictionary_map());
// Slow-to-slow migration is trivial.
object->set_map(*new_map);
} else if (!new_map->is_dictionary_map()) {
MigrateFastToFast(object, new_map); MigrateFastToFast(object, new_map);
if (old_map->is_prototype_map()) { if (old_map->is_prototype_map()) {
DCHECK(!old_map->is_stable()); DCHECK(!old_map->is_stable());
...@@ -3176,21 +3182,13 @@ void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map, ...@@ -3176,21 +3182,13 @@ void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map,
old_map->GetHeap()->empty_descriptor_array(), old_map->GetHeap()->empty_descriptor_array(),
LayoutDescriptor::FastPointerLayout()); LayoutDescriptor::FastPointerLayout());
// Ensure that no transition was inserted for prototype migrations. // Ensure that no transition was inserted for prototype migrations.
DCHECK_EQ(0, TransitionArray::NumberOfTransitions( DCHECK_EQ(
old_map->raw_transitions())); 0, TransitionArray::NumberOfTransitions(old_map->raw_transitions()));
DCHECK(new_map->GetBackPointer()->IsUndefined()); DCHECK(new_map->GetBackPointer()->IsUndefined());
} }
} else { } else {
MigrateFastToSlow(object, new_map, expected_additional_properties); MigrateFastToSlow(object, new_map, expected_additional_properties);
} }
} else {
// For slow-to-fast migrations JSObject::MigrateSlowToFast()
// must be used instead.
CHECK(new_map->is_dictionary_map());
// Slow-to-slow migration is trivial.
object->set_map(*new_map);
}
// Careful: Don't allocate here! // Careful: Don't allocate here!
// For some callers of this method, |object| might be in an inconsistent // For some callers of this method, |object| might be in an inconsistent
...@@ -9930,28 +9928,32 @@ bool DescriptorArray::CanHoldValue(int descriptor, Object* value) { ...@@ -9930,28 +9928,32 @@ bool DescriptorArray::CanHoldValue(int descriptor, Object* value) {
return false; return false;
} }
namespace {
// static Handle<Map> UpdateDescriptorForValue(Handle<Map> map, int descriptor,
Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor,
Handle<Object> value) { Handle<Object> value) {
// Dictionaries can store any property value. if (map->instance_descriptors()->CanHoldValue(descriptor, *value)) return map;
if (map->is_dictionary_map()) return map;
// Migrate to the newest map before storing the property.
map = Update(map);
Handle<DescriptorArray> descriptors(map->instance_descriptors());
if (descriptors->CanHoldValue(descriptor, *value)) return map;
Isolate* isolate = map->GetIsolate(); Isolate* isolate = map->GetIsolate();
PropertyAttributes attributes = PropertyAttributes attributes =
descriptors->GetDetails(descriptor).attributes(); map->instance_descriptors()->GetDetails(descriptor).attributes();
Representation representation = value->OptimalRepresentation(); Representation representation = value->OptimalRepresentation();
Handle<FieldType> type = value->OptimalType(isolate, representation); Handle<FieldType> type = value->OptimalType(isolate, representation);
return ReconfigureProperty(map, descriptor, kData, attributes, representation, return Map::ReconfigureProperty(map, descriptor, kData, attributes,
type, FORCE_FIELD); representation, type, FORCE_FIELD);
}
} // namespace
// static
Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor,
Handle<Object> value) {
// Dictionaries can store any property value.
if (map->is_dictionary_map()) return map;
// Update to the newest map before storing the property.
return UpdateDescriptorForValue(Update(map), descriptor, value);
} }
...@@ -9975,7 +9977,7 @@ Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name, ...@@ -9975,7 +9977,7 @@ Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name,
->GetDetails(descriptor) ->GetDetails(descriptor)
.attributes()); .attributes());
return Map::PrepareForDataProperty(transition, descriptor, value); return UpdateDescriptorForValue(transition, descriptor, value);
} }
TransitionFlag flag = INSERT_TRANSITION; TransitionFlag flag = INSERT_TRANSITION;
......
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