Index: src/objects-inl.h |
diff --git a/src/objects-inl.h b/src/objects-inl.h |
index 28efb743d431f2921b9094efcf7094da2b136fcf..fcc6b6a5ad7a5d176e65f64d45ef9d932cfcc8f7 100644 |
--- a/src/objects-inl.h |
+++ b/src/objects-inl.h |
@@ -1401,13 +1401,69 @@ FixedArrayBase* JSObject::elements() { |
} |
+MaybeObject* JSObject::EnsureCanContainNonSmiElements() { |
+ if (FLAG_smi_only_arrays && |
+ (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS)) { |
+#ifdef DEBUG |
+ Heap* heap = GetHeap(); |
+ FixedArray* fixed_array = FixedArray::cast(elements()); |
+ for (int i = 0; i < fixed_array->length(); i++) { |
+ Object* current = fixed_array->get(i); |
+ ASSERT(current->IsSmi() || current == heap->the_hole_value()); |
+ } |
+#endif |
+ Object* obj; |
+ MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS); |
+ if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
+ set_map(Map::cast(obj)); |
+ } |
+ return this; |
+} |
+ |
+ |
+MaybeObject* JSObject::EnsureCanContainElements(Object** objects, |
+ uint32_t count) { |
+ if (FLAG_smi_only_arrays && |
+ map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) { |
+ for (uint32_t i = 0; i < count; ++i) { |
+ Object* current = *objects++; |
+ if (!current->IsSmi() && current != GetHeap()->the_hole_value()) { |
+ return EnsureCanContainNonSmiElements(); |
+ } |
+ } |
+ } |
+ return this; |
+} |
+ |
+ |
+MaybeObject* JSObject::EnsureCanContainElements(FixedArray* elements) { |
+ if (FLAG_smi_only_arrays) { |
+ Object** objects = reinterpret_cast<Object**>( |
+ FIELD_ADDR(elements, elements->OffsetOfElementAt(0))); |
+ return EnsureCanContainElements(objects, elements->length()); |
+ } else { |
+ return this; |
+ } |
+} |
+ |
+ |
void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { |
- ASSERT(map()->has_fast_elements() == |
+ ASSERT((map()->has_fast_elements() || |
+ map()->has_fast_smi_only_elements()) == |
(value->map() == GetHeap()->fixed_array_map() || |
value->map() == GetHeap()->fixed_cow_array_map())); |
ASSERT(map()->has_fast_double_elements() == |
value->IsFixedDoubleArray()); |
ASSERT(value->HasValidElements()); |
+#ifdef DEBUG |
+ if (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) { |
+ Heap* heap = GetHeap(); |
Sven Panne
2011/09/16 09:19:32
Copy-n-paste from above, perhaps introduce a helpe
danno
2011/09/21 14:32:04
Done.
|
+ for (int i = 0; i < value->length(); i++) { |
+ Object* current = FixedArray::cast(value)->get(i); |
+ ASSERT(current->IsSmi() || current == heap->the_hole_value()); |
+ } |
+ } |
+#endif |
WRITE_FIELD(this, kElementsOffset, value); |
CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kElementsOffset, mode); |
} |
@@ -1420,7 +1476,7 @@ void JSObject::initialize_properties() { |
void JSObject::initialize_elements() { |
- ASSERT(map()->has_fast_elements()); |
+ ASSERT(map()->has_fast_elements() || map()->has_fast_smi_only_elements()); |
ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
} |
@@ -1428,9 +1484,11 @@ void JSObject::initialize_elements() { |
MaybeObject* JSObject::ResetElements() { |
Object* obj; |
- { MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS); |
- if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
- } |
+ ElementsKind elements_kind = FLAG_smi_only_arrays |
+ ? FAST_SMI_ONLY_ELEMENTS |
+ : FAST_ELEMENTS; |
+ MaybeObject* maybe_obj = GetElementsTransitionMap(elements_kind); |
+ if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
set_map(Map::cast(obj)); |
initialize_elements(); |
return this; |
@@ -1768,7 +1826,7 @@ void FixedDoubleArray::Initialize(FixedDoubleArray* from) { |
void FixedDoubleArray::Initialize(FixedArray* from) { |
int old_length = from->length(); |
- ASSERT(old_length < length()); |
+ ASSERT(old_length <= length()); |
for (int i = 0; i < old_length; i++) { |
Object* hole_or_object = from->get(i); |
if (hole_or_object->IsTheHole()) { |
@@ -4065,7 +4123,7 @@ void JSRegExp::SetDataAtUnchecked(int index, Object* value, Heap* heap) { |
ElementsKind JSObject::GetElementsKind() { |
ElementsKind kind = map()->elements_kind(); |
- ASSERT((kind == FAST_ELEMENTS && |
+ ASSERT(((kind == FAST_ELEMENTS || kind == FAST_SMI_ONLY_ELEMENTS) && |
(elements()->map() == GetHeap()->fixed_array_map() || |
elements()->map() == GetHeap()->fixed_cow_array_map())) || |
(kind == FAST_DOUBLE_ELEMENTS && |
@@ -4088,6 +4146,11 @@ bool JSObject::HasFastElements() { |
} |
+bool JSObject::HasFastSmiOnlyElements() { |
+ return GetElementsKind() == FAST_SMI_ONLY_ELEMENTS; |
+} |
+ |
+ |
bool JSObject::HasFastDoubleElements() { |
return GetElementsKind() == FAST_DOUBLE_ELEMENTS; |
} |
@@ -4098,6 +4161,11 @@ bool JSObject::HasDictionaryElements() { |
} |
+bool JSObject::HasNonStrictArgumentsElements() { |
+ return GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
+} |
+ |
+ |
bool JSObject::HasExternalArrayElements() { |
HeapObject* array = elements(); |
ASSERT(array != NULL); |
@@ -4149,7 +4217,7 @@ bool JSObject::AllowsSetElementsLength() { |
MaybeObject* JSObject::EnsureWritableFastElements() { |
- ASSERT(HasFastElements()); |
+ ASSERT(HasFastElements() || HasFastSmiOnlyElements()); |
FixedArray* elems = FixedArray::cast(elements()); |
Isolate* isolate = GetIsolate(); |
if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; |
@@ -4514,7 +4582,7 @@ void Map::ClearCodeCache(Heap* heap) { |
void JSArray::EnsureSize(int required_size) { |
- ASSERT(HasFastElements()); |
+ ASSERT(HasFastElements() || HasFastSmiOnlyElements()); |
FixedArray* elts = FixedArray::cast(elements()); |
const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
if (elts->length() < required_size) { |
@@ -4536,9 +4604,12 @@ void JSArray::set_length(Smi* length) { |
} |
-void JSArray::SetContent(FixedArray* storage) { |
+MaybeObject* JSArray::SetContent(FixedArray* storage) { |
+ MaybeObject* maybe_object = EnsureCanContainElements(storage); |
+ if (maybe_object->IsFailure()) return maybe_object; |
set_length(Smi::FromInt(storage->length())); |
set_elements(storage); |
+ return this; |
} |