Index: src/elements.cc |
diff --git a/src/elements.cc b/src/elements.cc |
index 3cf8378162844a1fc00525e3ccacdb6f47406ac5..031d5169290bab0c24da0d8b4537fae95b7b11b5 100644 |
--- a/src/elements.cc |
+++ b/src/elements.cc |
@@ -783,6 +783,45 @@ class ElementsAccessorBase : public ElementsAccessor { |
return new_elements; |
} |
+ static void TransitionElementsKindImpl(Handle<JSObject> object, |
+ Handle<Map> to_map) { |
+ Handle<Map> from_map = handle(object->map()); |
+ ElementsKind from_kind = from_map->elements_kind(); |
+ ElementsKind to_kind = to_map->elements_kind(); |
+ if (IsFastHoleyElementsKind(from_kind)) { |
+ to_kind = GetHoleyElementsKind(to_kind); |
+ } |
+ if (from_kind != to_kind) { |
+ // This method should never be called for any other case. |
+ DCHECK(IsFastElementsKind(from_kind)); |
+ DCHECK(IsFastElementsKind(to_kind)); |
+ DCHECK_NE(TERMINAL_FAST_ELEMENTS_KIND, from_kind); |
+ |
+ Handle<FixedArrayBase> from_elements(object->elements()); |
+ if (object->elements() == object->GetHeap()->empty_fixed_array() || |
+ IsFastDoubleElementsKind(from_kind) == |
+ IsFastDoubleElementsKind(to_kind)) { |
+ // No change is needed to the elements() buffer, the transition |
+ // only requires a map change. |
+ JSObject::MigrateToMap(object, to_map); |
+ } else { |
+ DCHECK((IsFastSmiElementsKind(from_kind) && |
+ IsFastDoubleElementsKind(to_kind)) || |
+ (IsFastDoubleElementsKind(from_kind) && |
+ IsFastObjectElementsKind(to_kind))); |
+ uint32_t capacity = static_cast<uint32_t>(object->elements()->length()); |
+ Handle<FixedArrayBase> elements = ConvertElementsWithCapacity( |
+ object, from_elements, from_kind, capacity); |
+ JSObject::SetMapAndElements(object, to_map, elements); |
+ } |
+ if (FLAG_trace_elements_transitions) { |
+ JSObject::PrintElementsTransition(stdout, object, from_kind, |
+ from_elements, to_kind, |
+ handle(object->elements())); |
+ } |
+ } |
+ } |
+ |
static void GrowCapacityAndConvertImpl(Handle<JSObject> object, |
uint32_t capacity) { |
ElementsKind from_kind = object->GetElementsKind(); |
@@ -822,6 +861,10 @@ class ElementsAccessorBase : public ElementsAccessor { |
} |
} |
+ void TransitionElementsKind(Handle<JSObject> object, Handle<Map> map) final { |
+ Subclass::TransitionElementsKindImpl(object, map); |
+ } |
+ |
void GrowCapacityAndConvert(Handle<JSObject> object, |
uint32_t capacity) final { |
Subclass::GrowCapacityAndConvertImpl(object, capacity); |
@@ -2255,6 +2298,11 @@ class SloppyArgumentsElementsAccessor |
} |
} |
+ static void TransitionElementsKindImpl(Handle<JSObject> object, |
+ Handle<Map> map) { |
+ UNREACHABLE(); |
+ } |
+ |
static void GrowCapacityAndConvertImpl(Handle<JSObject> object, |
uint32_t capacity) { |
UNREACHABLE(); |