| 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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 index = TO_INTEGER(index); | 1011 index = TO_INTEGER(index); |
| 1012 // If index is negative, index from the end of the array. | 1012 // If index is negative, index from the end of the array. |
| 1013 if (index < 0) { | 1013 if (index < 0) { |
| 1014 index = length + index; | 1014 index = length + index; |
| 1015 // If index is still negative, search the entire array. | 1015 // If index is still negative, search the entire array. |
| 1016 if (index < 0) index = 0; | 1016 if (index < 0) index = 0; |
| 1017 } | 1017 } |
| 1018 } | 1018 } |
| 1019 var min = index; | 1019 var min = index; |
| 1020 var max = length; | 1020 var max = length; |
| 1021 if (UseSparseVariant(this, length, true)) { | 1021 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1022 var intervals = %GetArrayKeys(this, length); | 1022 var intervals = %GetArrayKeys(this, length); |
| 1023 if (intervals.length == 2 && intervals[0] < 0) { | 1023 if (intervals.length == 2 && intervals[0] < 0) { |
| 1024 // A single interval. | 1024 // A single interval. |
| 1025 var intervalMin = -(intervals[0] + 1); | 1025 var intervalMin = -(intervals[0] + 1); |
| 1026 var intervalMax = intervalMin + intervals[1]; | 1026 var intervalMax = intervalMin + intervals[1]; |
| 1027 min = MAX(min, intervalMin); | 1027 if (min < intervalMin) min = intervalMin; |
| 1028 max = intervalMax; // Capped by length already. | 1028 max = intervalMax; // Capped by length already. |
| 1029 // Fall through to loop below. | 1029 // Fall through to loop below. |
| 1030 } else { | 1030 } else { |
| 1031 if (intervals.length == 0) return -1; | 1031 if (intervals.length == 0) return -1; |
| 1032 // Get all the keys in sorted order. | 1032 // Get all the keys in sorted order. |
| 1033 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1033 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1034 var n = sortedKeys.length; | 1034 var n = sortedKeys.length; |
| 1035 var i = 0; | 1035 var i = 0; |
| 1036 while (i < n && sortedKeys[i] < index) i++; | 1036 while (i < n && sortedKeys[i] < index) i++; |
| 1037 while (i < n) { | 1037 while (i < n) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1067 } else { | 1067 } else { |
| 1068 index = TO_INTEGER(index); | 1068 index = TO_INTEGER(index); |
| 1069 // If index is negative, index from end of the array. | 1069 // If index is negative, index from end of the array. |
| 1070 if (index < 0) index += length; | 1070 if (index < 0) index += length; |
| 1071 // If index is still negative, do not search the array. | 1071 // If index is still negative, do not search the array. |
| 1072 if (index < 0) return -1; | 1072 if (index < 0) return -1; |
| 1073 else if (index >= length) index = length - 1; | 1073 else if (index >= length) index = length - 1; |
| 1074 } | 1074 } |
| 1075 var min = 0; | 1075 var min = 0; |
| 1076 var max = index; | 1076 var max = index; |
| 1077 if (UseSparseVariant(this, length, true)) { | 1077 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1078 var intervals = %GetArrayKeys(this, index + 1); | 1078 var intervals = %GetArrayKeys(this, index + 1); |
| 1079 if (intervals.length == 2 && intervals[0] < 0) { | 1079 if (intervals.length == 2 && intervals[0] < 0) { |
| 1080 // A single interval. | 1080 // A single interval. |
| 1081 var intervalMin = -(intervals[0] + 1); | 1081 var intervalMin = -(intervals[0] + 1); |
| 1082 var intervalMax = intervalMin + intervals[1]; | 1082 var intervalMax = intervalMin + intervals[1]; |
| 1083 min = MAX(min, intervalMin); | 1083 if (min < intervalMin) min = intervalMin; |
| 1084 max = intervalMax; // Capped by index already. | 1084 max = intervalMax; // Capped by index already. |
| 1085 // Fall through to loop below. | 1085 // Fall through to loop below. |
| 1086 } else { | 1086 } else { |
| 1087 if (intervals.length == 0) return -1; | 1087 if (intervals.length == 0) return -1; |
| 1088 // Get all the keys in sorted order. | 1088 // Get all the keys in sorted order. |
| 1089 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1089 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1090 var i = sortedKeys.length - 1; | 1090 var i = sortedKeys.length - 1; |
| 1091 while (i >= 0) { | 1091 while (i >= 0) { |
| 1092 var key = sortedKeys[i]; | 1092 var key = sortedKeys[i]; |
| 1093 if (!IS_UNDEFINED(key) && this[key] === element) return key; | 1093 if (!IS_UNDEFINED(key) && this[key] === element) return key; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1223 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1224 "reduce", getFunction("reduce", ArrayReduce, 1), | 1224 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1225 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1225 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1226 )); | 1226 )); |
| 1227 | 1227 |
| 1228 %FinishArrayPrototypeSetup($Array.prototype); | 1228 %FinishArrayPrototypeSetup($Array.prototype); |
| 1229 } | 1229 } |
| 1230 | 1230 |
| 1231 | 1231 |
| 1232 SetupArray(); | 1232 SetupArray(); |
| OLD | NEW |