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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1212 return IndexOfValueSlowPath(isolate, receiver, value, start_from, length); | 1212 return IndexOfValueSlowPath(isolate, receiver, value, start_from, length); |
1213 } | 1213 } |
1214 | 1214 |
1215 Maybe<int64_t> IndexOfValue(Isolate* isolate, Handle<JSObject> receiver, | 1215 Maybe<int64_t> IndexOfValue(Isolate* isolate, Handle<JSObject> receiver, |
1216 Handle<Object> value, uint32_t start_from, | 1216 Handle<Object> value, uint32_t start_from, |
1217 uint32_t length) final { | 1217 uint32_t length) final { |
1218 return Subclass::IndexOfValueImpl(isolate, receiver, value, start_from, | 1218 return Subclass::IndexOfValueImpl(isolate, receiver, value, start_from, |
1219 length); | 1219 length); |
1220 } | 1220 } |
1221 | 1221 |
1222 static Maybe<int64_t> LastIndexOfValueImpl(Isolate* isolate, | |
1223 Handle<JSObject> receiver, | |
1224 Handle<Object> value, | |
1225 int64_t start_from) { | |
1226 UNREACHABLE(); | |
1227 } | |
1228 | |
1229 Maybe<int64_t> LastIndexOfValue(Isolate* isolate, Handle<JSObject> receiver, | |
1230 Handle<Object> value, | |
1231 int64_t start_from) final { | |
1232 return Subclass::LastIndexOfValueImpl(isolate, receiver, value, start_from); | |
1233 } | |
1234 | |
1222 static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store, | 1235 static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store, |
1223 uint32_t entry) { | 1236 uint32_t entry) { |
1224 return entry; | 1237 return entry; |
1225 } | 1238 } |
1226 | 1239 |
1227 static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder, | 1240 static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder, |
1228 FixedArrayBase* backing_store, | 1241 FixedArrayBase* backing_store, |
1229 uint32_t index, PropertyFilter filter) { | 1242 uint32_t index, PropertyFilter filter) { |
1230 uint32_t length = Subclass::GetMaxIndex(holder, backing_store); | 1243 uint32_t length = Subclass::GetMaxIndex(holder, backing_store); |
1231 if (IsHoleyElementsKind(kind())) { | 1244 if (IsHoleyElementsKind(kind())) { |
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2908 if (static_cast<double>(typed_search_value) != search_value) { | 2921 if (static_cast<double>(typed_search_value) != search_value) { |
2909 return Just<int64_t>(-1); // Loss of precision. | 2922 return Just<int64_t>(-1); // Loss of precision. |
2910 } | 2923 } |
2911 | 2924 |
2912 for (uint32_t k = start_from; k < length; ++k) { | 2925 for (uint32_t k = start_from; k < length; ++k) { |
2913 ctype element_k = elements->get_scalar(k); | 2926 ctype element_k = elements->get_scalar(k); |
2914 if (element_k == typed_search_value) return Just<int64_t>(k); | 2927 if (element_k == typed_search_value) return Just<int64_t>(k); |
2915 } | 2928 } |
2916 return Just<int64_t>(-1); | 2929 return Just<int64_t>(-1); |
2917 } | 2930 } |
2931 | |
2932 static Maybe<int64_t> LastIndexOfValueImpl(Isolate* isolate, | |
2933 Handle<JSObject> receiver, | |
2934 Handle<Object> value, | |
2935 int64_t start_from) { | |
2936 DisallowHeapAllocation no_gc; | |
Camillo Bruni
2017/03/14 09:58:21
I think we can just do
DCHECK(WasNeutered(*receive
Choongwoo Han
2017/03/14 16:12:31
Done.
| |
2937 | |
2938 if (WasNeutered(*receiver) || !value->IsNumber()) return Just<int64_t>(-1); | |
2939 BackingStore* elements = BackingStore::cast(receiver->elements()); | |
2940 | |
2941 double search_value = value->Number(); | |
2942 | |
2943 if (!std::isfinite(search_value)) { | |
2944 if (!std::is_integral<ctype>::value) { | |
2945 // Integral types cannot represent +Inf or NaN. | |
2946 return Just<int64_t>(-1); | |
2947 } else if (std::isnan(search_value)) { | |
2948 // Strict Equality Comparison of NaN is always false. | |
2949 return Just<int64_t>(-1); | |
2950 } | |
2951 } else if (search_value < std::numeric_limits<ctype>::lowest() || | |
2952 search_value > std::numeric_limits<ctype>::max()) { | |
2953 // Return -1 if value can't be represented in this ElementsKind. | |
2954 return Just<int64_t>(-1); | |
2955 } | |
2956 | |
2957 ctype typed_search_value = static_cast<ctype>(search_value); | |
2958 if (static_cast<double>(typed_search_value) != search_value) { | |
2959 return Just<int64_t>(-1); // Loss of precision. | |
2960 } | |
2961 | |
2962 DCHECK_LT(start_from, elements->length()); | |
2963 | |
2964 for (int64_t k = start_from; k >= 0; --k) { | |
2965 ctype element_k = elements->get_scalar(k); | |
2966 if (element_k == typed_search_value) return Just<int64_t>(k); | |
2967 } | |
2968 return Just<int64_t>(-1); | |
2969 } | |
2918 }; | 2970 }; |
2919 | 2971 |
2920 #define FIXED_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \ | 2972 #define FIXED_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \ |
2921 typedef TypedElementsAccessor<TYPE##_ELEMENTS, ctype> \ | 2973 typedef TypedElementsAccessor<TYPE##_ELEMENTS, ctype> \ |
2922 Fixed##Type##ElementsAccessor; | 2974 Fixed##Type##ElementsAccessor; |
2923 | 2975 |
2924 TYPED_ARRAYS(FIXED_ELEMENTS_ACCESSOR) | 2976 TYPED_ARRAYS(FIXED_ELEMENTS_ACCESSOR) |
2925 #undef FIXED_ELEMENTS_ACCESSOR | 2977 #undef FIXED_ELEMENTS_ACCESSOR |
2926 | 2978 |
2927 template <typename Subclass, typename ArgumentsAccessor, typename KindTraits> | 2979 template <typename Subclass, typename ArgumentsAccessor, typename KindTraits> |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3863 insertion_index += len; | 3915 insertion_index += len; |
3864 } | 3916 } |
3865 | 3917 |
3866 DCHECK_EQ(insertion_index, result_len); | 3918 DCHECK_EQ(insertion_index, result_len); |
3867 return result_array; | 3919 return result_array; |
3868 } | 3920 } |
3869 | 3921 |
3870 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3922 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
3871 } // namespace internal | 3923 } // namespace internal |
3872 } // namespace v8 | 3924 } // namespace v8 |
OLD | NEW |