Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: src/builtins/builtins-typedarray.cc

Issue 2733193002: [typedarrays] Move %TypedArray%.prototype.indexOf to C++ (Closed)
Patch Set: Add comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/typedarray.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698