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

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

Issue 2748113002: Set undefined when calling a %TypedArray%.indexOf withtout arguments (Closed)
Patch Set: 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 | « no previous file | no next file » | 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (args.length() > 2) { 538 if (args.length() > 2) {
539 Handle<Object> num; 539 Handle<Object> num;
540 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 540 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
541 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); 541 isolate, num, Object::ToInteger(isolate, args.at<Object>(2)));
542 index = CapRelativeIndex(num, 0, len); 542 index = CapRelativeIndex(num, 0, len);
543 } 543 }
544 544
545 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin. 545 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
546 if (V8_UNLIKELY(array->WasNeutered())) return isolate->heap()->false_value(); 546 if (V8_UNLIKELY(array->WasNeutered())) return isolate->heap()->false_value();
547 547
548 Handle<Object> search_element = args.at<Object>(1); 548 Handle<Object> search_element = args.atOrUndefined(isolate, 1);
549 ElementsAccessor* elements = array->GetElementsAccessor(); 549 ElementsAccessor* elements = array->GetElementsAccessor();
550 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element, 550 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element,
551 static_cast<uint32_t>(index), 551 static_cast<uint32_t>(index),
552 static_cast<uint32_t>(len)); 552 static_cast<uint32_t>(len));
553 MAYBE_RETURN(result, isolate->heap()->exception()); 553 MAYBE_RETURN(result, isolate->heap()->exception());
554 return *isolate->factory()->ToBoolean(result.FromJust()); 554 return *isolate->factory()->ToBoolean(result.FromJust());
555 } 555 }
556 556
557 BUILTIN(TypedArrayPrototypeIndexOf) { 557 BUILTIN(TypedArrayPrototypeIndexOf) {
558 HandleScope scope(isolate); 558 HandleScope scope(isolate);
(...skipping 10 matching lines...) Expand all
569 if (args.length() > 2) { 569 if (args.length() > 2) {
570 Handle<Object> num; 570 Handle<Object> num;
571 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 571 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
572 isolate, num, Object::ToInteger(isolate, args.at<Object>(2))); 572 isolate, num, Object::ToInteger(isolate, args.at<Object>(2)));
573 index = CapRelativeIndex(num, 0, len); 573 index = CapRelativeIndex(num, 0, len);
574 } 574 }
575 575
576 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin. 576 // TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
577 if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1); 577 if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1);
578 578
579 Handle<Object> search_element = args.at<Object>(1); 579 Handle<Object> search_element = args.atOrUndefined(isolate, 1);
580 ElementsAccessor* elements = array->GetElementsAccessor(); 580 ElementsAccessor* elements = array->GetElementsAccessor();
581 Maybe<int64_t> result = elements->IndexOfValue(isolate, array, search_element, 581 Maybe<int64_t> result = elements->IndexOfValue(isolate, array, search_element,
582 static_cast<uint32_t>(index), 582 static_cast<uint32_t>(index),
583 static_cast<uint32_t>(len)); 583 static_cast<uint32_t>(len));
584 MAYBE_RETURN(result, isolate->heap()->exception()); 584 MAYBE_RETURN(result, isolate->heap()->exception());
585 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); 585 return *isolate->factory()->NewNumberFromInt64(result.FromJust());
586 } 586 }
587 587
588 } // namespace internal 588 } // namespace internal
589 } // namespace v8 589 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698