<!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>[185038] 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/185038">185038</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-31 02:28:54 -0700 (Sun, 31 May 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Array#reduce and reduceRight don't follow ToLength
https://bugs.webkit.org/show_bug.cgi?id=145364
Source/JavaScriptCore:
Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
Patch by Jordan Harband <ljharb@gmail.com> on 2015-05-31
Reviewed by Yusuke Suzuki.
* builtins/Array.prototype.js:
(reduce):
(reduceRight):
* runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototype::finishCreation):
(JSC::arrayProtoFuncReduce): Deleted.
(JSC::arrayProtoFuncReduceRight): Deleted.
LayoutTests:
Patch by Jordan Harband <ljharb@gmail.com> on 2015-05-31
Reviewed by Yusuke Suzuki.
* js/array-reduce-expected.txt:
* js/array-reduceRight-expected.txt:
* js/dom/array-prototype-properties-expected.txt:
* js/dom/script-tests/array-prototype-properties.js:
* js/script-tests/array-reduce.js:
* js/script-tests/array-reduceRight.js:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsarrayreduceexpectedtxt">trunk/LayoutTests/js/array-reduce-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsarrayreduceRightexpectedtxt">trunk/LayoutTests/js/array-reduceRight-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdomarrayprototypepropertiesexpectedtxt">trunk/LayoutTests/js/dom/array-prototype-properties-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdomscripttestsarrayprototypepropertiesjs">trunk/LayoutTests/js/dom/script-tests/array-prototype-properties.js</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayreducejs">trunk/LayoutTests/js/script-tests/array-reduce.js</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayreduceRightjs">trunk/LayoutTests/js/script-tests/array-reduceRight.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="#trunkLayoutTestsjsregressarrayprototypereduceexpectedtxt">trunk/LayoutTests/js/regress/array-prototype-reduce-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsregressarrayprototypereducehtml">trunk/LayoutTests/js/regress/array-prototype-reduce.html</a></li>
<li><a href="#trunkLayoutTestsjsregressarrayprototypereduceRightexpectedtxt">trunk/LayoutTests/js/regress/array-prototype-reduceRight-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsregressarrayprototypereduceRighthtml">trunk/LayoutTests/js/regress/array-prototype-reduceRight.html</a></li>
<li><a href="#trunkLayoutTestsjsregressscripttestsarrayprototypereducejs">trunk/LayoutTests/js/regress/script-tests/array-prototype-reduce.js</a></li>
<li><a href="#trunkLayoutTestsjsregressscripttestsarrayprototypereduceRightjs">trunk/LayoutTests/js/regress/script-tests/array-prototype-reduceRight.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/ChangeLog        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-05-31 Jordan Harband <ljharb@gmail.com>
+
+ Array#reduce and reduceRight don't follow ToLength
+ https://bugs.webkit.org/show_bug.cgi?id=145364
+
+ Reviewed by Yusuke Suzuki.
+
+ * js/array-reduce-expected.txt:
+ * js/array-reduceRight-expected.txt:
+ * js/dom/array-prototype-properties-expected.txt:
+ * js/dom/script-tests/array-prototype-properties.js:
+ * js/script-tests/array-reduce.js:
+ * js/script-tests/array-reduceRight.js:
+
</ins><span class="cx"> 2015-05-30 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> FTL codegen for MultiGetByOffset and MultiPutByOffset where the structure set is already proved should have an unreachable default case instead of an exit
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayreduceexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/array-reduce-expected.txt (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-reduce-expected.txt        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/array-reduce-expected.txt        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> PASS toUnorderedObject([0,1,2,3,4,5]).reduce(function(a,b,i) {return a.concat([i,b]);}, []) is [0,0,1,1,2,2,3,3,4,4,5,5]
</span><span class="cx"> PASS [0,1,2,3,4,5].reduce(function(a,b,i) {return a.concat([i,b]);}, []) is [0,0,1,1,2,2,3,3,4,4,5,5]
</span><span class="cx"> PASS [2,3].reduce(function() {'use strict'; return this;}) is undefined
</span><ins>+PASS Array.prototype.reduce.call(negativeLengthObject, function (a, b) { return a + b; }, 100) is 100
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayreduceRightexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/array-reduceRight-expected.txt (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-reduceRight-expected.txt        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/array-reduceRight-expected.txt        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> PASS toUnorderedObject([0,1,2,3,4,5]).reduceRight(function(a,b,i) {return a.concat([i,b]);}, []) is [5,5,4,4,3,3,2,2,1,1,0,0]
</span><span class="cx"> PASS [0,1,2,3,4,5].reduceRight(function(a,b,i) {return a.concat([i,b]);}, []) is [5,5,4,4,3,3,2,2,1,1,0,0]
</span><span class="cx"> PASS [2,3].reduceRight(function() {'use strict'; return this;}) is undefined
</span><ins>+PASS Array.prototype.reduceRight.call(negativeLengthObject, function (a, b) { return a + b; }, 100) is 100
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsdomarrayprototypepropertiesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/dom/array-prototype-properties-expected.txt (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/array-prototype-properties-expected.txt        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/dom/array-prototype-properties-expected.txt        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -19,10 +19,10 @@
</span><span class="cx"> PASS Array.prototype.forEach.call(undefined, toString) threw exception TypeError: Array.prototype.forEach requires that |this| not be undefined.
</span><span class="cx"> PASS Array.prototype.some.call(undefined, toString) threw exception TypeError: Array.prototype.some requires that |this| not be undefined.
</span><span class="cx"> PASS Array.prototype.indexOf.call(undefined, 0) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.indexOf.call(undefined, 0)').
</span><del>-PASS Array.prototype.indlastIndexOfexOf.call(undefined, 0) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.indlastIndexOfexOf.call').
</del><ins>+PASS Array.prototype.lastIndexOf.call(undefined, 0) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.lastIndexOf.call(undefined, 0)').
</ins><span class="cx"> PASS Array.prototype.filter.call(undefined, toString) threw exception TypeError: Array.prototype.filter requires that |this| not be undefined.
</span><del>-PASS Array.prototype.reduce.call(undefined, toString) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.reduce.call(undefined, toString)').
-PASS Array.prototype.reduceRight.call(undefined, toString) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.reduceRight.call(undefined, toString)').
</del><ins>+PASS Array.prototype.reduce.call(undefined, toString) threw exception TypeError: Array.prototype.reduce requires that |this| not be undefined.
+PASS Array.prototype.reduceRight.call(undefined, toString) threw exception TypeError: Array.prototype.reduceRight requires that |this| not be undefined.
</ins><span class="cx"> PASS Array.prototype.map.call(undefined, toString) threw exception TypeError: Array.prototype.map requires that |this| not be undefined.
</span><span class="cx"> PASS [{toLocaleString:function(){throw 1}},{toLocaleString:function(){throw 2}}].toLocaleString() threw exception 1.
</span><span class="cx"> PASS successfullyParsed is true
</span></span></pre></div>
<a id="trunkLayoutTestsjsdomscripttestsarrayprototypepropertiesjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/dom/script-tests/array-prototype-properties.js (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/script-tests/array-prototype-properties.js        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/dom/script-tests/array-prototype-properties.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -19,7 +19,7 @@
</span><span class="cx"> shouldThrow("Array.prototype.forEach.call(undefined, toString)");
</span><span class="cx"> shouldThrow("Array.prototype.some.call(undefined, toString)");
</span><span class="cx"> shouldThrow("Array.prototype.indexOf.call(undefined, 0)");
</span><del>-shouldThrow("Array.prototype.indlastIndexOfexOf.call(undefined, 0)");
</del><ins>+shouldThrow("Array.prototype.lastIndexOf.call(undefined, 0)");
</ins><span class="cx"> shouldThrow("Array.prototype.filter.call(undefined, toString)");
</span><span class="cx"> shouldThrow("Array.prototype.reduce.call(undefined, toString)");
</span><span class="cx"> shouldThrow("Array.prototype.reduceRight.call(undefined, toString)");
</span></span></pre></div>
<a id="trunkLayoutTestsjsregressarrayprototypereduceexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/array-prototype-reduce-expected.txt (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/array-prototype-reduce-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/regress/array-prototype-reduce-expected.txt        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/array-prototype-reduce
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressarrayprototypereducehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/array-prototype-reduce.html (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/array-prototype-reduce.html         (rev 0)
+++ trunk/LayoutTests/js/regress/array-prototype-reduce.html        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/array-prototype-reduce.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressarrayprototypereduceRightexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/array-prototype-reduceRight-expected.txt (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/array-prototype-reduceRight-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/regress/array-prototype-reduceRight-expected.txt        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/array-prototype-reduceRight
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressarrayprototypereduceRighthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/array-prototype-reduceRight.html (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/array-prototype-reduceRight.html         (rev 0)
+++ trunk/LayoutTests/js/regress/array-prototype-reduceRight.html        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/array-prototype-reduceRight.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressscripttestsarrayprototypereducejs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/script-tests/array-prototype-reduce.js (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/script-tests/array-prototype-reduce.js         (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/array-prototype-reduce.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+var result = 0;
+function test1(a) {
+ result << 1;
+ result++;
+ return true;
+}
+function test2(a,b) {
+ result ^= 3;
+ result *= 3;
+ return true;
+}
+function test3(a,b,c) {
+ result ^= result >> 1;
+ return true;
+}
+
+var result = 0;
+var array = []
+for (var i = 0; i < 100000; ++i)
+ array[i] = 1;
+
+for (var i = 0; i < 10; i++) {
+ array.reduce(test1, {});
+ array.reduce(test2, {});
+ array.reduce(test3, {});
+}
+
+if (result != 1428810496)
+ throw "Error: bad result: " + result;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressscripttestsarrayprototypereduceRightjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/script-tests/array-prototype-reduceRight.js (0 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/script-tests/array-prototype-reduceRight.js         (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/array-prototype-reduceRight.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+var result = 0;
+function test1(a) {
+ result << 1;
+ result++;
+ return true;
+}
+function test2(a,b) {
+ result ^= 3;
+ result *= 3;
+ return true;
+}
+function test3(a,b,c) {
+ result ^= result >> 1;
+ return true;
+}
+
+var result = 0;
+var array = []
+for (var i = 0; i < 100000; ++i)
+ array[i] = 1;
+
+for (var i = 0; i < 10; i++) {
+ array.reduceRight(test1, {});
+ array.reduceRight(test2, {});
+ array.reduceRight(test3, {});
+}
+
+if (result != 1428810496)
+ throw "Error: bad result: " + result;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayreducejs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/array-reduce.js (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-reduce.js        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/script-tests/array-reduce.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -66,3 +66,6 @@
</span><span class="cx"> shouldBe("toUnorderedObject([0,1,2,3,4,5]).reduce(function(a,b,i) {return a.concat([i,b]);}, [])", "[0,0,1,1,2,2,3,3,4,4,5,5]");
</span><span class="cx"> shouldBe("[0,1,2,3,4,5].reduce(function(a,b,i) {return a.concat([i,b]);}, [])", "[0,0,1,1,2,2,3,3,4,4,5,5]");
</span><span class="cx"> shouldBe("[2,3].reduce(function() {'use strict'; return this;})", "undefined");
</span><ins>+
+var negativeLengthObject = { length: -1, 0: 1, 1: 2 };
+shouldBe("Array.prototype.reduce.call(negativeLengthObject, function (a, b) { return a + b; }, 100)", "100");
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayreduceRightjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/array-reduceRight.js (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-reduceRight.js        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/LayoutTests/js/script-tests/array-reduceRight.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -68,3 +68,6 @@
</span><span class="cx"> shouldBe("toUnorderedObject([0,1,2,3,4,5]).reduceRight(function(a,b,i) {return a.concat([i,b]);}, [])", "[5,5,4,4,3,3,2,2,1,1,0,0]");
</span><span class="cx"> shouldBe("[0,1,2,3,4,5].reduceRight(function(a,b,i) {return a.concat([i,b]);}, [])", "[5,5,4,4,3,3,2,2,1,1,0,0]");
</span><span class="cx"> shouldBe("[2,3].reduceRight(function() {'use strict'; return this;})", "undefined");
</span><ins>+
+var negativeLengthObject = { length: -1, 0: 1, 1: 2 };
+shouldBe("Array.prototype.reduceRight.call(negativeLengthObject, function (a, b) { return a + b; }, 100)", "100");
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-05-31 Jordan Harband <ljharb@gmail.com>
+
+ Array#reduce and reduceRight don't follow ToLength
+ https://bugs.webkit.org/show_bug.cgi?id=145364
+ Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
+
+ Reviewed by Yusuke Suzuki.
+
+ * builtins/Array.prototype.js:
+ (reduce):
+ (reduceRight):
+ * runtime/ArrayPrototype.cpp:
+ (JSC::ArrayPrototype::finishCreation):
+ (JSC::arrayProtoFuncReduce): Deleted.
+ (JSC::arrayProtoFuncReduceRight): Deleted.
+
</ins><span class="cx"> 2015-05-29 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> FTL codegen for MultiGetByOffset and MultiPutByOffset where the structure set is already proved should have an unreachable default case instead of an exit
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsArrayprototypejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/Array.prototype.js (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/Array.prototype.js        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/Source/JavaScriptCore/builtins/Array.prototype.js        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -24,6 +24,80 @@
</span><span class="cx"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx"> */
</span><span class="cx">
</span><ins>+function reduce(callback /*, initialValue */)
+{
+ "use strict";
+ if (this === null)
+ throw new @TypeError("Array.prototype.reduce requires that |this| not be null");
+
+ if (this === undefined)
+ throw new @TypeError("Array.prototype.reduce requires that |this| not be undefined");
+
+ var array = @Object(this);
+ var length = @ToLength(array.length);
+
+ if (typeof callback !== "function")
+ throw new @TypeError("Array.prototype.reduce callback must be a function");
+
+ if (length === 0 && arguments.length < 2)
+ throw new @TypeError("reduce of empty array with no initial value");
+
+ var accumulator, k = 0;
+ if (arguments.length > 1)
+ accumulator = arguments[1];
+ else {
+ while (k < length && !(k in array))
+ k += 1;
+ if (k >= length)
+ throw new @TypeError("reduce of empty array with no initial value");
+ accumulator = array[k++];
+ }
+
+ while (k < length) {
+ if (k in array)
+ accumulator = callback.@call(undefined, accumulator, array[k], k, array);
+ k += 1;
+ }
+ return accumulator;
+}
+
+function reduceRight(callback /*, initialValue */)
+{
+ "use strict";
+ if (this === null)
+ throw new @TypeError("Array.prototype.reduceRight requires that |this| not be null");
+
+ if (this === undefined)
+ throw new @TypeError("Array.prototype.reduceRight requires that |this| not be undefined");
+
+ var array = @Object(this);
+ var length = @ToLength(array.length);
+
+ if (typeof callback !== "function")
+ throw new @TypeError("Array.prototype.reduceRight callback must be a function");
+
+ if (length === 0 && arguments.length < 2)
+ throw new @TypeError("reduceRight of empty array with no initial value");
+
+ var accumulator, k = length - 1;
+ if (arguments.length > 1)
+ accumulator = arguments[1];
+ else {
+ while (k >= 0 && !(k in array))
+ k -= 1;
+ if (k < 0)
+ throw new @TypeError("reduceRight of empty array with no initial value");
+ accumulator = array[k--];
+ }
+
+ while (k >= 0) {
+ if (k in array)
+ accumulator = callback.@call(undefined, accumulator, array[k], k, array);
+ k -= 1;
+ }
+ return accumulator;
+}
+
</ins><span class="cx"> function every(callback /*, thisArg */) {
</span><span class="cx"> "use strict";
</span><span class="cx"> if (this === null)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeArrayPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp (185037 => 185038)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2015-05-31 05:53:06 UTC (rev 185037)
+++ trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2015-05-31 09:28:54 UTC (rev 185038)
</span><span class="lines">@@ -109,8 +109,8 @@
</span><span class="cx"> JSC_NATIVE_FUNCTION("indexOf", arrayProtoFuncIndexOf, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_FUNCTION("lastIndexOf", arrayProtoFuncLastIndexOf, DontEnum, 1);
</span><span class="cx"> JSC_BUILTIN_FUNCTION("filter", arrayPrototypeFilterCodeGenerator, DontEnum);
</span><del>- JSC_NATIVE_FUNCTION("reduce", arrayProtoFuncReduce, DontEnum, 1);
- JSC_NATIVE_FUNCTION("reduceRight", arrayProtoFuncReduceRight, DontEnum, 1);
</del><ins>+ JSC_BUILTIN_FUNCTION("reduce", arrayPrototypeReduceCodeGenerator, DontEnum);
+ JSC_BUILTIN_FUNCTION("reduceRight", arrayPrototypeReduceRightCodeGenerator, DontEnum);
</ins><span class="cx"> JSC_BUILTIN_FUNCTION("map", arrayPrototypeMapCodeGenerator, DontEnum);
</span><span class="cx"> JSC_NATIVE_FUNCTION(vm.propertyNames->entries, arrayProtoFuncEntries, DontEnum, 0);
</span><span class="cx"> JSC_NATIVE_FUNCTION(vm.propertyNames->keys, arrayProtoFuncKeys, DontEnum, 0);
</span><span class="lines">@@ -720,159 +720,6 @@
</span><span class="cx"> return JSValue::encode(result);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec)
-{
- JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
- unsigned length = getLength(exec, thisObj);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
-
- JSValue function = exec->argument(0);
- CallData callData;
- CallType callType = getCallData(function, callData);
- if (callType == CallTypeNone)
- return throwVMTypeError(exec);
-
- unsigned i = 0;
- JSValue rv;
- if (!length && exec->argumentCount() == 1)
- return throwVMTypeError(exec);
-
- JSArray* array = 0;
- if (isJSArray(thisObj))
- array = asArray(thisObj);
-
- if (exec->argumentCount() >= 2)
- rv = exec->uncheckedArgument(1);
- else if (array && array->canGetIndexQuickly(0)) {
- rv = array->getIndexQuickly(0);
- i = 1;
- } else {
- for (i = 0; i < length; i++) {
- rv = getProperty(exec, thisObj, i);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
- if (rv)
- break;
- }
- if (!rv)
- return throwVMTypeError(exec);
- i++;
- }
-
- if (callType == CallTypeJS && array) {
- CachedCall cachedCall(exec, jsCast<JSFunction*>(function), 4);
- for (; i < length && !exec->hadException(); ++i) {
- cachedCall.setThis(jsUndefined());
- cachedCall.setArgument(0, rv);
- JSValue v;
- if (LIKELY(array->canGetIndexQuickly(i)))
- v = array->getIndexQuickly(i);
- else
- break; // length has been made unsafe while we enumerate fallback to slow path
- cachedCall.setArgument(1, v);
- cachedCall.setArgument(2, jsNumber(i));
- cachedCall.setArgument(3, array);
- rv = cachedCall.call();
- }
- if (i == length) // only return if we reached the end of the array
- return JSValue::encode(rv);
- }
-
- for (; i < length && !exec->hadException(); ++i) {
- JSValue prop = getProperty(exec, thisObj, i);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
- if (!prop)
- continue;
-
- MarkedArgumentBuffer eachArguments;
- eachArguments.append(rv);
- eachArguments.append(prop);
- eachArguments.append(jsNumber(i));
- eachArguments.append(thisObj);
-
- rv = call(exec, function, callType, callData, jsUndefined(), eachArguments);
- }
- return JSValue::encode(rv);
-}
-
-EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec)
-{
- JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
- unsigned length = getLength(exec, thisObj);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
-
- JSValue function = exec->argument(0);
- CallData callData;
- CallType callType = getCallData(function, callData);
- if (callType == CallTypeNone)
- return throwVMTypeError(exec);
-
- unsigned i = 0;
- JSValue rv;
- if (!length && exec->argumentCount() == 1)
- return throwVMTypeError(exec);
-
- JSArray* array = 0;
- if (isJSArray(thisObj))
- array = asArray(thisObj);
-
- if (exec->argumentCount() >= 2)
- rv = exec->uncheckedArgument(1);
- else if (array && array->canGetIndexQuickly(length - 1)) {
- rv = array->getIndexQuickly(length - 1);
- i = 1;
- } else {
- for (i = 0; i < length; i++) {
- rv = getProperty(exec, thisObj, length - i - 1);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
- if (rv)
- break;
- }
- if (!rv)
- return throwVMTypeError(exec);
- i++;
- }
-
- if (callType == CallTypeJS && array) {
- CachedCall cachedCall(exec, jsCast<JSFunction*>(function), 4);
- for (; i < length && !exec->hadException(); ++i) {
- unsigned idx = length - i - 1;
- cachedCall.setThis(jsUndefined());
- cachedCall.setArgument(0, rv);
- if (UNLIKELY(!array->canGetIndexQuickly(idx)))
- break; // length has been made unsafe while we enumerate fallback to slow path
- cachedCall.setArgument(1, array->getIndexQuickly(idx));
- cachedCall.setArgument(2, jsNumber(idx));
- cachedCall.setArgument(3, array);
- rv = cachedCall.call();
- }
- if (i == length) // only return if we reached the end of the array
- return JSValue::encode(rv);
- }
-
- for (; i < length && !exec->hadException(); ++i) {
- unsigned idx = length - i - 1;
- JSValue prop = getProperty(exec, thisObj, idx);
- if (exec->hadException())
- return JSValue::encode(jsUndefined());
- if (!prop)
- continue;
-
- MarkedArgumentBuffer eachArguments;
- eachArguments.append(rv);
- eachArguments.append(prop);
- eachArguments.append(jsNumber(idx));
- eachArguments.append(thisObj);
-
- rv = call(exec, function, callType, callData, jsUndefined(), eachArguments);
- }
- return JSValue::encode(rv);
-}
-
</del><span class="cx"> EncodedJSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> // 15.4.4.14
</span></span></pre>
</div>
</div>
</body>
</html>