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/objects-inl.h" | 10 #include "src/objects-inl.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 | 14 |
14 class TypedArrayBuiltinsAssembler : public CodeStubAssembler { | 15 class TypedArrayBuiltinsAssembler : public CodeStubAssembler { |
15 public: | 16 public: |
16 explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state) | 17 explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state) |
17 : CodeStubAssembler(state) {} | 18 : CodeStubAssembler(state) {} |
18 | 19 |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 to = to * element_size; | 450 to = to * element_size; |
450 from = from * element_size; | 451 from = from * element_size; |
451 count = count * element_size; | 452 count = count * element_size; |
452 | 453 |
453 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 454 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
454 std::memmove(data + to, data + from, count); | 455 std::memmove(data + to, data + from, count); |
455 | 456 |
456 return *array; | 457 return *array; |
457 } | 458 } |
458 | 459 |
| 460 BUILTIN(TypedArrayPrototypeIncludes) { |
| 461 HandleScope scope(isolate); |
| 462 |
| 463 Handle<JSTypedArray> array; |
| 464 const char* method = "%TypedArray%.prototype.includes"; |
| 465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 466 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
| 467 |
| 468 if (args.length() < 2) return isolate->heap()->false_value(); |
| 469 |
| 470 int64_t len = array->length_value(); |
| 471 |
| 472 if (len == 0) return isolate->heap()->false_value(); |
| 473 |
| 474 int64_t index = 0; |
| 475 if (args.length() > 2) { |
| 476 Handle<Object> num; |
| 477 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 478 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); |
| 479 index = CapRelativeIndex(num, 0, len); |
| 480 } |
| 481 |
| 482 Handle<Object> search_element = args.at<Object>(1); |
| 483 ElementsAccessor* elements = array->GetElementsAccessor(); |
| 484 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, |
| 485 static_cast<uint32_t>(index), |
| 486 static_cast<uint32_t>(len)); |
| 487 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 488 } |
| 489 |
459 } // namespace internal | 490 } // namespace internal |
460 } // namespace v8 | 491 } // namespace v8 |
OLD | NEW |