<!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
<rdar://problem/19654521>
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 -> @floor
- Math.abs -> @abs
- Number -> @Number
- Array -> @Array
- isFinite -> @isFinite
* builtins/ArrayConstructor.js: Added.
(from): Implementation of Array.from in JavaScript.
* runtime/ArrayConstructor.cpp: Add "from" 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 <dino@apple.com>
+
+ ES6: Implement Array.from()
+ https://bugs.webkit.org/show_bug.cgi?id=141054
+ <rdar://problem/19654521>
+
+ 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 <mmaxfield@apple.com>
</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 "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+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>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/array-from.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</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"> "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']",
</span><span class="cx"> "Function": "['length', 'name', 'prototype']",
</span><span class="cx"> "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
</span><del>- "Array": "['isArray', 'length', 'name', 'of', 'prototype']",
</del><ins>+ "Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
</ins><span class="cx"> "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
</span><span class="cx"> "String": "['fromCharCode', 'length', 'name', 'prototype']",
</span><span class="cx"> "String.prototype": "['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="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("Tests for Array.from");
+
+function section(title) {
+ debug("");
+ debug(title);
+ debug("-------");
+}
+
+section("Length of Array.from");
+shouldBe("Array.from.length", "1");
+
+section("Simple construction");
+shouldBeTrue("Array.from instanceof Function")
+shouldBe("Array.from([1])", "[1]");
+shouldBe("Array.from([1, 2, 3])", "[1, 2, 3]");
+shouldBe("Array.from([1, 2, 3]).length", "3");
+shouldBe("Array.from('abc')", "['a', 'b', 'c']");
+shouldBe("Array.from('abc').length", "3");
+shouldBe("Array.from(Array.from([4, 5, 6]))", "[4, 5, 6]");
+shouldBe("Array.from([null, null])", "[null, null]");
+shouldBe("Array.from([]).length", "0");
+shouldBe("Array.from(new Uint8Array([1, 2, 3]))", "[1, 2, 3]");
+
+section("Incorrect construction");
+shouldThrow("Array.from()");
+shouldThrow("Array.from(null)");
+shouldThrow("Array.from(undefined)");
+debug("Declare wayTooSmall = { length: -1 }");
+wayTooSmall = { length: -1 };
+shouldBe("Array.from(wayTooSmall)", "[]");
+debug("Declare wayTooBig = { length: Infinity }");
+wayTooBig = { length: Infinity };
+shouldThrow("Array.from(wayTooBig)");
+
+section("Mapped construction");
+shouldBe("Array.from([1, 2, 3], function (x) { return x * 10; })", "[10, 20, 30]");
+shouldBe("Array.from([1, 2, 3], function (x) { return null; })", "[null, null, null]");
+shouldBe("Array.from([1, 2, 3], function (x) { }).length", "3");
+shouldBe("Array.from({length: 5}, function(v, k) { return k; })", "[0, 1, 2, 3, 4]");
+
+debug("Declare var bacon = { eggs: 5 }")
+var bacon = {
+ eggs: 5
+};
+
+shouldBe("Array.from([1, 2, 3], function (x) { return x * this.eggs; }, bacon)", "[5, 10, 15]");
+
+section("Incorrect mapped construction");
+shouldThrow("Array.from([1, 2, 3], null)");
+shouldThrow("Array.from([1, 2, 3], [])");
+shouldThrow("Array.from([1, 2, 3], [1])");
+
+section("Weird construction");
+var numberOfPassingSpans = document.querySelectorAll('span.pass').length;
+shouldBe("Array.from(document.querySelectorAll('span.pass')).length", "numberOfPassingSpans");
+shouldBe("Array.from(Math).length", "0");
+debug("Declare wayTooWrong = { length: NaN }");
+wayTooWrong = { length: NaN };
+shouldBe("Array.from(wayTooWrong)", "[]");
+
+section("Array with holes");
+arrayWithHoles = [];
+arrayWithHoles[3] = true;
+arrayWithHoles[9] = "hi";
+
+shouldBe("Array.from(arrayWithHoles)", "[,,, true,,,, , , 'hi']");
+
+section("Modify length during construction");
+var crazyPants = {
+ _length: 3,
+ get 0() {
+ return "one";
+ },
+ get 1() {
+ return "two";
+ },
+ get 2() {
+ return "three";
+ },
+ get 3() {
+ return "four";
+ },
+ get 4() {
+ return "ERROR: this should never be called";
+ },
+ get length() {
+ return ++crazyPants._length;
+ }
+};
+shouldBe("Array.from(crazyPants)", "['one', 'two', 'three', 'four']");
+
+section("Modify length during mapping");
+crazyPants._length = 3; // Reset the length
+shouldBe("Array.from(crazyPants, function (x) { crazyPants.length = x; return x; })", "['one', 'two', 'three', 'four']");
+
+section("Construction using Set object");
+var set = new Set;
+set.add("zero");
+set.add("one");
+set.add("two");
+shouldBe("Array.from(set)", "['zero', 'one', 'two']");
</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 <dino@apple.com>
+
+ ES6: Implement Array.from()
+ https://bugs.webkit.org/show_bug.cgi?id=141054
+ <rdar://problem/19654521>
+
+ 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 -> @floor
+ - Math.abs -> @abs
+ - Number -> @Number
+ - Array -> @Array
+ - isFinite -> @isFinite
+
+ * builtins/ArrayConstructor.js: Added.
+ (from): Implementation of Array.from in JavaScript.
+ * runtime/ArrayConstructor.cpp: Add "from" 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 <bpoulain@apple.com>
</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 */) {
+
+ "use strict";
+
+ if (arrayLike == null)
+ throw new @TypeError("Array.from requires an array-like object - not null or undefined");
+
+ var thisObj = this;
+
+ var items = @Object(arrayLike);
+ var mapFn = arguments.length > 1 ? arguments[1] : undefined;
+
+ var thisArg;
+
+ if (typeof mapFn !== "undefined") {
+ if (typeof mapFn !== 'function')
+ throw new @TypeError("Array.from requires that the second argument, when provided, be a function");
+
+ if (arguments.length > 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 > 0 ? 1 : -1) * @floor(@abs(numberValue));
+ }
+ // originally Math.min(Math.max(length, 0), maxSafeInteger));
+ var itemsLength = lengthValue > 0 ? (lengthValue < maxSafeInteger ? lengthValue : maxSafeInteger) : 0;
+
+ var result = (typeof thisObj === 'function') ? @Object(new thisObj(itemsLength)) : new @Array(itemsLength);
+
+ var k = 0;
+ while (k < itemsLength) {
+ var value = items[k];
+ if (mapFn)
+ result[k] = typeof thisArg === "undefined" ? 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->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->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
</span><span class="cx"> GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
</span><span class="lines">@@ -411,7 +416,12 @@
</span><span class="cx"> GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
</span><span class="cx"> GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
</span><span class="cx"> GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
</span><del>- GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly)
</del><ins>+ GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(vm.propertyNames->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->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL globalPrivateFuncFloor(ExecState* exec)
+{
+ return JSValue::encode(jsNumber(floor(exec->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>