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 "src/elements.h" | 5 #include "src/elements.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2969 | 2969 |
2970 | 2970 |
2971 void ElementsAccessor::TearDown() { | 2971 void ElementsAccessor::TearDown() { |
2972 if (elements_accessors_ == NULL) return; | 2972 if (elements_accessors_ == NULL) return; |
2973 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; | 2973 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; |
2974 ELEMENTS_LIST(ACCESSOR_DELETE) | 2974 ELEMENTS_LIST(ACCESSOR_DELETE) |
2975 #undef ACCESSOR_DELETE | 2975 #undef ACCESSOR_DELETE |
2976 elements_accessors_ = NULL; | 2976 elements_accessors_ = NULL; |
2977 } | 2977 } |
2978 | 2978 |
2979 | |
2980 Handle<JSArray> ElementsAccessor::Concat(Isolate* isolate, Arguments* args, | 2979 Handle<JSArray> ElementsAccessor::Concat(Isolate* isolate, Arguments* args, |
2981 uint32_t concat_size) { | 2980 uint32_t concat_size, |
2982 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2); | 2981 uint32_t result_len) { |
2983 STATIC_ASSERT(FixedDoubleArray::kMaxLength < kHalfOfMaxInt); | 2982 ElementsKind result_elements_kind = GetInitialFastElementsKind(); |
2984 USE(kHalfOfMaxInt); | |
2985 uint32_t result_len = 0; | |
2986 bool has_raw_doubles = false; | 2983 bool has_raw_doubles = false; |
2987 ElementsKind result_elements_kind = GetInitialFastElementsKind(); | |
2988 { | 2984 { |
2989 DisallowHeapAllocation no_gc; | 2985 DisallowHeapAllocation no_gc; |
2990 bool is_holey = false; | 2986 bool is_holey = false; |
2991 // Iterate through all the arguments performing checks | |
2992 // and calculating total length. | |
2993 for (uint32_t i = 0; i < concat_size; i++) { | 2987 for (uint32_t i = 0; i < concat_size; i++) { |
2994 JSArray* array = JSArray::cast((*args)[i]); | 2988 Object* arg = (*args)[i]; |
2995 uint32_t len = 0; | 2989 ElementsKind arg_kind = JSArray::cast(arg)->GetElementsKind(); |
2996 array->length()->ToArrayLength(&len); | |
2997 | |
2998 // We shouldn't overflow when adding another len. | |
2999 result_len += len; | |
3000 DCHECK(0 <= result_len); | |
3001 DCHECK(result_len <= FixedDoubleArray::kMaxLength); | |
3002 | |
3003 ElementsKind arg_kind = array->GetElementsKind(); | |
3004 has_raw_doubles = has_raw_doubles || IsFastDoubleElementsKind(arg_kind); | 2990 has_raw_doubles = has_raw_doubles || IsFastDoubleElementsKind(arg_kind); |
3005 is_holey = is_holey || IsFastHoleyElementsKind(arg_kind); | 2991 is_holey = is_holey || IsFastHoleyElementsKind(arg_kind); |
3006 result_elements_kind = | 2992 result_elements_kind = |
3007 GetMoreGeneralElementsKind(result_elements_kind, arg_kind); | 2993 GetMoreGeneralElementsKind(result_elements_kind, arg_kind); |
3008 } | 2994 } |
3009 if (is_holey) { | 2995 if (is_holey) { |
3010 result_elements_kind = GetHoleyElementsKind(result_elements_kind); | 2996 result_elements_kind = GetHoleyElementsKind(result_elements_kind); |
3011 } | 2997 } |
3012 } | 2998 } |
3013 | 2999 |
(...skipping 24 matching lines...) Expand all Loading... |
3038 insertion_index += len; | 3024 insertion_index += len; |
3039 } | 3025 } |
3040 | 3026 |
3041 DCHECK_EQ(insertion_index, result_len); | 3027 DCHECK_EQ(insertion_index, result_len); |
3042 return result_array; | 3028 return result_array; |
3043 } | 3029 } |
3044 | 3030 |
3045 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3031 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
3046 } // namespace internal | 3032 } // namespace internal |
3047 } // namespace v8 | 3033 } // namespace v8 |
OLD | NEW |