OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 10016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10027 | 10027 |
10028 if (fast_elements_) { | 10028 if (fast_elements_) { |
10029 if (index < static_cast<uint32_t>(storage_->length())) { | 10029 if (index < static_cast<uint32_t>(storage_->length())) { |
10030 storage_->set(index, *elm); | 10030 storage_->set(index, *elm); |
10031 return; | 10031 return; |
10032 } | 10032 } |
10033 // Our initial estimate of length was foiled, possibly by | 10033 // Our initial estimate of length was foiled, possibly by |
10034 // getters on the arrays increasing the length of later arrays | 10034 // getters on the arrays increasing the length of later arrays |
10035 // during iteration. | 10035 // during iteration. |
10036 // This shouldn't happen in anything but pathological cases. | 10036 // This shouldn't happen in anything but pathological cases. |
10037 SetDictionaryMode(index); | 10037 SetDictionaryMode(); |
10038 // Fall-through to dictionary mode. | 10038 // Fall-through to dictionary mode. |
10039 } | 10039 } |
10040 ASSERT(!fast_elements_); | 10040 ASSERT(!fast_elements_); |
10041 Handle<SeededNumberDictionary> dict( | 10041 Handle<SeededNumberDictionary> dict( |
10042 SeededNumberDictionary::cast(*storage_)); | 10042 SeededNumberDictionary::cast(*storage_)); |
10043 Handle<SeededNumberDictionary> result = | 10043 Handle<SeededNumberDictionary> result = |
10044 SeededNumberDictionary::AtNumberPut(dict, index, elm); | 10044 SeededNumberDictionary::AtNumberPut(dict, index, elm); |
10045 if (!result.is_identical_to(dict)) { | 10045 if (!result.is_identical_to(dict)) { |
10046 // Dictionary needed to grow. | 10046 // Dictionary needed to grow. |
10047 clear_storage(); | 10047 clear_storage(); |
10048 set_storage(*result); | 10048 set_storage(*result); |
10049 } | 10049 } |
10050 } | 10050 } |
10051 | 10051 |
10052 void increase_index_offset(uint32_t delta) { | 10052 void increase_index_offset(uint32_t delta) { |
10053 if (JSObject::kMaxElementCount - index_offset_ < delta) { | 10053 if (JSObject::kMaxElementCount - index_offset_ < delta) { |
10054 index_offset_ = JSObject::kMaxElementCount; | 10054 index_offset_ = JSObject::kMaxElementCount; |
10055 } else { | 10055 } else { |
10056 index_offset_ += delta; | 10056 index_offset_ += delta; |
10057 } | 10057 } |
| 10058 // If the initial length estimate was off (see special case in visit()), |
| 10059 // but the array blowing the limit didn't contain elements beyond the |
| 10060 // provided-for index range, go to dictionary mode now. |
| 10061 if (fast_elements_ && |
| 10062 index_offset_ >= static_cast<uint32_t>( |
| 10063 FixedArrayBase::cast(*storage_)->length())) { |
| 10064 SetDictionaryMode(); |
| 10065 } |
10058 } | 10066 } |
10059 | 10067 |
10060 bool exceeds_array_limit() { | 10068 bool exceeds_array_limit() { |
10061 return exceeds_array_limit_; | 10069 return exceeds_array_limit_; |
10062 } | 10070 } |
10063 | 10071 |
10064 Handle<JSArray> ToArray() { | 10072 Handle<JSArray> ToArray() { |
10065 Handle<JSArray> array = isolate_->factory()->NewJSArray(0); | 10073 Handle<JSArray> array = isolate_->factory()->NewJSArray(0); |
10066 Handle<Object> length = | 10074 Handle<Object> length = |
10067 isolate_->factory()->NewNumber(static_cast<double>(index_offset_)); | 10075 isolate_->factory()->NewNumber(static_cast<double>(index_offset_)); |
10068 Handle<Map> map = JSObject::GetElementsTransitionMap( | 10076 Handle<Map> map = JSObject::GetElementsTransitionMap( |
10069 array, | 10077 array, |
10070 fast_elements_ ? FAST_HOLEY_ELEMENTS : DICTIONARY_ELEMENTS); | 10078 fast_elements_ ? FAST_HOLEY_ELEMENTS : DICTIONARY_ELEMENTS); |
10071 array->set_map(*map); | 10079 array->set_map(*map); |
10072 array->set_length(*length); | 10080 array->set_length(*length); |
10073 array->set_elements(*storage_); | 10081 array->set_elements(*storage_); |
10074 return array; | 10082 return array; |
10075 } | 10083 } |
10076 | 10084 |
10077 private: | 10085 private: |
10078 // Convert storage to dictionary mode. | 10086 // Convert storage to dictionary mode. |
10079 void SetDictionaryMode(uint32_t index) { | 10087 void SetDictionaryMode() { |
10080 ASSERT(fast_elements_); | 10088 ASSERT(fast_elements_); |
10081 Handle<FixedArray> current_storage(*storage_); | 10089 Handle<FixedArray> current_storage(*storage_); |
10082 Handle<SeededNumberDictionary> slow_storage( | 10090 Handle<SeededNumberDictionary> slow_storage( |
10083 SeededNumberDictionary::New(isolate_, current_storage->length())); | 10091 SeededNumberDictionary::New(isolate_, current_storage->length())); |
10084 uint32_t current_length = static_cast<uint32_t>(current_storage->length()); | 10092 uint32_t current_length = static_cast<uint32_t>(current_storage->length()); |
10085 for (uint32_t i = 0; i < current_length; i++) { | 10093 for (uint32_t i = 0; i < current_length; i++) { |
10086 HandleScope loop_scope(isolate_); | 10094 HandleScope loop_scope(isolate_); |
10087 Handle<Object> element(current_storage->get(i), isolate_); | 10095 Handle<Object> element(current_storage->get(i), isolate_); |
10088 if (!element->IsTheHole()) { | 10096 if (!element->IsTheHole()) { |
10089 Handle<SeededNumberDictionary> new_storage = | 10097 Handle<SeededNumberDictionary> new_storage = |
(...skipping 5123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15213 } | 15221 } |
15214 return NULL; | 15222 return NULL; |
15215 } | 15223 } |
15216 | 15224 |
15217 | 15225 |
15218 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15226 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15219 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15227 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15220 } | 15228 } |
15221 | 15229 |
15222 } } // namespace v8::internal | 15230 } } // namespace v8::internal |
OLD | NEW |