Introduce an abstraction to write to a field.
BUG= R=ishell@chromium.org Review URL: https://codereview.chromium.org/236063016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20792 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
cf26c1421a
commit
10714e29fa
@ -1907,22 +1907,7 @@ void JSObject::AddFastProperty(Handle<JSObject> object,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSObject::MigrateToMap(object, new_map);
|
JSObject::MigrateToNewProperty(object, new_map, value);
|
||||||
|
|
||||||
PropertyDetails details = new_map->GetLastDescriptorDetails();
|
|
||||||
if (details.type() != FIELD) return;
|
|
||||||
|
|
||||||
Representation representation = details.representation();
|
|
||||||
int index = details.field_index();
|
|
||||||
|
|
||||||
if (representation.IsDouble()) {
|
|
||||||
// Nothing more to be done.
|
|
||||||
if (value->IsUninitialized()) return;
|
|
||||||
HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(index));
|
|
||||||
box->set_value(value->Number());
|
|
||||||
} else {
|
|
||||||
object->FastPropertyAtPut(index, *value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3954,31 +3939,42 @@ MaybeHandle<Object> JSObject::SetPropertyUsingTransition(
|
|||||||
field_representation, field_type, FORCE_FIELD);
|
field_representation, field_type, FORCE_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSObject::MigrateToMap(object, transition_map);
|
JSObject::MigrateToNewProperty(object, transition_map, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
// Reload.
|
|
||||||
descriptors = handle(transition_map->instance_descriptors());
|
|
||||||
details = descriptors->GetDetails(descriptor);
|
|
||||||
|
|
||||||
if (details.type() != FIELD) return value;
|
void JSObject::MigrateToNewProperty(Handle<JSObject> object,
|
||||||
|
Handle<Map> map,
|
||||||
|
Handle<Object> value) {
|
||||||
|
JSObject::MigrateToMap(object, map);
|
||||||
|
if (map->GetLastDescriptorDetails().type() != FIELD) return;
|
||||||
|
object->WriteToField(map->LastAdded(), *value);
|
||||||
|
}
|
||||||
|
|
||||||
int field_index = descriptors->GetFieldIndex(descriptor);
|
|
||||||
|
void JSObject::WriteToField(int descriptor, Object* value) {
|
||||||
|
DisallowHeapAllocation no_gc;
|
||||||
|
|
||||||
|
DescriptorArray* desc = map()->instance_descriptors();
|
||||||
|
PropertyDetails details = desc->GetDetails(descriptor);
|
||||||
|
|
||||||
|
ASSERT(details.type() == FIELD);
|
||||||
|
|
||||||
|
int field_index = desc->GetFieldIndex(descriptor);
|
||||||
if (details.representation().IsDouble()) {
|
if (details.representation().IsDouble()) {
|
||||||
// Nothing more to be done.
|
// Nothing more to be done.
|
||||||
if (value->IsUninitialized()) return value;
|
if (value->IsUninitialized()) return;
|
||||||
HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(field_index));
|
HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(field_index));
|
||||||
box->set_value(value->Number());
|
box->set_value(value->Number());
|
||||||
} else {
|
} else {
|
||||||
object->FastPropertyAtPut(field_index, *value);
|
FastPropertyAtPut(field_index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void SetPropertyToField(LookupResult* lookup,
|
static void SetPropertyToField(LookupResult* lookup,
|
||||||
Handle<Object> value) {
|
Handle<Object> value) {
|
||||||
Representation representation = lookup->representation();
|
|
||||||
if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) {
|
if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) {
|
||||||
Representation field_representation = value->OptimalRepresentation();
|
Representation field_representation = value->OptimalRepresentation();
|
||||||
Handle<HeapType> field_type = value->OptimalType(
|
Handle<HeapType> field_type = value->OptimalType(
|
||||||
@ -3987,20 +3983,8 @@ static void SetPropertyToField(LookupResult* lookup,
|
|||||||
lookup->GetDescriptorIndex(),
|
lookup->GetDescriptorIndex(),
|
||||||
field_representation, field_type,
|
field_representation, field_type,
|
||||||
FORCE_FIELD);
|
FORCE_FIELD);
|
||||||
DescriptorArray* desc = lookup->holder()->map()->instance_descriptors();
|
|
||||||
int descriptor = lookup->GetDescriptorIndex();
|
|
||||||
representation = desc->GetDetails(descriptor).representation();
|
|
||||||
}
|
}
|
||||||
|
lookup->holder()->WriteToField(lookup->GetDescriptorIndex(), *value);
|
||||||
if (representation.IsDouble()) {
|
|
||||||
HeapNumber* storage = HeapNumber::cast(lookup->holder()->RawFastPropertyAt(
|
|
||||||
lookup->GetFieldIndex().field_index()));
|
|
||||||
storage->set_value(value->Number());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lookup->holder()->FastPropertyAtPut(
|
|
||||||
lookup->GetFieldIndex().field_index(), *value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4030,9 +4014,7 @@ static void ConvertAndSetLocalProperty(LookupResult* lookup,
|
|||||||
JSObject::MigrateToMap(object, new_map);
|
JSObject::MigrateToMap(object, new_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorArray* descriptors = object->map()->instance_descriptors();
|
object->WriteToField(descriptor_index, *value);
|
||||||
int index = descriptors->GetDetails(descriptor_index).field_index();
|
|
||||||
object->FastPropertyAtPut(index, *value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -5227,9 +5209,7 @@ Handle<Object> JSObject::SetHiddenPropertiesHashTable(Handle<JSObject> object,
|
|||||||
int sorted_index = descriptors->GetSortedKeyIndex(0);
|
int sorted_index = descriptors->GetSortedKeyIndex(0);
|
||||||
if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string()
|
if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string()
|
||||||
&& sorted_index < object->map()->NumberOfOwnDescriptors()) {
|
&& sorted_index < object->map()->NumberOfOwnDescriptors()) {
|
||||||
ASSERT(descriptors->GetType(sorted_index) == FIELD);
|
object->WriteToField(sorted_index, *value);
|
||||||
object->FastPropertyAtPut(descriptors->GetFieldIndex(sorted_index),
|
|
||||||
*value);
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2610,6 +2610,7 @@ class JSObject: public JSReceiver {
|
|||||||
int index);
|
int index);
|
||||||
inline Object* RawFastPropertyAt(int index);
|
inline Object* RawFastPropertyAt(int index);
|
||||||
inline void FastPropertyAtPut(int index, Object* value);
|
inline void FastPropertyAtPut(int index, Object* value);
|
||||||
|
void WriteToField(int descriptor, Object* value);
|
||||||
|
|
||||||
// Access to in object properties.
|
// Access to in object properties.
|
||||||
inline int GetInObjectPropertyOffset(int index);
|
inline int GetInObjectPropertyOffset(int index);
|
||||||
@ -2900,6 +2901,10 @@ class JSObject: public JSReceiver {
|
|||||||
ValueType value_type,
|
ValueType value_type,
|
||||||
TransitionFlag flag);
|
TransitionFlag flag);
|
||||||
|
|
||||||
|
static void MigrateToNewProperty(Handle<JSObject> object,
|
||||||
|
Handle<Map> transition,
|
||||||
|
Handle<Object> value);
|
||||||
|
|
||||||
// Add a property to a slow-case object.
|
// Add a property to a slow-case object.
|
||||||
static void AddSlowProperty(Handle<JSObject> object,
|
static void AddSlowProperty(Handle<JSObject> object,
|
||||||
Handle<Name> name,
|
Handle<Name> name,
|
||||||
|
Loading…
Reference in New Issue
Block a user