OLD | NEW |
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 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 | 1340 |
1341 // For .indexOf, we don't need to pass in the number of arguments | 1341 // For .indexOf, we don't need to pass in the number of arguments |
1342 // at the callsite since ToInteger(undefined) == 0; however, for | 1342 // at the callsite since ToInteger(undefined) == 0; however, for |
1343 // .lastIndexOf, we need to pass it, since the behavior for passing | 1343 // .lastIndexOf, we need to pass it, since the behavior for passing |
1344 // undefined is 0 but for not including the argument is length-1. | 1344 // undefined is 0 but for not including the argument is length-1. |
1345 function InnerArrayIndexOf(array, element, index, length) { | 1345 function InnerArrayIndexOf(array, element, index, length) { |
1346 if (length == 0) return -1; | 1346 if (length == 0) return -1; |
1347 if (IS_UNDEFINED(index)) { | 1347 if (IS_UNDEFINED(index)) { |
1348 index = 0; | 1348 index = 0; |
1349 } else { | 1349 } else { |
1350 index = TO_INTEGER(index); | 1350 index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0 |
1351 // If index is negative, index from the end of the array. | 1351 // If index is negative, index from the end of the array. |
1352 if (index < 0) { | 1352 if (index < 0) { |
1353 index = length + index; | 1353 index = length + index; |
1354 // If index is still negative, search the entire array. | 1354 // If index is still negative, search the entire array. |
1355 if (index < 0) index = 0; | 1355 if (index < 0) index = 0; |
1356 } | 1356 } |
1357 } | 1357 } |
1358 var min = index; | 1358 var min = index; |
1359 var max = length; | 1359 var max = length; |
1360 if (UseSparseVariant(array, length, IS_ARRAY(array), max - min)) { | 1360 if (UseSparseVariant(array, length, IS_ARRAY(array), max - min)) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 var length = TO_LENGTH(this.length); | 1402 var length = TO_LENGTH(this.length); |
1403 return InnerArrayIndexOf(this, element, index, length); | 1403 return InnerArrayIndexOf(this, element, index, length); |
1404 } | 1404 } |
1405 | 1405 |
1406 | 1406 |
1407 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) { | 1407 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) { |
1408 if (length == 0) return -1; | 1408 if (length == 0) return -1; |
1409 if (argumentsLength < 2) { | 1409 if (argumentsLength < 2) { |
1410 index = length - 1; | 1410 index = length - 1; |
1411 } else { | 1411 } else { |
1412 index = TO_INTEGER(index); | 1412 index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0 |
1413 // If index is negative, index from end of the array. | 1413 // If index is negative, index from end of the array. |
1414 if (index < 0) index += length; | 1414 if (index < 0) index += length; |
1415 // If index is still negative, do not search the array. | 1415 // If index is still negative, do not search the array. |
1416 if (index < 0) return -1; | 1416 if (index < 0) return -1; |
1417 else if (index >= length) index = length - 1; | 1417 else if (index >= length) index = length - 1; |
1418 } | 1418 } |
1419 var min = 0; | 1419 var min = 0; |
1420 var max = index; | 1420 var max = index; |
1421 if (UseSparseVariant(array, length, IS_ARRAY(array), index)) { | 1421 if (UseSparseVariant(array, length, IS_ARRAY(array), index)) { |
1422 %NormalizeElements(array); | 1422 %NormalizeElements(array); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 %InstallToContext([ | 1951 %InstallToContext([ |
1952 "array_pop", ArrayPop, | 1952 "array_pop", ArrayPop, |
1953 "array_push", ArrayPush, | 1953 "array_push", ArrayPush, |
1954 "array_shift", ArrayShift, | 1954 "array_shift", ArrayShift, |
1955 "array_splice", ArraySplice, | 1955 "array_splice", ArraySplice, |
1956 "array_slice", ArraySlice, | 1956 "array_slice", ArraySlice, |
1957 "array_unshift", ArrayUnshift, | 1957 "array_unshift", ArrayUnshift, |
1958 ]); | 1958 ]); |
1959 | 1959 |
1960 }); | 1960 }); |
OLD | NEW |