}
-MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition(
+MaybeObject* JSObject::ConvertTransitionToMapTransition(
+ int transition_index,
String* name,
Object* new_value,
PropertyAttributes attributes) {
Map* old_map = map();
- FixedArray* old_properties = properties();
Object* result;
MaybeObject* maybe_result =
// with the map of "new Object()" cannot have transitions in the first place.
ASSERT(map() != GetIsolate()->empty_object_map());
- TransitionArray* new_transitions;
- MaybeObject* maybe_new_transitions = old_map->AddTransition(name, map());
- if (!maybe_new_transitions->To(&new_transitions)) {
- // Undo changes and return failure.
- set_map(old_map);
- set_properties(old_properties);
- return maybe_new_transitions;
- }
-
- MaybeObject* transition_added = old_map->set_transitions(new_transitions);
- if (transition_added->IsFailure()) {
- // Undo changes and return failure.
- set_map(old_map);
- set_properties(old_properties);
- return transition_added;
- }
-
+ // TODO(verwaest): From here on we lose existing map transitions, causing
+ // invalid back pointers. This will change once we can store multiple
+ // transitions with the same key.
+ old_map->SetTransition(transition_index, map());
map()->SetBackPointer(old_map);
return result;
}
}
// Otherwise, replace with a map transition to a new map with a FIELD,
// even if the value is a constant function.
- return self->ConvertDescriptorToFieldAndMapTransition(*name,
- *value,
- attributes);
+ return ConvertTransitionToMapTransition(
+ result->GetTransitionIndex(), *name, *value, attributes);
}
case HANDLER:
case NONEXISTENT:
// Was transition to CONSTANT_FUNCTION. Replace with a map transition to a
// new map with a FIELD, even if the value is a function.
- return ConvertDescriptorToFieldAndMapTransition(name, value, attributes);
+ return ConvertTransitionToMapTransition(
+ result.GetTransitionIndex(), name, value, attributes);
}
case HANDLER:
case NONEXISTENT:
MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
- // Converts a descriptor of any other type to a real field,
- // backed by the properties array. Descriptors of visible
- // types, such as CONSTANT_FUNCTION, keep their enumeration order.
- // Converts the descriptor on the original object's map to a
- // map transition, and the the new field is on the object's new map.
- MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition(
+ // Replaces an existing transition with a transition to a map with a FIELD.
+ MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition(
+ int transition_index,
String* name,
Object* new_value,
PropertyAttributes attributes);
- // Converts a descriptor of any other type to a real field,
- // backed by the properties array. Descriptors of visible
- // types, such as CONSTANT_FUNCTION, keep their enumeration order.
+ // Converts a descriptor of any other type to a real field, backed by the
+ // properties array.
MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
String* name,
Object* new_value,
MUST_USE_RESULT inline MaybeObject* set_elements_transition_map(
Map* transitioned_map);
inline TransitionArray* transitions();
- MUST_USE_RESULT inline MaybeObject* AddTransition(String* key,
- Object* value);
+ inline void SetTransition(int index, Object* value);
+ MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, Object* value);
MUST_USE_RESULT inline MaybeObject* set_transitions(
TransitionArray* transitions);
inline void ClearTransitions(Heap* heap,