Diff
Modified: trunk/LayoutTests/ChangeLog (184847 => 184848)
--- trunk/LayoutTests/ChangeLog 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/LayoutTests/ChangeLog 2015-05-25 03:51:17 UTC (rev 184848)
@@ -1,3 +1,15 @@
+2015-05-24 Jordan Harband <[email protected]>
+
+ Array#findIndex/find should not skip holes
+ https://bugs.webkit.org/show_bug.cgi?id=145361
+
+ Reviewed by Yusuke Suzuki.
+
+ * js/array-find-expected.txt:
+ * js/array-findIndex-expected.txt:
+ * js/script-tests/array-find.js:
+ * js/script-tests/array-findIndex.js:
+
2015-05-23 Antti Koivisto <[email protected]>
Permanent redirects should have long implicit cache lifetime
Modified: trunk/LayoutTests/js/array-find-expected.txt (184847 => 184848)
--- trunk/LayoutTests/js/array-find-expected.txt 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/LayoutTests/js/array-find-expected.txt 2015-05-25 03:51:17 UTC (rev 184848)
@@ -15,8 +15,8 @@
PASS [undefined, 0, null, ''].find(passFalse) is undefined
PASS [undefined, 0, null, false].find(passEmptyString) is undefined
PASS [undefined, null, false, ''].find(passZero) is undefined
+Array with holes
PASS (new Array(20)).find(passUndefined) is undefined
-Array with holes
PASS arrayWithHoles.find(passUndefined) is undefined
PASS arrayWithHoles.find(passZero) is 0
PASS arrayWithHoles.find(passNull) is null
@@ -50,13 +50,16 @@
PASS [].find({}) threw exception TypeError: Array.prototype.find callback must be a function.
PASS [].find(null) threw exception TypeError: Array.prototype.find callback must be a function.
PASS [].find(undefined) threw exception TypeError: Array.prototype.find callback must be a function.
-Callbacks in the expected order and skipping holes
-find callback called with index 10
-find callback called with index 20
-find callback called with index 30
-find callback called with index 40
-find callback called with index 50
-PASS numberOfCallbacksInFindInArrayWithHoles() is 5
+Callbacks in the expected order and *not* skipping holes
+find callback called with index 0
+find callback called with index 1
+find callback called with index 2
+find callback called with index 3
+find callback called with index 4
+find callback called with index 5
+find callback called with index 6
+find callback called with index 7
+PASS numberOfCallbacksInFindInArrayWithHoles() is 8
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/js/array-findIndex-expected.txt (184847 => 184848)
--- trunk/LayoutTests/js/array-findIndex-expected.txt 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/LayoutTests/js/array-findIndex-expected.txt 2015-05-25 03:51:17 UTC (rev 184848)
@@ -15,14 +15,14 @@
PASS [undefined, 0, null, ''].findIndex(passFalse) is -1
PASS [undefined, 0, null, false].findIndex(passEmptyString) is -1
PASS [undefined, null, false, ''].findIndex(passZero) is -1
-PASS (new Array(20)).findIndex(passUndefined) is -1
Array with holes
-PASS arrayWithHoles.findIndex(passUndefined) is -1
-PASS arrayWithHoles.findIndex(passZero) is 10
-PASS arrayWithHoles.findIndex(passNull) is 20
-PASS arrayWithHoles.findIndex(passFalse) is 30
-PASS arrayWithHoles.findIndex(passEmptyString) is 40
-PASS arrayWithHoles.findIndex(passUndefined) is 50
+PASS (new Array(20)).findIndex(passUndefined) is 0
+PASS arrayWithHoles.findIndex(passUndefined) is 0
+PASS arrayWithHoles.findIndex(passZero) is 1
+PASS arrayWithHoles.findIndex(passNull) is 3
+PASS arrayWithHoles.findIndex(passFalse) is 5
+PASS arrayWithHoles.findIndex(passEmptyString) is 7
+PASS arrayWithHoles.findIndex(passUndefined) is 2
Generic Object
PASS toObject([undefined, 0, null, false, '']).findIndex(passUndefined) is 0
PASS toObject([undefined, 0, null, false, '']).findIndex(passZero) is 1
@@ -34,7 +34,7 @@
PASS toObject([undefined, 0, null, '']).findIndex(passFalse) is -1
PASS toObject([undefined, 0, null, false]).findIndex(passEmptyString) is -1
PASS toObject([undefined, null, false, '']).findIndex(passZero) is -1
-PASS toObject(new Array(20)).findIndex(passUndefined) is -1
+PASS toObject(new Array(20)).findIndex(passUndefined) is 0
Array-like object with invalid lengths
PASS var obj = { 0: 1, 1: 2, 2: 3, length: 0 }; Array.prototype.findIndex.call(obj, throwError) is -1
PASS var obj = { 0: 1, 1: 2, 2: 3, length: -0 }; Array.prototype.findIndex.call(obj, throwError) is -1
@@ -51,13 +51,16 @@
PASS [].findIndex({}) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex(null) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex(undefined) threw exception TypeError: Array.prototype.findIndex callback must be a function.
-Callbacks in the expected order and skipping holes
-find callback called with index 10
-find callback called with index 20
-find callback called with index 30
-find callback called with index 40
-find callback called with index 50
-PASS numberOfCallbacksInFindIndexInArrayWithHoles() is 5
+Callbacks in the expected order and *not* skipping holes
+find callback called with index 0
+find callback called with index 1
+find callback called with index 2
+find callback called with index 3
+find callback called with index 4
+find callback called with index 5
+find callback called with index 6
+find callback called with index 7
+PASS numberOfCallbacksInFindIndexInArrayWithHoles() is 8
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/js/script-tests/array-find.js (184847 => 184848)
--- trunk/LayoutTests/js/script-tests/array-find.js 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/LayoutTests/js/script-tests/array-find.js 2015-05-25 03:51:17 UTC (rev 184848)
@@ -43,11 +43,10 @@
return (index === 0 && array[0] === element);
}
arrayWithHoles = [];
-arrayWithHoles[10] = 0;
-arrayWithHoles[20] = null;
-arrayWithHoles[30] = false;
-arrayWithHoles[40] = "";
-arrayWithHoles[50] = undefined;
+arrayWithHoles[1] = 0;
+arrayWithHoles[3] = null;
+arrayWithHoles[5] = false;
+arrayWithHoles[7] = "";
function numberOfCallbacksInFindInArrayWithHoles() {
var count = 0;
arrayWithHoles.find(function(element, index, array) {
@@ -67,9 +66,9 @@
shouldBe("[undefined, 0, null, ''].find(passFalse)", "undefined");
shouldBe("[undefined, 0, null, false].find(passEmptyString)", "undefined");
shouldBe("[undefined, null, false, ''].find(passZero)", "undefined");
-shouldBe("(new Array(20)).find(passUndefined)", "undefined");
debug("Array with holes")
+shouldBe("(new Array(20)).find(passUndefined)", "undefined");
shouldBe("arrayWithHoles.find(passUndefined)", "undefined");
shouldBe("arrayWithHoles.find(passZero)", "0");
shouldBe("arrayWithHoles.find(passNull)", "null");
@@ -111,5 +110,5 @@
shouldThrow("[].find(null)", "'TypeError: Array.prototype.find callback must be a function'");
shouldThrow("[].find(undefined)", "'TypeError: Array.prototype.find callback must be a function'");
-debug("Callbacks in the expected order and skipping holes");
-shouldBe("numberOfCallbacksInFindInArrayWithHoles()", "5");
+debug("Callbacks in the expected order and *not* skipping holes");
+shouldBe("numberOfCallbacksInFindInArrayWithHoles()", "8");
Modified: trunk/LayoutTests/js/script-tests/array-findIndex.js (184847 => 184848)
--- trunk/LayoutTests/js/script-tests/array-findIndex.js 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/LayoutTests/js/script-tests/array-findIndex.js 2015-05-25 03:51:17 UTC (rev 184848)
@@ -42,11 +42,11 @@
array.shift();
return (index === 0 && array[0] === element);
}
-arrayWithHoles = [];
-arrayWithHoles[10] = 0;
-arrayWithHoles[20] = null;
-arrayWithHoles[30] = false;
-arrayWithHoles[40] = "";
+var arrayWithHoles = [];
+arrayWithHoles[1] = 0;
+arrayWithHoles[3] = null;
+arrayWithHoles[5] = false;
+arrayWithHoles[7] = "";
function numberOfCallbacksInFindIndexInArrayWithHoles() {
var count = 0;
arrayWithHoles.find(function(element, index, array) {
@@ -66,16 +66,16 @@
shouldBe("[undefined, 0, null, ''].findIndex(passFalse)", "-1");
shouldBe("[undefined, 0, null, false].findIndex(passEmptyString)", "-1");
shouldBe("[undefined, null, false, ''].findIndex(passZero)", "-1");
-shouldBe("(new Array(20)).findIndex(passUndefined)", "-1");
debug("Array with holes");
-shouldBe("arrayWithHoles.findIndex(passUndefined)", "-1");
-shouldBe("arrayWithHoles.findIndex(passZero)", "10");
-shouldBe("arrayWithHoles.findIndex(passNull)", "20");
-shouldBe("arrayWithHoles.findIndex(passFalse)", "30");
-shouldBe("arrayWithHoles.findIndex(passEmptyString)", "40");
-arrayWithHoles[50] = undefined;
-shouldBe("arrayWithHoles.findIndex(passUndefined)", "50");
+shouldBe("(new Array(20)).findIndex(passUndefined)", "0");
+shouldBe("arrayWithHoles.findIndex(passUndefined)", "0");
+shouldBe("arrayWithHoles.findIndex(passZero)", "1");
+shouldBe("arrayWithHoles.findIndex(passNull)", "3");
+shouldBe("arrayWithHoles.findIndex(passFalse)", "5");
+shouldBe("arrayWithHoles.findIndex(passEmptyString)", "7");
+arrayWithHoles[0] = {};
+shouldBe("arrayWithHoles.findIndex(passUndefined)", "2");
debug("Generic Object");
shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passUndefined)", "0");
@@ -88,7 +88,7 @@
shouldBe("toObject([undefined, 0, null, '']).findIndex(passFalse)", "-1");
shouldBe("toObject([undefined, 0, null, false]).findIndex(passEmptyString)", "-1");
shouldBe("toObject([undefined, null, false, '']).findIndex(passZero)", "-1");
-shouldBe("toObject(new Array(20)).findIndex(passUndefined)", "-1");
+shouldBe("toObject(new Array(20)).findIndex(passUndefined)", "0");
debug("Array-like object with invalid lengths");
var throwError = function throwError() {
@@ -112,5 +112,5 @@
shouldThrow("[].findIndex(null)", "'TypeError: Array.prototype.findIndex callback must be a function'");
shouldThrow("[].findIndex(undefined)", "'TypeError: Array.prototype.findIndex callback must be a function'");
-debug("Callbacks in the expected order and skipping holes");
-shouldBe("numberOfCallbacksInFindIndexInArrayWithHoles()", "5");
+debug("Callbacks in the expected order and *not* skipping holes");
+shouldBe("numberOfCallbacksInFindIndexInArrayWithHoles()", "8");
Modified: trunk/Source/_javascript_Core/ChangeLog (184847 => 184848)
--- trunk/Source/_javascript_Core/ChangeLog 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-05-25 03:51:17 UTC (rev 184848)
@@ -1,3 +1,16 @@
+2015-05-24 Jordan Harband <[email protected]>
+
+ Array#findIndex/find should not skip holes
+ https://bugs.webkit.org/show_bug.cgi?id=145361
+ per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.findindex
+ and https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.find
+
+ Reviewed by Yusuke Suzuki.
+
+ * builtins/Array.prototype.js:
+ (find): Deleted.
+ (findIndex): Deleted.
+
2015-05-24 Brian J. Burg <[email protected]>
Web Inspector: Uncaught exception when using Inspect tool on SVG elements
Modified: trunk/Source/_javascript_Core/builtins/Array.prototype.js (184847 => 184848)
--- trunk/Source/_javascript_Core/builtins/Array.prototype.js 2015-05-25 02:38:22 UTC (rev 184847)
+++ trunk/Source/_javascript_Core/builtins/Array.prototype.js 2015-05-25 03:51:17 UTC (rev 184848)
@@ -208,8 +208,6 @@
var thisArg = arguments.length > 1 ? arguments[1] : undefined;
for (var i = 0; i < length; i++) {
- if (!(i in array))
- continue;
var kValue = array[i];
if (callback.@call(thisArg, kValue, i, array))
return kValue;
@@ -233,8 +231,6 @@
var thisArg = arguments.length > 1 ? arguments[1] : undefined;
for (var i = 0; i < length; i++) {
- if (!(i in array))
- continue;
if (callback.@call(thisArg, array[i], i, array))
return i;
}