<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[167797] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/167797">167797</a></dd>
<dt>Author</dt> <dd>graouts@webkit.org</dd>
<dt>Date</dt> <dd>2014-04-25 01:25:59 -0700 (Fri, 25 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement Array.prototype.find()
https://bugs.webkit.org/show_bug.cgi?id=130966
Reviewed by Oliver Hunt.
Source/JavaScriptCore:
Implement Array.prototype.find() and Array.prototype.findIndex() as proposed in the Harmony spec.
* builtins/Array.prototype.js:
(find):
(findIndex):
* runtime/ArrayPrototype.cpp:
LayoutTests:
* js/Object-getOwnPropertyNames-expected.txt:
* js/array-find-expected.txt: Added.
* js/array-find.html: Added.
* js/array-findIndex-expected.txt: Added.
* js/array-findIndex.html: Added.
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/array-find.js: Added.
* js/script-tests/array-findIndex.js: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsObjectgetOwnPropertyNamesexpectedtxt">trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsObjectgetOwnPropertyNamesjs">trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsArrayprototypejs">trunk/Source/JavaScriptCore/builtins/Array.prototype.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeArrayPrototypecpp">trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsarrayfindexpectedtxt">trunk/LayoutTests/js/array-find-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsarrayfindhtml">trunk/LayoutTests/js/array-find.html</a></li>
<li><a href="#trunkLayoutTestsjsarrayfindIndexexpectedtxt">trunk/LayoutTests/js/array-findIndex-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsarrayfindIndexhtml">trunk/LayoutTests/js/array-findIndex.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayfindjs">trunk/LayoutTests/js/script-tests/array-find.js</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayfindIndexjs">trunk/LayoutTests/js/script-tests/array-findIndex.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/LayoutTests/ChangeLog        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-04-25 Antoine Quint <graouts@webkit.org>
+
+ Implement Array.prototype.find()
+ https://bugs.webkit.org/show_bug.cgi?id=130966
+
+ Reviewed by Oliver Hunt.
+
+ * js/Object-getOwnPropertyNames-expected.txt:
+ * js/array-find-expected.txt: Added.
+ * js/array-find.html: Added.
+ * js/array-findIndex-expected.txt: Added.
+ * js/array-findIndex.html: Added.
+ * js/script-tests/Object-getOwnPropertyNames.js:
+ * js/script-tests/array-find.js: Added.
+ * js/script-tests/array-findIndex.js: Added.
+
</ins><span class="cx"> 2014-04-25 Ion Rosca <rosca@adobe.com>
</span><span class="cx">
</span><span class="cx"> Incomplete body painting when using blend modes
</span></span></pre></div>
<a id="trunkLayoutTestsjsObjectgetOwnPropertyNamesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx"> PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'prototype']
</span><del>-PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
</del><ins>+PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
</ins><span class="cx"> PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
</span><span class="cx"> PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayfindexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-find-expected.txt (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-find-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/array-find-expected.txt        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+Tests for Array.prototype.find
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS [undefined, 0, null, false, ''].find(passUndefined) is undefined
+PASS [undefined, 0, null, false, ''].find(passZero) is 0
+PASS [undefined, 0, null, false, ''].find(passNull) is null
+PASS [undefined, 0, null, false, ''].find(passFalse) is false
+PASS [undefined, 0, null, false, ''].find(passEmptyString) is ''
+PASS [0, null, false, ''].find(passUndefined) is undefined
+PASS [undefined, 0, false, ''].find(passNull) is undefined
+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
+PASS (new Array(20)).find(passUndefined) is undefined
+PASS arrayWithHoles.find(passUndefined) is undefined
+PASS arrayWithHoles.find(passZero) is 0
+PASS arrayWithHoles.find(passNull) is null
+PASS arrayWithHoles.find(passFalse) is false
+PASS arrayWithHoles.find(passEmptyString) is ''
+PASS toObject([undefined, 0, null, false, '']).find(passUndefined) is undefined
+PASS toObject([undefined, 0, null, false, '']).find(passZero) is 0
+PASS toObject([undefined, 0, null, false, '']).find(passNull) is null
+PASS toObject([undefined, 0, null, false, '']).find(passFalse) is false
+PASS toObject([undefined, 0, null, false, '']).find(passEmptyString) is ''
+PASS toObject([0, null, false, '']).find(passUndefined) is undefined
+PASS toObject([undefined, 0, false, '']).find(passNull) is undefined
+PASS toObject([undefined, 0, null, '']).find(passFalse) is undefined
+PASS toObject([undefined, 0, null, false]).find(passEmptyString) is undefined
+PASS toObject([undefined, null, false, '']).find(passZero) is undefined
+PASS toObject(new Array(20)).find(passUndefined) is undefined
+PASS [0,1,2,3,4,5,6,7,8,9].find(findItemAddedDuringSearch) is undefined
+PASS [0,1,2,3,4,5,6,7,8,9].find(findItemRemovedDuringSearch) is undefined
+PASS Array.prototype.find.call(undefined, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be undefined.
+PASS Array.prototype.find.call(null, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be null.
+PASS [].find(1) threw exception TypeError: Array.prototype.find callback must be a function.
+PASS [].find('hello') threw exception TypeError: Array.prototype.find callback must be a function.
+PASS [].find([]) threw exception TypeError: Array.prototype.find callback must be a function.
+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.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsarrayfindhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-find.html (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-find.html         (rev 0)
+++ trunk/LayoutTests/js/array-find.html        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/array-find.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsarrayfindIndexexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-findIndex-expected.txt (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-findIndex-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/array-findIndex-expected.txt        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+Tests for Array.prototype.findIndex
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS [undefined, 0, null, false, ''].findIndex(passUndefined) is 0
+PASS [undefined, 0, null, false, ''].findIndex(passZero) is 1
+PASS [undefined, 0, null, false, ''].findIndex(passNull) is 2
+PASS [undefined, 0, null, false, ''].findIndex(passFalse) is 3
+PASS [undefined, 0, null, false, ''].findIndex(passEmptyString) is 4
+PASS [0, null, false, ''].findIndex(passUndefined) is -1
+PASS [undefined, 0, false, ''].findIndex(passNull) is -1
+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 0
+PASS arrayWithHoles.findIndex(passUndefined) is 0
+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 toObject([undefined, 0, null, false, '']).findIndex(passUndefined) is 0
+PASS toObject([undefined, 0, null, false, '']).findIndex(passZero) is 1
+PASS toObject([undefined, 0, null, false, '']).findIndex(passNull) is 2
+PASS toObject([undefined, 0, null, false, '']).findIndex(passFalse) is 3
+PASS toObject([undefined, 0, null, false, '']).findIndex(passEmptyString) is 4
+PASS toObject([0, null, false, '']).findIndex(passUndefined) is -1
+PASS toObject([undefined, 0, false, '']).findIndex(passNull) is -1
+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 0
+PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch) is -1
+PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch) is -1
+PASS Array.prototype.findIndex.call(undefined, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be undefined.
+PASS Array.prototype.findIndex.call(null, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null.
+PASS [].findIndex(1) threw exception TypeError: Array.prototype.findIndex callback must be a function.
+PASS [].findIndex('hello') threw exception TypeError: Array.prototype.findIndex callback must be a function.
+PASS [].findIndex([]) threw exception TypeError: Array.prototype.findIndex callback must be a function.
+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.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsarrayfindIndexhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-findIndex.html (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-findIndex.html         (rev 0)
+++ trunk/LayoutTests/js/array-findIndex.html        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/array-findIndex.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsObjectgetOwnPropertyNamesjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx"> "Function": "['length', 'name', 'prototype']",
</span><span class="cx"> "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
</span><span class="cx"> "Array": "['isArray', 'length', 'name', 'prototype']",
</span><del>- "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
</del><ins>+ "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
</ins><span class="cx"> "String": "['fromCharCode', 'length', 'name', 'prototype']",
</span><span class="cx"> "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
</span><span class="cx"> "Boolean": "['length', 'name', 'prototype']",
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayfindjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/array-find.js (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-find.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/array-find.js        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,92 @@
</span><ins>+description("Tests for Array.prototype.find");
+
+function passUndefined(element, index, array) {
+ return typeof element === "undefined";
+}
+function passZero(element, index, array) {
+ return element === 0;
+}
+function passNull(element, index, array) {
+ return element === null;
+}
+function passFalse(element, index, array) {
+ return element === false;
+}
+function passEmptyString(element, index, array) {
+ return element === "";
+}
+function passEven(a) {
+ return !(a & 1);
+}
+function passAfter5(element, index) {
+ return index >= 5;
+}
+function toObject(array) {
+ var result = {};
+ result.length = array.length;
+ for (var i in array)
+ result[i] = array[i];
+ result.find=Array.prototype.find;
+ return result;
+}
+function findItemAddedDuringSearch(element, index, array) {
+ if (index === 0)
+ array.push(array.length);
+ return (index === array.length - 1);
+}
+function findItemRemovedDuringSearch(element, index, array) {
+ if (index === 0)
+ array.shift();
+ return (index === 0 && array[0] === element);
+}
+arrayWithHoles = [];
+arrayWithHoles[10] = 0;
+arrayWithHoles[20] = null;
+arrayWithHoles[30] = false;
+arrayWithHoles[40] = "";
+
+shouldBe("[undefined, 0, null, false, ''].find(passUndefined)", "undefined");
+shouldBe("[undefined, 0, null, false, ''].find(passZero)", "0");
+shouldBe("[undefined, 0, null, false, ''].find(passNull)", "null");
+shouldBe("[undefined, 0, null, false, ''].find(passFalse)", "false");
+shouldBe("[undefined, 0, null, false, ''].find(passEmptyString)", "''");
+shouldBe("[0, null, false, ''].find(passUndefined)", "undefined");
+shouldBe("[undefined, 0, false, ''].find(passNull)", "undefined");
+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");
+
+// Array with holes.
+shouldBe("arrayWithHoles.find(passUndefined)", "undefined");
+shouldBe("arrayWithHoles.find(passZero)", "0");
+shouldBe("arrayWithHoles.find(passNull)", "null");
+shouldBe("arrayWithHoles.find(passFalse)", "false");
+shouldBe("arrayWithHoles.find(passEmptyString)", "''");
+
+// Generic Object
+shouldBe("toObject([undefined, 0, null, false, '']).find(passUndefined)", "undefined");
+shouldBe("toObject([undefined, 0, null, false, '']).find(passZero)", "0");
+shouldBe("toObject([undefined, 0, null, false, '']).find(passNull)", "null");
+shouldBe("toObject([undefined, 0, null, false, '']).find(passFalse)", "false");
+shouldBe("toObject([undefined, 0, null, false, '']).find(passEmptyString)", "''");
+shouldBe("toObject([0, null, false, '']).find(passUndefined)", "undefined");
+shouldBe("toObject([undefined, 0, false, '']).find(passNull)", "undefined");
+shouldBe("toObject([undefined, 0, null, '']).find(passFalse)", "undefined");
+shouldBe("toObject([undefined, 0, null, false]).find(passEmptyString)", "undefined");
+shouldBe("toObject([undefined, null, false, '']).find(passZero)", "undefined");
+shouldBe("toObject(new Array(20)).find(passUndefined)", "undefined");
+
+// Modification during search
+shouldBe("[0,1,2,3,4,5,6,7,8,9].find(findItemAddedDuringSearch)", "undefined");
+shouldBe("[0,1,2,3,4,5,6,7,8,9].find(findItemRemovedDuringSearch)", "undefined");
+
+// Exeptions
+shouldThrow("Array.prototype.find.call(undefined, function() {})", "'TypeError: Array.prototype.find requires that |this| not be undefined'");
+shouldThrow("Array.prototype.find.call(null, function() {})", "'TypeError: Array.prototype.find requires that |this| not be null'");
+shouldThrow("[].find(1)", "'TypeError: Array.prototype.find callback must be a function'");
+shouldThrow("[].find('hello')", "'TypeError: Array.prototype.find callback must be a function'");
+shouldThrow("[].find([])", "'TypeError: Array.prototype.find callback must be a function'");
+shouldThrow("[].find({})", "'TypeError: Array.prototype.find callback must be a function'");
+shouldThrow("[].find(null)", "'TypeError: Array.prototype.find callback must be a function'");
+shouldThrow("[].find(undefined)", "'TypeError: Array.prototype.find callback must be a function'");
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayfindIndexjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/array-findIndex.js (0 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-findIndex.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/array-findIndex.js        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -0,0 +1,92 @@
</span><ins>+description("Tests for Array.prototype.findIndex");
+
+function passUndefined(element, index, array) {
+ return typeof element === "undefined";
+}
+function passZero(element, index, array) {
+ return element === 0;
+}
+function passNull(element, index, array) {
+ return element === null;
+}
+function passFalse(element, index, array) {
+ return element === false;
+}
+function passEmptyString(element, index, array) {
+ return element === "";
+}
+function passEven(a) {
+ return !(a & 1);
+}
+function passAfter5(element, index) {
+ return index >= 5;
+}
+function toObject(array) {
+ var result = {};
+ result.length = array.length;
+ for (var i in array)
+ result[i] = array[i];
+ result.findIndex=Array.prototype.findIndex;
+ return result;
+}
+function findItemAddedDuringSearch(element, index, array) {
+ if (index === 0)
+ array.push(array.length);
+ return (index === array.length - 1);
+}
+function findItemRemovedDuringSearch(element, index, array) {
+ if (index === 0)
+ array.shift();
+ return (index === 0 && array[0] === element);
+}
+arrayWithHoles = [];
+arrayWithHoles[10] = 0;
+arrayWithHoles[20] = null;
+arrayWithHoles[30] = false;
+arrayWithHoles[40] = "";
+
+shouldBe("[undefined, 0, null, false, ''].findIndex(passUndefined)", "0");
+shouldBe("[undefined, 0, null, false, ''].findIndex(passZero)", "1");
+shouldBe("[undefined, 0, null, false, ''].findIndex(passNull)", "2");
+shouldBe("[undefined, 0, null, false, ''].findIndex(passFalse)", "3");
+shouldBe("[undefined, 0, null, false, ''].findIndex(passEmptyString)", "4");
+shouldBe("[0, null, false, ''].findIndex(passUndefined)", "-1");
+shouldBe("[undefined, 0, false, ''].findIndex(passNull)", "-1");
+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)", "0");
+
+// Array with holes.
+shouldBe("arrayWithHoles.findIndex(passUndefined)", "0");
+shouldBe("arrayWithHoles.findIndex(passZero)", "10");
+shouldBe("arrayWithHoles.findIndex(passNull)", "20");
+shouldBe("arrayWithHoles.findIndex(passFalse)", "30");
+shouldBe("arrayWithHoles.findIndex(passEmptyString)", "40");
+
+// Generic Object
+shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passUndefined)", "0");
+shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passZero)", "1");
+shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passNull)", "2");
+shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passFalse)", "3");
+shouldBe("toObject([undefined, 0, null, false, '']).findIndex(passEmptyString)", "4");
+shouldBe("toObject([0, null, false, '']).findIndex(passUndefined)", "-1");
+shouldBe("toObject([undefined, 0, false, '']).findIndex(passNull)", "-1");
+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)", "0");
+
+// Modification during search
+shouldBe("[0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch)", "-1");
+shouldBe("[0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch)", "-1");
+
+// Exeptions
+shouldThrow("Array.prototype.findIndex.call(undefined, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be undefined'");
+shouldThrow("Array.prototype.findIndex.call(null, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be null'");
+shouldThrow("[].findIndex(1)", "'TypeError: Array.prototype.findIndex callback must be a function'");
+shouldThrow("[].findIndex('hello')", "'TypeError: Array.prototype.findIndex callback must be a function'");
+shouldThrow("[].findIndex([])", "'TypeError: Array.prototype.findIndex callback must be a function'");
+shouldThrow("[].findIndex({})", "'TypeError: Array.prototype.findIndex callback must be a function'");
+shouldThrow("[].findIndex(null)", "'TypeError: Array.prototype.findIndex callback must be a function'");
+shouldThrow("[].findIndex(undefined)", "'TypeError: Array.prototype.findIndex callback must be a function'");
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-04-25 Antoine Quint <graouts@webkit.org>
+
+ Implement Array.prototype.find()
+ https://bugs.webkit.org/show_bug.cgi?id=130966
+
+ Reviewed by Oliver Hunt.
+
+ Implement Array.prototype.find() and Array.prototype.findIndex() as proposed in the Harmony spec.
+
+ * builtins/Array.prototype.js:
+ (find):
+ (findIndex):
+ * runtime/ArrayPrototype.cpp:
+
</ins><span class="cx"> 2014-04-24 Brady Eidson <beidson@apple.com>
</span><span class="cx">
</span><span class="cx"> Rename "IMAGE_CONTROLS" feature to "SERVICE_CONTROLS"
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsArrayprototypejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/Array.prototype.js (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/Array.prototype.js        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/Source/JavaScriptCore/builtins/Array.prototype.js        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -189,3 +189,46 @@
</span><span class="cx"> return O;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+function find(callback /*, thisArg */) {
+ "use strict";
+ if (this === null)
+ throw new @TypeError("Array.prototype.find requires that |this| not be null");
+
+ if (this === undefined)
+ throw new @TypeError("Array.prototype.find requires that |this| not be undefined");
+
+ var array = @Object(this);
+ var length = array.length >>> 0;
+
+ if (typeof callback !== "function")
+ throw new @TypeError("Array.prototype.find callback must be a function");
+
+ var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+ for (var i = 0; i < length; i++) {
+ if (callback.@call(thisArg, array[i], i, array))
+ return array[i];
+ }
+ return undefined;
+}
+
+function findIndex(callback /*, thisArg */) {
+ "use strict";
+ if (this === null)
+ throw new @TypeError("Array.prototype.findIndex requires that |this| not be null");
+
+ if (this === undefined)
+ throw new @TypeError("Array.prototype.findIndex requires that |this| not be undefined");
+
+ var array = @Object(this);
+ var length = array.length >>> 0;
+
+ if (typeof callback !== "function")
+ throw new @TypeError("Array.prototype.findIndex callback must be a function");
+
+ var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+ for (var i = 0; i < length; i++) {
+ if (callback.@call(thisArg, array[i], i, array))
+ return i;
+ }
+ return -1;
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeArrayPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp (167796 => 167797)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2014-04-25 08:04:28 UTC (rev 167796)
+++ trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2014-04-25 08:25:59 UTC (rev 167797)
</span><span class="lines">@@ -115,6 +115,8 @@
</span><span class="cx"> map arrayProtoFuncMap DontEnum|Function 1
</span><span class="cx"> entries arrayProtoFuncEntries DontEnum|Function 0
</span><span class="cx"> keys arrayProtoFuncKeys DontEnum|Function 0
</span><ins>+ find arrayProtoFuncFind DontEnum|Function 1
+ findIndex arrayProtoFuncFindIndex DontEnum|Function 1
</ins><span class="cx"> @end
</span><span class="cx"> */
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>