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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 HandleScope scope(isolate); | 461 HandleScope scope(isolate); |
462 | 462 |
463 Handle<JSTypedArray> array; | 463 Handle<JSTypedArray> array; |
464 const char* method = "%TypedArray%.prototype.includes"; | 464 const char* method = "%TypedArray%.prototype.includes"; |
465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
466 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | 466 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
467 | 467 |
468 if (args.length() < 2) return isolate->heap()->false_value(); | 468 if (args.length() < 2) return isolate->heap()->false_value(); |
469 | 469 |
470 int64_t len = array->length_value(); | 470 int64_t len = array->length_value(); |
471 | |
472 if (len == 0) return isolate->heap()->false_value(); | 471 if (len == 0) return isolate->heap()->false_value(); |
473 | 472 |
474 int64_t index = 0; | 473 int64_t index = 0; |
475 if (args.length() > 2) { | 474 if (args.length() > 2) { |
476 Handle<Object> num; | 475 Handle<Object> num; |
477 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 476 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
478 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); | 477 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); |
479 index = CapRelativeIndex(num, 0, len); | 478 index = CapRelativeIndex(num, 0, len); |
480 } | 479 } |
481 | 480 |
482 Handle<Object> search_element = args.at<Object>(1); | 481 Handle<Object> search_element = args.at<Object>(1); |
483 ElementsAccessor* elements = array->GetElementsAccessor(); | 482 ElementsAccessor* elements = array->GetElementsAccessor(); |
484 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, | 483 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, |
485 static_cast<uint32_t>(index), | 484 static_cast<uint32_t>(index), |
486 static_cast<uint32_t>(len)); | 485 static_cast<uint32_t>(len)); |
487 return *isolate->factory()->ToBoolean(result.FromJust()); | 486 return *isolate->factory()->ToBoolean(result.FromJust()); |
488 } | 487 } |
489 | 488 |
489 BUILTIN(TypedArrayPrototypeIndexOf) { | |
490 HandleScope scope(isolate); | |
491 | |
492 Handle<JSTypedArray> array; | |
493 const char* method = "%TypedArray%.prototype.indexOf"; | |
494 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
495 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | |
496 | |
497 int64_t len = array->length_value(); | |
498 if (len == 0) return Smi::FromInt(-1); | |
499 | |
500 int64_t index = 0; | |
501 if (args.length() > 2) { | |
502 Handle<Object> num; | |
503 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
504 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); | |
505 index = CapRelativeIndex(num, 0, len); | |
506 } | |
507 | |
Camillo Bruni
2017/03/07 08:45:34
Could you do the IsNeutered check here?
Ultimatel
Choongwoo Han
2017/03/07 09:29:35
Done. I also added neutering check for TA.p.includ
| |
508 Handle<Object> search_element = args.at<Object>(1); | |
509 ElementsAccessor* elements = array->GetElementsAccessor(); | |
510 Maybe<int64_t> result = elements->IndexOfValue(isolate, array, search_element, | |
511 static_cast<uint32_t>(index), | |
512 static_cast<uint32_t>(len)); | |
513 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); | |
514 } | |
515 | |
490 } // namespace internal | 516 } // namespace internal |
491 } // namespace v8 | 517 } // namespace v8 |
OLD | NEW |