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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = this.length; |
957 if (index == null) { | 957 if (IS_UNDEFINED(index)) { |
958 index = 0; | 958 index = 0; |
959 } else { | 959 } else { |
960 index = TO_INTEGER(index); | 960 index = TO_INTEGER(index); |
961 // If index is negative, index from the end of the array. | 961 // If index is negative, index from the end of the array. |
962 if (index < 0) index = length + index; | 962 if (index < 0) index = length + index; |
963 // If index is still negative, search the entire array. | 963 // If index is still negative, search the entire array. |
964 if (index < 0) index = 0; | 964 if (index < 0) index = 0; |
965 } | 965 } |
966 if (!IS_UNDEFINED(element)) { | 966 if (!IS_UNDEFINED(element)) { |
967 for (var i = index; i < length; i++) { | 967 for (var i = index; i < length; i++) { |
968 if (this[i] === element) return i; | 968 if (this[i] === element) return i; |
969 } | 969 } |
970 return -1; | 970 return -1; |
971 } | 971 } |
972 // Lookup through the array. | 972 // Lookup through the array. |
973 for (var i = index; i < length; i++) { | 973 for (var i = index; i < length; i++) { |
974 if (IS_UNDEFINED(this[i]) && i in this) { | 974 if (IS_UNDEFINED(this[i]) && i in this) { |
975 return i; | 975 return i; |
976 } | 976 } |
977 } | 977 } |
978 return -1; | 978 return -1; |
979 } | 979 } |
980 | 980 |
981 | 981 |
982 function ArrayLastIndexOf(element, index) { | 982 function ArrayLastIndexOf(element, index) { |
983 var length = this.length; | 983 var length = this.length; |
984 if (index == null) { | 984 if (%_ArgumentsLength() < 2) { |
985 index = length - 1; | 985 index = length - 1; |
986 } else { | 986 } else { |
987 index = TO_INTEGER(index); | 987 index = TO_INTEGER(index); |
988 // If index is negative, index from end of the array. | 988 // If index is negative, index from end of the array. |
989 if (index < 0) index = length + index; | 989 if (index < 0) index = length + index; |
990 // If index is still negative, do not search the array. | 990 // If index is still negative, do not search the array. |
991 if (index < 0) index = -1; | 991 if (index < 0) index = -1; |
992 else if (index >= length) index = length - 1; | 992 else if (index >= length) index = length - 1; |
993 } | 993 } |
994 // Lookup through the array. | 994 // Lookup through the array. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1118 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1119 "reduce", getFunction("reduce", ArrayReduce, 1), | 1119 "reduce", getFunction("reduce", ArrayReduce, 1), |
1120 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1120 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
1121 )); | 1121 )); |
1122 | 1122 |
1123 %FinishArrayPrototypeSetup($Array.prototype); | 1123 %FinishArrayPrototypeSetup($Array.prototype); |
1124 } | 1124 } |
1125 | 1125 |
1126 | 1126 |
1127 SetupArray(); | 1127 SetupArray(); |
OLD | NEW |