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 |
481 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin. | |
482 if (V8_UNLIKELY(array->WasNeutered())) return isolate->heap()->false_value(); | |
483 | |
482 Handle<Object> search_element = args.at<Object>(1); | 484 Handle<Object> search_element = args.at<Object>(1); |
483 ElementsAccessor* elements = array->GetElementsAccessor(); | 485 ElementsAccessor* elements = array->GetElementsAccessor(); |
484 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, | 486 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, |
485 static_cast<uint32_t>(index), | 487 static_cast<uint32_t>(index), |
486 static_cast<uint32_t>(len)); | 488 static_cast<uint32_t>(len)); |
489 MAYBE_RETURN(result, isolate->heap()->exception()); | |
Camillo Bruni
2017/03/07 13:59:53
Technically not necessary, given that you can only
| |
487 return *isolate->factory()->ToBoolean(result.FromJust()); | 490 return *isolate->factory()->ToBoolean(result.FromJust()); |
488 } | 491 } |
489 | 492 |
493 BUILTIN(TypedArrayPrototypeIndexOf) { | |
494 HandleScope scope(isolate); | |
495 | |
496 Handle<JSTypedArray> array; | |
497 const char* method = "%TypedArray%.prototype.indexOf"; | |
498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
499 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | |
500 | |
501 int64_t len = array->length_value(); | |
502 if (len == 0) return Smi::FromInt(-1); | |
503 | |
504 int64_t index = 0; | |
505 if (args.length() > 2) { | |
506 Handle<Object> num; | |
507 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
508 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); | |
509 index = CapRelativeIndex(num, 0, len); | |
510 } | |
511 | |
512 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin. | |
513 if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1); | |
514 | |
515 Handle<Object> search_element = args.at<Object>(1); | |
516 ElementsAccessor* elements = array->GetElementsAccessor(); | |
517 Maybe<int64_t> result = elements->IndexOfValue(isolate, array, search_element, | |
518 static_cast<uint32_t>(index), | |
519 static_cast<uint32_t>(len)); | |
520 MAYBE_RETURN(result, isolate->heap()->exception()); | |
521 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); | |
522 } | |
523 | |
490 } // namespace internal | 524 } // namespace internal |
491 } // namespace v8 | 525 } // namespace v8 |
OLD | NEW |