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 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var Delete; | 14 var Delete; |
15 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
16 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
17 var InternalPackedArray = utils.InternalPackedArray; | 17 var InternalPackedArray = utils.InternalPackedArray; |
18 var MathMin; | 18 var MathMin; |
19 var ObjectHasOwnProperty; | 19 var ObjectHasOwnProperty; |
20 var ObjectIsFrozen; | 20 var ObjectIsFrozen; |
21 var ObjectIsSealed; | 21 var ObjectIsSealed; |
22 var ObjectToString; | 22 var ObjectToString; |
23 var ToNumber; | |
24 var ToString; | |
25 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); | 23 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); |
26 | 24 |
27 utils.Import(function(from) { | 25 utils.Import(function(from) { |
28 Delete = from.Delete; | 26 Delete = from.Delete; |
29 MathMin = from.MathMin; | 27 MathMin = from.MathMin; |
30 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 28 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
31 ObjectIsFrozen = from.ObjectIsFrozen; | 29 ObjectIsFrozen = from.ObjectIsFrozen; |
32 ObjectIsSealed = from.ObjectIsSealed; | 30 ObjectIsSealed = from.ObjectIsSealed; |
33 ObjectToString = from.ObjectToString; | 31 ObjectToString = from.ObjectToString; |
34 ToNumber = from.ToNumber; | |
35 ToString = from.ToString; | |
36 }); | 32 }); |
37 | 33 |
38 // ------------------------------------------------------------------- | 34 // ------------------------------------------------------------------- |
39 | 35 |
40 // Global list of arrays visited during toString, toLocaleString and | 36 // Global list of arrays visited during toString, toLocaleString and |
41 // join invocations. | 37 // join invocations. |
42 var visited_arrays = new InternalArray(); | 38 var visited_arrays = new InternalArray(); |
43 | 39 |
44 | 40 |
45 // Gets a sorted array of array keys. Useful for operations on sparse | 41 // Gets a sorted array of array keys. Useful for operations on sparse |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 function InnerArraySort(array, length, comparefn) { | 881 function InnerArraySort(array, length, comparefn) { |
886 // In-place QuickSort algorithm. | 882 // In-place QuickSort algorithm. |
887 // For short (length <= 22) arrays, insertion sort is used for efficiency. | 883 // For short (length <= 22) arrays, insertion sort is used for efficiency. |
888 | 884 |
889 if (!IS_CALLABLE(comparefn)) { | 885 if (!IS_CALLABLE(comparefn)) { |
890 comparefn = function (x, y) { | 886 comparefn = function (x, y) { |
891 if (x === y) return 0; | 887 if (x === y) return 0; |
892 if (%_IsSmi(x) && %_IsSmi(y)) { | 888 if (%_IsSmi(x) && %_IsSmi(y)) { |
893 return %SmiLexicographicCompare(x, y); | 889 return %SmiLexicographicCompare(x, y); |
894 } | 890 } |
895 x = ToString(x); | 891 x = TO_STRING(x); |
896 y = ToString(y); | 892 y = TO_STRING(y); |
897 if (x == y) return 0; | 893 if (x == y) return 0; |
898 else return x < y ? -1 : 1; | 894 else return x < y ? -1 : 1; |
899 }; | 895 }; |
900 } | 896 } |
901 var InsertionSort = function InsertionSort(a, from, to) { | 897 var InsertionSort = function InsertionSort(a, from, to) { |
902 for (var i = from + 1; i < to; i++) { | 898 for (var i = from + 1; i < to; i++) { |
903 var element = a[i]; | 899 var element = a[i]; |
904 for (var j = i - 1; j >= from; j--) { | 900 for (var j = i - 1; j >= from; j--) { |
905 var tmp = a[j]; | 901 var tmp = a[j]; |
906 var order = comparefn(tmp, element); | 902 var order = comparefn(tmp, element); |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 %InstallToContext([ | 1654 %InstallToContext([ |
1659 "array_pop", ArrayPop, | 1655 "array_pop", ArrayPop, |
1660 "array_push", ArrayPush, | 1656 "array_push", ArrayPush, |
1661 "array_shift", ArrayShift, | 1657 "array_shift", ArrayShift, |
1662 "array_splice", ArraySplice, | 1658 "array_splice", ArraySplice, |
1663 "array_slice", ArraySlice, | 1659 "array_slice", ArraySlice, |
1664 "array_unshift", ArrayUnshift, | 1660 "array_unshift", ArrayUnshift, |
1665 ]); | 1661 ]); |
1666 | 1662 |
1667 }); | 1663 }); |
OLD | NEW |