<!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>[180370] 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/180370">180370</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2015-02-19 16:20:54 -0800 (Thu, 19 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>ES6: Implement Array.from()
https://bugs.webkit.org/show_bug.cgi?id=141054
&lt;rdar://problem/19654521&gt;

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Implement the Array.from() ES6 method
as defined in Section 22.1.2.1 of the specification.

Given that we can't rely on the built-in
global functions or objects to be untainted,
I had to expose a few of them directly to
the function via private names. In particular:
- Math.floor -&gt; @floor
- Math.abs -&gt; @abs
- Number -&gt; @Number
- Array -&gt; @Array
- isFinite -&gt; @isFinite

* builtins/ArrayConstructor.js: Added.
(from): Implementation of Array.from in JavaScript.
* runtime/ArrayConstructor.cpp: Add &quot;from&quot; to the lookup
table for the constructor object.
* runtime/CommonIdentifiers.h: Add the private versions
of the identifiers listed above.
* runtime/JSGlobalObject.cpp: Add the implementations of
those identifiers to the global object (using their
private names).
(JSC::JSGlobalObject::init):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalPrivateFuncAbs): Implementation of the abs function.
(JSC::globalPrivateFuncFloor): Implementation of the floor function.
* runtime/JSGlobalObjectFunctions.h:

LayoutTests:

Test for Array.from(). The test has
one expected failure: using from() on a
Set object, which will be addressed in
a followup:
https://bugs.webkit.org/show_bug.cgi?id=141055

* js/array-from-expected.txt: Added.
* js/array-from.html: Added.
* js/script-tests/array-from.js: Added.
* js/Object-getOwnPropertyNames.html: Update results for the new value on the constructor.</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="#trunkSourceJavaScriptCoreruntimeArrayConstructorcpp">trunk/Source/JavaScriptCore/runtime/ArrayConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeCommonIdentifiersh">trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionscpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionsh">trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsarrayfromexpectedtxt">trunk/LayoutTests/js/array-from-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsarrayfromhtml">trunk/LayoutTests/js/array-from.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayfromjs">trunk/LayoutTests/js/script-tests/array-from.js</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsArrayConstructorjs">trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/LayoutTests/ChangeLog        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2015-02-19  Dean Jackson  &lt;dino@apple.com&gt;
+
+        ES6: Implement Array.from()
+        https://bugs.webkit.org/show_bug.cgi?id=141054
+        &lt;rdar://problem/19654521&gt;
+
+        Reviewed by Filip Pizlo.
+
+        Test for Array.from(). The test has
+        one expected failure: using from() on a
+        Set object, which will be addressed in
+        a followup:
+        https://bugs.webkit.org/show_bug.cgi?id=141055
+
+        * js/array-from-expected.txt: Added.
+        * js/array-from.html: Added.
+        * js/script-tests/array-from.js: Added.
+        * js/Object-getOwnPropertyNames.html: Update results for the new value on the constructor.
+
</ins><span class="cx"> 2015-02-19  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Update fast/text/glyph-reordering.html after r177774
</span></span></pre></div>
<a id="trunkLayoutTestsjsObjectgetOwnPropertyNamesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx"> PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']
</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><del>-PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'of', 'prototype']
</del><ins>+PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
</ins><span class="cx"> 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']
</span><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', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayfromexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-from-expected.txt (0 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-from-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/array-from-expected.txt        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -0,0 +1,74 @@
</span><ins>+Tests for Array.from
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+
+Length of Array.from
+-------
+PASS Array.from.length is 1
+
+Simple construction
+-------
+PASS Array.from instanceof Function is true
+PASS Array.from([1]) is [1]
+PASS Array.from([1, 2, 3]) is [1, 2, 3]
+PASS Array.from([1, 2, 3]).length is 3
+PASS Array.from('abc') is ['a', 'b', 'c']
+PASS Array.from('abc').length is 3
+PASS Array.from(Array.from([4, 5, 6])) is [4, 5, 6]
+PASS Array.from([null, null]) is [null, null]
+PASS Array.from([]).length is 0
+PASS Array.from(new Uint8Array([1, 2, 3])) is [1, 2, 3]
+
+Incorrect construction
+-------
+PASS Array.from() threw exception TypeError: Array.from requires an array-like object - not null or undefined.
+PASS Array.from(null) threw exception TypeError: Array.from requires an array-like object - not null or undefined.
+PASS Array.from(undefined) threw exception TypeError: Array.from requires an array-like object - not null or undefined.
+Declare wayTooSmall = { length: -1 }
+PASS Array.from(wayTooSmall) is []
+Declare wayTooBig = { length: Infinity }
+PASS Array.from(wayTooBig) threw exception RangeError: Array size is not a small enough positive integer..
+
+Mapped construction
+-------
+PASS Array.from([1, 2, 3], function (x) { return x * 10; }) is [10, 20, 30]
+PASS Array.from([1, 2, 3], function (x) { return null; }) is [null, null, null]
+PASS Array.from([1, 2, 3], function (x) { }).length is 3
+PASS Array.from({length: 5}, function(v, k) { return k; }) is [0, 1, 2, 3, 4]
+Declare var bacon = { eggs: 5 }
+PASS Array.from([1, 2, 3], function (x) { return x * this.eggs; }, bacon) is [5, 10, 15]
+
+Incorrect mapped construction
+-------
+PASS Array.from([1, 2, 3], null) threw exception TypeError: Array.from requires that the second argument, when provided, be a function.
+PASS Array.from([1, 2, 3], []) threw exception TypeError: Array.from requires that the second argument, when provided, be a function.
+PASS Array.from([1, 2, 3], [1]) threw exception TypeError: Array.from requires that the second argument, when provided, be a function.
+
+Weird construction
+-------
+PASS Array.from(document.querySelectorAll('span.pass')).length is numberOfPassingSpans
+PASS Array.from(Math).length is 0
+Declare wayTooWrong = { length: NaN }
+PASS Array.from(wayTooWrong) is []
+
+Array with holes
+-------
+PASS Array.from(arrayWithHoles) is [,,, true,,,, , , 'hi']
+
+Modify length during construction
+-------
+PASS Array.from(crazyPants) is ['one', 'two', 'three', 'four']
+
+Modify length during mapping
+-------
+PASS Array.from(crazyPants, function (x) { crazyPants.length = x; return x; }) is ['one', 'two', 'three', 'four']
+
+Construction using Set object
+-------
+FAIL Array.from(set) should be zero,one,two. Was .
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins><span class="cx">Property changes on: trunk/LayoutTests/js/array-from-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsjsarrayfromhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/array-from.html (0 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-from.html                                (rev 0)
+++ trunk/LayoutTests/js/array-from.html        2015-02-20 00:20:54 UTC (rev 180370)
</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-from.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 class="cx">Property changes on: trunk/LayoutTests/js/array-from.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsjsscripttestsObjectgetOwnPropertyNamesjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">     &quot;Object.prototype&quot;: &quot;['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']&quot;,
</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><del>-    &quot;Array&quot;: &quot;['isArray', 'length', 'name', 'of', 'prototype']&quot;,
</del><ins>+    &quot;Array&quot;: &quot;['from', 'isArray', 'length', 'name', 'of', 'prototype']&quot;,
</ins><span class="cx">     &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;,
</span><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', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']&quot;,
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayfromjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/array-from.js (0 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-from.js                                (rev 0)
+++ trunk/LayoutTests/js/script-tests/array-from.js        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -0,0 +1,101 @@
</span><ins>+description(&quot;Tests for Array.from&quot;);
+
+function section(title) {
+    debug(&quot;&quot;);
+    debug(title);
+    debug(&quot;-------&quot;);
+}
+
+section(&quot;Length of Array.from&quot;);
+shouldBe(&quot;Array.from.length&quot;, &quot;1&quot;);
+
+section(&quot;Simple construction&quot;);
+shouldBeTrue(&quot;Array.from instanceof Function&quot;)
+shouldBe(&quot;Array.from([1])&quot;, &quot;[1]&quot;);
+shouldBe(&quot;Array.from([1, 2, 3])&quot;, &quot;[1, 2, 3]&quot;);
+shouldBe(&quot;Array.from([1, 2, 3]).length&quot;, &quot;3&quot;);
+shouldBe(&quot;Array.from('abc')&quot;, &quot;['a', 'b', 'c']&quot;);
+shouldBe(&quot;Array.from('abc').length&quot;, &quot;3&quot;);
+shouldBe(&quot;Array.from(Array.from([4, 5, 6]))&quot;, &quot;[4, 5, 6]&quot;);
+shouldBe(&quot;Array.from([null, null])&quot;, &quot;[null, null]&quot;);
+shouldBe(&quot;Array.from([]).length&quot;, &quot;0&quot;);
+shouldBe(&quot;Array.from(new Uint8Array([1, 2, 3]))&quot;, &quot;[1, 2, 3]&quot;);
+
+section(&quot;Incorrect construction&quot;);
+shouldThrow(&quot;Array.from()&quot;);
+shouldThrow(&quot;Array.from(null)&quot;);
+shouldThrow(&quot;Array.from(undefined)&quot;);
+debug(&quot;Declare wayTooSmall = { length: -1 }&quot;);
+wayTooSmall = { length: -1 };
+shouldBe(&quot;Array.from(wayTooSmall)&quot;, &quot;[]&quot;);
+debug(&quot;Declare wayTooBig = { length: Infinity }&quot;);
+wayTooBig = { length: Infinity };
+shouldThrow(&quot;Array.from(wayTooBig)&quot;);
+
+section(&quot;Mapped construction&quot;);
+shouldBe(&quot;Array.from([1, 2, 3], function (x) { return x * 10; })&quot;, &quot;[10, 20, 30]&quot;);
+shouldBe(&quot;Array.from([1, 2, 3], function (x) { return null; })&quot;, &quot;[null, null, null]&quot;);
+shouldBe(&quot;Array.from([1, 2, 3], function (x) { }).length&quot;, &quot;3&quot;);
+shouldBe(&quot;Array.from({length: 5}, function(v, k) { return k; })&quot;, &quot;[0, 1, 2, 3, 4]&quot;);
+
+debug(&quot;Declare var bacon = { eggs: 5 }&quot;)
+var bacon = {
+    eggs: 5
+};
+
+shouldBe(&quot;Array.from([1, 2, 3], function (x) { return x * this.eggs; }, bacon)&quot;, &quot;[5, 10, 15]&quot;);
+
+section(&quot;Incorrect mapped construction&quot;);
+shouldThrow(&quot;Array.from([1, 2, 3], null)&quot;);
+shouldThrow(&quot;Array.from([1, 2, 3], [])&quot;);
+shouldThrow(&quot;Array.from([1, 2, 3], [1])&quot;);
+
+section(&quot;Weird construction&quot;);
+var numberOfPassingSpans = document.querySelectorAll('span.pass').length;
+shouldBe(&quot;Array.from(document.querySelectorAll('span.pass')).length&quot;, &quot;numberOfPassingSpans&quot;);
+shouldBe(&quot;Array.from(Math).length&quot;, &quot;0&quot;);
+debug(&quot;Declare wayTooWrong = { length: NaN }&quot;);
+wayTooWrong = { length: NaN };
+shouldBe(&quot;Array.from(wayTooWrong)&quot;, &quot;[]&quot;);
+
+section(&quot;Array with holes&quot;);
+arrayWithHoles = [];
+arrayWithHoles[3] = true;
+arrayWithHoles[9] = &quot;hi&quot;;
+
+shouldBe(&quot;Array.from(arrayWithHoles)&quot;, &quot;[,,, true,,,, , , 'hi']&quot;);
+
+section(&quot;Modify length during construction&quot;);
+var crazyPants = {
+    _length: 3,
+    get 0() {
+        return &quot;one&quot;;
+    },
+    get 1() {
+        return &quot;two&quot;;
+    },
+    get 2() {
+        return &quot;three&quot;;
+    },
+    get 3() {
+        return &quot;four&quot;;
+    },
+    get 4() {
+        return &quot;ERROR: this should never be called&quot;;
+    },
+    get length() {
+        return ++crazyPants._length;
+    }
+};
+shouldBe(&quot;Array.from(crazyPants)&quot;, &quot;['one', 'two', 'three', 'four']&quot;);
+
+section(&quot;Modify length during mapping&quot;);
+crazyPants._length = 3; // Reset the length
+shouldBe(&quot;Array.from(crazyPants, function (x) { crazyPants.length = x; return x; })&quot;, &quot;['one', 'two', 'three', 'four']&quot;);
+
+section(&quot;Construction using Set object&quot;);
+var set = new Set;
+set.add(&quot;zero&quot;);
+set.add(&quot;one&quot;);
+set.add(&quot;two&quot;);
+shouldBe(&quot;Array.from(set)&quot;, &quot;['zero', 'one', 'two']&quot;);
</ins><span class="cx">Property changes on: trunk/LayoutTests/js/script-tests/array-from.js
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2015-02-19  Dean Jackson  &lt;dino@apple.com&gt;
+
+        ES6: Implement Array.from()
+        https://bugs.webkit.org/show_bug.cgi?id=141054
+        &lt;rdar://problem/19654521&gt;
+
+        Reviewed by Filip Pizlo.
+
+        Implement the Array.from() ES6 method
+        as defined in Section 22.1.2.1 of the specification.
+
+        Given that we can't rely on the built-in
+        global functions or objects to be untainted,
+        I had to expose a few of them directly to
+        the function via private names. In particular:
+        - Math.floor -&gt; @floor
+        - Math.abs -&gt; @abs
+        - Number -&gt; @Number
+        - Array -&gt; @Array
+        - isFinite -&gt; @isFinite
+
+        * builtins/ArrayConstructor.js: Added.
+        (from): Implementation of Array.from in JavaScript.
+        * runtime/ArrayConstructor.cpp: Add &quot;from&quot; to the lookup
+        table for the constructor object.
+        * runtime/CommonIdentifiers.h: Add the private versions
+        of the identifiers listed above.
+        * runtime/JSGlobalObject.cpp: Add the implementations of
+        those identifiers to the global object (using their
+        private names).
+        (JSC::JSGlobalObject::init):
+        * runtime/JSGlobalObjectFunctions.cpp:
+        (JSC::globalPrivateFuncAbs): Implementation of the abs function.
+        (JSC::globalPrivateFuncFloor): Implementation of the floor function.
+        * runtime/JSGlobalObjectFunctions.h:
+
</ins><span class="cx"> 2015-02-19  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Refine the FTL part of ArithPow
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsArrayConstructorjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js (0 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function from(arrayLike /*, mapFn, thisArg */) {
+
+    &quot;use strict&quot;;
+
+    if (arrayLike == null)
+         throw new @TypeError(&quot;Array.from requires an array-like object - not null or undefined&quot;);
+
+    var thisObj = this;
+
+    var items = @Object(arrayLike);
+    var mapFn = arguments.length &gt; 1 ? arguments[1] : undefined;
+
+    var thisArg;
+
+    if (typeof mapFn !== &quot;undefined&quot;) {
+        if (typeof mapFn !== 'function')
+            throw new @TypeError(&quot;Array.from requires that the second argument, when provided, be a function&quot;);
+
+        if (arguments.length &gt; 2)
+            thisArg = arguments[2];
+    }
+
+    var maxSafeInteger = 9007199254740991;
+    var numberValue = @Number(items.length);
+    var lengthValue;
+    if (numberValue != numberValue) {  // isNaN(numberValue)
+        lengthValue = 0;
+    } else if (numberValue === 0 || !@isFinite(numberValue)) {
+        lengthValue = numberValue;
+    } else {
+        lengthValue = (numberValue &gt; 0 ? 1 : -1) * @floor(@abs(numberValue));
+    }
+    // originally Math.min(Math.max(length, 0), maxSafeInteger));
+    var itemsLength = lengthValue &gt; 0 ? (lengthValue &lt; maxSafeInteger ? lengthValue : maxSafeInteger) : 0;
+
+    var result = (typeof thisObj === 'function') ? @Object(new thisObj(itemsLength)) : new @Array(itemsLength);
+
+    var k = 0;
+    while (k &lt; itemsLength) {
+        var value = items[k];
+        if (mapFn)
+            result[k] = typeof thisArg === &quot;undefined&quot; ? mapFn(value, k) : mapFn.@call(thisArg, value, k);
+        else
+            result[k] = value;
+        k += 1;
+    }
+
+    result.length = itemsLength;
+    return result;
+}
</ins><span class="cx">Property changes on: trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceJavaScriptCoreruntimeArrayConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ArrayConstructor.cpp (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ArrayConstructor.cpp        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/runtime/ArrayConstructor.cpp        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx"> @begin arrayConstructorTable
</span><span class="cx">   isArray   arrayConstructorIsArray     DontEnum|Function 1
</span><span class="cx">   of        arrayConstructorOf          DontEnum|Function 0
</span><ins>+  from      arrayConstructorFrom        DontEnum|Function 0
</ins><span class="cx"> @end
</span><span class="cx"> */
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeCommonIdentifiersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -246,6 +246,11 @@
</span><span class="cx">     macro(deferred) \
</span><span class="cx">     macro(countdownHolder) \
</span><span class="cx">     macro(Object) \
</span><ins>+    macro(Number) \
+    macro(Array) \
+    macro(abs) \
+    macro(floor) \
+    macro(isFinite) \
</ins><span class="cx">     macro(TypeError) \
</span><span class="cx">     macro(undefined) \
</span><span class="cx">     macro(BuiltinLog)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -404,6 +404,11 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames-&gt;emptyIdentifier.string(), globalFuncBuiltinLog);
</span><ins>+
+    JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), globalPrivateFuncAbs);
+    JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), globalPrivateFuncFloor);
+    JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite);
+
</ins><span class="cx">     GlobalPropertyInfo staticGlobals[] = {
</span><span class="cx">         GlobalPropertyInfo(vm.propertyNames-&gt;NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
</span><span class="cx">         GlobalPropertyInfo(vm.propertyNames-&gt;Infinity, jsNumber(std::numeric_limits&lt;double&gt;::infinity()), DontEnum | DontDelete | ReadOnly),
</span><span class="lines">@@ -411,7 +416,12 @@
</span><span class="cx">         GlobalPropertyInfo(vm.propertyNames-&gt;undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
</span><span class="cx">         GlobalPropertyInfo(vm.propertyNames-&gt;ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
</span><span class="cx">         GlobalPropertyInfo(vm.propertyNames-&gt;TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
</span><del>-        GlobalPropertyInfo(vm.propertyNames-&gt;BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly)
</del><ins>+        GlobalPropertyInfo(vm.propertyNames-&gt;BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames-&gt;ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames-&gt;NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames-&gt;absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames-&gt;floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames-&gt;isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
</ins><span class="cx">     };
</span><span class="cx">     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -709,6 +709,16 @@
</span><span class="cx">     return throwVMTypeError(exec);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+EncodedJSValue JSC_HOST_CALL globalPrivateFuncAbs(ExecState* exec)
+{
+    return JSValue::encode(jsNumber(fabs(exec-&gt;argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL globalPrivateFuncFloor(ExecState* exec)
+{
+    return JSValue::encode(jsNumber(floor(exec-&gt;argument(0).toNumber(exec))));
+}
+
</ins><span class="cx"> class GlobalFuncProtoGetterFunctor {
</span><span class="cx"> public:
</span><span class="cx">     GlobalFuncProtoGetterFunctor(JSObject* thisObject)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h (180369 => 180370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h        2015-02-20 00:13:16 UTC (rev 180369)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h        2015-02-20 00:20:54 UTC (rev 180370)
</span><span class="lines">@@ -52,7 +52,11 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL globalFuncProtoGetter(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL globalFuncProtoSetter(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL globalFuncBuiltinLog(ExecState*);
</span><del>-    
</del><ins>+
+// These global functions are only exposed to built-ins with private names e.g. @abs
+EncodedJSValue JSC_HOST_CALL globalPrivateFuncAbs(ExecState*);
+EncodedJSValue JSC_HOST_CALL globalPrivateFuncFloor(ExecState*);
+
</ins><span class="cx"> static const double mantissaOverflowLowerBound = 9007199254740992.0;
</span><span class="cx"> double parseIntOverflow(const LChar*, unsigned length, int radix);
</span><span class="cx"> bool isStrWhiteSpace(UChar);
</span></span></pre>
</div>
</div>

</body>
</html>