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

Side by Side Diff: src/js/typedarray.js

Issue 2243523002: [builtins] IndexOf/LastIndexOf implementation for typedarrays (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 10 matching lines...) Expand all
21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype;
22 var GlobalDataView = global.DataView; 22 var GlobalDataView = global.DataView;
23 var GlobalObject = global.Object; 23 var GlobalObject = global.Object;
24 var InnerArrayCopyWithin; 24 var InnerArrayCopyWithin;
25 var InnerArrayEvery; 25 var InnerArrayEvery;
26 var InnerArrayFill; 26 var InnerArrayFill;
27 var InnerArrayFilter; 27 var InnerArrayFilter;
28 var InnerArrayFind; 28 var InnerArrayFind;
29 var InnerArrayFindIndex; 29 var InnerArrayFindIndex;
30 var InnerArrayForEach; 30 var InnerArrayForEach;
31 var InnerArrayIndexOf;
32 var InnerArrayJoin; 31 var InnerArrayJoin;
33 var InnerArrayLastIndexOf;
34 var InnerArrayReduce; 32 var InnerArrayReduce;
35 var InnerArrayReduceRight; 33 var InnerArrayReduceRight;
36 var InnerArraySome; 34 var InnerArraySome;
37 var InnerArraySort; 35 var InnerArraySort;
38 var InnerArrayToLocaleString; 36 var InnerArrayToLocaleString;
39 var InternalArray = utils.InternalArray; 37 var InternalArray = utils.InternalArray;
40 var IsNaN; 38 var IsNaN;
41 var MaxSimple; 39 var MaxSimple;
42 var MinSimple; 40 var MinSimple;
43 var PackedArrayReverse; 41 var PackedArrayReverse;
(...skipping 28 matching lines...) Expand all
72 ArrayValues = from.ArrayValues; 70 ArrayValues = from.ArrayValues;
73 GetIterator = from.GetIterator; 71 GetIterator = from.GetIterator;
74 GetMethod = from.GetMethod; 72 GetMethod = from.GetMethod;
75 InnerArrayCopyWithin = from.InnerArrayCopyWithin; 73 InnerArrayCopyWithin = from.InnerArrayCopyWithin;
76 InnerArrayEvery = from.InnerArrayEvery; 74 InnerArrayEvery = from.InnerArrayEvery;
77 InnerArrayFill = from.InnerArrayFill; 75 InnerArrayFill = from.InnerArrayFill;
78 InnerArrayFilter = from.InnerArrayFilter; 76 InnerArrayFilter = from.InnerArrayFilter;
79 InnerArrayFind = from.InnerArrayFind; 77 InnerArrayFind = from.InnerArrayFind;
80 InnerArrayFindIndex = from.InnerArrayFindIndex; 78 InnerArrayFindIndex = from.InnerArrayFindIndex;
81 InnerArrayForEach = from.InnerArrayForEach; 79 InnerArrayForEach = from.InnerArrayForEach;
82 InnerArrayIndexOf = from.InnerArrayIndexOf;
83 InnerArrayJoin = from.InnerArrayJoin; 80 InnerArrayJoin = from.InnerArrayJoin;
84 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf;
85 InnerArrayReduce = from.InnerArrayReduce; 81 InnerArrayReduce = from.InnerArrayReduce;
86 InnerArrayReduceRight = from.InnerArrayReduceRight; 82 InnerArrayReduceRight = from.InnerArrayReduceRight;
87 InnerArraySome = from.InnerArraySome; 83 InnerArraySome = from.InnerArraySome;
88 InnerArraySort = from.InnerArraySort; 84 InnerArraySort = from.InnerArraySort;
89 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 85 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
90 IsNaN = from.IsNaN; 86 IsNaN = from.IsNaN;
91 MaxSimple = from.MaxSimple; 87 MaxSimple = from.MaxSimple;
92 MinSimple = from.MinSimple; 88 MinSimple = from.MinSimple;
93 PackedArrayReverse = from.PackedArrayReverse; 89 PackedArrayReverse = from.PackedArrayReverse;
94 SpeciesConstructor = from.SpeciesConstructor; 90 SpeciesConstructor = from.SpeciesConstructor;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 561
566 return InnerArraySort(this, length, comparefn); 562 return InnerArraySort(this, length, comparefn);
567 } 563 }
568 564
569 565
570 // ES6 section 22.2.3.13 566 // ES6 section 22.2.3.13
571 function TypedArrayIndexOf(element, index) { 567 function TypedArrayIndexOf(element, index) {
572 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
573 569
574 var length = %_TypedArrayGetLength(this); 570 var length = %_TypedArrayGetLength(this);
575 return InnerArrayIndexOf(this, element, index, length); 571
572 if (length === 0) return -1;
573 var n = TO_INTEGER(index);
574
Camillo Bruni 2016/08/12 09:35:17 If the input is not a number return -1: if (!IS_NU
mattloring 2016/08/12 17:52:43 Done.
575 var k;
576 if (n >= 0) {
577 k = n;
578 } else {
579 k = length + n;
580 if (k < 0) {
581 k = 0;
582 }
583 }
584
585 while (k < length) {
586 var elementK = this[k];
587 if (k in this && element === elementK) {
Camillo Bruni 2016/08/12 09:35:17 This "in" check is not necessary since the typed a
mattloring 2016/08/12 17:52:43 Done.
588 return k;
589 }
590 ++k;
591 }
592 return -1;
576 } 593 }
577 %FunctionSetLength(TypedArrayIndexOf, 1); 594 %FunctionSetLength(TypedArrayIndexOf, 1);
578 595
579 596
580 // ES6 section 22.2.3.16 597 // ES6 section 22.2.3.16
581 function TypedArrayLastIndexOf(element, index) { 598 function TypedArrayLastIndexOf(element, index) {
582 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 599 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
583 600
584 var length = %_TypedArrayGetLength(this); 601 var length = %_TypedArrayGetLength(this);
585 602
586 return InnerArrayLastIndexOf(this, element, index, length, 603 if (length === 0) return -1;
587 arguments.length); 604 var n;
605 if (arguments.length < 2) {
606 n = length - 1;
607 } else {
608 n = TO_INTEGER(index);
609 }
Camillo Bruni 2016/08/12 09:35:17 Add: if (!IS_NUMBER(element)) return -1;
mattloring 2016/08/12 17:52:43 Done.
610
611 var k;
612 if (n >= 0) {
613 if (length <= n) {
614 k = length - 1;
615 } else {
616 k = n;
617 }
618 } else {
619 k = length + n;
620 }
621
622 while (k >= 0) {
623 var elementK = this[k];
624 if (k in this && element === elementK) {
Camillo Bruni 2016/08/12 09:35:17 same here: you can remove the "in" check.
mattloring 2016/08/12 17:52:43 Done.
625 return k;
626 }
627 --k;
628 }
629 return -1;
588 } 630 }
589 %FunctionSetLength(TypedArrayLastIndexOf, 1); 631 %FunctionSetLength(TypedArrayLastIndexOf, 1);
590 632
591 633
592 // ES6 draft 07-15-13, section 22.2.3.18 634 // ES6 draft 07-15-13, section 22.2.3.18
593 function TypedArrayMap(f, thisArg) { 635 function TypedArrayMap(f, thisArg) {
594 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 636 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
595 637
596 var length = %_TypedArrayGetLength(this); 638 var length = %_TypedArrayGetLength(this);
597 var result = TypedArraySpeciesCreate(this, length); 639 var result = TypedArraySpeciesCreate(this, length);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 "setUint32", DataViewSetUint32JS, 964 "setUint32", DataViewSetUint32JS,
923 965
924 "getFloat32", DataViewGetFloat32JS, 966 "getFloat32", DataViewGetFloat32JS,
925 "setFloat32", DataViewSetFloat32JS, 967 "setFloat32", DataViewSetFloat32JS,
926 968
927 "getFloat64", DataViewGetFloat64JS, 969 "getFloat64", DataViewGetFloat64JS,
928 "setFloat64", DataViewSetFloat64JS 970 "setFloat64", DataViewSetFloat64JS
929 ]); 971 ]);
930 972
931 }) 973 })
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