OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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, exports) { | 5 (function(global, exports) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 function TypedArrayFindIndex(predicate, thisArg) { | 84 function TypedArrayFindIndex(predicate, thisArg) { |
85 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 85 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
86 | 86 |
87 var length = %_TypedArrayGetLength(this); | 87 var length = %_TypedArrayGetLength(this); |
88 | 88 |
89 return $innerArrayFindIndex(predicate, thisArg, this, length); | 89 return $innerArrayFindIndex(predicate, thisArg, this, length); |
90 } | 90 } |
91 %FunctionSetLength(TypedArrayFindIndex, 1); | 91 %FunctionSetLength(TypedArrayFindIndex, 1); |
92 | 92 |
93 | 93 |
94 function TypedArrayComparefn(x, y) { | |
arv (Not doing code reviews)
2015/05/19 15:49:31
This is OK for now but I think we might want to in
dehrenberg
2015/05/19 16:39:09
Acknowledged.
| |
95 if ($isNaN(x) && $isNaN(y)) { | |
96 return 0; | |
97 } else if ($isNaN(x)) { | |
arv (Not doing code reviews)
2015/05/19 15:49:31
no else after return
The order can be changed to
dehrenberg
2015/05/19 16:39:08
Done.
| |
98 return 1; | |
99 } else if ($isNaN(y)) { | |
100 return -1; | |
101 } else if (x < y) { | |
102 return -1; | |
arv (Not doing code reviews)
2015/05/19 15:49:31
Do we care about -1? Generally this just has to be
dehrenberg
2015/05/19 16:39:09
Done.
| |
103 } else if (x > y) { | |
104 return 1; | |
105 } else if (x === y && x === 0) { | |
106 if (%_IsMinusZero(x) && !%_IsMinusZero(y)) { | |
107 return -1; | |
108 } else if (!%_IsMinusZero(x) && %_IsMinusZero(y)) { | |
arv (Not doing code reviews)
2015/05/19 15:49:31
reorg to reduce test?
dehrenberg
2015/05/19 16:39:08
Done.
| |
109 return 1; | |
110 } | |
111 } | |
112 return 0; | |
113 } | |
114 | |
115 | |
116 // ES6 draft 05-18-15, section 22.2.3.25 | |
117 function TypedArraySort(comparefn) { | |
118 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | |
119 | |
120 var length = %_TypedArrayGetLength(this); | |
121 | |
122 if (IS_UNDEFINED(comparefn)) { | |
123 comparefn = TypedArrayComparefn; | |
124 } | |
125 | |
126 return %_CallFunction(this, length, comparefn, $innerArraySort); | |
127 } | |
128 | |
129 | |
94 // ES6 draft 08-24-14, section 22.2.2.2 | 130 // ES6 draft 08-24-14, section 22.2.2.2 |
95 function TypedArrayOf() { | 131 function TypedArrayOf() { |
96 var length = %_ArgumentsLength(); | 132 var length = %_ArgumentsLength(); |
97 var array = new this(length); | 133 var array = new this(length); |
98 for (var i = 0; i < length; i++) { | 134 for (var i = 0; i < length; i++) { |
99 array[i] = %_Arguments(i); | 135 array[i] = %_Arguments(i); |
100 } | 136 } |
101 return array; | 137 return array; |
102 } | 138 } |
103 | 139 |
(...skipping 29 matching lines...) Expand all Loading... | |
133 "of", TypedArrayOf | 169 "of", TypedArrayOf |
134 ]); | 170 ]); |
135 | 171 |
136 // Set up non-enumerable functions on the prototype object. | 172 // Set up non-enumerable functions on the prototype object. |
137 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 173 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
138 "copyWithin", TypedArrayCopyWithin, | 174 "copyWithin", TypedArrayCopyWithin, |
139 "every", TypedArrayEvery, | 175 "every", TypedArrayEvery, |
140 "forEach", TypedArrayForEach, | 176 "forEach", TypedArrayForEach, |
141 "find", TypedArrayFind, | 177 "find", TypedArrayFind, |
142 "findIndex", TypedArrayFindIndex, | 178 "findIndex", TypedArrayFindIndex, |
143 "fill", TypedArrayFill | 179 "fill", TypedArrayFill, |
180 "sort", TypedArraySort | |
144 ]); | 181 ]); |
145 endmacro | 182 endmacro |
146 | 183 |
147 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 184 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
148 | 185 |
149 }) | 186 }) |
OLD | NEW |