| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 var result = %_FastAsciiArrayJoin(elements, ""); | 152 var result = %_FastAsciiArrayJoin(elements, ""); |
| 153 if (!IS_UNDEFINED(result)) return result; | 153 if (!IS_UNDEFINED(result)) return result; |
| 154 return %StringBuilderConcat(elements, elements_length, ''); | 154 return %StringBuilderConcat(elements, elements_length, ''); |
| 155 } finally { | 155 } finally { |
| 156 // Make sure to pop the visited array no matter what happens. | 156 // Make sure to pop the visited array no matter what happens. |
| 157 if (is_array) visited_arrays.pop(); | 157 if (is_array) visited_arrays.pop(); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 function ConvertToString(x) { | 162 function ConvertToString(e) { |
| 163 if (IS_STRING(x)) return x; | 163 if (e == null) return ''; |
| 164 if (IS_NUMBER(x)) return %_NumberToString(x); | 164 else return ToString(e); |
| 165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | |
| 166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); | |
| 167 } | 165 } |
| 168 | 166 |
| 169 | 167 |
| 170 function ConvertToLocaleString(e) { | 168 function ConvertToLocaleString(e) { |
| 171 if (e == null) { | 169 if (e == null) { |
| 172 return ''; | 170 return ''; |
| 173 } else { | 171 } else { |
| 174 // e_obj's toLocaleString might be overwritten, check if it is a function. | 172 // e_obj's toLocaleString might be overwritten, check if it is a function. |
| 175 // Call ToString if toLocaleString is not a function. | 173 // Call ToString if toLocaleString is not a function. |
| 176 // See issue 877615. | 174 // See issue 877615. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 throw new $TypeError('Array.prototype.toString is not generic'); | 358 throw new $TypeError('Array.prototype.toString is not generic'); |
| 361 } | 359 } |
| 362 return Join(this, this.length, ',', ConvertToLocaleString); | 360 return Join(this, this.length, ',', ConvertToLocaleString); |
| 363 } | 361 } |
| 364 | 362 |
| 365 | 363 |
| 366 function ArrayJoin(separator) { | 364 function ArrayJoin(separator) { |
| 367 if (IS_UNDEFINED(separator)) { | 365 if (IS_UNDEFINED(separator)) { |
| 368 separator = ','; | 366 separator = ','; |
| 369 } else if (!IS_STRING(separator)) { | 367 } else if (!IS_STRING(separator)) { |
| 370 separator = NonStringToString(separator); | 368 separator = ToString(separator); |
| 371 } | 369 } |
| 372 | 370 |
| 373 var result = %_FastAsciiArrayJoin(this, separator); | 371 var result = %_FastAsciiArrayJoin(this, separator); |
| 374 if (!IS_UNDEFINED(result)) return result; | 372 if (!IS_UNDEFINED(result)) return result; |
| 375 | 373 |
| 376 return Join(this, TO_UINT32(this.length), separator, ConvertToString); | 374 var length = TO_UINT32(this.length); |
| 375 return Join(this, length, separator, ConvertToString); |
| 377 } | 376 } |
| 378 | 377 |
| 379 | 378 |
| 380 // Removes the last element from the array and returns it. See | 379 // Removes the last element from the array and returns it. See |
| 381 // ECMA-262, section 15.4.4.6. | 380 // ECMA-262, section 15.4.4.6. |
| 382 function ArrayPop() { | 381 function ArrayPop() { |
| 383 var n = TO_UINT32(this.length); | 382 var n = TO_UINT32(this.length); |
| 384 if (n == 0) { | 383 if (n == 0) { |
| 385 this.length = n; | 384 this.length = n; |
| 386 return; | 385 return; |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1171 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1173 "reduce", getFunction("reduce", ArrayReduce, 1), | 1172 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1174 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1173 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1175 )); | 1174 )); |
| 1176 | 1175 |
| 1177 %FinishArrayPrototypeSetup($Array.prototype); | 1176 %FinishArrayPrototypeSetup($Array.prototype); |
| 1178 } | 1177 } |
| 1179 | 1178 |
| 1180 | 1179 |
| 1181 SetupArray(); | 1180 SetupArray(); |
| OLD | NEW |