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

Unified Diff: src/array.js

Issue 614733002: Array.prototype.{reduce, reduceRight}: Wrong order of operations when determining initial value. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | test/mjsunit/array-reduce.js » ('j') | test/mjsunit/array-reduce.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 44deff7de42c60986741615b1be389f9668dbf85..d7ae4ec76d3aefe593f43f58914f786abbb00ef0 100644
--- a/src/array.js
+++ b/src/array.js
@@ -1394,13 +1394,15 @@ function ArrayReduce(callback, current) {
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError('called_non_callable', [callback]);
}
+ if (length == 0 && IS_UNDEFINED(current)) {
+ throw MakeTypeError('reduce_no_initial', []);
+ }
wingo 2014/10/07 11:04:31 I think the test should be %_ArgumentsLength() < 2
arv (Not doing code reviews) 2014/10/07 14:16:02 Yup. The spec says: "If initialValue is present, t
Diego Pino 2014/10/09 10:18:57 What I intended to code with that line was step 7
var i = 0;
find_initial: if (%_ArgumentsLength() < 2) {
for (; i < length; i++) {
- current = array[i];
- if (!IS_UNDEFINED(current) || i in array) {
- i++;
+ if (i in array) {
+ current = array[i++];
break find_initial;
}
}
@@ -1431,13 +1433,15 @@ function ArrayReduceRight(callback, current) {
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError('called_non_callable', [callback]);
}
+ if (length == 0 && IS_UNDEFINED(current)) {
+ throw MakeTypeError('reduce_no_initial', []);
+ }
wingo 2014/10/07 11:04:31 likewise
arv (Not doing code reviews) 2014/10/07 14:16:02 Yup. https://people.mozilla.org/~jorendorff/es6-dr
var i = length - 1;
find_initial: if (%_ArgumentsLength() < 2) {
for (; i >= 0; i--) {
- current = array[i];
- if (!IS_UNDEFINED(current) || i in array) {
- i--;
+ if (i in array) {
+ current = array[i--];
break find_initial;
}
}
« no previous file with comments | « no previous file | test/mjsunit/array-reduce.js » ('j') | test/mjsunit/array-reduce.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698