| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 var current = this[i]; | 946 var current = this[i]; |
| 947 if (!IS_UNDEFINED(current) || i in this) { | 947 if (!IS_UNDEFINED(current) || i in this) { |
| 948 result[i] = f.call(receiver, current, i, this); | 948 result[i] = f.call(receiver, current, i, this); |
| 949 } | 949 } |
| 950 } | 950 } |
| 951 return result; | 951 return result; |
| 952 } | 952 } |
| 953 | 953 |
| 954 | 954 |
| 955 function ArrayIndexOf(element, index) { | 955 function ArrayIndexOf(element, index) { |
| 956 var length = this.length; | 956 var length = TO_UINT32(this.length); |
| 957 if (length == 0) return -1; |
| 957 if (IS_UNDEFINED(index)) { | 958 if (IS_UNDEFINED(index)) { |
| 958 index = 0; | 959 index = 0; |
| 959 } else { | 960 } else { |
| 960 index = TO_INTEGER(index); | 961 index = TO_INTEGER(index); |
| 961 // If index is negative, index from the end of the array. | 962 // If index is negative, index from the end of the array. |
| 962 if (index < 0) index = length + index; | 963 if (index < 0) index = length + index; |
| 963 // If index is still negative, search the entire array. | 964 // If index is still negative, search the entire array. |
| 964 if (index < 0) index = 0; | 965 if (index < 0) index = 0; |
| 965 } | 966 } |
| 967 // Lookup through the array. |
| 966 if (!IS_UNDEFINED(element)) { | 968 if (!IS_UNDEFINED(element)) { |
| 967 for (var i = index; i < length; i++) { | 969 for (var i = index; i < length; i++) { |
| 968 if (this[i] === element) return i; | 970 if (this[i] === element) return i; |
| 969 } | 971 } |
| 970 return -1; | 972 return -1; |
| 971 } | 973 } |
| 972 // Lookup through the array. | |
| 973 for (var i = index; i < length; i++) { | 974 for (var i = index; i < length; i++) { |
| 974 if (IS_UNDEFINED(this[i]) && i in this) { | 975 if (IS_UNDEFINED(this[i]) && i in this) { |
| 975 return i; | 976 return i; |
| 976 } | 977 } |
| 977 } | 978 } |
| 978 return -1; | 979 return -1; |
| 979 } | 980 } |
| 980 | 981 |
| 981 | 982 |
| 982 function ArrayLastIndexOf(element, index) { | 983 function ArrayLastIndexOf(element, index) { |
| 983 var length = this.length; | 984 var length = TO_UINT32(this.length); |
| 985 if (length == 0) return -1; |
| 984 if (%_ArgumentsLength() < 2) { | 986 if (%_ArgumentsLength() < 2) { |
| 985 index = length - 1; | 987 index = length - 1; |
| 986 } else { | 988 } else { |
| 987 index = TO_INTEGER(index); | 989 index = TO_INTEGER(index); |
| 988 // If index is negative, index from end of the array. | 990 // If index is negative, index from end of the array. |
| 989 if (index < 0) index = length + index; | 991 if (index < 0) index = length + index; |
| 990 // If index is still negative, do not search the array. | 992 // If index is still negative, do not search the array. |
| 991 if (index < 0) index = -1; | 993 if (index < 0) index = -1; |
| 992 else if (index >= length) index = length - 1; | 994 else if (index >= length) index = length - 1; |
| 993 } | 995 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1120 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1119 "reduce", getFunction("reduce", ArrayReduce, 1), | 1121 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1120 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1122 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1121 )); | 1123 )); |
| 1122 | 1124 |
| 1123 %FinishArrayPrototypeSetup($Array.prototype); | 1125 %FinishArrayPrototypeSetup($Array.prototype); |
| 1124 } | 1126 } |
| 1125 | 1127 |
| 1126 | 1128 |
| 1127 SetupArray(); | 1129 SetupArray(); |
| OLD | NEW |