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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 for (var i = 0; i < m; i++) { | 515 for (var i = 0; i < m; i++) { |
516 array[i+n] = %_Arguments(i); | 516 array[i+n] = %_Arguments(i); |
517 } | 517 } |
518 | 518 |
519 var new_length = n + m; | 519 var new_length = n + m; |
520 array.length = new_length; | 520 array.length = new_length; |
521 return new_length; | 521 return new_length; |
522 } | 522 } |
523 | 523 |
524 | 524 |
525 // Returns an array containing the array elements of the object followed | |
526 // by the array elements of each argument in order. See ECMA-262, | |
527 // section 15.4.4.7. | |
528 function ArrayConcatJS(arg1) { // length == 1 | |
529 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat"); | |
530 | |
531 var array = TO_OBJECT(this); | |
532 var arg_count = %_ArgumentsLength(); | |
533 var arrays = new InternalArray(1 + arg_count); | |
534 arrays[0] = array; | |
535 for (var i = 0; i < arg_count; i++) { | |
536 arrays[i + 1] = %_Arguments(i); | |
537 } | |
538 | |
539 return %ArrayConcat(arrays); | |
540 } | |
541 | |
542 | |
543 // For implementing reverse() on large, sparse arrays. | 525 // For implementing reverse() on large, sparse arrays. |
544 function SparseReverse(array, len) { | 526 function SparseReverse(array, len) { |
545 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); | 527 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); |
546 var high_counter = keys.length - 1; | 528 var high_counter = keys.length - 1; |
547 var low_counter = 0; | 529 var low_counter = 0; |
548 while (low_counter <= high_counter) { | 530 while (low_counter <= high_counter) { |
549 var i = keys[low_counter]; | 531 var i = keys[low_counter]; |
550 var j = keys[high_counter]; | 532 var j = keys[high_counter]; |
551 | 533 |
552 var j_complement = len - j - 1; | 534 var j_complement = len - j - 1; |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 // Set up non-enumerable functions of the Array.prototype object and | 1617 // Set up non-enumerable functions of the Array.prototype object and |
1636 // set their names. | 1618 // set their names. |
1637 // Manipulate the length of some of the functions to meet | 1619 // Manipulate the length of some of the functions to meet |
1638 // expectations set by ECMA-262 or Mozilla. | 1620 // expectations set by ECMA-262 or Mozilla. |
1639 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 1621 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ |
1640 "toString", getFunction("toString", ArrayToString), | 1622 "toString", getFunction("toString", ArrayToString), |
1641 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), | 1623 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), |
1642 "join", getFunction("join", ArrayJoin), | 1624 "join", getFunction("join", ArrayJoin), |
1643 "pop", getFunction("pop", ArrayPop), | 1625 "pop", getFunction("pop", ArrayPop), |
1644 "push", getFunction("push", ArrayPush, 1), | 1626 "push", getFunction("push", ArrayPush, 1), |
1645 "concat", getFunction("concat", ArrayConcatJS, 1), | |
1646 "reverse", getFunction("reverse", ArrayReverse), | 1627 "reverse", getFunction("reverse", ArrayReverse), |
1647 "shift", getFunction("shift", ArrayShift), | 1628 "shift", getFunction("shift", ArrayShift), |
1648 "unshift", getFunction("unshift", ArrayUnshift, 1), | 1629 "unshift", getFunction("unshift", ArrayUnshift, 1), |
1649 "slice", getFunction("slice", ArraySlice, 2), | 1630 "slice", getFunction("slice", ArraySlice, 2), |
1650 "splice", getFunction("splice", ArraySplice, 2), | 1631 "splice", getFunction("splice", ArraySplice, 2), |
1651 "sort", getFunction("sort", ArraySort), | 1632 "sort", getFunction("sort", ArraySort), |
1652 "filter", getFunction("filter", ArrayFilter, 1), | 1633 "filter", getFunction("filter", ArrayFilter, 1), |
1653 "forEach", getFunction("forEach", ArrayForEach, 1), | 1634 "forEach", getFunction("forEach", ArrayForEach, 1), |
1654 "some", getFunction("some", ArraySome, 1), | 1635 "some", getFunction("some", ArraySome, 1), |
1655 "every", getFunction("every", ArrayEvery, 1), | 1636 "every", getFunction("every", ArrayEvery, 1), |
1656 "map", getFunction("map", ArrayMap, 1), | 1637 "map", getFunction("map", ArrayMap, 1), |
1657 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), | 1638 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), |
1658 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1639 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1659 "reduce", getFunction("reduce", ArrayReduce, 1), | 1640 "reduce", getFunction("reduce", ArrayReduce, 1), |
1660 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1641 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
1661 ]); | 1642 ]); |
1662 | 1643 |
1663 %FinishArrayPrototypeSetup(GlobalArray.prototype); | 1644 %FinishArrayPrototypeSetup(GlobalArray.prototype); |
1664 | 1645 |
1665 // The internal Array prototype doesn't need to be fancy, since it's never | 1646 // The internal Array prototype doesn't need to be fancy, since it's never |
1666 // exposed to user code. | 1647 // exposed to user code. |
1667 // Adding only the functions that are actually used. | 1648 // Adding only the functions that are actually used. |
1668 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ | 1649 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ |
1669 "concat", getFunction("concat", ArrayConcatJS), | |
1670 "indexOf", getFunction("indexOf", ArrayIndexOf), | 1650 "indexOf", getFunction("indexOf", ArrayIndexOf), |
1671 "join", getFunction("join", ArrayJoin), | 1651 "join", getFunction("join", ArrayJoin), |
1672 "pop", getFunction("pop", ArrayPop), | 1652 "pop", getFunction("pop", ArrayPop), |
1673 "push", getFunction("push", ArrayPush), | 1653 "push", getFunction("push", ArrayPush), |
1674 "shift", getFunction("shift", ArrayShift), | 1654 "shift", getFunction("shift", ArrayShift), |
1675 "splice", getFunction("splice", ArraySplice) | 1655 "splice", getFunction("splice", ArraySplice) |
1676 ]); | 1656 ]); |
1677 | 1657 |
1678 utils.SetUpLockedPrototype(InternalPackedArray, GlobalArray(), [ | 1658 utils.SetUpLockedPrototype(InternalPackedArray, GlobalArray(), [ |
1679 "join", getFunction("join", ArrayJoin), | 1659 "join", getFunction("join", ArrayJoin), |
(...skipping 19 matching lines...) Expand all Loading... |
1699 to.InnerArrayMap = InnerArrayMap; | 1679 to.InnerArrayMap = InnerArrayMap; |
1700 to.InnerArrayReduce = InnerArrayReduce; | 1680 to.InnerArrayReduce = InnerArrayReduce; |
1701 to.InnerArrayReduceRight = InnerArrayReduceRight; | 1681 to.InnerArrayReduceRight = InnerArrayReduceRight; |
1702 to.InnerArraySome = InnerArraySome; | 1682 to.InnerArraySome = InnerArraySome; |
1703 to.InnerArraySort = InnerArraySort; | 1683 to.InnerArraySort = InnerArraySort; |
1704 to.InnerArrayToLocaleString = InnerArrayToLocaleString; | 1684 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1705 to.PackedArrayReverse = PackedArrayReverse; | 1685 to.PackedArrayReverse = PackedArrayReverse; |
1706 }); | 1686 }); |
1707 | 1687 |
1708 %InstallToContext([ | 1688 %InstallToContext([ |
1709 "array_concat", ArrayConcatJS, | |
1710 "array_pop", ArrayPop, | 1689 "array_pop", ArrayPop, |
1711 "array_push", ArrayPush, | 1690 "array_push", ArrayPush, |
1712 "array_shift", ArrayShift, | 1691 "array_shift", ArrayShift, |
1713 "array_splice", ArraySplice, | 1692 "array_splice", ArraySplice, |
1714 "array_slice", ArraySlice, | 1693 "array_slice", ArraySlice, |
1715 "array_unshift", ArrayUnshift, | 1694 "array_unshift", ArrayUnshift, |
1716 ]); | 1695 ]); |
1717 | 1696 |
1718 }); | 1697 }); |
OLD | NEW |