OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var $arrayConcat; | 5 var $arrayConcat; |
6 var $arrayPush; | 6 var $arrayPush; |
7 var $arrayPop; | 7 var $arrayPop; |
8 var $arrayShift; | 8 var $arrayShift; |
9 var $arraySlice; | 9 var $arraySlice; |
10 var $arraySplice; | 10 var $arraySplice; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 array = $toObject(this); | 391 array = $toObject(this); |
392 func = array.join; | 392 func = array.join; |
393 } | 393 } |
394 if (!IS_SPEC_FUNCTION(func)) { | 394 if (!IS_SPEC_FUNCTION(func)) { |
395 return %_CallFunction(array, ObjectToString); | 395 return %_CallFunction(array, ObjectToString); |
396 } | 396 } |
397 return %_CallFunction(array, func); | 397 return %_CallFunction(array, func); |
398 } | 398 } |
399 | 399 |
400 | 400 |
| 401 function InnerArrayToLocaleString(array, length) { |
| 402 var len = TO_UINT32(length); |
| 403 if (len === 0) return ""; |
| 404 return Join(array, len, ',', ConvertToLocaleString); |
| 405 } |
| 406 |
| 407 |
401 function ArrayToLocaleString() { | 408 function ArrayToLocaleString() { |
402 var array = $toObject(this); | 409 var array = $toObject(this); |
403 var arrayLen = array.length; | 410 var arrayLen = array.length; |
404 var len = TO_UINT32(arrayLen); | 411 return InnerArrayToLocaleString(array, arrayLen); |
405 if (len === 0) return ""; | |
406 return Join(array, len, ',', ConvertToLocaleString); | |
407 } | 412 } |
408 | 413 |
409 | 414 |
410 function ArrayJoin(separator) { | 415 function InnerArrayJoin(separator, array, length) { |
411 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); | |
412 | |
413 var array = TO_OBJECT_INLINE(this); | |
414 var length = TO_UINT32(array.length); | |
415 if (IS_UNDEFINED(separator)) { | 416 if (IS_UNDEFINED(separator)) { |
416 separator = ','; | 417 separator = ','; |
417 } else if (!IS_STRING(separator)) { | 418 } else if (!IS_STRING(separator)) { |
418 separator = $nonStringToString(separator); | 419 separator = $nonStringToString(separator); |
419 } | 420 } |
420 | 421 |
421 var result = %_FastOneByteArrayJoin(array, separator); | 422 var result = %_FastOneByteArrayJoin(array, separator); |
422 if (!IS_UNDEFINED(result)) return result; | 423 if (!IS_UNDEFINED(result)) return result; |
423 | 424 |
424 // Fast case for one-element arrays. | 425 // Fast case for one-element arrays. |
425 if (length === 1) { | 426 if (length === 1) { |
426 var e = array[0]; | 427 var e = array[0]; |
427 if (IS_STRING(e)) return e; | 428 if (IS_STRING(e)) return e; |
428 if (IS_NULL_OR_UNDEFINED(e)) return ''; | 429 if (IS_NULL_OR_UNDEFINED(e)) return ''; |
429 return $nonStringToString(e); | 430 return $nonStringToString(e); |
430 } | 431 } |
431 | 432 |
432 return Join(array, length, separator, ConvertToString); | 433 return Join(array, length, separator, ConvertToString); |
433 } | 434 } |
434 | 435 |
435 | 436 |
| 437 function ArrayJoin(separator) { |
| 438 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); |
| 439 |
| 440 var array = TO_OBJECT_INLINE(this); |
| 441 var length = TO_UINT32(array.length); |
| 442 |
| 443 return InnerArrayJoin(separator, array, length); |
| 444 } |
| 445 |
| 446 |
436 function ObservedArrayPop(n) { | 447 function ObservedArrayPop(n) { |
437 n--; | 448 n--; |
438 var value = this[n]; | 449 var value = this[n]; |
439 | 450 |
440 try { | 451 try { |
441 $observeBeginPerformSplice(this); | 452 $observeBeginPerformSplice(this); |
442 delete this[n]; | 453 delete this[n]; |
443 this.length = n; | 454 this.length = n; |
444 } finally { | 455 } finally { |
445 $observeEndPerformSplice(this); | 456 $observeEndPerformSplice(this); |
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 "pop", getFunction("pop", ArrayPop), | 1658 "pop", getFunction("pop", ArrayPop), |
1648 "push", getFunction("push", ArrayPush), | 1659 "push", getFunction("push", ArrayPush), |
1649 "shift", getFunction("shift", ArrayShift) | 1660 "shift", getFunction("shift", ArrayShift) |
1650 ]); | 1661 ]); |
1651 | 1662 |
1652 // ------------------------------------------------------------------- | 1663 // ------------------------------------------------------------------- |
1653 // Exports | 1664 // Exports |
1654 | 1665 |
1655 utils.Export(function(to) { | 1666 utils.Export(function(to) { |
1656 to.ArrayJoin = ArrayJoin; | 1667 to.ArrayJoin = ArrayJoin; |
| 1668 to.ArrayToString = ArrayToString; |
1657 to.InnerArrayEvery = InnerArrayEvery; | 1669 to.InnerArrayEvery = InnerArrayEvery; |
1658 to.InnerArrayFilter = InnerArrayFilter; | 1670 to.InnerArrayFilter = InnerArrayFilter; |
1659 to.InnerArrayForEach = InnerArrayForEach; | 1671 to.InnerArrayForEach = InnerArrayForEach; |
1660 to.InnerArrayIndexOf = InnerArrayIndexOf; | 1672 to.InnerArrayIndexOf = InnerArrayIndexOf; |
| 1673 to.InnerArrayJoin = InnerArrayJoin; |
1661 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; | 1674 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; |
1662 to.InnerArrayMap = InnerArrayMap; | 1675 to.InnerArrayMap = InnerArrayMap; |
1663 to.InnerArrayReverse = InnerArrayReverse; | 1676 to.InnerArrayReverse = InnerArrayReverse; |
1664 to.InnerArraySome = InnerArraySome; | 1677 to.InnerArraySome = InnerArraySome; |
1665 to.InnerArraySort = InnerArraySort; | 1678 to.InnerArraySort = InnerArraySort; |
| 1679 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1666 }); | 1680 }); |
1667 | 1681 |
1668 $arrayConcat = ArrayConcatJS; | 1682 $arrayConcat = ArrayConcatJS; |
1669 $arrayPush = ArrayPush; | 1683 $arrayPush = ArrayPush; |
1670 $arrayPop = ArrayPop; | 1684 $arrayPop = ArrayPop; |
1671 $arrayShift = ArrayShift; | 1685 $arrayShift = ArrayShift; |
1672 $arraySlice = ArraySlice; | 1686 $arraySlice = ArraySlice; |
1673 $arraySplice = ArraySplice; | 1687 $arraySplice = ArraySplice; |
1674 $arrayUnshift = ArrayUnshift; | 1688 $arrayUnshift = ArrayUnshift; |
1675 | 1689 |
1676 }); | 1690 }); |
OLD | NEW |