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

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

Issue 1154423014: Implement %TypedArray%.prototype.{reduce,reduceRight} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
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, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 InnerArrayCopyWithin = from.InnerArrayCopyWithin; 52 InnerArrayCopyWithin = from.InnerArrayCopyWithin;
53 InnerArrayEvery = from.InnerArrayEvery; 53 InnerArrayEvery = from.InnerArrayEvery;
54 InnerArrayFill = from.InnerArrayFill; 54 InnerArrayFill = from.InnerArrayFill;
55 InnerArrayFilter = from.InnerArrayFilter; 55 InnerArrayFilter = from.InnerArrayFilter;
56 InnerArrayFind = from.InnerArrayFind; 56 InnerArrayFind = from.InnerArrayFind;
57 InnerArrayFindIndex = from.InnerArrayFindIndex; 57 InnerArrayFindIndex = from.InnerArrayFindIndex;
58 InnerArrayForEach = from.InnerArrayForEach; 58 InnerArrayForEach = from.InnerArrayForEach;
59 InnerArrayIndexOf = from.InnerArrayIndexOf; 59 InnerArrayIndexOf = from.InnerArrayIndexOf;
60 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf; 60 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf;
61 InnerArrayMap = from.InnerArrayMap; 61 InnerArrayMap = from.InnerArrayMap;
62 InnerArrayReduce = from.InnerArrayReduce;
63 InnerArrayReduceRight = from.InnerArrayReduceRight;
62 InnerArrayReverse = from.InnerArrayReverse; 64 InnerArrayReverse = from.InnerArrayReverse;
63 InnerArraySome = from.InnerArraySome; 65 InnerArraySome = from.InnerArraySome;
64 InnerArraySort = from.InnerArraySort; 66 InnerArraySort = from.InnerArraySort;
65 IsNaN = from.IsNaN; 67 IsNaN = from.IsNaN;
66 }); 68 });
67 69
68 // ------------------------------------------------------------------- 70 // -------------------------------------------------------------------
69 71
70 function ConstructTypedArray(constructor, array) { 72 function ConstructTypedArray(constructor, array) {
71 // TODO(littledan): This is an approximation of the spec, which requires 73 // TODO(littledan): This is an approximation of the spec, which requires
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 function TypedArraySome(f, receiver) { 245 function TypedArraySome(f, receiver) {
244 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 246 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
245 247
246 var length = %_TypedArrayGetLength(this); 248 var length = %_TypedArrayGetLength(this);
247 249
248 return InnerArraySome(f, receiver, this, length); 250 return InnerArraySome(f, receiver, this, length);
249 } 251 }
250 %FunctionSetLength(TypedArraySome, 1); 252 %FunctionSetLength(TypedArraySome, 1);
251 253
252 254
255 // ES6 draft 07-15-13, section 22.2.3.19
256 function TypedArrayReduce(callback, current) {
257 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
258
259 var length = %_TypedArrayGetLength(this);
260 return InnerArrayReduce(callback, current, this, length,
261 %_ArgumentsLength());
262 }
263 %FunctionSetLength(TypedArrayReduce, 1);
264
265
266 // ES6 draft 07-15-13, section 22.2.3.19
267 function TypedArrayReduceRight(callback, current) {
268 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
269
270 var length = %_TypedArrayGetLength(this);
271 return InnerArrayReduceRight(callback, current, this, length,
272 %_ArgumentsLength());
273 }
274 %FunctionSetLength(TypedArrayReduceRight, 1);
275
276
253 // ES6 draft 08-24-14, section 22.2.2.2 277 // ES6 draft 08-24-14, section 22.2.2.2
254 function TypedArrayOf() { 278 function TypedArrayOf() {
255 var length = %_ArgumentsLength(); 279 var length = %_ArgumentsLength();
256 var array = new this(length); 280 var array = new this(length);
257 for (var i = 0; i < length; i++) { 281 for (var i = 0; i < length; i++) {
258 array[i] = %_Arguments(i); 282 array[i] = %_Arguments(i);
259 } 283 }
260 return array; 284 return array;
261 } 285 }
262 286
(...skipping 19 matching lines...) Expand all
282 "copyWithin", TypedArrayCopyWithin, 306 "copyWithin", TypedArrayCopyWithin,
283 "every", TypedArrayEvery, 307 "every", TypedArrayEvery,
284 "fill", TypedArrayFill, 308 "fill", TypedArrayFill,
285 "filter", TypedArrayFilter, 309 "filter", TypedArrayFilter,
286 "find", TypedArrayFind, 310 "find", TypedArrayFind,
287 "findIndex", TypedArrayFindIndex, 311 "findIndex", TypedArrayFindIndex,
288 "indexOf", TypedArrayIndexOf, 312 "indexOf", TypedArrayIndexOf,
289 "lastIndexOf", TypedArrayLastIndexOf, 313 "lastIndexOf", TypedArrayLastIndexOf,
290 "forEach", TypedArrayForEach, 314 "forEach", TypedArrayForEach,
291 "map", TypedArrayMap, 315 "map", TypedArrayMap,
316 "reduce", TypedArrayReduce,
317 "reduceRight", TypedArrayReduceRight,
292 "reverse", TypedArrayReverse, 318 "reverse", TypedArrayReverse,
293 "some", TypedArraySome, 319 "some", TypedArraySome,
294 "sort", TypedArraySort 320 "sort", TypedArraySort
295 ]); 321 ]);
296 endmacro 322 endmacro
297 323
298 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 324 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
299 325
300 }) 326 })
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/prologue.js » ('j') | test/mjsunit/harmony/typedarray-reduce.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698