Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: src/js/array.js

Issue 1553043002: [builtins] Migrate a bunch of Object builtins to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/contexts.h ('k') | src/js/object-observe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var AddIndexedProperty; 14 var AddIndexedProperty;
15 var FLAG_harmony_tolength; 15 var FLAG_harmony_tolength;
16 var GetIterator; 16 var GetIterator;
17 var GetMethod; 17 var GetMethod;
18 var GlobalArray = global.Array; 18 var GlobalArray = global.Array;
19 var InternalArray = utils.InternalArray; 19 var InternalArray = utils.InternalArray;
20 var InternalPackedArray = utils.InternalPackedArray; 20 var InternalPackedArray = utils.InternalPackedArray;
21 var MakeTypeError; 21 var MakeTypeError;
22 var MaxSimple; 22 var MaxSimple;
23 var MinSimple; 23 var MinSimple;
24 var ObjectDefineProperty; 24 var ObjectDefineProperty;
25 var ObjectHasOwnProperty; 25 var ObjectHasOwnProperty;
26 var ObjectIsFrozen;
27 var ObjectIsSealed;
28 var ObjectToString = utils.ImportNow("object_to_string"); 26 var ObjectToString = utils.ImportNow("object_to_string");
29 var ObserveBeginPerformSplice; 27 var ObserveBeginPerformSplice;
30 var ObserveEndPerformSplice; 28 var ObserveEndPerformSplice;
31 var ObserveEnqueueSpliceRecord; 29 var ObserveEnqueueSpliceRecord;
32 var SameValueZero; 30 var SameValueZero;
33 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 31 var iteratorSymbol = utils.ImportNow("iterator_symbol");
34 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); 32 var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
35 33
36 utils.Import(function(from) { 34 utils.Import(function(from) {
37 AddIndexedProperty = from.AddIndexedProperty; 35 AddIndexedProperty = from.AddIndexedProperty;
38 GetIterator = from.GetIterator; 36 GetIterator = from.GetIterator;
39 GetMethod = from.GetMethod; 37 GetMethod = from.GetMethod;
40 MakeTypeError = from.MakeTypeError; 38 MakeTypeError = from.MakeTypeError;
41 MaxSimple = from.MaxSimple; 39 MaxSimple = from.MaxSimple;
42 MinSimple = from.MinSimple; 40 MinSimple = from.MinSimple;
43 ObjectDefineProperty = from.ObjectDefineProperty; 41 ObjectDefineProperty = from.ObjectDefineProperty;
44 ObjectHasOwnProperty = from.ObjectHasOwnProperty; 42 ObjectHasOwnProperty = from.ObjectHasOwnProperty;
45 ObjectIsFrozen = from.ObjectIsFrozen;
46 ObjectIsSealed = from.ObjectIsSealed;
47 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice; 43 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice;
48 ObserveEndPerformSplice = from.ObserveEndPerformSplice; 44 ObserveEndPerformSplice = from.ObserveEndPerformSplice;
49 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; 45 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord;
50 SameValueZero = from.SameValueZero; 46 SameValueZero = from.SameValueZero;
51 }); 47 });
52 48
53 utils.ImportFromExperimental(function(from) { 49 utils.ImportFromExperimental(function(from) {
54 FLAG_harmony_tolength = from.FLAG_harmony_tolength; 50 FLAG_harmony_tolength = from.FLAG_harmony_tolength;
55 }); 51 });
56 52
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); 661 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
666 662
667 var array = TO_OBJECT(this); 663 var array = TO_OBJECT(this);
668 var len = TO_LENGTH_OR_UINT32(array.length); 664 var len = TO_LENGTH_OR_UINT32(array.length);
669 665
670 if (len === 0) { 666 if (len === 0) {
671 array.length = 0; 667 array.length = 0;
672 return; 668 return;
673 } 669 }
674 670
675 if (ObjectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed); 671 if (%object_is_sealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed);
676 672
677 if (%IsObserved(array)) 673 if (%IsObserved(array))
678 return ObservedArrayShift.call(array, len); 674 return ObservedArrayShift.call(array, len);
679 675
680 var first = array[0]; 676 var first = array[0];
681 677
682 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) { 678 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
683 SparseMove(array, 0, 1, len, 0); 679 SparseMove(array, 0, 1, len, 0);
684 } else { 680 } else {
685 SimpleMove(array, 0, 1, len, 0); 681 SimpleMove(array, 0, 1, len, 0);
(...skipping 30 matching lines...) Expand all
716 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); 712 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
717 713
718 if (%IsObserved(this)) 714 if (%IsObserved(this))
719 return ObservedArrayUnshift.apply(this, arguments); 715 return ObservedArrayUnshift.apply(this, arguments);
720 716
721 var array = TO_OBJECT(this); 717 var array = TO_OBJECT(this);
722 var len = TO_LENGTH_OR_UINT32(array.length); 718 var len = TO_LENGTH_OR_UINT32(array.length);
723 var num_arguments = %_ArgumentsLength(); 719 var num_arguments = %_ArgumentsLength();
724 720
725 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) && 721 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) &&
726 !ObjectIsSealed(array)) { 722 !%object_is_sealed(array)) {
727 SparseMove(array, 0, 0, len, num_arguments); 723 SparseMove(array, 0, 0, len, num_arguments);
728 } else { 724 } else {
729 SimpleMove(array, 0, 0, len, num_arguments); 725 SimpleMove(array, 0, 0, len, num_arguments);
730 } 726 }
731 727
732 for (var i = 0; i < num_arguments; i++) { 728 for (var i = 0; i < num_arguments; i++) {
733 array[i] = %_Arguments(i); 729 array[i] = %_Arguments(i);
734 } 730 }
735 731
736 var new_length = len + num_arguments; 732 var new_length = len + num_arguments;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 var num_arguments = %_ArgumentsLength(); 858 var num_arguments = %_ArgumentsLength();
863 var array = TO_OBJECT(this); 859 var array = TO_OBJECT(this);
864 var len = TO_LENGTH_OR_UINT32(array.length); 860 var len = TO_LENGTH_OR_UINT32(array.length);
865 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 861 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
866 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 862 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
867 start_i); 863 start_i);
868 var deleted_elements = []; 864 var deleted_elements = [];
869 deleted_elements.length = del_count; 865 deleted_elements.length = del_count;
870 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 866 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
871 867
872 if (del_count != num_elements_to_add && ObjectIsSealed(array)) { 868 if (del_count != num_elements_to_add && %object_is_sealed(array)) {
873 throw MakeTypeError(kArrayFunctionsOnSealed); 869 throw MakeTypeError(kArrayFunctionsOnSealed);
874 } else if (del_count > 0 && ObjectIsFrozen(array)) { 870 } else if (del_count > 0 && %object_is_frozen(array)) {
875 throw MakeTypeError(kArrayFunctionsOnFrozen); 871 throw MakeTypeError(kArrayFunctionsOnFrozen);
876 } 872 }
877 873
878 var changed_elements = del_count; 874 var changed_elements = del_count;
879 if (num_elements_to_add != del_count) { 875 if (num_elements_to_add != del_count) {
880 // If the slice needs to do a actually move elements after the insertion 876 // If the slice needs to do a actually move elements after the insertion
881 // point, then include those in the estimate of changed elements. 877 // point, then include those in the estimate of changed elements.
882 changed_elements += len - start_i - del_count; 878 changed_elements += len - start_i - del_count;
883 } 879 }
884 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) { 880 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) {
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 if (i > length) i = length; 1664 if (i > length) i = length;
1669 } 1665 }
1670 1666
1671 if (end < 0) { 1667 if (end < 0) {
1672 end += length; 1668 end += length;
1673 if (end < 0) end = 0; 1669 if (end < 0) end = 0;
1674 } else { 1670 } else {
1675 if (end > length) end = length; 1671 if (end > length) end = length;
1676 } 1672 }
1677 1673
1678 if ((end - i) > 0 && ObjectIsFrozen(array)) { 1674 if ((end - i) > 0 && %object_is_frozen(array)) {
1679 throw MakeTypeError(kArrayFunctionsOnFrozen); 1675 throw MakeTypeError(kArrayFunctionsOnFrozen);
1680 } 1676 }
1681 1677
1682 for (; i < end; i++) 1678 for (; i < end; i++)
1683 array[i] = value; 1679 array[i] = value;
1684 return array; 1680 return array;
1685 } 1681 }
1686 1682
1687 1683
1688 // ES6, draft 04-05-14, section 22.1.3.6 1684 // ES6, draft 04-05-14, section 22.1.3.6
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 %InstallToContext([ 1960 %InstallToContext([
1965 "array_pop", ArrayPop, 1961 "array_pop", ArrayPop,
1966 "array_push", ArrayPush, 1962 "array_push", ArrayPush,
1967 "array_shift", ArrayShift, 1963 "array_shift", ArrayShift,
1968 "array_splice", ArraySplice, 1964 "array_splice", ArraySplice,
1969 "array_slice", ArraySlice, 1965 "array_slice", ArraySlice,
1970 "array_unshift", ArrayUnshift, 1966 "array_unshift", ArrayUnshift,
1971 ]); 1967 ]);
1972 1968
1973 }); 1969 });
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/js/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698