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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 to = to * element_size; | 514 to = to * element_size; |
515 from = from * element_size; | 515 from = from * element_size; |
516 count = count * element_size; | 516 count = count * element_size; |
517 | 517 |
518 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 518 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
519 std::memmove(data + to, data + from, count); | 519 std::memmove(data + to, data + from, count); |
520 | 520 |
521 return *array; | 521 return *array; |
522 } | 522 } |
523 | 523 |
| 524 BUILTIN(TypedArrayPrototypeFill) { |
| 525 HandleScope scope(isolate); |
| 526 |
| 527 Handle<JSTypedArray> array; |
| 528 const char* method = "%TypedArray%.prototype.fill"; |
| 529 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 530 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
| 531 |
| 532 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 533 |
| 534 int64_t len = array->length_value(); |
| 535 int64_t start = 0; |
| 536 int64_t end = len; |
| 537 |
| 538 if (args.length() > 2) { |
| 539 Handle<Object> num = args.atOrUndefined(isolate, 2); |
| 540 if (!num->IsUndefined(isolate)) { |
| 541 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 542 isolate, num, Object::ToInteger(isolate, num)); |
| 543 start = CapRelativeIndex(num, 0, len); |
| 544 |
| 545 num = args.atOrUndefined(isolate, 3); |
| 546 if (!num->IsUndefined(isolate)) { |
| 547 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 548 isolate, num, Object::ToInteger(isolate, num)); |
| 549 end = CapRelativeIndex(num, 0, len); |
| 550 } |
| 551 } |
| 552 } |
| 553 |
| 554 int64_t count = end - start; |
| 555 if (count <= 0) return *array; |
| 556 |
| 557 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 558 |
| 559 // Ensure processed indexes are within array bounds |
| 560 DCHECK_GE(start, 0); |
| 561 DCHECK_LT(start, len); |
| 562 DCHECK_GE(end, 0); |
| 563 DCHECK_LE(end, len); |
| 564 DCHECK_LE(count, len); |
| 565 |
| 566 Handle<Object> obj_value = args.atOrUndefined(isolate, 1); |
| 567 |
| 568 return array->GetElementsAccessor()->Fill(isolate, array, obj_value, |
| 569 static_cast<uint32_t>(start), |
| 570 static_cast<uint32_t>(end)); |
| 571 } |
| 572 |
524 BUILTIN(TypedArrayPrototypeIncludes) { | 573 BUILTIN(TypedArrayPrototypeIncludes) { |
525 HandleScope scope(isolate); | 574 HandleScope scope(isolate); |
526 | 575 |
527 Handle<JSTypedArray> array; | 576 Handle<JSTypedArray> array; |
528 const char* method = "%TypedArray%.prototype.includes"; | 577 const char* method = "%TypedArray%.prototype.includes"; |
529 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 578 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
530 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | 579 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
531 | 580 |
532 if (args.length() < 2) return isolate->heap()->false_value(); | 581 if (args.length() < 2) return isolate->heap()->false_value(); |
533 | 582 |
(...skipping 12 matching lines...) Expand all Loading... |
546 Handle<Object> search_element = args.at<Object>(1); | 595 Handle<Object> search_element = args.at<Object>(1); |
547 ElementsAccessor* elements = array->GetElementsAccessor(); | 596 ElementsAccessor* elements = array->GetElementsAccessor(); |
548 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, | 597 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, |
549 static_cast<uint32_t>(index), | 598 static_cast<uint32_t>(index), |
550 static_cast<uint32_t>(len)); | 599 static_cast<uint32_t>(len)); |
551 return *isolate->factory()->ToBoolean(result.FromJust()); | 600 return *isolate->factory()->ToBoolean(result.FromJust()); |
552 } | 601 } |
553 | 602 |
554 } // namespace internal | 603 } // namespace internal |
555 } // namespace v8 | 604 } // namespace v8 |
OLD | NEW |