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

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: Ensure -0 is never returned 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;
adamk 2016/08/15 20:38:54 I suspect these were the last importers of these f
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 if (!IS_NUMBER(element)) return -1;
574 var n = TO_INTEGER(index);
575
576 var k;
577 if (n === 0) {
578 k = 0;
579 } else if (n > 0) {
580 k = n;
581 } else {
582 k = length + n;
583 if (k < 0) {
584 k = 0;
585 }
586 }
587
588 while (k < length) {
589 var elementK = this[k];
590 if (element === elementK) {
591 return k;
592 }
593 ++k;
594 }
595 return -1;
576 } 596 }
577 %FunctionSetLength(TypedArrayIndexOf, 1); 597 %FunctionSetLength(TypedArrayIndexOf, 1);
578 598
579 599
580 // ES6 section 22.2.3.16 600 // ES6 section 22.2.3.16
581 function TypedArrayLastIndexOf(element, index) { 601 function TypedArrayLastIndexOf(element, index) {
582 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 602 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
583 603
584 var length = %_TypedArrayGetLength(this); 604 var length = %_TypedArrayGetLength(this);
585 605
586 return InnerArrayLastIndexOf(this, element, index, length, 606 if (length === 0) return -1;
587 arguments.length); 607 if (!IS_NUMBER(element)) return -1;
608 var n;
609 if (arguments.length < 2) {
610 n = length - 1;
611 } else {
612 n = TO_INTEGER(index);
613 }
614
615 var k;
616 if (n >= 0) {
617 if (length <= n) {
618 k = length - 1;
619 } else if (n === 0) {
620 k = 0;
621 } else {
622 k = n;
623 }
624 } else {
625 k = length + n;
626 }
627
628 while (k >= 0) {
629 var elementK = this[k];
630 if (element === elementK) {
631 return k;
632 }
633 --k;
634 }
635 return -1;
588 } 636 }
589 %FunctionSetLength(TypedArrayLastIndexOf, 1); 637 %FunctionSetLength(TypedArrayLastIndexOf, 1);
590 638
591 639
592 // ES6 draft 07-15-13, section 22.2.3.18 640 // ES6 draft 07-15-13, section 22.2.3.18
593 function TypedArrayMap(f, thisArg) { 641 function TypedArrayMap(f, thisArg) {
594 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 642 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
595 643
596 var length = %_TypedArrayGetLength(this); 644 var length = %_TypedArrayGetLength(this);
597 var result = TypedArraySpeciesCreate(this, length); 645 var result = TypedArraySpeciesCreate(this, length);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 "setUint32", DataViewSetUint32JS, 970 "setUint32", DataViewSetUint32JS,
923 971
924 "getFloat32", DataViewGetFloat32JS, 972 "getFloat32", DataViewGetFloat32JS,
925 "setFloat32", DataViewSetFloat32JS, 973 "setFloat32", DataViewSetFloat32JS,
926 974
927 "getFloat64", DataViewGetFloat64JS, 975 "getFloat64", DataViewGetFloat64JS,
928 "setFloat64", DataViewSetFloat64JS 976 "setFloat64", DataViewSetFloat64JS
929 ]); 977 ]);
930 978
931 }) 979 })
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