<!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>[162866] branches/jsCStack/Source/JavaScriptCore</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/162866">162866</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-01-27 13:52:39 -0800 (Mon, 27 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>FTL should support NewArrayWithSize
https://bugs.webkit.org/show_bug.cgi?id=127698

Reviewed by Mark Hahnenberg.

* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileNewArrayWithSize):
* tests/stress/new-array-storage-array-with-size.js: Added.
(foo):
(test):
* tests/stress/new-array-with-size-with-bad-time.js: Added.
(foo):
* tests/stress/new-contiguous-array-with-size.js: Added.
(foo):
(test):
* tests/stress/new-double-array-with-size.js: Added.
(foo):
(test):
* tests/stress/new-int32-array-with-size.js: Added.
(foo):
(test):
* tests/stress/new-undecided-array-with-size.js: Added.
(foo):
(test):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoreChangeLog">branches/jsCStack/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreftlFTLCapabilitiescpp">branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewarraystoragearraywithsizejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-storage-array-with-size.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewarraywithsizewithbadtimejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-with-size-with-bad-time.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewcontiguousarraywithsizejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-contiguous-array-with-size.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewdoublearraywithsizejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-double-array-with-size.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewint32arraywithsizejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-int32-array-with-size.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressnewundecidedarraywithsizejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/new-undecided-array-with-size.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjsCStackSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ChangeLog (162865 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-27 21:45:10 UTC (rev 162865)
+++ branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2014-01-27  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        FTL should support NewArrayWithSize
+        https://bugs.webkit.org/show_bug.cgi?id=127698
+
+        Reviewed by Mark Hahnenberg.
+
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileNode):
+        (JSC::FTL::LowerDFGToLLVM::compileNewArrayWithSize):
+        * tests/stress/new-array-storage-array-with-size.js: Added.
+        (foo):
+        (test):
+        * tests/stress/new-array-with-size-with-bad-time.js: Added.
+        (foo):
+        * tests/stress/new-contiguous-array-with-size.js: Added.
+        (foo):
+        (test):
+        * tests/stress/new-double-array-with-size.js: Added.
+        (foo):
+        (test):
+        * tests/stress/new-int32-array-with-size.js: Added.
+        (foo):
+        (test):
+        * tests/stress/new-undecided-array-with-size.js: Added.
+        (foo):
+        (test):
+
</ins><span class="cx"> 2014-01-27  Michael Saboff  &lt;msaboff@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         CStack Branch: [X86-32] testapi crashes in gatherConservativeRoots()
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreftlFTLCapabilitiescpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp (162865 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2014-01-27 21:45:10 UTC (rev 162865)
+++ branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -130,6 +130,7 @@
</span><span class="cx">     case GetCallee:
</span><span class="cx">     case ToString:
</span><span class="cx">     case MakeRope:
</span><ins>+    case NewArrayWithSize:
</ins><span class="cx">         // These are OK.
</span><span class="cx">         break;
</span><span class="cx">     case GetById:
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (162865 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-01-27 21:45:10 UTC (rev 162865)
+++ branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -423,6 +423,9 @@
</span><span class="cx">         case NewArrayBuffer:
</span><span class="cx">             compileNewArrayBuffer();
</span><span class="cx">             break;
</span><ins>+        case NewArrayWithSize:
+            compileNewArrayWithSize();
+            break;
</ins><span class="cx">         case AllocatePropertyStorage:
</span><span class="cx">             compileAllocatePropertyStorage();
</span><span class="cx">             break;
</span><span class="lines">@@ -2237,6 +2240,109 @@
</span><span class="cx">             m_out.constIntPtr(m_node-&gt;numConstants())));
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void compileNewArrayWithSize()
+    {
+        LValue publicLength = lowInt32(m_node-&gt;child1());
+        
+        JSGlobalObject* globalObject = m_graph.globalObjectFor(m_node-&gt;codeOrigin);
+        Structure* structure = globalObject-&gt;arrayStructureForIndexingTypeDuringAllocation(
+            m_node-&gt;indexingType());
+        
+        if (!globalObject-&gt;isHavingABadTime() &amp;&amp; !hasArrayStorage(m_node-&gt;indexingType())) {
+            ASSERT(
+                hasUndecided(structure-&gt;indexingType())
+                || hasInt32(structure-&gt;indexingType())
+                || hasDouble(structure-&gt;indexingType())
+                || hasContiguous(structure-&gt;indexingType()));
+
+            LBasicBlock fastCase = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize fast case&quot;));
+            LBasicBlock largeCase = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize large case&quot;));
+            LBasicBlock failCase = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize fail case&quot;));
+            LBasicBlock slowCase = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize slow case&quot;));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize continuation&quot;));
+            
+            m_out.branch(
+                m_out.aboveOrEqual(publicLength, m_out.constInt32(MIN_SPARSE_ARRAY_INDEX)),
+                largeCase, fastCase);
+
+            LBasicBlock lastNext = m_out.appendTo(fastCase, largeCase);
+            
+            // We don't round up to BASE_VECTOR_LEN for new Array(blah).
+            LValue vectorLength = publicLength;
+            
+            LValue payloadSize =
+                m_out.shl(m_out.zeroExt(vectorLength, m_out.intPtr), m_out.constIntPtr(3));
+            
+            LValue butterflySize = m_out.add(
+                payloadSize, m_out.constIntPtr(sizeof(IndexingHeader)));
+            
+            LValue endOfStorage = allocateBasicStorageAndGetEnd(butterflySize, failCase);
+            
+            LValue butterfly = m_out.sub(endOfStorage, payloadSize);
+            
+            LValue object = allocateObject&lt;JSArray&gt;(
+                m_out.constIntPtr(structure), butterfly, failCase);
+            
+            m_out.store32(publicLength, butterfly, m_heaps.Butterfly_publicLength);
+            m_out.store32(vectorLength, butterfly, m_heaps.Butterfly_vectorLength);
+            
+            if (hasDouble(m_node-&gt;indexingType())) {
+                LBasicBlock initLoop = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize double init loop&quot;));
+                LBasicBlock initDone = FTL_NEW_BLOCK(m_out, (&quot;NewArrayWithSize double init done&quot;));
+                
+                ValueFromBlock originalIndex = m_out.anchor(vectorLength);
+                ValueFromBlock originalPointer = m_out.anchor(butterfly);
+                m_out.branch(m_out.notZero32(vectorLength), initLoop, initDone);
+                
+                LBasicBlock initLastNext = m_out.appendTo(initLoop, initDone);
+                LValue index = m_out.phi(m_out.int32, originalIndex);
+                LValue pointer = m_out.phi(m_out.intPtr, originalPointer);
+                
+                m_out.store64(
+                    m_out.constInt64(bitwise_cast&lt;int64_t&gt;(QNaN)),
+                    TypedPointer(m_heaps.indexedDoubleProperties.atAnyIndex(), pointer));
+                
+                LValue nextIndex = m_out.sub(index, m_out.int32One);
+                addIncoming(index, m_out.anchor(nextIndex));
+                addIncoming(pointer, m_out.anchor(m_out.add(pointer, m_out.intPtrEight)));
+                m_out.branch(m_out.notZero32(nextIndex), initLoop, initDone);
+                
+                m_out.appendTo(initDone, initLastNext);
+            }
+            
+            ValueFromBlock fastResult = m_out.anchor(object);
+            m_out.jump(continuation);
+            
+            m_out.appendTo(largeCase, failCase);
+            ValueFromBlock largeStructure = m_out.anchor(m_out.constIntPtr(
+                globalObject-&gt;arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage)));
+            m_out.jump(slowCase);
+            
+            m_out.appendTo(failCase, slowCase);
+            ValueFromBlock failStructure = m_out.anchor(m_out.constIntPtr(structure));
+            m_out.jump(slowCase);
+            
+            m_out.appendTo(slowCase, continuation);
+            LValue structureValue = m_out.phi(
+                m_out.intPtr, largeStructure, failStructure);
+            ValueFromBlock slowResult = m_out.anchor(vmCall(
+                m_out.operation(operationNewArrayWithSize),
+                m_callFrame, structureValue, publicLength));
+            m_out.jump(continuation);
+            
+            m_out.appendTo(continuation, lastNext);
+            setJSValue(m_out.phi(m_out.intPtr, fastResult, slowResult));
+            return;
+        }
+        
+        LValue structureValue = m_out.select(
+            m_out.aboveOrEqual(publicLength, m_out.constInt32(MIN_SPARSE_ARRAY_INDEX)),
+            m_out.constIntPtr(
+                globalObject-&gt;arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage)),
+            m_out.constIntPtr(structure));
+        setJSValue(vmCall(m_out.operation(operationNewArrayWithSize), m_callFrame, structureValue, publicLength));
+    }
+    
</ins><span class="cx">     void compileAllocatePropertyStorage()
</span><span class="cx">     {
</span><span class="cx">         StructureTransitionData&amp; data = m_node-&gt;structureTransitionData();
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewarraystoragearraywithsizejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-storage-array-with-size.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-storage-array-with-size.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-storage-array-with-size.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size)
+        throw &quot;Error: bad result: &quot; + result;
+    var sawThings = false;
+    for (var s in result)
+        sawThings = true;
+    if (sawThings)
+        throw &quot;Error: array is in bad state: &quot; + result;
+    result[0] = &quot;42.5&quot;;
+    if (result[0] != &quot;42.5&quot;)
+        throw &quot;Error: array is in wierd state: &quot; + result;
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(1000000);
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewarraywithsizewithbadtimejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-with-size-with-bad-time.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-with-size-with-bad-time.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-array-with-size-with-bad-time.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+var poke;
+Array.prototype.__defineSetter__(&quot;1&quot;, function() {
+    poke = &quot;poke&quot;;
+});
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size)
+        throw &quot;Error: bad result: &quot; + result;
+    var sawThings = false;
+    for (var s in result) {
+        if (s != &quot;1&quot;)
+            sawThings = true;
+    }
+    if (sawThings)
+        throw &quot;Error: array is in bad state: &quot; + result;
+    result[0] = &quot;42.5&quot;;
+    if (result[0] != &quot;42.5&quot;)
+        throw &quot;Error: array is in wierd state: &quot; + result;
+    poke = null;
+    result[1] = 42;
+    if (poke != &quot;poke&quot;)
+        throw &quot;Error: setter not called.&quot;;
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(42);
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewcontiguousarraywithsizejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-contiguous-array-with-size.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-contiguous-array-with-size.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-contiguous-array-with-size.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size) {
+        print(&quot;Got a weird length: &quot; + result.length);
+        throw &quot;Error: bad result: &quot; + result;
+    }
+    var sawThings = false;
+    for (var s in result)
+        sawThings = true;
+    if (sawThings) {
+        print(&quot;Saw things!&quot;);
+        throw &quot;Error: array is in bad state: &quot; + result;
+    }
+    result[0] = &quot;42.5&quot;;
+    if (result[0] != &quot;42.5&quot;) {
+        print(&quot;Didn't store what I thought I stored.&quot;);
+        throw &quot;Error: array is in wierd state: &quot; + result;
+    }
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(0);
+    test(1);
+    test(42);
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewdoublearraywithsizejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-double-array-with-size.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-double-array-with-size.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-double-array-with-size.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size)
+        throw &quot;Error: bad result: &quot; + result;
+    var sawThings = false;
+    for (var s in result)
+        sawThings = true;
+    if (sawThings)
+        throw &quot;Error: array is in bad state: &quot; + result;
+    result[0] = 42.5;
+    if (result[0] != 42.5)
+        throw &quot;Error: array is in wierd state: &quot; + result;
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(0);
+    test(1);
+    test(42);
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewint32arraywithsizejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-int32-array-with-size.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-int32-array-with-size.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-int32-array-with-size.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size)
+        throw &quot;Error: bad result: &quot; + result;
+    var sawThings = false;
+    for (var s in result)
+        sawThings = true;
+    if (sawThings)
+        throw &quot;Error: array is in bad state: &quot; + result;
+    result[0] = 42;
+    if (result[0] != 42)
+        throw &quot;Error: array is in wierd state: &quot; + result;
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(0);
+    test(1);
+    test(42);
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressnewundecidedarraywithsizejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/new-undecided-array-with-size.js (0 => 162866)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/new-undecided-array-with-size.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/new-undecided-array-with-size.js        2014-01-27 21:52:39 UTC (rev 162866)
</span><span class="lines">@@ -0,0 +1,22 @@
</span><ins>+function foo(x) {
+    return new Array(x);
+}
+
+noInline(foo);
+
+function test(size) {
+    var result = foo(size);
+    if (result.length != size)
+        throw &quot;Error: bad result: &quot; + result;
+    var sawThings = false;
+    for (var s in result)
+        sawThings = true;
+    if (sawThings)
+        throw &quot;Error: array is in bad state: &quot; + result;
+}
+
+for (var i = 0; i &lt; 100000; ++i) {
+    test(0);
+    test(1);
+    test(42);
+}
</ins></span></pre>
</div>
</div>

</body>
</html>