Changeset 169162 in webkit
- Timestamp:
- May 21, 2014 9:14:55 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r169160 r169162 1 2014-05-21 Antoine Quint <graouts@webkit.org> 2 3 Array.prototype.find and findIndex should skip holes 4 https://bugs.webkit.org/show_bug.cgi?id=132658 5 6 Reviewed by Geoffrey Garen. 7 8 * js/array-find-expected.txt: 9 * js/array-findIndex-expected.txt: 10 * js/script-tests/array-find.js: 11 * js/script-tests/array-findIndex.js: 12 1 13 2014-05-21 Radu Stavila <stavila@adobe.com> 2 14 -
trunk/LayoutTests/js/array-find-expected.txt
r167797 r169162 41 41 PASS [].find(null) threw exception TypeError: Array.prototype.find callback must be a function. 42 42 PASS [].find(undefined) threw exception TypeError: Array.prototype.find callback must be a function. 43 find callback called with index 10 44 find callback called with index 20 45 find callback called with index 30 46 find callback called with index 40 47 find callback called with index 50 48 PASS numberOfCallbacksInFindInArrayWithHoles() is 5 43 49 PASS successfullyParsed is true 44 50 -
trunk/LayoutTests/js/array-findIndex-expected.txt
r167797 r169162 14 14 PASS [undefined, 0, null, false].findIndex(passEmptyString) is -1 15 15 PASS [undefined, null, false, ''].findIndex(passZero) is -1 16 PASS (new Array(20)).findIndex(passUndefined) is 017 PASS arrayWithHoles.findIndex(passUndefined) is 016 PASS (new Array(20)).findIndex(passUndefined) is -1 17 PASS arrayWithHoles.findIndex(passUndefined) is -1 18 18 PASS arrayWithHoles.findIndex(passZero) is 10 19 19 PASS arrayWithHoles.findIndex(passNull) is 20 20 20 PASS arrayWithHoles.findIndex(passFalse) is 30 21 21 PASS arrayWithHoles.findIndex(passEmptyString) is 40 22 PASS arrayWithHoles.findIndex(passUndefined) is 50 22 23 PASS toObject([undefined, 0, null, false, '']).findIndex(passUndefined) is 0 23 24 PASS toObject([undefined, 0, null, false, '']).findIndex(passZero) is 1 … … 30 31 PASS toObject([undefined, 0, null, false]).findIndex(passEmptyString) is -1 31 32 PASS toObject([undefined, null, false, '']).findIndex(passZero) is -1 32 PASS toObject(new Array(20)).findIndex(passUndefined) is 033 PASS toObject(new Array(20)).findIndex(passUndefined) is -1 33 34 PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch) is -1 34 35 PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch) is -1 … … 41 42 PASS [].findIndex(null) threw exception TypeError: Array.prototype.findIndex callback must be a function. 42 43 PASS [].findIndex(undefined) threw exception TypeError: Array.prototype.findIndex callback must be a function. 44 find callback called with index 10 45 find callback called with index 20 46 find callback called with index 30 47 find callback called with index 40 48 find callback called with index 50 49 PASS numberOfCallbacksInFindIndexInArrayWithHoles() is 5 43 50 PASS successfullyParsed is true 44 51 -
trunk/LayoutTests/js/script-tests/array-find.js
r167797 r169162 45 45 arrayWithHoles[30] = false; 46 46 arrayWithHoles[40] = ""; 47 arrayWithHoles[50] = undefined; 48 function numberOfCallbacksInFindInArrayWithHoles() { 49 var count = 0; 50 arrayWithHoles.find(function(element, index, array) { 51 debug("find callback called with index " + index); 52 count++; 53 }); 54 return count; 55 } 47 56 48 57 shouldBe("[undefined, 0, null, false, ''].find(passUndefined)", "undefined"); … … 91 100 shouldThrow("[].find(null)", "'TypeError: Array.prototype.find callback must be a function'"); 92 101 shouldThrow("[].find(undefined)", "'TypeError: Array.prototype.find callback must be a function'"); 102 103 // Callbacks in the expected order and skipping holes. 104 shouldBe("numberOfCallbacksInFindInArrayWithHoles()", "5"); -
trunk/LayoutTests/js/script-tests/array-findIndex.js
r167797 r169162 45 45 arrayWithHoles[30] = false; 46 46 arrayWithHoles[40] = ""; 47 function numberOfCallbacksInFindIndexInArrayWithHoles() { 48 var count = 0; 49 arrayWithHoles.find(function(element, index, array) { 50 debug("find callback called with index " + index); 51 count++; 52 }); 53 return count; 54 } 47 55 48 56 shouldBe("[undefined, 0, null, false, ''].findIndex(passUndefined)", "0"); … … 56 64 shouldBe("[undefined, 0, null, false].findIndex(passEmptyString)", "-1"); 57 65 shouldBe("[undefined, null, false, ''].findIndex(passZero)", "-1"); 58 shouldBe("(new Array(20)).findIndex(passUndefined)", " 0");66 shouldBe("(new Array(20)).findIndex(passUndefined)", "-1"); 59 67 60 68 // Array with holes. 61 shouldBe("arrayWithHoles.findIndex(passUndefined)", " 0");69 shouldBe("arrayWithHoles.findIndex(passUndefined)", "-1"); 62 70 shouldBe("arrayWithHoles.findIndex(passZero)", "10"); 63 71 shouldBe("arrayWithHoles.findIndex(passNull)", "20"); 64 72 shouldBe("arrayWithHoles.findIndex(passFalse)", "30"); 65 73 shouldBe("arrayWithHoles.findIndex(passEmptyString)", "40"); 74 arrayWithHoles[50] = undefined; 75 shouldBe("arrayWithHoles.findIndex(passUndefined)", "50"); 66 76 67 77 // Generic Object … … 76 86 shouldBe("toObject([undefined, 0, null, false]).findIndex(passEmptyString)", "-1"); 77 87 shouldBe("toObject([undefined, null, false, '']).findIndex(passZero)", "-1"); 78 shouldBe("toObject(new Array(20)).findIndex(passUndefined)", " 0");88 shouldBe("toObject(new Array(20)).findIndex(passUndefined)", "-1"); 79 89 80 90 // Modification during search … … 91 101 shouldThrow("[].findIndex(null)", "'TypeError: Array.prototype.findIndex callback must be a function'"); 92 102 shouldThrow("[].findIndex(undefined)", "'TypeError: Array.prototype.findIndex callback must be a function'"); 103 104 // Callbacks in the expected order and skipping holes. 105 shouldBe("numberOfCallbacksInFindIndexInArrayWithHoles()", "5"); -
trunk/Source/JavaScriptCore/ChangeLog
r169159 r169162 1 2014-05-21 Antoine Quint <graouts@webkit.org> 2 3 Array.prototype.find and findIndex should skip holes 4 https://bugs.webkit.org/show_bug.cgi?id=132658 5 6 Reviewed by Geoffrey Garen. 7 8 Skip holes in the array when iterating such that callback isn't called. 9 10 * builtins/Array.prototype.js: 11 (find): 12 (findIndex): 13 1 14 2014-05-21 Eva Balazsfalvi <evab.u-szeged@partner.samsung.com> 2 15 -
trunk/Source/JavaScriptCore/builtins/Array.prototype.js
r167797 r169162 206 206 var thisArg = arguments.length > 1 ? arguments[1] : undefined; 207 207 for (var i = 0; i < length; i++) { 208 if (!(i in array)) 209 continue; 208 210 if (callback.@call(thisArg, array[i], i, array)) 209 211 return array[i]; … … 228 230 var thisArg = arguments.length > 1 ? arguments[1] : undefined; 229 231 for (var i = 0; i < length; i++) { 232 if (!(i in array)) 233 continue; 230 234 if (callback.@call(thisArg, array[i], i, array)) 231 235 return i;
Note: See TracChangeset
for help on using the changeset viewer.