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/elements.h" | 9 #include "src/elements.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 } // namespace | 457 } // namespace |
458 | 458 |
459 BUILTIN(TypedArrayPrototypeCopyWithin) { | 459 BUILTIN(TypedArrayPrototypeCopyWithin) { |
460 HandleScope scope(isolate); | 460 HandleScope scope(isolate); |
461 | 461 |
462 Handle<JSTypedArray> array; | 462 Handle<JSTypedArray> array; |
463 const char* method = "%TypedArray%.prototype.copyWithin"; | 463 const char* method = "%TypedArray%.prototype.copyWithin"; |
464 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 464 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
465 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | 465 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
466 | 466 |
467 if (V8_UNLIKELY(array->WasNeutered())) return *array; | |
468 | |
469 int64_t len = array->length_value(); | 467 int64_t len = array->length_value(); |
470 int64_t to = 0; | 468 int64_t to = 0; |
471 int64_t from = 0; | 469 int64_t from = 0; |
472 int64_t final = len; | 470 int64_t final = len; |
473 | 471 |
474 if (V8_LIKELY(args.length() > 1)) { | 472 if (V8_LIKELY(args.length() > 1)) { |
475 Handle<Object> num; | 473 Handle<Object> num; |
476 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 474 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
477 isolate, num, Object::ToInteger(isolate, args.at<Object>(1))); | 475 isolate, num, Object::ToInteger(isolate, args.at<Object>(1))); |
478 to = CapRelativeIndex(num, 0, len); | 476 to = CapRelativeIndex(num, 0, len); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 to = to * element_size; | 512 to = to * element_size; |
515 from = from * element_size; | 513 from = from * element_size; |
516 count = count * element_size; | 514 count = count * element_size; |
517 | 515 |
518 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 516 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
519 std::memmove(data + to, data + from, count); | 517 std::memmove(data + to, data + from, count); |
520 | 518 |
521 return *array; | 519 return *array; |
522 } | 520 } |
523 | 521 |
| 522 BUILTIN(TypedArrayPrototypeFill) { |
| 523 HandleScope scope(isolate); |
| 524 |
| 525 Handle<JSTypedArray> array; |
| 526 const char* method = "%TypedArray%.prototype.fill"; |
| 527 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 528 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
| 529 |
| 530 int64_t len = array->length_value(); |
| 531 int64_t start = 0; |
| 532 int64_t end = len; |
| 533 |
| 534 if (args.length() > 2) { |
| 535 Handle<Object> num = args.atOrUndefined(isolate, 2); |
| 536 if (!num->IsUndefined(isolate)) { |
| 537 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 538 isolate, num, Object::ToInteger(isolate, num)); |
| 539 start = CapRelativeIndex(num, 0, len); |
| 540 |
| 541 num = args.atOrUndefined(isolate, 3); |
| 542 if (!num->IsUndefined(isolate)) { |
| 543 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 544 isolate, num, Object::ToInteger(isolate, num)); |
| 545 end = CapRelativeIndex(num, 0, len); |
| 546 } |
| 547 } |
| 548 } |
| 549 |
| 550 int64_t count = end - start; |
| 551 if (count <= 0) return *array; |
| 552 |
| 553 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 554 |
| 555 // Ensure processed indexes are within array bounds |
| 556 DCHECK_GE(start, 0); |
| 557 DCHECK_LT(start, len); |
| 558 DCHECK_GE(end, 0); |
| 559 DCHECK_LE(end, len); |
| 560 DCHECK_LE(count, len); |
| 561 |
| 562 Handle<Object> obj_value = args.atOrUndefined(isolate, 1); |
| 563 |
| 564 return array->GetElementsAccessor()->Fill(isolate, array, obj_value, |
| 565 static_cast<uint32_t>(start), |
| 566 static_cast<uint32_t>(end)); |
| 567 } |
| 568 |
524 BUILTIN(TypedArrayPrototypeIncludes) { | 569 BUILTIN(TypedArrayPrototypeIncludes) { |
525 HandleScope scope(isolate); | 570 HandleScope scope(isolate); |
526 | 571 |
527 Handle<JSTypedArray> array; | 572 Handle<JSTypedArray> array; |
528 const char* method = "%TypedArray%.prototype.includes"; | 573 const char* method = "%TypedArray%.prototype.includes"; |
529 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 574 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
530 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | 575 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
531 | 576 |
532 if (args.length() < 2) return isolate->heap()->false_value(); | 577 if (args.length() < 2) return isolate->heap()->false_value(); |
533 | 578 |
(...skipping 12 matching lines...) Expand all Loading... |
546 Handle<Object> search_element = args.at<Object>(1); | 591 Handle<Object> search_element = args.at<Object>(1); |
547 ElementsAccessor* elements = array->GetElementsAccessor(); | 592 ElementsAccessor* elements = array->GetElementsAccessor(); |
548 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, | 593 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, |
549 static_cast<uint32_t>(index), | 594 static_cast<uint32_t>(index), |
550 static_cast<uint32_t>(len)); | 595 static_cast<uint32_t>(len)); |
551 return *isolate->factory()->ToBoolean(result.FromJust()); | 596 return *isolate->factory()->ToBoolean(result.FromJust()); |
552 } | 597 } |
553 | 598 |
554 } // namespace internal | 599 } // namespace internal |
555 } // namespace v8 | 600 } // namespace v8 |
OLD | NEW |