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 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 cache->Update(descriptors, name, number); | 2078 cache->Update(descriptors, name, number); |
2079 } | 2079 } |
2080 if (number != DescriptorArray::kNotFound) { | 2080 if (number != DescriptorArray::kNotFound) { |
2081 result->DescriptorResult(holder, descriptors->GetDetails(number), number); | 2081 result->DescriptorResult(holder, descriptors->GetDetails(number), number); |
2082 } else { | 2082 } else { |
2083 result->NotFound(); | 2083 result->NotFound(); |
2084 } | 2084 } |
2085 } | 2085 } |
2086 | 2086 |
2087 | 2087 |
| 2088 // If |map| is contained in |maps_list|, returns |map|; otherwise returns NULL. |
| 2089 static bool ContainsMap(MapList* maps_list, Map* map) { |
| 2090 for (int i = 0; i < maps_list->length(); ++i) { |
| 2091 if (maps_list->at(i) == map) return true; |
| 2092 } |
| 2093 return false; |
| 2094 } |
| 2095 |
| 2096 |
| 2097 Map* Map::FindTransitionedMap(MapList* candidates) { |
| 2098 ElementsKind elms_kind = elements_kind(); |
| 2099 if (elms_kind == FAST_DOUBLE_ELEMENTS) { |
| 2100 bool dummy = true; |
| 2101 Map* fast_map = LookupElementsTransitionMap(FAST_ELEMENTS, &dummy); |
| 2102 if (fast_map == NULL) return NULL; |
| 2103 if (ContainsMap(candidates, fast_map)) return fast_map; |
| 2104 return NULL; |
| 2105 } |
| 2106 if (elms_kind == FAST_SMI_ONLY_ELEMENTS) { |
| 2107 bool dummy = true; |
| 2108 Map* double_map = LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, &dummy); |
| 2109 // In the current implementation, if the DOUBLE map doesn't exist, the |
| 2110 // FAST map can't exist either. |
| 2111 if (double_map == NULL) return NULL; |
| 2112 Map* fast_map = double_map->LookupElementsTransitionMap(FAST_ELEMENTS, |
| 2113 &dummy); |
| 2114 if (fast_map != NULL && ContainsMap(candidates, fast_map)) return fast_map; |
| 2115 if (ContainsMap(candidates, double_map)) return double_map; |
| 2116 } |
| 2117 return NULL; |
| 2118 } |
| 2119 |
| 2120 |
2088 static Map* GetElementsTransitionMapFromDescriptor(Object* descriptor_contents, | 2121 static Map* GetElementsTransitionMapFromDescriptor(Object* descriptor_contents, |
2089 ElementsKind elements_kind) { | 2122 ElementsKind elements_kind) { |
2090 if (descriptor_contents->IsMap()) { | 2123 if (descriptor_contents->IsMap()) { |
2091 Map* map = Map::cast(descriptor_contents); | 2124 Map* map = Map::cast(descriptor_contents); |
2092 if (map->elements_kind() == elements_kind) { | 2125 if (map->elements_kind() == elements_kind) { |
2093 return map; | 2126 return map; |
2094 } | 2127 } |
2095 return NULL; | 2128 return NULL; |
2096 } | 2129 } |
2097 | 2130 |
(...skipping 7208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9306 } | 9339 } |
9307 } | 9340 } |
9308 } | 9341 } |
9309 // All possible cases have been handled above. Add a return to avoid the | 9342 // All possible cases have been handled above. Add a return to avoid the |
9310 // complaints from the compiler. | 9343 // complaints from the compiler. |
9311 UNREACHABLE(); | 9344 UNREACHABLE(); |
9312 return isolate->heap()->null_value(); | 9345 return isolate->heap()->null_value(); |
9313 } | 9346 } |
9314 | 9347 |
9315 | 9348 |
| 9349 MUST_USE_RESULT MaybeObject* JSObject::TransitionElementsKind( |
| 9350 ElementsKind to_kind) { |
| 9351 ElementsKind from_kind = map()->elements_kind(); |
| 9352 FixedArrayBase* elms = FixedArrayBase::cast(elements()); |
| 9353 uint32_t capacity = static_cast<uint32_t>(elms->length()); |
| 9354 uint32_t length = capacity; |
| 9355 if (IsJSArray()) { |
| 9356 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length)); |
| 9357 } |
| 9358 if (from_kind == FAST_SMI_ONLY_ELEMENTS) { |
| 9359 if (to_kind == FAST_DOUBLE_ELEMENTS) { |
| 9360 MaybeObject* maybe_result = |
| 9361 SetFastDoubleElementsCapacityAndLength(capacity, length); |
| 9362 if (maybe_result->IsFailure()) return maybe_result; |
| 9363 return this; |
| 9364 } else if (to_kind == FAST_ELEMENTS) { |
| 9365 MaybeObject* maybe_new_map = GetElementsTransitionMap(FAST_ELEMENTS); |
| 9366 Map* new_map; |
| 9367 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 9368 set_map(new_map); |
| 9369 return this; |
| 9370 } |
| 9371 } else if (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS) { |
| 9372 MaybeObject* maybe_result = SetFastElementsCapacityAndLength( |
| 9373 capacity, length, kDontAllowSmiOnlyElements); |
| 9374 if (maybe_result->IsFailure()) return maybe_result; |
| 9375 return this; |
| 9376 } |
| 9377 // This method should never be called for any other case than the ones |
| 9378 // handled above. |
| 9379 UNREACHABLE(); |
| 9380 return GetIsolate()->heap()->null_value(); |
| 9381 } |
| 9382 |
| 9383 |
| 9384 // static |
| 9385 bool Map::IsValidElementsTransition(ElementsKind from_kind, |
| 9386 ElementsKind to_kind) { |
| 9387 return |
| 9388 (from_kind == FAST_SMI_ONLY_ELEMENTS && |
| 9389 (to_kind == FAST_DOUBLE_ELEMENTS || to_kind == FAST_ELEMENTS)) || |
| 9390 (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS); |
| 9391 } |
| 9392 |
| 9393 |
9316 MaybeObject* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, | 9394 MaybeObject* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, |
9317 Object* value) { | 9395 Object* value) { |
9318 uint32_t old_len = 0; | 9396 uint32_t old_len = 0; |
9319 CHECK(length()->ToArrayIndex(&old_len)); | 9397 CHECK(length()->ToArrayIndex(&old_len)); |
9320 // Check to see if we need to update the length. For now, we make | 9398 // Check to see if we need to update the length. For now, we make |
9321 // sure that the length stays within 32-bits (unsigned). | 9399 // sure that the length stays within 32-bits (unsigned). |
9322 if (index >= old_len && index != 0xffffffff) { | 9400 if (index >= old_len && index != 0xffffffff) { |
9323 Object* len; | 9401 Object* len; |
9324 { MaybeObject* maybe_len = | 9402 { MaybeObject* maybe_len = |
9325 GetHeap()->NumberFromDouble(static_cast<double>(index) + 1); | 9403 GetHeap()->NumberFromDouble(static_cast<double>(index) + 1); |
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12248 if (break_point_objects()->IsUndefined()) return 0; | 12326 if (break_point_objects()->IsUndefined()) return 0; |
12249 // Single break point. | 12327 // Single break point. |
12250 if (!break_point_objects()->IsFixedArray()) return 1; | 12328 if (!break_point_objects()->IsFixedArray()) return 1; |
12251 // Multiple break points. | 12329 // Multiple break points. |
12252 return FixedArray::cast(break_point_objects())->length(); | 12330 return FixedArray::cast(break_point_objects())->length(); |
12253 } | 12331 } |
12254 #endif // ENABLE_DEBUGGER_SUPPORT | 12332 #endif // ENABLE_DEBUGGER_SUPPORT |
12255 | 12333 |
12256 | 12334 |
12257 } } // namespace v8::internal | 12335 } } // namespace v8::internal |
OLD | NEW |