Index: src/builtins.cc |
diff --git a/src/builtins.cc b/src/builtins.cc |
index de006c17b74bf517f409aa5336ce8191b38b2c6e..15ea202ae938de91c5f1ade0b6e1d3b804c17b84 100644 |
--- a/src/builtins.cc |
+++ b/src/builtins.cc |
@@ -203,17 +203,7 @@ RUNTIME_FUNCTION(MaybeObject*, ArrayConstructor_StubFailure) { |
holey = (value > 0 && value < JSObject::kInitialMaxFastElementArray); |
} |
- // Allocate the initial map if absent. |
- if (!function->has_initial_map()) { |
- Object* initial_map; |
- { MaybeObject* maybe_initial_map = |
- isolate->heap()->AllocateInitialMap(*function); |
- if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map; |
- } |
- function->set_initial_map(Map::cast(initial_map)); |
- Map::cast(initial_map)->set_constructor(*function); |
- } |
- |
+ ASSERT(function->has_initial_map()); |
ElementsKind kind = function->initial_map()->elements_kind(); |
if (holey) { |
kind = GetHoleyElementsKind(kind); |
@@ -221,23 +211,20 @@ RUNTIME_FUNCTION(MaybeObject*, ArrayConstructor_StubFailure) { |
MaybeObject* maybe_array; |
if (*type_info != isolate->heap()->undefined_value()) { |
- ASSERT(type_info->IsJSGlobalPropertyCell()); |
JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(*type_info); |
if (cell->value()->IsSmi()) { |
Smi* smi = Smi::cast(cell->value()); |
ElementsKind to_kind = static_cast<ElementsKind>(smi->value()); |
- if (holey) { |
+ if (holey && !IsFastHoleyElementsKind(to_kind)) { |
to_kind = GetHoleyElementsKind(to_kind); |
+ // Update the allocation site info to reflect the advice alteration. |
+ cell->set_value(Smi::FromInt(to_kind)); |
} |
- if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { |
- maybe_array = isolate->heap()->AllocateEmptyJSArray(to_kind); |
- } else { |
- AllocationSiteMode mode = AllocationSiteInfo::GetMode(kind); |
- maybe_array = isolate->heap()->AllocateEmptyJSArray(kind, |
- mode, |
- &type_info); |
- } |
+ AllocationSiteMode mode = AllocationSiteInfo::GetMode(to_kind); |
+ maybe_array = isolate->heap()->AllocateEmptyJSArray(kind, |
+ mode, |
+ &type_info); |
if (!maybe_array->To(&array)) return maybe_array; |
} |
} |
@@ -265,8 +252,9 @@ static MaybeObject* ArrayCodeGenericCommon(Arguments* args, |
array = JSArray::cast((*args)[0]); |
// Initialize elements and length in case later allocations fail so that the |
// array object is initialized in a valid state. |
- array->set_length(Smi::FromInt(0)); |
- array->set_elements(heap->empty_fixed_array()); |
+ MaybeObject* maybe_array = array->Initialize(0); |
+ if (maybe_array->IsFailure()) return maybe_array; |
+ |
AllocationSiteInfo* info = AllocationSiteInfo::FindForJSObject(array); |
ElementsKind to_kind = array->GetElementsKind(); |
if (info != NULL && info->GetElementsKindPayload(&to_kind)) { |
@@ -280,8 +268,7 @@ static MaybeObject* ArrayCodeGenericCommon(Arguments* args, |
ElementsKindToString(to_kind)); |
} |
- MaybeObject* maybe_array = |
- array->TransitionElementsKind(to_kind); |
+ maybe_array = array->TransitionElementsKind(to_kind); |
if (maybe_array->IsFailure()) return maybe_array; |
} |
} |
@@ -298,8 +285,6 @@ static MaybeObject* ArrayCodeGenericCommon(Arguments* args, |
} |
} else { |
// Allocate the JS Array |
- // TODO(mvstanton): There is no allocation info advice for this case. |
- // How to address? |
MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); |
if (!maybe_obj->To(&array)) return maybe_obj; |
} |
@@ -307,10 +292,9 @@ static MaybeObject* ArrayCodeGenericCommon(Arguments* args, |
Arguments adjusted_arguments(args->length() - 1, args->arguments() - 1); |
ASSERT(adjusted_arguments.length() < 1 || |
adjusted_arguments[0] == (*args)[1]); |
- { MaybeObject* maybe_obj = ArrayConstructInitializeElements(array, |
- &adjusted_arguments); |
- if (!maybe_obj->To(&array)) return maybe_obj; |
- } |
+ MaybeObject* maybe_obj = ArrayConstructInitializeElements(array, |
+ &adjusted_arguments); |
+ if (!maybe_obj->To(&array)) return maybe_obj; |
return array; |
} |