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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 } cmp; | 463 } cmp; |
464 Object** start = | 464 Object** start = |
465 reinterpret_cast<Object**>(indices->GetFirstElementAddress()); | 465 reinterpret_cast<Object**>(indices->GetFirstElementAddress()); |
466 std::sort(start, start + sort_size, cmp); | 466 std::sort(start, start + sort_size, cmp); |
467 if (write_barrier_mode != SKIP_WRITE_BARRIER) { | 467 if (write_barrier_mode != SKIP_WRITE_BARRIER) { |
468 FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(indices->GetIsolate()->heap(), *indices, | 468 FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(indices->GetIsolate()->heap(), *indices, |
469 0, sort_size); | 469 0, sort_size); |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 static Object* FillNumberSlowPath(Isolate* isolate, Handle<JSTypedArray> array, | |
474 Handle<Object> obj_value, | |
475 uint32_t start, uint32_t end) { | |
476 Handle<Object> cast_value; | |
477 ElementsAccessor* elements = array->GetElementsAccessor(); | |
478 | |
479 for (uint32_t k = start; k < end; ++k) { | |
480 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
481 isolate, cast_value, Object::ToNumber(obj_value)); | |
482 // TODO(caitp,cbruni): throw on neutered array | |
483 if (V8_UNLIKELY(array->WasNeutered())) return *array; | |
484 elements->Set(array, k, *cast_value); | |
485 } | |
486 return *array; | |
487 } | |
488 | |
473 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, | 489 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, |
474 Handle<JSObject> receiver, | 490 Handle<JSObject> receiver, |
475 Handle<Object> value, | 491 Handle<Object> value, |
476 uint32_t start_from, uint32_t length) { | 492 uint32_t start_from, uint32_t length) { |
477 bool search_for_hole = value->IsUndefined(isolate); | 493 bool search_for_hole = value->IsUndefined(isolate); |
478 for (uint32_t k = start_from; k < length; ++k) { | 494 for (uint32_t k = start_from; k < length; ++k) { |
479 LookupIterator it(isolate, receiver, k); | 495 LookupIterator it(isolate, receiver, k); |
480 if (!it.IsFound()) { | 496 if (!it.IsFound()) { |
481 if (search_for_hole) return Just(true); | 497 if (search_for_hole) return Just(true); |
482 continue; | 498 continue; |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 | 1200 |
1185 static uint32_t GetCapacityImpl(JSObject* holder, | 1201 static uint32_t GetCapacityImpl(JSObject* holder, |
1186 FixedArrayBase* backing_store) { | 1202 FixedArrayBase* backing_store) { |
1187 return backing_store->length(); | 1203 return backing_store->length(); |
1188 } | 1204 } |
1189 | 1205 |
1190 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { | 1206 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { |
1191 return Subclass::GetCapacityImpl(holder, backing_store); | 1207 return Subclass::GetCapacityImpl(holder, backing_store); |
1192 } | 1208 } |
1193 | 1209 |
1210 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver, | |
1211 Handle<Object> obj_value, uint32_t start, | |
1212 uint32_t end) { | |
1213 UNREACHABLE(); | |
1214 return *receiver; | |
1215 } | |
1216 | |
1217 Object* Fill(Isolate* isolate, Handle<JSObject> receiver, | |
1218 Handle<Object> obj_value, uint32_t start, uint32_t end) { | |
1219 return Subclass::FillImpl(isolate, receiver, obj_value, start, end); | |
1220 } | |
1221 | |
1194 static Maybe<bool> IncludesValueImpl(Isolate* isolate, | 1222 static Maybe<bool> IncludesValueImpl(Isolate* isolate, |
1195 Handle<JSObject> receiver, | 1223 Handle<JSObject> receiver, |
1196 Handle<Object> value, | 1224 Handle<Object> value, |
1197 uint32_t start_from, uint32_t length) { | 1225 uint32_t start_from, uint32_t length) { |
1198 return IncludesValueSlowPath(isolate, receiver, value, start_from, length); | 1226 return IncludesValueSlowPath(isolate, receiver, value, start_from, length); |
1199 } | 1227 } |
1200 | 1228 |
1201 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver, | 1229 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver, |
1202 Handle<Object> value, uint32_t start_from, | 1230 Handle<Object> value, uint32_t start_from, |
1203 uint32_t length) final { | 1231 uint32_t length) final { |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2808 if (get_entries) { | 2836 if (get_entries) { |
2809 value = MakeEntryPair(isolate, index, value); | 2837 value = MakeEntryPair(isolate, index, value); |
2810 } | 2838 } |
2811 values_or_entries->set(count++, *value); | 2839 values_or_entries->set(count++, *value); |
2812 } | 2840 } |
2813 } | 2841 } |
2814 *nof_items = count; | 2842 *nof_items = count; |
2815 return Just(true); | 2843 return Just(true); |
2816 } | 2844 } |
2817 | 2845 |
2846 static inline uint8_t ConvertNumberToUint8Clamped(Handle<Object> obj_value) { | |
Camillo Bruni
2017/03/20 10:20:22
I just realized that we can simplify this further
rongjie
2017/03/20 12:05:24
Done.
| |
2847 if (obj_value->IsSmi()) { | |
2848 int value = Smi::cast(*obj_value)->value(); | |
2849 return FixedTypedArray<Uint8ClampedArrayTraits>::from_int(value); | |
2850 } else { | |
2851 DCHECK(obj_value->IsHeapNumber()); | |
2852 double value = HeapNumber::cast(*obj_value)->value(); | |
2853 return FixedTypedArray<Uint8ClampedArrayTraits>::from_double(value); | |
2854 } | |
2855 } | |
2856 | |
2857 static inline ctype ConvertToNumber(Handle<Object> obj_value) { | |
2858 ctype value = 0; | |
2859 if (obj_value->IsSmi()) { | |
2860 value = static_cast<ctype>(Smi::cast(*obj_value)->value()); | |
Camillo Bruni
2017/03/20 10:20:22
value = BackingStore::from_int(value);
rongjie
2017/03/20 12:05:24
Done.
| |
2861 } else { | |
2862 DCHECK(obj_value->IsHeapNumber()); | |
2863 value = static_cast<ctype>(HeapNumber::cast(*obj_value)->value()); | |
Camillo Bruni
2017/03/20 10:20:22
value = BackingStore::from_double(value);
rongjie
2017/03/20 12:05:24
Done.
| |
2864 } | |
2865 return value; | |
2866 } | |
2867 | |
2868 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver, | |
2869 Handle<Object> obj_value, uint32_t start, | |
2870 uint32_t end) { | |
2871 Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(receiver); | |
2872 DCHECK(!array->WasNeutered()); | |
2873 | |
2874 if (!obj_value->IsNumber()) { | |
2875 return FillNumberSlowPath(isolate, array, obj_value, start, end); | |
2876 } | |
2877 | |
2878 ctype value = 0; | |
2879 if (Kind == UINT8_CLAMPED_ELEMENTS) { | |
Camillo Bruni
2017/03/20 10:20:22
Drop the UINT8_CLAMPED_ELEMENTS check and use the
rongjie
2017/03/20 12:05:24
Done.
| |
2880 value = ConvertNumberToUint8Clamped(obj_value); | |
2881 } else { | |
2882 value = ConvertToNumber(obj_value); | |
2883 } | |
2884 | |
2885 // Ensure indexes are within array bounds | |
2886 DCHECK_LE(0, start); | |
2887 DCHECK_LE(start, end); | |
2888 DCHECK_LE(end, array->length_value()); | |
2889 | |
2890 DisallowHeapAllocation no_gc; | |
2891 BackingStore* elements = BackingStore::cast(receiver->elements()); | |
2892 ctype* data = static_cast<ctype*>(elements->DataPtr()); | |
2893 std::fill(data + start, data + end, value); | |
2894 return *array; | |
2895 } | |
2896 | |
2818 static Maybe<bool> IncludesValueImpl(Isolate* isolate, | 2897 static Maybe<bool> IncludesValueImpl(Isolate* isolate, |
2819 Handle<JSObject> receiver, | 2898 Handle<JSObject> receiver, |
2820 Handle<Object> value, | 2899 Handle<Object> value, |
2821 uint32_t start_from, uint32_t length) { | 2900 uint32_t start_from, uint32_t length) { |
2822 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); | 2901 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); |
2823 DisallowHeapAllocation no_gc; | 2902 DisallowHeapAllocation no_gc; |
2824 | 2903 |
2825 // TODO(caitp): return Just(false) here when implementing strict throwing on | 2904 // TODO(caitp): return Just(false) here when implementing strict throwing on |
2826 // neutered views. | 2905 // neutered views. |
2827 if (WasNeutered(*receiver)) { | 2906 if (WasNeutered(*receiver)) { |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3865 insertion_index += len; | 3944 insertion_index += len; |
3866 } | 3945 } |
3867 | 3946 |
3868 DCHECK_EQ(insertion_index, result_len); | 3947 DCHECK_EQ(insertion_index, result_len); |
3869 return result_array; | 3948 return result_array; |
3870 } | 3949 } |
3871 | 3950 |
3872 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3951 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
3873 } // namespace internal | 3952 } // namespace internal |
3874 } // namespace v8 | 3953 } // namespace v8 |
OLD | NEW |