<!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  &lt;graouts@webkit.org&gt;
+
+        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  &lt;rosca@adobe.com&gt;
</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 &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+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>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script src=&quot;script-tests/array-find.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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 &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+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>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script src=&quot;script-tests/array-findIndex.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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">     &quot;Function&quot;: &quot;['length', 'name', 'prototype']&quot;,
</span><span class="cx">     &quot;Function.prototype&quot;: &quot;['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']&quot;,
</span><span class="cx">     &quot;Array&quot;: &quot;['isArray', 'length', 'name', 'prototype']&quot;,
</span><del>-    &quot;Array.prototype&quot;: &quot;['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']&quot;,
</del><ins>+    &quot;Array.prototype&quot;: &quot;['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']&quot;,
</ins><span class="cx">     &quot;String&quot;: &quot;['fromCharCode', 'length', 'name', 'prototype']&quot;,
</span><span class="cx">     &quot;String.prototype&quot;: &quot;['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']&quot;,
</span><span class="cx">     &quot;Boolean&quot;: &quot;['length', 'name', 'prototype']&quot;,
</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(&quot;Tests for Array.prototype.find&quot;);
+
+function passUndefined(element, index, array) {
+    return typeof element === &quot;undefined&quot;;
+}
+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 === &quot;&quot;;
+}
+function passEven(a) {
+    return !(a &amp; 1);
+}
+function passAfter5(element, index) {
+    return index &gt;= 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 &amp;&amp; array[0] === element);
+}
+arrayWithHoles = [];
+arrayWithHoles[10] = 0;
+arrayWithHoles[20] = null;
+arrayWithHoles[30] = false;
+arrayWithHoles[40] = &quot;&quot;;
+
+shouldBe(&quot;[undefined, 0, null, false, ''].find(passUndefined)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].find(passZero)&quot;, &quot;0&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].find(passNull)&quot;, &quot;null&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].find(passFalse)&quot;, &quot;false&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].find(passEmptyString)&quot;, &quot;''&quot;);
+shouldBe(&quot;[0, null, false, ''].find(passUndefined)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[undefined, 0, false, ''].find(passNull)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[undefined, 0, null, ''].find(passFalse)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[undefined, 0, null, false].find(passEmptyString)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[undefined, null, false, ''].find(passZero)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;(new Array(20)).find(passUndefined)&quot;, &quot;undefined&quot;);
+
+// Array with holes.
+shouldBe(&quot;arrayWithHoles.find(passUndefined)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;arrayWithHoles.find(passZero)&quot;, &quot;0&quot;);
+shouldBe(&quot;arrayWithHoles.find(passNull)&quot;, &quot;null&quot;);
+shouldBe(&quot;arrayWithHoles.find(passFalse)&quot;, &quot;false&quot;);
+shouldBe(&quot;arrayWithHoles.find(passEmptyString)&quot;, &quot;''&quot;);
+
+// Generic Object
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).find(passUndefined)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).find(passZero)&quot;, &quot;0&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).find(passNull)&quot;, &quot;null&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).find(passFalse)&quot;, &quot;false&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).find(passEmptyString)&quot;, &quot;''&quot;);
+shouldBe(&quot;toObject([0, null, false, '']).find(passUndefined)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject([undefined, 0, false, '']).find(passNull)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, '']).find(passFalse)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false]).find(passEmptyString)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject([undefined, null, false, '']).find(passZero)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;toObject(new Array(20)).find(passUndefined)&quot;, &quot;undefined&quot;);
+
+// Modification during search
+shouldBe(&quot;[0,1,2,3,4,5,6,7,8,9].find(findItemAddedDuringSearch)&quot;, &quot;undefined&quot;);
+shouldBe(&quot;[0,1,2,3,4,5,6,7,8,9].find(findItemRemovedDuringSearch)&quot;, &quot;undefined&quot;);
+
+// Exeptions
+shouldThrow(&quot;Array.prototype.find.call(undefined, function() {})&quot;, &quot;'TypeError: Array.prototype.find requires that |this| not be undefined'&quot;);
+shouldThrow(&quot;Array.prototype.find.call(null, function() {})&quot;, &quot;'TypeError: Array.prototype.find requires that |this| not be null'&quot;);
+shouldThrow(&quot;[].find(1)&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
+shouldThrow(&quot;[].find('hello')&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
+shouldThrow(&quot;[].find([])&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
+shouldThrow(&quot;[].find({})&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
+shouldThrow(&quot;[].find(null)&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
+shouldThrow(&quot;[].find(undefined)&quot;, &quot;'TypeError: Array.prototype.find callback must be a function'&quot;);
</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(&quot;Tests for Array.prototype.findIndex&quot;);
+
+function passUndefined(element, index, array) {
+    return typeof element === &quot;undefined&quot;;
+}
+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 === &quot;&quot;;
+}
+function passEven(a) {
+    return !(a &amp; 1);
+}
+function passAfter5(element, index) {
+    return index &gt;= 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 &amp;&amp; array[0] === element);
+}
+arrayWithHoles = [];
+arrayWithHoles[10] = 0;
+arrayWithHoles[20] = null;
+arrayWithHoles[30] = false;
+arrayWithHoles[40] = &quot;&quot;;
+
+shouldBe(&quot;[undefined, 0, null, false, ''].findIndex(passUndefined)&quot;, &quot;0&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].findIndex(passZero)&quot;, &quot;1&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].findIndex(passNull)&quot;, &quot;2&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].findIndex(passFalse)&quot;, &quot;3&quot;);
+shouldBe(&quot;[undefined, 0, null, false, ''].findIndex(passEmptyString)&quot;, &quot;4&quot;);
+shouldBe(&quot;[0, null, false, ''].findIndex(passUndefined)&quot;, &quot;-1&quot;);
+shouldBe(&quot;[undefined, 0, false, ''].findIndex(passNull)&quot;, &quot;-1&quot;);
+shouldBe(&quot;[undefined, 0, null, ''].findIndex(passFalse)&quot;, &quot;-1&quot;);
+shouldBe(&quot;[undefined, 0, null, false].findIndex(passEmptyString)&quot;, &quot;-1&quot;);
+shouldBe(&quot;[undefined, null, false, ''].findIndex(passZero)&quot;, &quot;-1&quot;);
+shouldBe(&quot;(new Array(20)).findIndex(passUndefined)&quot;, &quot;0&quot;);
+
+// Array with holes.
+shouldBe(&quot;arrayWithHoles.findIndex(passUndefined)&quot;, &quot;0&quot;);
+shouldBe(&quot;arrayWithHoles.findIndex(passZero)&quot;, &quot;10&quot;);
+shouldBe(&quot;arrayWithHoles.findIndex(passNull)&quot;, &quot;20&quot;);
+shouldBe(&quot;arrayWithHoles.findIndex(passFalse)&quot;, &quot;30&quot;);
+shouldBe(&quot;arrayWithHoles.findIndex(passEmptyString)&quot;, &quot;40&quot;);
+
+// Generic Object
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).findIndex(passUndefined)&quot;, &quot;0&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).findIndex(passZero)&quot;, &quot;1&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).findIndex(passNull)&quot;, &quot;2&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).findIndex(passFalse)&quot;, &quot;3&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false, '']).findIndex(passEmptyString)&quot;, &quot;4&quot;);
+shouldBe(&quot;toObject([0, null, false, '']).findIndex(passUndefined)&quot;, &quot;-1&quot;);
+shouldBe(&quot;toObject([undefined, 0, false, '']).findIndex(passNull)&quot;, &quot;-1&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, '']).findIndex(passFalse)&quot;, &quot;-1&quot;);
+shouldBe(&quot;toObject([undefined, 0, null, false]).findIndex(passEmptyString)&quot;, &quot;-1&quot;);
+shouldBe(&quot;toObject([undefined, null, false, '']).findIndex(passZero)&quot;, &quot;-1&quot;);
+shouldBe(&quot;toObject(new Array(20)).findIndex(passUndefined)&quot;, &quot;0&quot;);
+
+// Modification during search
+shouldBe(&quot;[0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch)&quot;, &quot;-1&quot;);
+shouldBe(&quot;[0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch)&quot;, &quot;-1&quot;);
+
+// Exeptions
+shouldThrow(&quot;Array.prototype.findIndex.call(undefined, function() {})&quot;, &quot;'TypeError: Array.prototype.findIndex requires that |this| not be undefined'&quot;);
+shouldThrow(&quot;Array.prototype.findIndex.call(null, function() {})&quot;, &quot;'TypeError: Array.prototype.findIndex requires that |this| not be null'&quot;);
+shouldThrow(&quot;[].findIndex(1)&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
+shouldThrow(&quot;[].findIndex('hello')&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
+shouldThrow(&quot;[].findIndex([])&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
+shouldThrow(&quot;[].findIndex({})&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
+shouldThrow(&quot;[].findIndex(null)&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
+shouldThrow(&quot;[].findIndex(undefined)&quot;, &quot;'TypeError: Array.prototype.findIndex callback must be a function'&quot;);
</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  &lt;graouts@webkit.org&gt;
+
+        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  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rename &quot;IMAGE_CONTROLS&quot; feature to &quot;SERVICE_CONTROLS&quot;
</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 */) {
+    &quot;use strict&quot;;
+    if (this === null)
+        throw new @TypeError(&quot;Array.prototype.find requires that |this| not be null&quot;);
+    
+    if (this === undefined)
+        throw new @TypeError(&quot;Array.prototype.find requires that |this| not be undefined&quot;);
+    
+    var array = @Object(this);
+    var length = array.length &gt;&gt;&gt; 0;
+    
+    if (typeof callback !== &quot;function&quot;)
+        throw new @TypeError(&quot;Array.prototype.find callback must be a function&quot;);
+    
+    var thisArg = arguments.length &gt; 1 ? arguments[1] : undefined;
+    for (var i = 0; i &lt; length; i++) {
+        if (callback.@call(thisArg, array[i], i, array))
+            return array[i];
+    }
+    return undefined;
+}
+
+function findIndex(callback /*, thisArg */) {
+    &quot;use strict&quot;;
+    if (this === null)
+        throw new @TypeError(&quot;Array.prototype.findIndex requires that |this| not be null&quot;);
+    
+    if (this === undefined)
+        throw new @TypeError(&quot;Array.prototype.findIndex requires that |this| not be undefined&quot;);
+    
+    var array = @Object(this);
+    var length = array.length &gt;&gt;&gt; 0;
+    
+    if (typeof callback !== &quot;function&quot;)
+        throw new @TypeError(&quot;Array.prototype.findIndex callback must be a function&quot;);
+    
+    var thisArg = arguments.length &gt; 1 ? arguments[1] : undefined;
+    for (var i = 0; i &lt; 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>