| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 var m = %_ArgumentsLength(); | 411 var m = %_ArgumentsLength(); |
| 412 for (var i = 0; i < m; i++) { | 412 for (var i = 0; i < m; i++) { |
| 413 this[i+n] = %_Arguments(i); | 413 this[i+n] = %_Arguments(i); |
| 414 } | 414 } |
| 415 this.length = n + m; | 415 this.length = n + m; |
| 416 return this.length; | 416 return this.length; |
| 417 } | 417 } |
| 418 | 418 |
| 419 | 419 |
| 420 function ArrayConcat(arg1) { // length == 1 | 420 function ArrayConcat(arg1) { // length == 1 |
| 421 // TODO: can we just use arguments? | |
| 422 var arg_count = %_ArgumentsLength(); | 421 var arg_count = %_ArgumentsLength(); |
| 423 var arrays = new $Array(1 + arg_count); | 422 var arrays = new $Array(1 + arg_count); |
| 424 arrays[0] = this; | 423 arrays[0] = this; |
| 425 for (var i = 0; i < arg_count; i++) { | 424 for (var i = 0; i < arg_count; i++) { |
| 426 arrays[i + 1] = %_Arguments(i); | 425 arrays[i + 1] = %_Arguments(i); |
| 427 } | 426 } |
| 428 | 427 |
| 429 return %ArrayConcat(arrays); | 428 return %ArrayConcat(arrays); |
| 430 } | 429 } |
| 431 | 430 |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 index = TO_INTEGER(index); | 1010 index = TO_INTEGER(index); |
| 1012 // If index is negative, index from the end of the array. | 1011 // If index is negative, index from the end of the array. |
| 1013 if (index < 0) { | 1012 if (index < 0) { |
| 1014 index = length + index; | 1013 index = length + index; |
| 1015 // If index is still negative, search the entire array. | 1014 // If index is still negative, search the entire array. |
| 1016 if (index < 0) index = 0; | 1015 if (index < 0) index = 0; |
| 1017 } | 1016 } |
| 1018 } | 1017 } |
| 1019 var min = index; | 1018 var min = index; |
| 1020 var max = length; | 1019 var max = length; |
| 1021 if (UseSparseVariant(this, length, true)) { | 1020 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1022 var intervals = %GetArrayKeys(this, length); | 1021 var intervals = %GetArrayKeys(this, length); |
| 1023 if (intervals.length == 2 && intervals[0] < 0) { | 1022 if (intervals.length == 2 && intervals[0] < 0) { |
| 1024 // A single interval. | 1023 // A single interval. |
| 1025 var intervalMin = -(intervals[0] + 1); | 1024 var intervalMin = -(intervals[0] + 1); |
| 1026 var intervalMax = intervalMin + intervals[1]; | 1025 var intervalMax = intervalMin + intervals[1]; |
| 1027 min = MAX(min, intervalMin); | 1026 if (min < intervalMin) min = intervalMin; |
| 1028 max = intervalMax; // Capped by length already. | 1027 max = intervalMax; // Capped by length already. |
| 1029 // Fall through to loop below. | 1028 // Fall through to loop below. |
| 1030 } else { | 1029 } else { |
| 1031 if (intervals.length == 0) return -1; | 1030 if (intervals.length == 0) return -1; |
| 1032 // Get all the keys in sorted order. | 1031 // Get all the keys in sorted order. |
| 1033 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1032 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1034 var n = sortedKeys.length; | 1033 var n = sortedKeys.length; |
| 1035 var i = 0; | 1034 var i = 0; |
| 1036 while (i < n && sortedKeys[i] < index) i++; | 1035 while (i < n && sortedKeys[i] < index) i++; |
| 1037 while (i < n) { | 1036 while (i < n) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1067 } else { | 1066 } else { |
| 1068 index = TO_INTEGER(index); | 1067 index = TO_INTEGER(index); |
| 1069 // If index is negative, index from end of the array. | 1068 // If index is negative, index from end of the array. |
| 1070 if (index < 0) index += length; | 1069 if (index < 0) index += length; |
| 1071 // If index is still negative, do not search the array. | 1070 // If index is still negative, do not search the array. |
| 1072 if (index < 0) return -1; | 1071 if (index < 0) return -1; |
| 1073 else if (index >= length) index = length - 1; | 1072 else if (index >= length) index = length - 1; |
| 1074 } | 1073 } |
| 1075 var min = 0; | 1074 var min = 0; |
| 1076 var max = index; | 1075 var max = index; |
| 1077 if (UseSparseVariant(this, length, true)) { | 1076 if (UseSparseVariant(this, length, IS_ARRAY(this))) { |
| 1078 var intervals = %GetArrayKeys(this, index + 1); | 1077 var intervals = %GetArrayKeys(this, index + 1); |
| 1079 if (intervals.length == 2 && intervals[0] < 0) { | 1078 if (intervals.length == 2 && intervals[0] < 0) { |
| 1080 // A single interval. | 1079 // A single interval. |
| 1081 var intervalMin = -(intervals[0] + 1); | 1080 var intervalMin = -(intervals[0] + 1); |
| 1082 var intervalMax = intervalMin + intervals[1]; | 1081 var intervalMax = intervalMin + intervals[1]; |
| 1083 min = MAX(min, intervalMin); | 1082 if (min < intervalMin) min = intervalMin; |
| 1084 max = intervalMax; // Capped by index already. | 1083 max = intervalMax; // Capped by index already. |
| 1085 // Fall through to loop below. | 1084 // Fall through to loop below. |
| 1086 } else { | 1085 } else { |
| 1087 if (intervals.length == 0) return -1; | 1086 if (intervals.length == 0) return -1; |
| 1088 // Get all the keys in sorted order. | 1087 // Get all the keys in sorted order. |
| 1089 var sortedKeys = GetSortedArrayKeys(this, intervals); | 1088 var sortedKeys = GetSortedArrayKeys(this, intervals); |
| 1090 var i = sortedKeys.length - 1; | 1089 var i = sortedKeys.length - 1; |
| 1091 while (i >= 0) { | 1090 while (i >= 0) { |
| 1092 var key = sortedKeys[i]; | 1091 var key = sortedKeys[i]; |
| 1093 if (!IS_UNDEFINED(key) && this[key] === element) return key; | 1092 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), | 1222 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1224 "reduce", getFunction("reduce", ArrayReduce, 1), | 1223 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1225 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1224 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1226 )); | 1225 )); |
| 1227 | 1226 |
| 1228 %FinishArrayPrototypeSetup($Array.prototype); | 1227 %FinishArrayPrototypeSetup($Array.prototype); |
| 1229 } | 1228 } |
| 1230 | 1229 |
| 1231 | 1230 |
| 1232 SetupArray(); | 1231 SetupArray(); |
| OLD | NEW |