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 bool Contains(MapList* maps_list, Map* map) { | |
danno
2011/10/18 08:57:03
nit: make static, rename to ContainsMap (Contains
Jakob Kummerow
2011/10/18 12:05:15
Done.
(For the record, I liked "Contains". It's a
| |
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 (Contains(candidates, fast_map)) return fast_map; | |
danno
2011/10/18 08:57:03
return NULL here?
Jakob Kummerow
2011/10/18 12:05:15
Done.
| |
2104 } | |
2105 if (elms_kind == FAST_SMI_ONLY_ELEMENTS) { | |
2106 bool dummy = true; | |
2107 Map* double_map = LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, &dummy); | |
2108 // In the current implementation, if the DOUBLE map doesn't exist, the | |
2109 // FAST map can't exist either. | |
2110 if (double_map == NULL) return NULL; | |
2111 Map* fast_map = double_map->LookupElementsTransitionMap(FAST_ELEMENTS, | |
2112 &dummy); | |
2113 if (fast_map != NULL && Contains(candidates, fast_map)) return fast_map; | |
2114 if (Contains(candidates, double_map)) return double_map; | |
2115 } | |
2116 return NULL; | |
2117 } | |
2118 | |
2119 | |
2088 static Map* GetElementsTransitionMapFromDescriptor(Object* descriptor_contents, | 2120 static Map* GetElementsTransitionMapFromDescriptor(Object* descriptor_contents, |
2089 ElementsKind elements_kind) { | 2121 ElementsKind elements_kind) { |
2090 if (descriptor_contents->IsMap()) { | 2122 if (descriptor_contents->IsMap()) { |
2091 Map* map = Map::cast(descriptor_contents); | 2123 Map* map = Map::cast(descriptor_contents); |
2092 if (map->elements_kind() == elements_kind) { | 2124 if (map->elements_kind() == elements_kind) { |
2093 return map; | 2125 return map; |
2094 } | 2126 } |
2095 return NULL; | 2127 return NULL; |
2096 } | 2128 } |
2097 | 2129 |
(...skipping 7208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9306 } | 9338 } |
9307 } | 9339 } |
9308 } | 9340 } |
9309 // All possible cases have been handled above. Add a return to avoid the | 9341 // All possible cases have been handled above. Add a return to avoid the |
9310 // complaints from the compiler. | 9342 // complaints from the compiler. |
9311 UNREACHABLE(); | 9343 UNREACHABLE(); |
9312 return isolate->heap()->null_value(); | 9344 return isolate->heap()->null_value(); |
9313 } | 9345 } |
9314 | 9346 |
9315 | 9347 |
9348 MUST_USE_RESULT MaybeObject* JSObject::TransitionElementsKind( | |
9349 ElementsKind to_kind) { | |
9350 ElementsKind from_kind = map()->elements_kind(); | |
9351 if (from_kind == FAST_SMI_ONLY_ELEMENTS) { | |
9352 FixedArray* elms = FixedArray::cast(elements()); | |
danno
2011/10/18 08:57:03
Change the type to FixedArrayBase*, then you can h
Jakob Kummerow
2011/10/18 12:05:15
Done. Good idea!
| |
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 (to_kind == FAST_DOUBLE_ELEMENTS) { | |
9359 MaybeObject* maybe_result = | |
9360 SetFastDoubleElementsCapacityAndLength(capacity, length); | |
9361 if (maybe_result->IsFailure()) return maybe_result; | |
9362 return this; | |
9363 } else if (to_kind == FAST_ELEMENTS) { | |
9364 MaybeObject* maybe_new_map = GetElementsTransitionMap(FAST_ELEMENTS); | |
9365 Map* new_map; | |
9366 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | |
9367 set_map(new_map); | |
9368 return this; | |
9369 } | |
9370 } else if (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS) { | |
9371 FixedDoubleArray* elms = FixedDoubleArray::cast(elements()); | |
9372 uint32_t capacity = static_cast<uint32_t>(elms->length()); | |
9373 uint32_t length = capacity; | |
9374 if (IsJSArray()) { | |
9375 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length)); | |
9376 } | |
9377 MaybeObject* maybe_result = SetFastElementsCapacityAndLength( | |
9378 capacity, length, kDontAllowSmiOnlyElements); | |
9379 if (maybe_result->IsFailure()) return maybe_result; | |
9380 return this; | |
9381 } | |
9382 // This method should never be called for any other case than the ones | |
9383 // handled above. | |
9384 UNREACHABLE(); | |
9385 return GetIsolate()->heap()->null_value(); | |
9386 } | |
9387 | |
9388 | |
9316 MaybeObject* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, | 9389 MaybeObject* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, |
9317 Object* value) { | 9390 Object* value) { |
9318 uint32_t old_len = 0; | 9391 uint32_t old_len = 0; |
9319 CHECK(length()->ToArrayIndex(&old_len)); | 9392 CHECK(length()->ToArrayIndex(&old_len)); |
9320 // Check to see if we need to update the length. For now, we make | 9393 // Check to see if we need to update the length. For now, we make |
9321 // sure that the length stays within 32-bits (unsigned). | 9394 // sure that the length stays within 32-bits (unsigned). |
9322 if (index >= old_len && index != 0xffffffff) { | 9395 if (index >= old_len && index != 0xffffffff) { |
9323 Object* len; | 9396 Object* len; |
9324 { MaybeObject* maybe_len = | 9397 { MaybeObject* maybe_len = |
9325 GetHeap()->NumberFromDouble(static_cast<double>(index) + 1); | 9398 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; | 12321 if (break_point_objects()->IsUndefined()) return 0; |
12249 // Single break point. | 12322 // Single break point. |
12250 if (!break_point_objects()->IsFixedArray()) return 1; | 12323 if (!break_point_objects()->IsFixedArray()) return 1; |
12251 // Multiple break points. | 12324 // Multiple break points. |
12252 return FixedArray::cast(break_point_objects())->length(); | 12325 return FixedArray::cast(break_point_objects())->length(); |
12253 } | 12326 } |
12254 #endif // ENABLE_DEBUGGER_SUPPORT | 12327 #endif // ENABLE_DEBUGGER_SUPPORT |
12255 | 12328 |
12256 | 12329 |
12257 } } // namespace v8::internal | 12330 } } // namespace v8::internal |
OLD | NEW |