Chromium Code Reviews| 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; |
| } |
| } |