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

Side by Side 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: Remove unnneded check (length is zero and 'current' is not defined). Fixed tests. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/array-reduce.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declarations have been made 7 // This file relies on the fact that the following declarations have been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 var array = ToObject(this); 1391 var array = ToObject(this);
1392 var length = ToUint32(array.length); 1392 var length = ToUint32(array.length);
1393 1393
1394 if (!IS_SPEC_FUNCTION(callback)) { 1394 if (!IS_SPEC_FUNCTION(callback)) {
1395 throw MakeTypeError('called_non_callable', [callback]); 1395 throw MakeTypeError('called_non_callable', [callback]);
1396 } 1396 }
1397 1397
1398 var i = 0; 1398 var i = 0;
1399 find_initial: if (%_ArgumentsLength() < 2) { 1399 find_initial: if (%_ArgumentsLength() < 2) {
1400 for (; i < length; i++) { 1400 for (; i < length; i++) {
1401 current = array[i]; 1401 if (i in array) {
1402 if (!IS_UNDEFINED(current) || i in array) { 1402 current = array[i++];
1403 i++;
1404 break find_initial; 1403 break find_initial;
1405 } 1404 }
1406 } 1405 }
1407 throw MakeTypeError('reduce_no_initial', []); 1406 throw MakeTypeError('reduce_no_initial', []);
1408 } 1407 }
1409 1408
1410 var receiver = %GetDefaultReceiver(callback); 1409 var receiver = %GetDefaultReceiver(callback);
1411 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); 1410 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
1412 for (; i < length; i++) { 1411 for (; i < length; i++) {
1413 if (i in array) { 1412 if (i in array) {
(...skipping 14 matching lines...) Expand all
1428 var array = ToObject(this); 1427 var array = ToObject(this);
1429 var length = ToUint32(array.length); 1428 var length = ToUint32(array.length);
1430 1429
1431 if (!IS_SPEC_FUNCTION(callback)) { 1430 if (!IS_SPEC_FUNCTION(callback)) {
1432 throw MakeTypeError('called_non_callable', [callback]); 1431 throw MakeTypeError('called_non_callable', [callback]);
1433 } 1432 }
1434 1433
1435 var i = length - 1; 1434 var i = length - 1;
1436 find_initial: if (%_ArgumentsLength() < 2) { 1435 find_initial: if (%_ArgumentsLength() < 2) {
1437 for (; i >= 0; i--) { 1436 for (; i >= 0; i--) {
1438 current = array[i]; 1437 if (i in array) {
1439 if (!IS_UNDEFINED(current) || i in array) { 1438 current = array[i--];
1440 i--;
1441 break find_initial; 1439 break find_initial;
1442 } 1440 }
1443 } 1441 }
1444 throw MakeTypeError('reduce_no_initial', []); 1442 throw MakeTypeError('reduce_no_initial', []);
1445 } 1443 }
1446 1444
1447 var receiver = %GetDefaultReceiver(callback); 1445 var receiver = %GetDefaultReceiver(callback);
1448 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); 1446 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
1449 for (; i >= 0; i--) { 1447 for (; i >= 0; i--) {
1450 if (i in array) { 1448 if (i in array) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 )); 1545 ));
1548 1546
1549 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( 1547 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array(
1550 "join", getFunction("join", ArrayJoin), 1548 "join", getFunction("join", ArrayJoin),
1551 "pop", getFunction("pop", ArrayPop), 1549 "pop", getFunction("pop", ArrayPop),
1552 "push", getFunction("push", ArrayPush) 1550 "push", getFunction("push", ArrayPush)
1553 )); 1551 ));
1554 } 1552 }
1555 1553
1556 SetUpArray(); 1554 SetUpArray();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/array-reduce.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698