<!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>[203101] 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/203101">203101</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-11 17:57:35 -0700 (Mon, 11 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Array.from() and Array.of() try to build objects even if &quot;this&quot; is not a constructor
https://bugs.webkit.org/show_bug.cgi?id=159604

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

The spec says IsConstructor(), we were just checking if &quot;this&quot;
is any function.

* builtins/ArrayConstructor.js:
(of):
(from):

LayoutTests:

* js/array-from-expected.txt:
* js/array-of-expected.txt:
* js/script-tests/array-from.js:
* js/script-tests/array-of.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsarrayfromexpectedtxt">trunk/LayoutTests/js/array-from-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsarrayofexpectedtxt">trunk/LayoutTests/js/array-of-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayfromjs">trunk/LayoutTests/js/script-tests/array-from.js</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsarrayofjs">trunk/LayoutTests/js/script-tests/array-of.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</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 (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/LayoutTests/ChangeLog        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-07-11  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        [JSC] Array.from() and Array.of() try to build objects even if &quot;this&quot; is not a constructor
+        https://bugs.webkit.org/show_bug.cgi?id=159604
+
+        Reviewed by Yusuke Suzuki.
+
+        * js/array-from-expected.txt:
+        * js/array-of-expected.txt:
+        * js/script-tests/array-from.js:
+        * js/script-tests/array-of.js:
+
</ins><span class="cx"> 2016-07-11  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Deleting in a text input inside an iframe causes the page to scroll incorrectly
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayfromexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/array-from-expected.txt (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-from-expected.txt        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/LayoutTests/js/array-from-expected.txt        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -67,6 +67,31 @@
</span><span class="cx"> Construction using Set object
</span><span class="cx"> -------
</span><span class="cx"> PASS Array.from(set) is ['zero', 'one', 'two']
</span><ins>+
+&quot;this&quot; is a constructor
+-------
+PASS Array.from.call(CustomConstructor, ['WebKit']).constructor is CustomConstructor
+PASS Object.getPrototypeOf(Array.from.call(CustomConstructor, ['WebKit'])) is CustomConstructor.prototype
+PASS Array.from.call(nonConstructor, ['WebKit']).length is 1
+PASS Array.from.call(nonConstructor, ['WebKit'])[0] is &quot;WebKit&quot;
+PASS Array.from.call(CustomConstructor, nonIterable).constructor is CustomConstructor
+PASS Object.getPrototypeOf(Array.from.call(CustomConstructor, nonIterable)) is CustomConstructor.prototype
+PASS Array.from.call(nonConstructor, nonIterable).length is 2
+PASS Array.from.call(nonConstructor, nonIterable)[0] is &quot;one&quot;
+PASS Array.from.call(nonConstructor, nonIterable)[1] is 2
+
+&quot;this&quot; is not a constructor
+-------
+PASS Array.from.call(nonConstructor, ['WebKit']).constructor is Array
+PASS Object.getPrototypeOf(Array.from.call(nonConstructor, ['WebKit'])) is Array.prototype
+PASS Array.from.call(nonConstructor, ['WebKit']).length is 1
+PASS Array.from.call(nonConstructor, ['WebKit'])[0] is &quot;WebKit&quot;
+PASS nonConstructorWasCalled is false
+PASS Array.from.call(nonConstructor, nonIterable).constructor is Array
+PASS Object.getPrototypeOf(Array.from.call(nonConstructor, nonIterable)) is Array.prototype
+PASS Array.from.call(nonConstructor, nonIterable).length is 2
+PASS Array.from.call(nonConstructor, nonIterable)[0] is &quot;one&quot;
+PASS Array.from.call(nonConstructor, nonIterable)[1] is 2
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsarrayofexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/array-of-expected.txt (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/array-of-expected.txt        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/LayoutTests/js/array-of-expected.txt        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -17,9 +17,16 @@
</span><span class="cx"> PASS x[1].length is 5
</span><span class="cx"> Check that a setter isn't called.
</span><span class="cx"> PASS Array.of(1, 2, 3) did not throw exception.
</span><ins>+&quot;this&quot; is a constructor
</ins><span class="cx"> PASS Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo is true
</span><span class="cx"> PASS Array.of.call(Foo, 'a', 'b', 'c').givenLength is 3
</span><span class="cx"> PASS var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]] is [3, 'a', 'b', 'c']
</span><ins>+&quot;this&quot; is not a constructor
+PASS Array.of.call(nonConstructor, Foo).constructor is Array
+PASS Object.getPrototypeOf(Array.of.call(nonConstructor, Foo)) is Array.prototype
+PASS Array.of.call(nonConstructor, Foo).length is 1
+PASS Array.of.call(nonConstructor, Foo)[0] is Foo
+PASS nonConstructorWasCalled is false
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayfromjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/array-from.js (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-from.js        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/LayoutTests/js/script-tests/array-from.js        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -100,3 +100,47 @@
</span><span class="cx"> set.add(&quot;one&quot;);
</span><span class="cx"> set.add(&quot;two&quot;);
</span><span class="cx"> shouldBe(&quot;Array.from(set)&quot;, &quot;['zero', 'one', 'two']&quot;);
</span><ins>+
+section(&quot;\&quot;this\&quot; is a constructor&quot;);
+var CustomConstructor = function (length) { this.givenLength = length; };
+shouldBe(&quot;Array.from.call(CustomConstructor, ['WebKit']).constructor&quot;, &quot;CustomConstructor&quot;);
+shouldBe(&quot;Object.getPrototypeOf(Array.from.call(CustomConstructor, ['WebKit']))&quot;, &quot;CustomConstructor.prototype&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, ['WebKit']).length&quot;, &quot;1&quot;);
+shouldBeEqualToString(&quot;Array.from.call(nonConstructor, ['WebKit'])[0]&quot;, &quot;WebKit&quot;);
+
+var nonIterable = {
+    get 0() {
+        return &quot;one&quot;;
+    },
+    get 1() {
+        return 2;
+    },
+    get 2() {
+        throw &quot;ERROR: this should never be called&quot;;
+    },
+    get length() {
+        return 2;
+    }
+};
+
+shouldBe(&quot;Array.from.call(CustomConstructor, nonIterable).constructor&quot;, &quot;CustomConstructor&quot;);
+shouldBe(&quot;Object.getPrototypeOf(Array.from.call(CustomConstructor, nonIterable))&quot;, &quot;CustomConstructor.prototype&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, nonIterable).length&quot;, &quot;2&quot;);
+shouldBeEqualToString(&quot;Array.from.call(nonConstructor, nonIterable)[0]&quot;, &quot;one&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, nonIterable)[1]&quot;, &quot;2&quot;);
+
+
+section(&quot;\&quot;this\&quot; is not a constructor&quot;);
+var nonConstructorWasCalled = false;
+var nonConstructor = () =&gt; { nonConstructorWasCalled = true; };
+shouldBe(&quot;Array.from.call(nonConstructor, ['WebKit']).constructor&quot;, &quot;Array&quot;);
+shouldBe(&quot;Object.getPrototypeOf(Array.from.call(nonConstructor, ['WebKit']))&quot;, &quot;Array.prototype&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, ['WebKit']).length&quot;, &quot;1&quot;);
+shouldBeEqualToString(&quot;Array.from.call(nonConstructor, ['WebKit'])[0]&quot;, &quot;WebKit&quot;);
+shouldBeFalse(&quot;nonConstructorWasCalled&quot;);
+
+shouldBe(&quot;Array.from.call(nonConstructor, nonIterable).constructor&quot;, &quot;Array&quot;);
+shouldBe(&quot;Object.getPrototypeOf(Array.from.call(nonConstructor, nonIterable))&quot;, &quot;Array.prototype&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, nonIterable).length&quot;, &quot;2&quot;);
+shouldBeEqualToString(&quot;Array.from.call(nonConstructor, nonIterable)[0]&quot;, &quot;one&quot;);
+shouldBe(&quot;Array.from.call(nonConstructor, nonIterable)[1]&quot;, &quot;2&quot;);
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsarrayofjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/array-of.js (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/array-of.js        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/LayoutTests/js/script-tests/array-of.js        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -25,7 +25,17 @@
</span><span class="cx"> 
</span><span class="cx"> shouldNotThrow(&quot;Array.of(1, 2, 3)&quot;);
</span><span class="cx"> 
</span><ins>+debug(&quot;\&quot;this\&quot; is a constructor&quot;);
</ins><span class="cx"> var Foo = function FooBar(length) { this.givenLength = length; };
</span><del>-shouldBeTrue(&quot;Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo&quot;)
</del><ins>+shouldBeTrue(&quot;Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo&quot;);
</ins><span class="cx"> shouldBe(&quot;Array.of.call(Foo, 'a', 'b', 'c').givenLength&quot;, &quot;3&quot;);
</span><span class="cx"> shouldBe(&quot;var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]]&quot;, &quot;[3, 'a', 'b', 'c']&quot;);
</span><ins>+
+debug(&quot;\&quot;this\&quot; is not a constructor&quot;);
+var nonConstructorWasCalled = false;
+var nonConstructor = () =&gt; { nonConstructorWasCalled = true; };
+shouldBe(&quot;Array.of.call(nonConstructor, Foo).constructor&quot;, &quot;Array&quot;);
+shouldBe(&quot;Object.getPrototypeOf(Array.of.call(nonConstructor, Foo))&quot;, &quot;Array.prototype&quot;);
+shouldBe(&quot;Array.of.call(nonConstructor, Foo).length&quot;, &quot;1&quot;);
+shouldBe(&quot;Array.of.call(nonConstructor, Foo)[0]&quot;, &quot;Foo&quot;);
+shouldBeFalse(&quot;nonConstructorWasCalled&quot;);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-07-11  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        [JSC] Array.from() and Array.of() try to build objects even if &quot;this&quot; is not a constructor
+        https://bugs.webkit.org/show_bug.cgi?id=159604
+
+        Reviewed by Yusuke Suzuki.
+
+        The spec says IsConstructor(), we were just checking if &quot;this&quot;
+        is any function.
+
+        * builtins/ArrayConstructor.js:
+        (of):
+        (from):
+
</ins><span class="cx"> 2016-07-11  Keith Miller  &lt;keith_miller@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         defineProperty on a index of a TypedArray should throw if configurable
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsArrayConstructorjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js (203100 => 203101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js        2016-07-12 00:16:19 UTC (rev 203100)
+++ trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js        2016-07-12 00:57:35 UTC (rev 203101)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,8 +28,7 @@
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><span class="cx">     var length = arguments.length;
</span><del>-    // TODO: Need isConstructor(this) instead of typeof &quot;function&quot; check.
-    var array = typeof this === 'function' ? new this(length) : new @Array(length);
</del><ins>+    var array = @isConstructor(this) ? new this(length) : new @Array(length);
</ins><span class="cx">     for (var k = 0; k &lt; length; ++k)
</span><span class="cx">         @putByValDirect(array, k, arguments[k]);
</span><span class="cx">     array.length = length;
</span><span class="lines">@@ -62,8 +61,7 @@
</span><span class="cx">         if (typeof iteratorMethod !== &quot;function&quot;)
</span><span class="cx">             throw new @TypeError(&quot;Array.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function&quot;);
</span><span class="cx"> 
</span><del>-        // TODO: Need isConstructor(thisObj) instead of typeof &quot;function&quot; check.
-        var result = (typeof thisObj === &quot;function&quot;) ? @Object(new thisObj()) : [];
</del><ins>+        var result = @isConstructor(thisObj) ? new thisObj() : [];
</ins><span class="cx"> 
</span><span class="cx">         var k = 0;
</span><span class="cx">         var iterator = iteratorMethod.@call(items);
</span><span class="lines">@@ -89,8 +87,7 @@
</span><span class="cx">     var arrayLike = @Object(items);
</span><span class="cx">     var arrayLikeLength = @toLength(arrayLike.length);
</span><span class="cx"> 
</span><del>-    // TODO: Need isConstructor(thisObj) instead of typeof &quot;function&quot; check.
-    var result = (typeof thisObj === &quot;function&quot;) ? @Object(new thisObj(arrayLikeLength)) : new @Array(arrayLikeLength);
</del><ins>+    var result = @isConstructor(thisObj) ? new thisObj(arrayLikeLength) : new @Array(arrayLikeLength);
</ins><span class="cx"> 
</span><span class="cx">     var k = 0;
</span><span class="cx">     while (k &lt; arrayLikeLength) {
</span></span></pre>
</div>
</div>

</body>
</html>