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

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: rebase 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 InnerArrayEvery = from.InnerArrayEvery; 57 InnerArrayEvery = from.InnerArrayEvery;
58 InnerArrayFill = from.InnerArrayFill; 58 InnerArrayFill = from.InnerArrayFill;
59 InnerArrayFilter = from.InnerArrayFilter; 59 InnerArrayFilter = from.InnerArrayFilter;
60 InnerArrayFind = from.InnerArrayFind; 60 InnerArrayFind = from.InnerArrayFind;
61 InnerArrayFindIndex = from.InnerArrayFindIndex; 61 InnerArrayFindIndex = from.InnerArrayFindIndex;
62 InnerArrayForEach = from.InnerArrayForEach; 62 InnerArrayForEach = from.InnerArrayForEach;
63 InnerArrayIndexOf = from.InnerArrayIndexOf; 63 InnerArrayIndexOf = from.InnerArrayIndexOf;
64 InnerArrayJoin = from.InnerArrayJoin; 64 InnerArrayJoin = from.InnerArrayJoin;
65 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf; 65 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf;
66 InnerArrayMap = from.InnerArrayMap; 66 InnerArrayMap = from.InnerArrayMap;
67 InnerArrayReduce = from.InnerArrayReduce;
68 InnerArrayReduceRight = from.InnerArrayReduceRight;
67 InnerArrayReverse = from.InnerArrayReverse; 69 InnerArrayReverse = from.InnerArrayReverse;
68 InnerArraySome = from.InnerArraySome; 70 InnerArraySome = from.InnerArraySome;
69 InnerArraySort = from.InnerArraySort; 71 InnerArraySort = from.InnerArraySort;
70 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 72 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
71 IsNaN = from.IsNaN; 73 IsNaN = from.IsNaN;
72 }); 74 });
73 75
74 // ------------------------------------------------------------------- 76 // -------------------------------------------------------------------
75 77
76 function ConstructTypedArray(constructor, array) { 78 function ConstructTypedArray(constructor, array) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 260
259 // ES6 section 22.2.3.27 261 // ES6 section 22.2.3.27
260 function TypedArrayToLocaleString() { 262 function TypedArrayToLocaleString() {
261 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 263 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
262 264
263 var length = %_TypedArrayGetLength(this); 265 var length = %_TypedArrayGetLength(this);
264 266
265 return InnerArrayToLocaleString(this, length); 267 return InnerArrayToLocaleString(this, length);
266 } 268 }
267 269
270
268 // ES6 section 22.2.3.28 271 // ES6 section 22.2.3.28
269 function TypedArrayToString() { 272 function TypedArrayToString() {
270 return %_CallFunction(this, ArrayToString); 273 return %_CallFunction(this, ArrayToString);
271 } 274 }
272 275
276
273 // ES6 section 22.2.3.14 277 // ES6 section 22.2.3.14
274 function TypedArrayJoin(separator) { 278 function TypedArrayJoin(separator) {
275 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 279 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
276 280
277 var length = %_TypedArrayGetLength(this); 281 var length = %_TypedArrayGetLength(this);
278 282
279 return InnerArrayJoin(separator, this, length); 283 return InnerArrayJoin(separator, this, length);
280 } 284 }
281 285
282 286
287 // ES6 draft 07-15-13, section 22.2.3.19
288 function TypedArrayReduce(callback, current) {
289 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
290
291 var length = %_TypedArrayGetLength(this);
292 return InnerArrayReduce(callback, current, this, length,
293 %_ArgumentsLength());
294 }
295 %FunctionSetLength(TypedArrayReduce, 1);
296
297
298 // ES6 draft 07-15-13, section 22.2.3.19
299 function TypedArrayReduceRight(callback, current) {
300 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
301
302 var length = %_TypedArrayGetLength(this);
303 return InnerArrayReduceRight(callback, current, this, length,
304 %_ArgumentsLength());
305 }
306 %FunctionSetLength(TypedArrayReduceRight, 1);
307
308
283 // ES6 draft 08-24-14, section 22.2.2.2 309 // ES6 draft 08-24-14, section 22.2.2.2
284 function TypedArrayOf() { 310 function TypedArrayOf() {
285 var length = %_ArgumentsLength(); 311 var length = %_ArgumentsLength();
286 var array = new this(length); 312 var array = new this(length);
287 for (var i = 0; i < length; i++) { 313 for (var i = 0; i < length; i++) {
288 array[i] = %_Arguments(i); 314 array[i] = %_Arguments(i);
289 } 315 }
290 return array; 316 return array;
291 } 317 }
292 318
(...skipping 20 matching lines...) Expand all
313 "every", TypedArrayEvery, 339 "every", TypedArrayEvery,
314 "fill", TypedArrayFill, 340 "fill", TypedArrayFill,
315 "filter", TypedArrayFilter, 341 "filter", TypedArrayFilter,
316 "find", TypedArrayFind, 342 "find", TypedArrayFind,
317 "findIndex", TypedArrayFindIndex, 343 "findIndex", TypedArrayFindIndex,
318 "indexOf", TypedArrayIndexOf, 344 "indexOf", TypedArrayIndexOf,
319 "join", TypedArrayJoin, 345 "join", TypedArrayJoin,
320 "lastIndexOf", TypedArrayLastIndexOf, 346 "lastIndexOf", TypedArrayLastIndexOf,
321 "forEach", TypedArrayForEach, 347 "forEach", TypedArrayForEach,
322 "map", TypedArrayMap, 348 "map", TypedArrayMap,
349 "reduce", TypedArrayReduce,
350 "reduceRight", TypedArrayReduceRight,
323 "reverse", TypedArrayReverse, 351 "reverse", TypedArrayReverse,
324 "some", TypedArraySome, 352 "some", TypedArraySome,
325 "sort", TypedArraySort, 353 "sort", TypedArraySort,
326 "toString", TypedArrayToString, 354 "toString", TypedArrayToString,
327 "toLocaleString", TypedArrayToLocaleString 355 "toLocaleString", TypedArrayToLocaleString
328 ]); 356 ]);
329 endmacro 357 endmacro
330 358
331 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 359 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
332 360
333 }) 361 })
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