diff --git a/src/harmony-array.js b/src/harmony-array.js index 5df1abde0f..51e2d01b50 100644 --- a/src/harmony-array.js +++ b/src/harmony-array.js @@ -100,12 +100,10 @@ function InnerArrayFind(predicate, thisArg, array, length) { } for (var i = 0; i < length; i++) { - if (i in array) { - var element = array[i]; - var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; - if (%_CallFunction(newThisArg, element, i, array, predicate)) { - return element; - } + var element = array[i]; + var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; + if (%_CallFunction(newThisArg, element, i, array, predicate)) { + return element; } } @@ -135,12 +133,10 @@ function InnerArrayFindIndex(predicate, thisArg, array, length) { } for (var i = 0; i < length; i++) { - if (i in array) { - var element = array[i]; - var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; - if (%_CallFunction(newThisArg, element, i, array, predicate)) { - return i; - } + var element = array[i]; + var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; + if (%_CallFunction(newThisArg, element, i, array, predicate)) { + return i; } } diff --git a/test/mjsunit/harmony/array-find.js b/test/mjsunit/harmony/array-find.js index eb32082277..44fc78292a 100644 --- a/test/mjsunit/harmony/array-find.js +++ b/test/mjsunit/harmony/array-find.js @@ -201,7 +201,7 @@ assertEquals(22, a.find(function(val) { return 22 === val; }), undefined); // -// Test predicate is only called for existing elements +// Test predicate is called for holes // (function() { var a = new Array(30); @@ -211,7 +211,27 @@ assertEquals(22, a.find(function(val) { return 22 === val; }), undefined); var count = 0; a.find(function() { count++; return false; }); - assertEquals(3, count); + assertEquals(30, count); +})(); + + +(function() { + var a = [0, 1, , 3]; + var count = 0; + var found = a.find(function(val) { return val === undefined; }); + assertEquals(undefined, found); +})(); + + +(function() { + var a = [0, 1, , 3]; + a.__proto__ = { + __proto__: Array.prototype, + 2: 42, + }; + var count = 0; + var found = a.find(function(val) { return val === 42; }); + assertEquals(42, found); })(); diff --git a/test/mjsunit/harmony/array-findindex.js b/test/mjsunit/harmony/array-findindex.js index a5df05a05c..7068a9cb40 100644 --- a/test/mjsunit/harmony/array-findindex.js +++ b/test/mjsunit/harmony/array-findindex.js @@ -201,7 +201,7 @@ assertEquals(3, a.findIndex(function(val) { return 24 === val; })); // -// Test predicate is only called for existing elements +// Test predicate is called for holes // (function() { var a = new Array(30); @@ -211,7 +211,27 @@ assertEquals(3, a.findIndex(function(val) { return 24 === val; })); var count = 0; a.findIndex(function() { count++; return false; }); - assertEquals(3, count); + assertEquals(30, count); +})(); + + +(function() { + var a = [0, 1, , 3]; + var count = 0; + var index = a.findIndex(function(val) { return val === undefined; }); + assertEquals(2, index); +})(); + + +(function() { + var a = [0, 1, , 3]; + a.__proto__ = { + __proto__: Array.prototype, + 2: 42, + }; + var count = 0; + var index = a.findIndex(function(val) { return val === 42; }); + assertEquals(2, index); })(); diff --git a/test/test262-es6/test262-es6.status b/test/test262-es6/test262-es6.status index f6b16ec38d..c8e16f0a08 100644 --- a/test/test262-es6/test262-es6.status +++ b/test/test262-es6/test262-es6.status @@ -48,8 +48,10 @@ # https://code.google.com/p/v8/issues/detail?id=705 'language/statements/for-in/12.6.4-2': [PASS, FAIL_OK], - # Array.find (currently requires --harmony-arrays) - 'built-ins/Array/prototype/find/Array.prototype.find_skip-empty': [FAIL], + ######################### HARNESS ISSUES ########################## + # These are failures due to our harness not working as supposed + + # Uses [onlyStrict] 'built-ins/Array/prototype/find/Array.prototype.find_this-undefined': [FAIL], ###################### MISSING ES6 FEATURES ####################### @@ -596,6 +598,8 @@ 'built-ins/Function/prototype/bind/15.3.4.5-21-4': [FAIL_OK], 'built-ins/Function/prototype/bind/15.3.4.5-21-5': [FAIL_OK], + # This invalid test has been fixed upstream. + 'built-ins/Array/prototype/find/Array.prototype.find_remove-after-start': [FAIL], ############################ SKIPPED TESTS #############################