OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 ArrayFrom; | 14 var AddIndexedProperty; |
15 var ArrayToString; | 15 var ArrayToString; |
16 var ArrayValues; | 16 var ArrayValues; |
17 var GetIterator; | |
18 var GetMethod; | |
17 var GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
18 var GlobalArrayBuffer = global.ArrayBuffer; | 20 var GlobalArrayBuffer = global.ArrayBuffer; |
19 var GlobalDataView = global.DataView; | 21 var GlobalDataView = global.DataView; |
20 var GlobalObject = global.Object; | 22 var GlobalObject = global.Object; |
21 var InternalArray = utils.InternalArray; | 23 var InternalArray = utils.InternalArray; |
22 var InnerArrayCopyWithin; | 24 var InnerArrayCopyWithin; |
23 var InnerArrayEvery; | 25 var InnerArrayEvery; |
24 var InnerArrayFill; | 26 var InnerArrayFill; |
25 var InnerArrayFilter; | 27 var InnerArrayFilter; |
26 var InnerArrayFind; | 28 var InnerArrayFind; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 FUNCTION(9, Uint8ClampedArray, 1) | 62 FUNCTION(9, Uint8ClampedArray, 1) |
61 endmacro | 63 endmacro |
62 | 64 |
63 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) | 65 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) |
64 var GlobalNAME = global.NAME; | 66 var GlobalNAME = global.NAME; |
65 endmacro | 67 endmacro |
66 | 68 |
67 TYPED_ARRAYS(DECLARE_GLOBALS) | 69 TYPED_ARRAYS(DECLARE_GLOBALS) |
68 | 70 |
69 utils.Import(function(from) { | 71 utils.Import(function(from) { |
70 ArrayFrom = from.ArrayFrom; | 72 AddIndexedProperty = from.AddIndexedProperty; |
71 ArrayToString = from.ArrayToString; | 73 ArrayToString = from.ArrayToString; |
72 ArrayValues = from.ArrayValues; | 74 ArrayValues = from.ArrayValues; |
75 GetIterator = from.GetIterator; | |
76 GetMethod = from.GetMethod; | |
73 InnerArrayCopyWithin = from.InnerArrayCopyWithin; | 77 InnerArrayCopyWithin = from.InnerArrayCopyWithin; |
74 InnerArrayEvery = from.InnerArrayEvery; | 78 InnerArrayEvery = from.InnerArrayEvery; |
75 InnerArrayFill = from.InnerArrayFill; | 79 InnerArrayFill = from.InnerArrayFill; |
76 InnerArrayFilter = from.InnerArrayFilter; | 80 InnerArrayFilter = from.InnerArrayFilter; |
77 InnerArrayFind = from.InnerArrayFind; | 81 InnerArrayFind = from.InnerArrayFind; |
78 InnerArrayFindIndex = from.InnerArrayFindIndex; | 82 InnerArrayFindIndex = from.InnerArrayFindIndex; |
79 InnerArrayForEach = from.InnerArrayForEach; | 83 InnerArrayForEach = from.InnerArrayForEach; |
80 InnerArrayIncludes = from.InnerArrayIncludes; | 84 InnerArrayIncludes = from.InnerArrayIncludes; |
81 InnerArrayIndexOf = from.InnerArrayIndexOf; | 85 InnerArrayIndexOf = from.InnerArrayIndexOf; |
82 InnerArrayJoin = from.InnerArrayJoin; | 86 InnerArrayJoin = from.InnerArrayJoin; |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 function TypedArrayOf() { | 757 function TypedArrayOf() { |
754 var length = arguments.length; | 758 var length = arguments.length; |
755 var array = TypedArrayCreate(this, length); | 759 var array = TypedArrayCreate(this, length); |
756 for (var i = 0; i < length; i++) { | 760 for (var i = 0; i < length; i++) { |
757 array[i] = arguments[i]; | 761 array[i] = arguments[i]; |
758 } | 762 } |
759 return array; | 763 return array; |
760 } | 764 } |
761 | 765 |
762 | 766 |
767 // ES#sec-iterabletoarraylike Runtime Semantics: IterableToArrayLike( items ) | |
768 function IterableToArrayLike(items) { | |
769 var iterable = GetMethod(items, iteratorSymbol); | |
770 if (!IS_UNDEFINED(iterable)) { | |
771 var array = new GlobalArray(); | |
adamk
2016/02/26 22:18:48
Can you use an InternalArray here and %MoveArrayCo
Dan Ehrenberg
2016/02/29 23:24:44
Done
| |
772 var i = 0; | |
773 for (var value of | |
774 { [iteratorSymbol]() { return GetIterator(items, iterable) } }) { | |
775 AddIndexedProperty(array, i, value); | |
776 i++; | |
777 } | |
778 return array; | |
779 } | |
780 return TO_OBJECT(items); | |
781 } | |
782 | |
783 | |
784 // ES#sec-%typedarray%.from | |
785 // %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) | |
763 function TypedArrayFrom(source, mapfn, thisArg) { | 786 function TypedArrayFrom(source, mapfn, thisArg) { |
764 // TODO(littledan): Investigate if there is a receiver which could be | 787 if (!%IsConstructor(this)) throw MakeTypeError(kNotConstructor, this); |
765 // faster to accumulate on than Array, e.g., a TypedVector. | 788 var mapping; |
766 // TODO(littledan) BUG(v8:4782): Rewrite this code to ensure that things | 789 if (!IS_UNDEFINED(mapfn)) { |
767 // happen in the right order, e.g., the constructor needs to be called | 790 if (!IS_CALLABLE(mapfn)) throw MakeTypeError(kCalledNonCallable, this); |
768 // before the mapping function on array-likes. | 791 mapping = true; |
769 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg); | 792 } else { |
770 return TypedArrayCreate(this, array); | 793 mapping = false; |
794 } | |
795 var arrayLike = IterableToArrayLike(source); | |
796 var length = TO_LENGTH(arrayLike.length); | |
797 var targetObject = TypedArrayCreate(this, length); | |
798 var value, mappedValue; | |
799 for (var i = 0; i < length; i++) { | |
800 value = arrayLike[i]; | |
801 if (mapping) { | |
802 mappedValue = %_Call(mapfn, thisArg, value, i); | |
803 } else { | |
804 mappedValue = value; | |
805 } | |
806 targetObject[i] = mappedValue; | |
807 } | |
808 return targetObject; | |
771 } | 809 } |
772 %FunctionSetLength(TypedArrayFrom, 1); | 810 %FunctionSetLength(TypedArrayFrom, 1); |
773 | 811 |
774 function TypedArray() { | 812 function TypedArray() { |
775 if (IS_UNDEFINED(new.target)) { | 813 if (IS_UNDEFINED(new.target)) { |
776 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); | 814 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); |
777 } | 815 } |
778 if (new.target === TypedArray) { | 816 if (new.target === TypedArray) { |
779 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); | 817 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); |
780 } | 818 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 "setUint32", DataViewSetUint32JS, | 981 "setUint32", DataViewSetUint32JS, |
944 | 982 |
945 "getFloat32", DataViewGetFloat32JS, | 983 "getFloat32", DataViewGetFloat32JS, |
946 "setFloat32", DataViewSetFloat32JS, | 984 "setFloat32", DataViewSetFloat32JS, |
947 | 985 |
948 "getFloat64", DataViewGetFloat64JS, | 986 "getFloat64", DataViewGetFloat64JS, |
949 "setFloat64", DataViewSetFloat64JS | 987 "setFloat64", DataViewSetFloat64JS |
950 ]); | 988 ]); |
951 | 989 |
952 }) | 990 }) |
OLD | NEW |