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

Side by Side Diff: src/harmony-typedarray.js

Issue 1148513002: Implement %TypedArray%.prototype.sort (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 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/array.js ('k') | test/mjsunit/harmony/typedarray-sort.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 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // ES6 draft 05-18-15, section 22.2.3.21 93 // ES6 draft 05-18-15, section 22.2.3.21
94 function TypedArrayReverse() { 94 function TypedArrayReverse() {
95 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 95 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
96 96
97 var length = %_TypedArrayGetLength(this); 97 var length = %_TypedArrayGetLength(this);
98 98
99 return $innerArrayReverse(this, length); 99 return $innerArrayReverse(this, length);
100 } 100 }
101 101
102 102
103 function TypedArrayComparefn(x, y) {
104 if ($isNaN(x) && $isNaN(y)) {
105 return $isNaN(y) ? 0 : 1;
106 }
107 if ($isNaN(x)) {
108 return 1;
109 }
110 if (x === 0 && x === y) {
111 if (%_IsMinusZero(x)) {
112 if (!%_IsMinusZero(y)) {
113 return -1;
114 }
115 } else if (%_IsMinusZero(y)) {
116 return 1;
117 }
118 }
119 return x - y;
120 }
121
122
123 // ES6 draft 05-18-15, section 22.2.3.25
124 function TypedArraySort(comparefn) {
125 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
126
127 var length = %_TypedArrayGetLength(this);
128
129 if (IS_UNDEFINED(comparefn)) {
130 comparefn = TypedArrayComparefn;
131 }
132
133 return %_CallFunction(this, length, comparefn, $innerArraySort);
134 }
135
136
103 // ES6 draft 08-24-14, section 22.2.2.2 137 // ES6 draft 08-24-14, section 22.2.2.2
104 function TypedArrayOf() { 138 function TypedArrayOf() {
105 var length = %_ArgumentsLength(); 139 var length = %_ArgumentsLength();
106 var array = new this(length); 140 var array = new this(length);
107 for (var i = 0; i < length; i++) { 141 for (var i = 0; i < length; i++) {
108 array[i] = %_Arguments(i); 142 array[i] = %_Arguments(i);
109 } 143 }
110 return array; 144 return array;
111 } 145 }
112 146
(...skipping 30 matching lines...) Expand all
143 ]); 177 ]);
144 178
145 // Set up non-enumerable functions on the prototype object. 179 // Set up non-enumerable functions on the prototype object.
146 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ 180 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [
147 "copyWithin", TypedArrayCopyWithin, 181 "copyWithin", TypedArrayCopyWithin,
148 "every", TypedArrayEvery, 182 "every", TypedArrayEvery,
149 "forEach", TypedArrayForEach, 183 "forEach", TypedArrayForEach,
150 "find", TypedArrayFind, 184 "find", TypedArrayFind,
151 "findIndex", TypedArrayFindIndex, 185 "findIndex", TypedArrayFindIndex,
152 "fill", TypedArrayFill, 186 "fill", TypedArrayFill,
153 "reverse", TypedArrayReverse 187 "reverse", TypedArrayReverse,
188 "sort", TypedArraySort
154 ]); 189 ]);
155 endmacro 190 endmacro
156 191
157 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 192 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
158 193
159 }) 194 })
OLDNEW
« no previous file with comments | « src/array.js ('k') | test/mjsunit/harmony/typedarray-sort.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698