Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 keys.push(key); | 60 keys.push(key); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 keys.sort(function(a, b) { return a - b; }); | 65 keys.sort(function(a, b) { return a - b; }); |
| 66 return keys; | 66 return keys; |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 // Optimized for sparse arrays if separator is ''. | 70 // Optimized for sparse arrays if separator is ''. |
|
Lasse Reichstein
2011/01/07 13:13:43
Make a comment saying that convert is only called
sandholm
2011/01/07 13:20:01
Done.
| |
| 71 function SparseJoin(array, len, convert) { | 71 function SparseJoin(array, len, convert) { |
| 72 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); | 72 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); |
| 73 var last_key = -1; | 73 var last_key = -1; |
| 74 var keys_length = keys.length; | 74 var keys_length = keys.length; |
| 75 | 75 |
| 76 var elements = new $Array(keys_length); | 76 var elements = new $Array(keys_length); |
| 77 var elements_length = 0; | 77 var elements_length = 0; |
| 78 | 78 |
| 79 for (var i = 0; i < keys_length; i++) { | 79 for (var i = 0; i < keys_length; i++) { |
| 80 var key = keys[i]; | 80 var key = keys[i]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return SparseJoin(array, length, convert); | 114 return SparseJoin(array, length, convert); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Fast case for one-element arrays. | 117 // Fast case for one-element arrays. |
| 118 if (length == 1) { | 118 if (length == 1) { |
| 119 var e = array[0]; | 119 var e = array[0]; |
| 120 if (!IS_UNDEFINED(e) || (0 in array)) { | 120 if (!IS_UNDEFINED(e) || (0 in array)) { |
| 121 if (IS_STRING(e)) return e; | 121 if (IS_STRING(e)) return e; |
| 122 return convert(e); | 122 return convert(e); |
| 123 } | 123 } |
| 124 return ''; | |
| 124 } | 125 } |
| 125 | 126 |
| 126 // Construct an array for the elements. | 127 // Construct an array for the elements. |
| 127 var elements; | 128 var elements; |
| 128 var elements_length = 0; | 129 var elements_length = 0; |
| 129 | 130 |
| 130 // We pull the empty separator check outside the loop for speed! | 131 // We pull the empty separator check outside the loop for speed! |
| 131 if (separator.length == 0) { | 132 if (separator.length == 0) { |
| 132 elements = new $Array(length); | 133 elements = new $Array(length); |
| 133 for (var i = 0; i < length; i++) { | 134 for (var i = 0; i < length; i++) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 153 if (!IS_UNDEFINED(result)) return result; | 154 if (!IS_UNDEFINED(result)) return result; |
| 154 return %StringBuilderConcat(elements, elements_length, ''); | 155 return %StringBuilderConcat(elements, elements_length, ''); |
| 155 } finally { | 156 } finally { |
| 156 // Make sure to pop the visited array no matter what happens. | 157 // Make sure to pop the visited array no matter what happens. |
| 157 if (is_array) visited_arrays.pop(); | 158 if (is_array) visited_arrays.pop(); |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 161 | 162 |
| 162 function ConvertToString(x) { | 163 function ConvertToString(x) { |
| 163 if (IS_STRING(x)) return x; | |
| 164 if (IS_NUMBER(x)) return %_NumberToString(x); | 164 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); | 166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 | 169 |
| 170 function ConvertToLocaleString(e) { | 170 function ConvertToLocaleString(e) { |
| 171 if (e == null) { | 171 if (e == null) { |
| 172 return ''; | 172 return ''; |
| 173 } else { | 173 } else { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1209 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1210 "reduce", getFunction("reduce", ArrayReduce, 1), | 1210 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1211 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1211 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1212 )); | 1212 )); |
| 1213 | 1213 |
| 1214 %FinishArrayPrototypeSetup($Array.prototype); | 1214 %FinishArrayPrototypeSetup($Array.prototype); |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 | 1217 |
| 1218 SetupArray(); | 1218 SetupArray(); |
| OLD | NEW |