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 internal_array = new InternalArray(); |
| 772 var i = 0; |
| 773 for (var value of |
| 774 { [iteratorSymbol]() { return GetIterator(items, iterable) } }) { |
| 775 internal_array[i] = value; |
| 776 i++; |
| 777 } |
| 778 var array = []; |
| 779 %MoveArrayContents(internal_array, array); |
| 780 return array; |
| 781 } |
| 782 return TO_OBJECT(items); |
| 783 } |
| 784 |
| 785 |
| 786 // ES#sec-%typedarray%.from |
| 787 // %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) |
763 function TypedArrayFrom(source, mapfn, thisArg) { | 788 function TypedArrayFrom(source, mapfn, thisArg) { |
764 // TODO(littledan): Investigate if there is a receiver which could be | 789 if (!%IsConstructor(this)) throw MakeTypeError(kNotConstructor, this); |
765 // faster to accumulate on than Array, e.g., a TypedVector. | 790 var mapping; |
766 // TODO(littledan) BUG(v8:4782): Rewrite this code to ensure that things | 791 if (!IS_UNDEFINED(mapfn)) { |
767 // happen in the right order, e.g., the constructor needs to be called | 792 if (!IS_CALLABLE(mapfn)) throw MakeTypeError(kCalledNonCallable, this); |
768 // before the mapping function on array-likes. | 793 mapping = true; |
769 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg); | 794 } else { |
770 return TypedArrayCreate(this, array); | 795 mapping = false; |
| 796 } |
| 797 var arrayLike = IterableToArrayLike(source); |
| 798 var length = TO_LENGTH(arrayLike.length); |
| 799 var targetObject = TypedArrayCreate(this, length); |
| 800 var value, mappedValue; |
| 801 for (var i = 0; i < length; i++) { |
| 802 value = arrayLike[i]; |
| 803 if (mapping) { |
| 804 mappedValue = %_Call(mapfn, thisArg, value, i); |
| 805 } else { |
| 806 mappedValue = value; |
| 807 } |
| 808 targetObject[i] = mappedValue; |
| 809 } |
| 810 return targetObject; |
771 } | 811 } |
772 %FunctionSetLength(TypedArrayFrom, 1); | 812 %FunctionSetLength(TypedArrayFrom, 1); |
773 | 813 |
774 function TypedArray() { | 814 function TypedArray() { |
775 if (IS_UNDEFINED(new.target)) { | 815 if (IS_UNDEFINED(new.target)) { |
776 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); | 816 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); |
777 } | 817 } |
778 if (new.target === TypedArray) { | 818 if (new.target === TypedArray) { |
779 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); | 819 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); |
780 } | 820 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 "setUint32", DataViewSetUint32JS, | 983 "setUint32", DataViewSetUint32JS, |
944 | 984 |
945 "getFloat32", DataViewGetFloat32JS, | 985 "getFloat32", DataViewGetFloat32JS, |
946 "setFloat32", DataViewSetFloat32JS, | 986 "setFloat32", DataViewSetFloat32JS, |
947 | 987 |
948 "getFloat64", DataViewGetFloat64JS, | 988 "getFloat64", DataViewGetFloat64JS, |
949 "setFloat64", DataViewSetFloat64JS | 989 "setFloat64", DataViewSetFloat64JS |
950 ]); | 990 ]); |
951 | 991 |
952 }) | 992 }) |
OLD | NEW |