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

Unified Diff: src/harmony-typedarray.js

Issue 1159663004: 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 side-by-side diff with in-line comments
Download patch
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 69512ca4b58c1d4b4512db68ea94defef4bcb83e..3968aec84674c57ec46af3388b3fb0109cb2598f 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -64,6 +64,8 @@ utils.Import(function(from) {
InnerArrayJoin = from.InnerArrayJoin;
InnerArrayLastIndexOf = from.InnerArrayLastIndexOf;
InnerArrayMap = from.InnerArrayMap;
+ InnerArrayReduce = from.InnerArrayReduce;
+ InnerArrayReduceRight = from.InnerArrayReduceRight;
InnerArrayReverse = from.InnerArrayReverse;
InnerArraySome = from.InnerArraySome;
InnerArraySort = from.InnerArraySort;
@@ -265,11 +267,13 @@ function TypedArrayToLocaleString() {
return InnerArrayToLocaleString(this, length);
}
+
// ES6 section 22.2.3.28
function TypedArrayToString() {
return %_CallFunction(this, ArrayToString);
}
+
// ES6 section 22.2.3.14
function TypedArrayJoin(separator) {
if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
@@ -280,6 +284,28 @@ function TypedArrayJoin(separator) {
}
+// ES6 draft 07-15-13, section 22.2.3.19
+function TypedArrayReduce(callback, current) {
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
+
+ var length = %_TypedArrayGetLength(this);
+ return InnerArrayReduce(callback, current, this, length,
+ %_ArgumentsLength());
+}
+%FunctionSetLength(TypedArrayReduce, 1);
+
+
+// ES6 draft 07-15-13, section 22.2.3.19
+function TypedArrayReduceRight(callback, current) {
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
+
+ var length = %_TypedArrayGetLength(this);
+ return InnerArrayReduceRight(callback, current, this, length,
+ %_ArgumentsLength());
+}
+%FunctionSetLength(TypedArrayReduceRight, 1);
+
+
// ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() {
var length = %_ArgumentsLength();
@@ -320,6 +346,8 @@ macro EXTEND_TYPED_ARRAY(NAME)
"lastIndexOf", TypedArrayLastIndexOf,
"forEach", TypedArrayForEach,
"map", TypedArrayMap,
+ "reduce", TypedArrayReduce,
+ "reduceRight", TypedArrayReduceRight,
"reverse", TypedArrayReverse,
"some", TypedArraySome,
"sort", TypedArraySort,
« 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