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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 elements = new $Array(length << 1); | 141 elements = new $Array(length << 1); |
142 for (var i = 0; i < length; i++) { | 142 for (var i = 0; i < length; i++) { |
143 var e = array[i]; | 143 var e = array[i]; |
144 if (i != 0) elements[elements_length++] = separator; | 144 if (i != 0) elements[elements_length++] = separator; |
145 if (!IS_UNDEFINED(e) || (i in array)) { | 145 if (!IS_UNDEFINED(e) || (i in array)) { |
146 if (!IS_STRING(e)) e = convert(e); | 146 if (!IS_STRING(e)) e = convert(e); |
147 elements[elements_length++] = e; | 147 elements[elements_length++] = e; |
148 } | 148 } |
149 } | 149 } |
150 } | 150 } |
| 151 elements.length = elements_length; |
| 152 var result = %_FastAsciiArrayJoin(elements, ""); |
| 153 if (!IS_UNDEFINED(result)) return result; |
151 return %StringBuilderConcat(elements, elements_length, ''); | 154 return %StringBuilderConcat(elements, elements_length, ''); |
152 } finally { | 155 } finally { |
153 // Make sure to pop the visited array no matter what happens. | 156 // Make sure to pop the visited array no matter what happens. |
154 if (is_array) visited_arrays.pop(); | 157 if (is_array) visited_arrays.pop(); |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
158 | 161 |
159 function ConvertToString(e) { | 162 function ConvertToString(e) { |
160 if (e == null) return ''; | 163 if (e == null) return ''; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 362 |
360 | 363 |
361 function ArrayJoin(separator) { | 364 function ArrayJoin(separator) { |
362 if (IS_UNDEFINED(separator)) { | 365 if (IS_UNDEFINED(separator)) { |
363 separator = ','; | 366 separator = ','; |
364 } else if (!IS_STRING(separator)) { | 367 } else if (!IS_STRING(separator)) { |
365 separator = ToString(separator); | 368 separator = ToString(separator); |
366 } | 369 } |
367 | 370 |
368 var result = %_FastAsciiArrayJoin(this, separator); | 371 var result = %_FastAsciiArrayJoin(this, separator); |
369 if (typeof result != "undefined") return result; | 372 if (!IS_UNDEFINED(result)) return result; |
370 | 373 |
371 var length = TO_UINT32(this.length); | 374 var length = TO_UINT32(this.length); |
372 return Join(this, length, separator, ConvertToString); | 375 return Join(this, length, separator, ConvertToString); |
373 } | 376 } |
374 | 377 |
375 | 378 |
376 // Removes the last element from the array and returns it. See | 379 // Removes the last element from the array and returns it. See |
377 // ECMA-262, section 15.4.4.6. | 380 // ECMA-262, section 15.4.4.6. |
378 function ArrayPop() { | 381 function ArrayPop() { |
379 var n = TO_UINT32(this.length); | 382 var n = TO_UINT32(this.length); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1171 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1169 "reduce", getFunction("reduce", ArrayReduce, 1), | 1172 "reduce", getFunction("reduce", ArrayReduce, 1), |
1170 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1173 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
1171 )); | 1174 )); |
1172 | 1175 |
1173 %FinishArrayPrototypeSetup($Array.prototype); | 1176 %FinishArrayPrototypeSetup($Array.prototype); |
1174 } | 1177 } |
1175 | 1178 |
1176 | 1179 |
1177 SetupArray(); | 1180 SetupArray(); |
OLD | NEW |