Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
| 7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
| 8 #include "src/counters.h" | 8 #include "src/counters.h" |
| 9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
| 10 | 10 |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 to = to * element_size; | 449 to = to * element_size; |
| 450 from = from * element_size; | 450 from = from * element_size; |
| 451 count = count * element_size; | 451 count = count * element_size; |
| 452 | 452 |
| 453 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 453 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
| 454 std::memmove(data + to, data + from, count); | 454 std::memmove(data + to, data + from, count); |
| 455 | 455 |
| 456 return *array; | 456 return *array; |
| 457 } | 457 } |
| 458 | 458 |
| 459 BUILTIN(TypedArrayPrototypeFill) { | |
| 460 HandleScope scope(isolate); | |
| 461 | |
| 462 Handle<JSTypedArray> array; | |
| 463 const char* method = "%TypedArray%.prototype.fill"; | |
| 464 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 465 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | |
| 466 | |
| 467 if (V8_UNLIKELY(array->WasNeutered())) return *array; | |
|
Camillo Bruni
2017/03/06 09:13:44
This check has to happen after all the argument co
rongjie
2017/03/06 10:35:49
Done.
| |
| 468 | |
| 469 int64_t len = array->length_value(); | |
| 470 int64_t start = 0; | |
| 471 int64_t end = len; | |
| 472 double fp = 0.0; | |
|
Camillo Bruni
2017/03/06 09:13:44
nit: please use proper variable names, fp is kind
rongjie
2017/03/06 10:35:49
Done.
| |
| 473 | |
| 474 if (V8_LIKELY(args.length() > 1)) { | |
| 475 Handle<Object> num; | |
| 476 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 477 isolate, num, Object::ToNumber(args.at<Object>(1))); | |
|
Camillo Bruni
2017/03/06 09:13:44
You cannot simply do a ToNumber on the value input
| |
| 478 | |
| 479 if (num->IsSmi()) { | |
| 480 fp = Smi::cast(*num)->value(); | |
| 481 } else { | |
| 482 DCHECK(num->IsHeapNumber()); | |
| 483 fp = HeapNumber::cast(*num)->value(); | |
| 484 } | |
| 485 if (array->type() == kExternalUint8ClampedArray) { | |
| 486 fp = std::min<double>(std::max<double>(0, fp), 255); | |
| 487 } | |
|
rongjie
2017/03/04 07:24:46
Casting integer to and from double might cause los
| |
| 488 | |
| 489 Handle<Object> optional = args.atOrUndefined(isolate, 2); | |
| 490 if (!optional->IsUndefined(isolate)) { | |
| 491 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 492 isolate, num, Object::ToInteger(isolate, optional)); | |
| 493 start = CapRelativeIndex(num, 0, len); | |
| 494 | |
| 495 optional = args.atOrUndefined(isolate, 3); | |
| 496 if (!optional->IsUndefined(isolate)) { | |
| 497 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 498 isolate, num, Object::ToInteger(isolate, optional)); | |
| 499 end = CapRelativeIndex(num, 0, len); | |
| 500 } | |
| 501 } | |
| 502 } | |
| 503 | |
| 504 int64_t count = end - start; | |
| 505 if (count <= 0) return *array; | |
| 506 | |
| 507 if (V8_UNLIKELY(array->WasNeutered())) return *array; | |
| 508 | |
| 509 // Ensure processed indexes are within array bounds | |
| 510 DCHECK_GE(start, 0); | |
| 511 DCHECK_LT(start, len); | |
| 512 DCHECK_GE(end, 0); | |
| 513 DCHECK_LE(end, len); | |
| 514 DCHECK_LE(count, len); | |
| 515 | |
| 516 switch (array->type()) { | |
| 517 #define TYPED_ARRAY_FILL(Type, type, TYPE, ctype, size) \ | |
| 518 case kExternal##Type##Array: { \ | |
| 519 ctype* backing_store = \ | |
| 520 static_cast<ctype*>(array->GetBuffer()->backing_store()); \ | |
| 521 ctype cast_value = static_cast<ctype>(fp); \ | |
| 522 std::fill(backing_store + start, backing_store + end, cast_value); \ | |
| 523 break; \ | |
| 524 } | |
| 525 | |
| 526 TYPED_ARRAYS(TYPED_ARRAY_FILL) | |
| 527 #undef TYPED_ARRAY_FILL | |
| 528 } | |
| 529 | |
| 530 return *array; | |
| 531 } | |
| 532 | |
| 459 } // namespace internal | 533 } // namespace internal |
| 460 } // namespace v8 | 534 } // namespace v8 |
| OLD | NEW |