| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 index = 0; | 1016 index = 0; |
| 1017 } else { | 1017 } else { |
| 1018 index = TO_INTEGER(index); | 1018 index = TO_INTEGER(index); |
| 1019 // If index is negative, index from the end of the array. | 1019 // If index is negative, index from the end of the array. |
| 1020 if (index < 0) index = length + index; | 1020 if (index < 0) index = length + index; |
| 1021 // If index is still negative, search the entire array. | 1021 // If index is still negative, search the entire array. |
| 1022 if (index < 0) index = 0; | 1022 if (index < 0) index = 0; |
| 1023 } | 1023 } |
| 1024 var min = index; | 1024 var min = index; |
| 1025 var max = length; | 1025 var max = length; |
| 1026 if (UseSparseVariant(this, length, true)) { | 1026 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1027 var intervals = %GetArrayKeys(this, length); | 1027 var intervals = %GetArrayKeys(this, length); |
| 1028 if (intervals.length == 2 && intervals[0] < 0) { | 1028 if (intervals.length == 2 && intervals[0] < 0) { |
| 1029 // A single interval. | 1029 // A single interval. |
| 1030 var intervalMin = -(intervals[0] + 1); | 1030 var intervalMin = -(intervals[0] + 1); |
| 1031 var intervalMax = intervalMin + intervals[1]; | 1031 var intervalMax = intervalMin + intervals[1]; |
| 1032 min = MAX(min, intervalMin); | 1032 if (min < intervalMin) min = intervalMin; |
| 1033 max = intervalMax; // Capped by length already. | 1033 max = intervalMax; // Capped by length already. |
| 1034 // Fall through to loop below. | 1034 // Fall through to loop below. |
| 1035 } else { | 1035 } else { |
| 1036 if (intervals.length == 0) return -1; | 1036 if (intervals.length == 0) return -1; |
| 1037 // Get all the keys in sorted order. | 1037 // Get all the keys in sorted order. |
| 1038 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1038 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1039 var n = sortedKeys.length; | 1039 var n = sortedKeys.length; |
| 1040 var i = 0; | 1040 var i = 0; |
| 1041 while (i < n && sortedKeys[i] < index) i++; | 1041 while (i < n && sortedKeys[i] < index) i++; |
| 1042 while (i < n) { | 1042 while (i < n) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1072 } else { | 1072 } else { |
| 1073 index = TO_INTEGER(index); | 1073 index = TO_INTEGER(index); |
| 1074 // If index is negative, index from end of the array. | 1074 // If index is negative, index from end of the array. |
| 1075 if (index < 0) index += length; | 1075 if (index < 0) index += length; |
| 1076 // If index is still negative, do not search the array. | 1076 // If index is still negative, do not search the array. |
| 1077 if (index < 0) return -1; | 1077 if (index < 0) return -1; |
| 1078 else if (index >= length) index = length - 1; | 1078 else if (index >= length) index = length - 1; |
| 1079 } | 1079 } |
| 1080 var min = 0; | 1080 var min = 0; |
| 1081 var max = index; | 1081 var max = index; |
| 1082 if (UseSparseVariant(this, length, true)) { | 1082 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1083 var intervals = %GetArrayKeys(this, index + 1); | 1083 var intervals = %GetArrayKeys(this, index + 1); |
| 1084 if (intervals.length == 2 && intervals[0] < 0) { | 1084 if (intervals.length == 2 && intervals[0] < 0) { |
| 1085 // A single interval. | 1085 // A single interval. |
| 1086 var intervalMin = -(intervals[0] + 1); | 1086 var intervalMin = -(intervals[0] + 1); |
| 1087 var intervalMax = intervalMin + intervals[1]; | 1087 var intervalMax = intervalMin + intervals[1]; |
| 1088 min = MAX(min, intervalMin); | 1088 if (min < intervalMin) min = intervalMin; |
| 1089 max = intervalMax; // Capped by index already. | 1089 max = intervalMax; // Capped by index already. |
| 1090 // Fall through to loop below. | 1090 // Fall through to loop below. |
| 1091 } else { | 1091 } else { |
| 1092 if (intervals.length == 0) return -1; | 1092 if (intervals.length == 0) return -1; |
| 1093 // Get all the keys in sorted order. | 1093 // Get all the keys in sorted order. |
| 1094 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1094 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1095 var i = sortedKeys.length - 1; | 1095 var i = sortedKeys.length - 1; |
| 1096 while (i >= 0) { | 1096 while (i >= 0) { |
| 1097 var key = sortedKeys[i]; | 1097 var key = sortedKeys[i]; |
| 1098 if (!IS_UNDEFINED(key) && this[key] === element) return key; | 1098 if (!IS_UNDEFINED(key) && this[key] === element) return key; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1228 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1229 "reduce", getFunction("reduce", ArrayReduce, 1), | 1229 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1230 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1230 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1231 )); | 1231 )); |
| 1232 | 1232 |
| 1233 %FinishArrayPrototypeSetup($Array.prototype); | 1233 %FinishArrayPrototypeSetup($Array.prototype); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 | 1236 |
| 1237 SetupArray(); | 1237 SetupArray(); |
| OLD | NEW |