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 const char* kMethodName = "%TypedArray%.prototype.fill"; | |
477 Handle<Object> cast_value; | |
478 ElementsAccessor* elements = array->GetElementsAccessor(); | |
479 | |
480 for (uint32_t k = start; k < end; ++k) { | |
481 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
482 isolate, cast_value, Object::ToNumber(obj_value)); | |
483 // IntegerIndexedElementSet step 5 | |
484 if (V8_UNLIKELY(array->WasNeutered())) { | |
Camillo Bruni
2017/03/13 08:12:58
Can you add a "TODO(caitp,cbruni): throw on neuter
rongjie
2017/03/13 08:43:01
Done.
| |
485 THROW_NEW_ERROR_RETURN_FAILURE( | |
486 isolate, NewTypeError(MessageTemplate::kDetachedOperation, | |
487 isolate->factory()->NewStringFromAsciiChecked( | |
488 kMethodName))); | |
489 } | |
490 elements->Set(array, k, *cast_value); | |
491 } | |
492 return *array; | |
493 } | |
494 | |
473 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, | 495 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, |
474 Handle<JSObject> receiver, | 496 Handle<JSObject> receiver, |
475 Handle<Object> value, | 497 Handle<Object> value, |
476 uint32_t start_from, uint32_t length) { | 498 uint32_t start_from, uint32_t length) { |
477 bool search_for_hole = value->IsUndefined(isolate); | 499 bool search_for_hole = value->IsUndefined(isolate); |
478 for (uint32_t k = start_from; k < length; ++k) { | 500 for (uint32_t k = start_from; k < length; ++k) { |
479 LookupIterator it(isolate, receiver, k); | 501 LookupIterator it(isolate, receiver, k); |
480 if (!it.IsFound()) { | 502 if (!it.IsFound()) { |
481 if (search_for_hole) return Just(true); | 503 if (search_for_hole) return Just(true); |
482 continue; | 504 continue; |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 | 1206 |
1185 static uint32_t GetCapacityImpl(JSObject* holder, | 1207 static uint32_t GetCapacityImpl(JSObject* holder, |
1186 FixedArrayBase* backing_store) { | 1208 FixedArrayBase* backing_store) { |
1187 return backing_store->length(); | 1209 return backing_store->length(); |
1188 } | 1210 } |
1189 | 1211 |
1190 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { | 1212 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { |
1191 return Subclass::GetCapacityImpl(holder, backing_store); | 1213 return Subclass::GetCapacityImpl(holder, backing_store); |
1192 } | 1214 } |
1193 | 1215 |
1216 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver, | |
1217 Handle<Object> obj_value, uint32_t start, uint32_t end) { | |
1218 UNREACHABLE(); | |
1219 return *receiver; | |
1220 } | |
1221 | |
1222 Object* Fill(Isolate* isolate, Handle<JSObject> receiver, | |
1223 Handle<Object> obj_value, uint32_t start, uint32_t end) { | |
1224 return Subclass::FillImpl(isolate, receiver, obj_value, start, end); | |
1225 } | |
1226 | |
1194 static Maybe<bool> IncludesValueImpl(Isolate* isolate, | 1227 static Maybe<bool> IncludesValueImpl(Isolate* isolate, |
1195 Handle<JSObject> receiver, | 1228 Handle<JSObject> receiver, |
1196 Handle<Object> value, | 1229 Handle<Object> value, |
1197 uint32_t start_from, uint32_t length) { | 1230 uint32_t start_from, uint32_t length) { |
1198 return IncludesValueSlowPath(isolate, receiver, value, start_from, length); | 1231 return IncludesValueSlowPath(isolate, receiver, value, start_from, length); |
1199 } | 1232 } |
1200 | 1233 |
1201 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver, | 1234 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver, |
1202 Handle<Object> value, uint32_t start_from, | 1235 Handle<Object> value, uint32_t start_from, |
1203 uint32_t length) final { | 1236 uint32_t length) final { |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2808 if (get_entries) { | 2841 if (get_entries) { |
2809 value = MakeEntryPair(isolate, index, value); | 2842 value = MakeEntryPair(isolate, index, value); |
2810 } | 2843 } |
2811 values_or_entries->set(count++, *value); | 2844 values_or_entries->set(count++, *value); |
2812 } | 2845 } |
2813 } | 2846 } |
2814 *nof_items = count; | 2847 *nof_items = count; |
2815 return Just(true); | 2848 return Just(true); |
2816 } | 2849 } |
2817 | 2850 |
2851 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver, | |
2852 Handle<Object> obj_value, uint32_t start, uint32_t end) { | |
2853 Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(receiver); | |
2854 if (obj_value->IsNumber()) { | |
Camillo Bruni
2017/03/13 08:12:58
nit: I prefer early returns and non-indented code
rongjie
2017/03/13 08:43:01
Done.
| |
2855 double value = 0.0; | |
Camillo Bruni
2017/03/13 08:12:58
ctype value = 0;
This way you can avoid an unnece
rongjie
2017/03/13 08:43:02
Done.
| |
2856 | |
2857 if (obj_value->IsSmi()) { | |
2858 value = Smi::cast(*obj_value)->value(); | |
Camillo Bruni
2017/03/13 08:12:58
value = static_cast<ctype>(Smi::cast(...));
rongjie
2017/03/13 08:43:02
Done.
| |
2859 } else { | |
2860 DCHECK(obj_value->IsHeapNumber()); | |
2861 value = HeapNumber::cast(*obj_value)->value(); | |
Camillo Bruni
2017/03/13 08:12:58
same here..
rongjie
2017/03/13 08:43:01
Done.
| |
2862 } | |
2863 if (array->type() == kExternalUint8ClampedArray) { | |
2864 value = std::min<double>(std::max<double>(0, value), 255); | |
2865 } | |
2866 | |
2867 Handle<FixedTypedArrayBase> elements( | |
2868 FixedTypedArrayBase::cast(array->elements())); | |
2869 ctype* data = static_cast<ctype*>(elements->DataPtr()); | |
2870 ctype cast_value = static_cast<ctype>(value); | |
2871 std::fill(data + start, data + end, cast_value); | |
Camillo Bruni
2017/03/13 08:12:58
Please add DCHECKS here as well for the range para
rongjie
2017/03/13 08:43:01
To ensure array->length_value() is not executed in
| |
2872 return *array; | |
2873 } else { | |
2874 return FillNumberSlowPath(isolate, array, obj_value, start, end); | |
2875 } | |
2876 } | |
2877 | |
2818 static Maybe<bool> IncludesValueImpl(Isolate* isolate, | 2878 static Maybe<bool> IncludesValueImpl(Isolate* isolate, |
2819 Handle<JSObject> receiver, | 2879 Handle<JSObject> receiver, |
2820 Handle<Object> value, | 2880 Handle<Object> value, |
2821 uint32_t start_from, uint32_t length) { | 2881 uint32_t start_from, uint32_t length) { |
2822 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); | 2882 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); |
2823 DisallowHeapAllocation no_gc; | 2883 DisallowHeapAllocation no_gc; |
2824 | 2884 |
2825 // TODO(caitp): return Just(false) here when implementing strict throwing on | 2885 // TODO(caitp): return Just(false) here when implementing strict throwing on |
2826 // neutered views. | 2886 // neutered views. |
2827 if (WasNeutered(*receiver)) { | 2887 if (WasNeutered(*receiver)) { |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3865 insertion_index += len; | 3925 insertion_index += len; |
3866 } | 3926 } |
3867 | 3927 |
3868 DCHECK_EQ(insertion_index, result_len); | 3928 DCHECK_EQ(insertion_index, result_len); |
3869 return result_array; | 3929 return result_array; |
3870 } | 3930 } |
3871 | 3931 |
3872 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3932 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
3873 } // namespace internal | 3933 } // namespace internal |
3874 } // namespace v8 | 3934 } // namespace v8 |
OLD | NEW |