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, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 // the prototype chain on non-Array objects. | 964 // the prototype chain on non-Array objects. |
965 // We do this by copying them to this object and sorting only | 965 // We do this by copying them to this object and sorting only |
966 // own elements. This is not very efficient, but sorting with | 966 // own elements. This is not very efficient, but sorting with |
967 // inherited elements happens very, very rarely, if at all. | 967 // inherited elements happens very, very rarely, if at all. |
968 // The specification allows "implementation dependent" behavior | 968 // The specification allows "implementation dependent" behavior |
969 // if an element on the prototype chain has an element that | 969 // if an element on the prototype chain has an element that |
970 // might interact with sorting. | 970 // might interact with sorting. |
971 max_prototype_element = CopyFromPrototype(array, length); | 971 max_prototype_element = CopyFromPrototype(array, length); |
972 } | 972 } |
973 | 973 |
| 974 if (!%object_is_extensible(array)) { |
| 975 // If the array have holes in the middle of the array, |
| 976 // hole indices can be defined while removing array holes. |
| 977 var last_hole = -1; |
| 978 var first_hole = -1; |
| 979 for (var i = 0; i < length; i++) { |
| 980 if (!HAS_OWN_PROPERTY(array, i)) { |
| 981 if (first_hole == -1) first_hole = i; |
| 982 last_hole = i; |
| 983 } |
| 984 } |
| 985 if (last_hole != -1 && last_hole < length - 1) { |
| 986 throw %make_type_error(kObjectNotExtensible, first_hole); |
| 987 } |
| 988 } |
| 989 |
974 // %RemoveArrayHoles returns -1 if fast removal is not supported. | 990 // %RemoveArrayHoles returns -1 if fast removal is not supported. |
975 var num_non_undefined = %RemoveArrayHoles(array, length); | 991 var num_non_undefined = %RemoveArrayHoles(array, length); |
976 | 992 |
977 if (num_non_undefined == -1) { | 993 if (num_non_undefined == -1) { |
978 // There were indexed accessors in the array. | 994 // There were indexed accessors in the array. |
979 // Move array holes and undefineds to the end using a Javascript function | 995 // Move array holes and undefineds to the end using a Javascript function |
980 // that is safe in the presence of accessors. | 996 // that is safe in the presence of accessors. |
981 num_non_undefined = SafeRemoveArrayHoles(array); | 997 num_non_undefined = SafeRemoveArrayHoles(array); |
982 } | 998 } |
983 | 999 |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 "array_pop", ArrayPop, | 1650 "array_pop", ArrayPop, |
1635 "array_push", ArrayPush, | 1651 "array_push", ArrayPush, |
1636 "array_shift", ArrayShift, | 1652 "array_shift", ArrayShift, |
1637 "array_splice", ArraySplice, | 1653 "array_splice", ArraySplice, |
1638 "array_slice", ArraySlice, | 1654 "array_slice", ArraySlice, |
1639 "array_unshift", ArrayUnshift, | 1655 "array_unshift", ArrayUnshift, |
1640 "array_values_iterator", ArrayValues, | 1656 "array_values_iterator", ArrayValues, |
1641 ]); | 1657 ]); |
1642 | 1658 |
1643 }); | 1659 }); |
OLD | NEW |