| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10465 result_double->set_value(static_cast<double>(result)); | 10465 result_double->set_value(static_cast<double>(result)); |
| 10466 return result_double; | 10466 return result_double; |
| 10467 } | 10467 } |
| 10468 | 10468 |
| 10469 | 10469 |
| 10470 // Collects all defined (non-hole) and non-undefined (array) elements at | 10470 // Collects all defined (non-hole) and non-undefined (array) elements at |
| 10471 // the start of the elements array. | 10471 // the start of the elements array. |
| 10472 // If the object is in dictionary mode, it is converted to fast elements | 10472 // If the object is in dictionary mode, it is converted to fast elements |
| 10473 // mode. | 10473 // mode. |
| 10474 MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) { | 10474 MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) { |
| 10475 ASSERT(!HasExternalArrayElements()); | |
| 10476 | |
| 10477 Heap* heap = GetHeap(); | 10475 Heap* heap = GetHeap(); |
| 10478 | 10476 |
| 10479 if (HasDictionaryElements()) { | 10477 if (HasDictionaryElements()) { |
| 10480 // Convert to fast elements containing only the existing properties. | 10478 // Convert to fast elements containing only the existing properties. |
| 10481 // Ordering is irrelevant, since we are going to sort anyway. | 10479 // Ordering is irrelevant, since we are going to sort anyway. |
| 10482 NumberDictionary* dict = element_dictionary(); | 10480 NumberDictionary* dict = element_dictionary(); |
| 10483 if (IsJSArray() || dict->requires_slow_elements() || | 10481 if (IsJSArray() || dict->requires_slow_elements() || |
| 10484 dict->max_number_key() >= limit) { | 10482 dict->max_number_key() >= limit) { |
| 10485 return PrepareSlowElementsForSort(limit); | 10483 return PrepareSlowElementsForSort(limit); |
| 10486 } | 10484 } |
| 10487 // Convert to fast elements. | 10485 // Convert to fast elements. |
| 10488 | 10486 |
| 10489 Object* obj; | 10487 Object* obj; |
| 10490 { MaybeObject* maybe_obj = map()->GetFastElementsMap(); | 10488 { MaybeObject* maybe_obj = map()->GetFastElementsMap(); |
| 10491 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 10489 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 10492 } | 10490 } |
| 10493 Map* new_map = Map::cast(obj); | 10491 Map* new_map = Map::cast(obj); |
| 10494 | 10492 |
| 10495 PretenureFlag tenure = heap->InNewSpace(this) ? NOT_TENURED: TENURED; | 10493 PretenureFlag tenure = heap->InNewSpace(this) ? NOT_TENURED: TENURED; |
| 10496 Object* new_array; | 10494 Object* new_array; |
| 10497 { MaybeObject* maybe_new_array = | 10495 { MaybeObject* maybe_new_array = |
| 10498 heap->AllocateFixedArray(dict->NumberOfElements(), tenure); | 10496 heap->AllocateFixedArray(dict->NumberOfElements(), tenure); |
| 10499 if (!maybe_new_array->ToObject(&new_array)) return maybe_new_array; | 10497 if (!maybe_new_array->ToObject(&new_array)) return maybe_new_array; |
| 10500 } | 10498 } |
| 10501 FixedArray* fast_elements = FixedArray::cast(new_array); | 10499 FixedArray* fast_elements = FixedArray::cast(new_array); |
| 10502 dict->CopyValuesTo(fast_elements); | 10500 dict->CopyValuesTo(fast_elements); |
| 10503 | 10501 |
| 10504 set_map(new_map); | 10502 set_map(new_map); |
| 10505 set_elements(fast_elements); | 10503 set_elements(fast_elements); |
| 10504 } else if (HasExternalArrayElements()) { |
| 10505 // External arrays cannot have holes or undefined elements. |
| 10506 return Smi::FromInt(ExternalArray::cast(elements())->length()); |
| 10506 } else { | 10507 } else { |
| 10507 Object* obj; | 10508 Object* obj; |
| 10508 { MaybeObject* maybe_obj = EnsureWritableFastElements(); | 10509 { MaybeObject* maybe_obj = EnsureWritableFastElements(); |
| 10509 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 10510 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 10510 } | 10511 } |
| 10511 } | 10512 } |
| 10512 ASSERT(HasFastElements()); | 10513 ASSERT(HasFastElements()); |
| 10513 | 10514 |
| 10514 // Collect holes at the end, undefined before that and the rest at the | 10515 // Collect holes at the end, undefined before that and the rest at the |
| 10515 // start, and return the number of non-hole, non-undefined values. | 10516 // start, and return the number of non-hole, non-undefined values. |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11849 if (break_point_objects()->IsUndefined()) return 0; | 11850 if (break_point_objects()->IsUndefined()) return 0; |
| 11850 // Single beak point. | 11851 // Single beak point. |
| 11851 if (!break_point_objects()->IsFixedArray()) return 1; | 11852 if (!break_point_objects()->IsFixedArray()) return 1; |
| 11852 // Multiple break points. | 11853 // Multiple break points. |
| 11853 return FixedArray::cast(break_point_objects())->length(); | 11854 return FixedArray::cast(break_point_objects())->length(); |
| 11854 } | 11855 } |
| 11855 #endif | 11856 #endif |
| 11856 | 11857 |
| 11857 | 11858 |
| 11858 } } // namespace v8::internal | 11859 } } // namespace v8::internal |
| OLD | NEW |