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

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

Issue 2744283002: [typedarrays] Implement %TypedArray%.prototype.lastIndexOf in C++ (Closed)
Patch Set: Correct integral value check 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/elements.cc ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 for (var i = 0; i < length; i++) { 1127 for (var i = 0; i < length; i++) {
1128 if (i in array) { 1128 if (i in array) {
1129 var element = array[i]; 1129 var element = array[i];
1130 %CreateDataProperty(result, i, %_Call(f, receiver, element, i, array)); 1130 %CreateDataProperty(result, i, %_Call(f, receiver, element, i, array));
1131 } 1131 }
1132 } 1132 }
1133 return result; 1133 return result;
1134 } 1134 }
1135 1135
1136 1136
1137 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) { 1137 function ArrayLastIndexOf(element, index) {
1138 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
1139
1140 var array = this;
1141 var length = TO_LENGTH(this.length);
1142
1138 if (length == 0) return -1; 1143 if (length == 0) return -1;
1139 if (argumentsLength < 2) { 1144 if (arguments.length < 2) {
1140 index = length - 1; 1145 index = length - 1;
1141 } else { 1146 } else {
1142 index = INVERT_NEG_ZERO(TO_INTEGER(index)); 1147 index = INVERT_NEG_ZERO(TO_INTEGER(index));
1143 // If index is negative, index from end of the array. 1148 // If index is negative, index from end of the array.
1144 if (index < 0) index += length; 1149 if (index < 0) index += length;
1145 // If index is still negative, do not search the array. 1150 // If index is still negative, do not search the array.
1146 if (index < 0) return -1; 1151 if (index < 0) return -1;
1147 else if (index >= length) index = length - 1; 1152 else if (index >= length) index = length - 1;
1148 } 1153 }
1149 var min = 0; 1154 var min = 0;
(...skipping 27 matching lines...) Expand all
1177 } 1182 }
1178 for (var i = max; i >= min; i--) { 1183 for (var i = max; i >= min; i--) {
1179 if (IS_UNDEFINED(array[i]) && i in array) { 1184 if (IS_UNDEFINED(array[i]) && i in array) {
1180 return i; 1185 return i;
1181 } 1186 }
1182 } 1187 }
1183 return -1; 1188 return -1;
1184 } 1189 }
1185 1190
1186 1191
1187 function ArrayLastIndexOf(element, index) {
1188 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
1189
1190 var length = TO_LENGTH(this.length);
1191 return InnerArrayLastIndexOf(this, element, index, length,
1192 arguments.length);
1193 }
1194
1195
1196 function InnerArrayReduce(callback, current, array, length, argumentsLength) { 1192 function InnerArrayReduce(callback, current, array, length, argumentsLength) {
1197 if (!IS_CALLABLE(callback)) { 1193 if (!IS_CALLABLE(callback)) {
1198 throw %make_type_error(kCalledNonCallable, callback); 1194 throw %make_type_error(kCalledNonCallable, callback);
1199 } 1195 }
1200 1196
1201 var i = 0; 1197 var i = 0;
1202 find_initial: if (argumentsLength < 2) { 1198 find_initial: if (argumentsLength < 2) {
1203 for (; i < length; i++) { 1199 for (; i < length; i++) {
1204 if (i in array) { 1200 if (i in array) {
1205 current = array[i++]; 1201 current = array[i++];
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 to.ArrayPush = ArrayPush; 1617 to.ArrayPush = ArrayPush;
1622 to.ArrayToString = ArrayToString; 1618 to.ArrayToString = ArrayToString;
1623 to.ArrayValues = IteratorFunctions.values, 1619 to.ArrayValues = IteratorFunctions.values,
1624 to.InnerArrayEvery = InnerArrayEvery; 1620 to.InnerArrayEvery = InnerArrayEvery;
1625 to.InnerArrayFill = InnerArrayFill; 1621 to.InnerArrayFill = InnerArrayFill;
1626 to.InnerArrayFilter = InnerArrayFilter; 1622 to.InnerArrayFilter = InnerArrayFilter;
1627 to.InnerArrayFind = InnerArrayFind; 1623 to.InnerArrayFind = InnerArrayFind;
1628 to.InnerArrayFindIndex = InnerArrayFindIndex; 1624 to.InnerArrayFindIndex = InnerArrayFindIndex;
1629 to.InnerArrayForEach = InnerArrayForEach; 1625 to.InnerArrayForEach = InnerArrayForEach;
1630 to.InnerArrayJoin = InnerArrayJoin; 1626 to.InnerArrayJoin = InnerArrayJoin;
1631 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
1632 to.InnerArrayReduce = InnerArrayReduce; 1627 to.InnerArrayReduce = InnerArrayReduce;
1633 to.InnerArrayReduceRight = InnerArrayReduceRight; 1628 to.InnerArrayReduceRight = InnerArrayReduceRight;
1634 to.InnerArraySome = InnerArraySome; 1629 to.InnerArraySome = InnerArraySome;
1635 to.InnerArraySort = InnerArraySort; 1630 to.InnerArraySort = InnerArraySort;
1636 to.InnerArrayToLocaleString = InnerArrayToLocaleString; 1631 to.InnerArrayToLocaleString = InnerArrayToLocaleString;
1637 to.PackedArrayReverse = PackedArrayReverse; 1632 to.PackedArrayReverse = PackedArrayReverse;
1638 }); 1633 });
1639 1634
1640 %InstallToContext([ 1635 %InstallToContext([
1641 "array_entries_iterator", IteratorFunctions.entries, 1636 "array_entries_iterator", IteratorFunctions.entries,
1642 "array_for_each_iterator", IteratorFunctions.forEach, 1637 "array_for_each_iterator", IteratorFunctions.forEach,
1643 "array_keys_iterator", IteratorFunctions.keys, 1638 "array_keys_iterator", IteratorFunctions.keys,
1644 "array_pop", ArrayPop, 1639 "array_pop", ArrayPop,
1645 "array_push", ArrayPush, 1640 "array_push", ArrayPush,
1646 "array_shift", ArrayShift, 1641 "array_shift", ArrayShift,
1647 "array_splice", ArraySplice, 1642 "array_splice", ArraySplice,
1648 "array_slice", ArraySlice, 1643 "array_slice", ArraySlice,
1649 "array_unshift", ArrayUnshift, 1644 "array_unshift", ArrayUnshift,
1650 "array_values_iterator", IteratorFunctions.values, 1645 "array_values_iterator", IteratorFunctions.values,
1651 ]); 1646 ]);
1652 1647
1653 }); 1648 });
OLDNEW
« no previous file with comments | « src/elements.cc ('k') | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698