<!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>[243577] branches/safari-607-branch</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/243577">243577</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2019-03-27 16:43:52 -0700 (Wed, 27 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/243280">r243280</a>. rdar://problem/49308036

    Cap length of an array with spread to MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
    https://bugs.webkit.org/show_bug.cgi?id=196055
    <rdar://problem/49067448>

    Reviewed by Yusuke Suzuki.

    JSTests:

    * stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js: Added.

    Source/JavaScriptCore:

    We are doing this because:
    1. We expect the array to be densely packed.
    2. SpeculativeJIT::compileAllocateNewArrayWithSize() (and the FTL equivalent)
       expects the array length to be less than MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
       if we don't want to use an ArrayStorage shape.
    3. There's no reason why an array with spread needs to be that large anyway.
       MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH is plenty.

    In this patch, we also add a debug assert in compileAllocateNewArrayWithSize() and
    emitAllocateButterfly() to check for overflows.

    * assembler/AbortReason.h:
    * dfg/DFGOperations.cpp:
    * dfg/DFGSpeculativeJIT.cpp:
    (JSC::DFG::SpeculativeJIT::compileCreateRest):
    (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
    (JSC::DFG::SpeculativeJIT::emitAllocateButterfly):
    (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize):
    * ftl/FTLLowerDFGToB3.cpp:
    (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread):
    * runtime/ArrayConventions.h:
    * runtime/CommonSlowPaths.cpp:
    (JSC::SLOW_PATH_DECL):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243280 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari607branchJSTestsChangeLog">branches/safari-607-branch/JSTests/ChangeLog</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreChangeLog">branches/safari-607-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreassemblerAbortReasonh">branches/safari-607-branch/Source/JavaScriptCore/assembler/AbortReason.h</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoredfgDFGOperationscpp">branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGOperations.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoredfgDFGSpeculativeJITcpp">branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp">branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreruntimeArrayConventionsh">branches/safari-607-branch/Source/JavaScriptCore/runtime/ArrayConventions.h</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreruntimeCommonSlowPathscpp">branches/safari-607-branch/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari607branchJSTestsstressnew_array_with_spreadshouldcaparraysizetoMIN_ARRAY_STORAGE_CONSTRUCTION_LENGTHjs">branches/safari-607-branch/JSTests/stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari607branchJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/JSTests/ChangeLog (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/JSTests/ChangeLog     2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/JSTests/ChangeLog        2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1,5 +1,59 @@
</span><span class="cx"> 2019-03-27  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r243280. rdar://problem/49308036
+
+    Cap length of an array with spread to MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
+    https://bugs.webkit.org/show_bug.cgi?id=196055
+    <rdar://problem/49067448>
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    * stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js: Added.
+    
+    Source/JavaScriptCore:
+    
+    We are doing this because:
+    1. We expect the array to be densely packed.
+    2. SpeculativeJIT::compileAllocateNewArrayWithSize() (and the FTL equivalent)
+       expects the array length to be less than MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
+       if we don't want to use an ArrayStorage shape.
+    3. There's no reason why an array with spread needs to be that large anyway.
+       MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH is plenty.
+    
+    In this patch, we also add a debug assert in compileAllocateNewArrayWithSize() and
+    emitAllocateButterfly() to check for overflows.
+    
+    * assembler/AbortReason.h:
+    * dfg/DFGOperations.cpp:
+    * dfg/DFGSpeculativeJIT.cpp:
+    (JSC::DFG::SpeculativeJIT::compileCreateRest):
+    (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
+    (JSC::DFG::SpeculativeJIT::emitAllocateButterfly):
+    (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize):
+    * ftl/FTLLowerDFGToB3.cpp:
+    (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread):
+    * runtime/ArrayConventions.h:
+    * runtime/CommonSlowPaths.cpp:
+    (JSC::SLOW_PATH_DECL):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-03-21  Mark Lam  <mark.lam@apple.com>
+
+            Cap length of an array with spread to MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
+            https://bugs.webkit.org/show_bug.cgi?id=196055
+            <rdar://problem/49067448>
+
+            Reviewed by Yusuke Suzuki.
+
+            * stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js: Added.
+
+2019-03-27  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r243069. rdar://problem/49308056
</span><span class="cx"> 
</span><span class="cx">     Structure::flattenDictionary() should clear unused property slots.
</span></span></pre></div>
<a id="branchessafari607branchJSTestsstressnew_array_with_spreadshouldcaparraysizetoMIN_ARRAY_STORAGE_CONSTRUCTION_LENGTHjs"></a>
<div class="addfile"><h4>Added: branches/safari-607-branch/JSTests/stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js (0 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/JSTests/stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js                                (rev 0)
+++ branches/safari-607-branch/JSTests/stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js   2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+//@ skip if $memoryLimited or $buildType == "debug"
+
+function test() {
+    function makeFoo(n) {
+        let src = "return function(a, b) { for (let i = 0; i < 20000; i++); return [";
+        for (let i = 0; i < n; i++) {
+            src += "...a";
+            if (i < n-1)
+                src += ",";
+        }
+        src += ",...b];}";
+        return (new Function(src))();
+    }
+
+    var NUM_SPREAD_ARGS = 8;
+    var foo = makeFoo(NUM_SPREAD_ARGS);
+
+    var b = [1.1, 1.1];
+    for (let i = 0; i < 10; i++)
+        foo(b, b);
+
+    function makeArray(len, v = 1.234) {
+        let a = [];
+        while (a.length < len)
+            a[a.length] = v;
+        return a;
+    }
+
+    var a = makeArray(0x20000040 / NUM_SPREAD_ARGS);
+    var c = []; c.length = 1;
+
+    var arr = foo(a, c);
+    print(arr.length);
+}
+
+var exception;
+try {
+    test();
+} catch (e) {
+    exception = e;
+}
+
+if (exception != "Error: Out of memory")
+    throw "FAILED";
</ins></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/ChangeLog (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/ChangeLog       2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/ChangeLog  2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1,5 +1,81 @@
</span><span class="cx"> 2019-03-27  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r243280. rdar://problem/49308036
+
+    Cap length of an array with spread to MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
+    https://bugs.webkit.org/show_bug.cgi?id=196055
+    <rdar://problem/49067448>
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    * stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js: Added.
+    
+    Source/JavaScriptCore:
+    
+    We are doing this because:
+    1. We expect the array to be densely packed.
+    2. SpeculativeJIT::compileAllocateNewArrayWithSize() (and the FTL equivalent)
+       expects the array length to be less than MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
+       if we don't want to use an ArrayStorage shape.
+    3. There's no reason why an array with spread needs to be that large anyway.
+       MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH is plenty.
+    
+    In this patch, we also add a debug assert in compileAllocateNewArrayWithSize() and
+    emitAllocateButterfly() to check for overflows.
+    
+    * assembler/AbortReason.h:
+    * dfg/DFGOperations.cpp:
+    * dfg/DFGSpeculativeJIT.cpp:
+    (JSC::DFG::SpeculativeJIT::compileCreateRest):
+    (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
+    (JSC::DFG::SpeculativeJIT::emitAllocateButterfly):
+    (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize):
+    * ftl/FTLLowerDFGToB3.cpp:
+    (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread):
+    * runtime/ArrayConventions.h:
+    * runtime/CommonSlowPaths.cpp:
+    (JSC::SLOW_PATH_DECL):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-03-21  Mark Lam  <mark.lam@apple.com>
+
+            Cap length of an array with spread to MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
+            https://bugs.webkit.org/show_bug.cgi?id=196055
+            <rdar://problem/49067448>
+
+            Reviewed by Yusuke Suzuki.
+
+            We are doing this because:
+            1. We expect the array to be densely packed.
+            2. SpeculativeJIT::compileAllocateNewArrayWithSize() (and the FTL equivalent)
+               expects the array length to be less than MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
+               if we don't want to use an ArrayStorage shape.
+            3. There's no reason why an array with spread needs to be that large anyway.
+               MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH is plenty.
+
+            In this patch, we also add a debug assert in compileAllocateNewArrayWithSize() and
+            emitAllocateButterfly() to check for overflows.
+
+            * assembler/AbortReason.h:
+            * dfg/DFGOperations.cpp:
+            * dfg/DFGSpeculativeJIT.cpp:
+            (JSC::DFG::SpeculativeJIT::compileCreateRest):
+            (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
+            (JSC::DFG::SpeculativeJIT::emitAllocateButterfly):
+            (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize):
+            * ftl/FTLLowerDFGToB3.cpp:
+            (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread):
+            * runtime/ArrayConventions.h:
+            * runtime/CommonSlowPaths.cpp:
+            (JSC::SLOW_PATH_DECL):
+
+2019-03-27  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r243069. rdar://problem/49308056
</span><span class="cx"> 
</span><span class="cx">     Structure::flattenDictionary() should clear unused property slots.
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreassemblerAbortReasonh"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/assembler/AbortReason.h (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/assembler/AbortReason.h 2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/assembler/AbortReason.h    2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2019 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">@@ -73,6 +73,7 @@
</span><span class="cx">     RepatchInsaneArgumentCount                        = 310,
</span><span class="cx">     TGInvalidPointer                                  = 320,
</span><span class="cx">     TGNotSupported                                    = 330,
</span><ins>+    UncheckedOverflow                                 = 335,
</ins><span class="cx">     YARRNoInputConsumed                               = 340,
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoredfgDFGOperationscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGOperations.cpp (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGOperations.cpp   2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGOperations.cpp      2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011-2019 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">@@ -2702,6 +2702,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     unsigned length = checkedLength.unsafeGet();
</span><ins>+    if (UNLIKELY(length >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)) {
+        throwOutOfMemoryError(exec, scope);
+        return nullptr;
+    }
+
</ins><span class="cx">     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
</span><span class="cx">     Structure* structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous);
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp       2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp  2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -7671,6 +7671,10 @@
</span><span class="cx">         GPRReg arrayLengthGPR = arrayLength.gpr();
</span><span class="cx">         GPRReg arrayResultGPR = arrayResult.gpr();
</span><span class="cx"> 
</span><ins>+        // We can tell compileAllocateNewArrayWithSize() that it does not need to check
+        // for large arrays and use ArrayStorage structure because arrayLength here will
+        // always be bounded by stack size. Realistically, we won't be able to push enough
+        // arguments to have arrayLength exceed MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
</ins><span class="cx">         bool shouldAllowForArrayStorageStructureForLargeArrays = false;
</span><span class="cx">         ASSERT(m_jit.graph().globalObjectFor(node->origin.semantic)->restParameterStructure()->indexingMode() == ArrayWithContiguous || m_jit.graph().globalObjectFor(node->origin.semantic)->isHavingABadTime());
</span><span class="cx">         compileAllocateNewArrayWithSize(m_jit.graph().globalObjectFor(node->origin.semantic), arrayResultGPR, arrayLengthGPR, ArrayWithContiguous, shouldAllowForArrayStorageStructureForLargeArrays);
</span><span class="lines">@@ -8024,7 +8028,12 @@
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            speculationCheck(Overflow, JSValueRegs(), nullptr, m_jit.branch32(MacroAssembler::AboveOrEqual, lengthGPR, TrustedImm32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)));
</ins><span class="cx"> 
</span><ins>+            // We can tell compileAllocateNewArrayWithSize() that it does not need to
+            // check for large arrays and use ArrayStorage structure because we already
+            // ensured above that the spread array length will definitely fit in a
+            // non-ArrayStorage shaped array.
</ins><span class="cx">             bool shouldAllowForArrayStorageStructureForLargeArrays = false;
</span><span class="cx">             ASSERT(m_jit.graph().globalObjectFor(node->origin.semantic)->restParameterStructure()->indexingType() == ArrayWithContiguous || m_jit.graph().globalObjectFor(node->origin.semantic)->isHavingABadTime());
</span><span class="cx">             compileAllocateNewArrayWithSize(m_jit.graph().globalObjectFor(node->origin.semantic), resultGPR, lengthGPR, ArrayWithContiguous, shouldAllowForArrayStorageStructureForLargeArrays);
</span><span class="lines">@@ -11700,6 +11709,11 @@
</span><span class="cx">     m_jit.zeroExtend32ToPtr(sizeGPR, scratch1);
</span><span class="cx">     m_jit.lshift32(TrustedImm32(3), scratch1);
</span><span class="cx">     m_jit.add32(TrustedImm32(sizeof(IndexingHeader)), scratch1, scratch2);
</span><ins>+#if !ASSERT_DISABLED
+    MacroAssembler::Jump didNotOverflow = m_jit.branch32(MacroAssembler::AboveOrEqual, scratch2, sizeGPR);
+    m_jit.abortWithReason(UncheckedOverflow);
+    didNotOverflow.link(&m_jit);
+#endif
</ins><span class="cx">     m_jit.emitAllocateVariableSized(
</span><span class="cx">         storageResultGPR, m_jit.vm()->jsValueGigacageAuxiliarySpace, scratch2, scratch1, scratch3, slowCases);
</span><span class="cx">     m_jit.addPtr(TrustedImm32(sizeof(IndexingHeader)), storageResultGPR);
</span><span class="lines">@@ -13005,6 +13019,14 @@
</span><span class="cx">     MacroAssembler::JumpList slowCases;
</span><span class="cx">     if (shouldConvertLargeSizeToArrayStorage)
</span><span class="cx">         slowCases.append(m_jit.branch32(MacroAssembler::AboveOrEqual, sizeGPR, TrustedImm32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)));
</span><ins>+#if !ASSERT_DISABLED
+    else {
+        MacroAssembler::Jump lengthIsWithinLimits;
+        lengthIsWithinLimits = m_jit.branch32(MacroAssembler::Below, sizeGPR, TrustedImm32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH));
+        m_jit.abortWithReason(UncheckedOverflow);
+        lengthIsWithinLimits.link(&m_jit);
+    }
+#endif
</ins><span class="cx"> 
</span><span class="cx">     // We can use resultGPR as a scratch right now.
</span><span class="cx">     emitAllocateButterfly(storageGPR, sizeGPR, scratchGPR, scratch2GPR, resultGPR, slowCases);
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp 2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp    2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -5811,6 +5811,9 @@
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            LValue exceedsMaxAllowedLength = m_out.aboveOrEqual(length, m_out.constInt32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH));
+            blessSpeculation(m_out.speculate(exceedsMaxAllowedLength), Overflow, noValue(), nullptr, m_origin);
+
</ins><span class="cx">             RegisteredStructure structure = m_graph.registerStructure(m_graph.globalObjectFor(m_node->origin.semantic)->originalArrayStructureForIndexingType(ArrayWithContiguous));
</span><span class="cx">             ArrayValues arrayValues = allocateUninitializedContiguousJSArray(length, structure);
</span><span class="cx">             LValue result = arrayValues.array;
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreruntimeArrayConventionsh"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/runtime/ArrayConventions.h (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/runtime/ArrayConventions.h      2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/runtime/ArrayConventions.h 2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
</span><del>- *  Copyright (C) 2003-2017 Apple Inc. All rights reserved.
</del><ins>+ *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  *  This library is free software; you can redistribute it and/or
</span><span class="cx">  *  modify it under the terms of the GNU Lesser General Public
</span><span class="lines">@@ -65,7 +65,7 @@
</span><span class="cx"> #define MIN_SPARSE_ARRAY_INDEX 100000U
</span><span class="cx"> // If you try to allocate a contiguous array larger than this, then we will allocate an ArrayStorage
</span><span class="cx"> // array instead. We allow for an array that occupies 1GB of VM.
</span><del>-#define MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH 1024 * 1024 * 1024 / 8
</del><ins>+#define MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH (1024 * 1024 * 1024 / 8)
</ins><span class="cx"> #define MAX_STORAGE_VECTOR_INDEX (MAX_STORAGE_VECTOR_LENGTH - 1)
</span><span class="cx"> // 0xFFFFFFFF is a bit weird -- is not an array index even though it's an integer.
</span><span class="cx"> #define MAX_ARRAY_INDEX 0xFFFFFFFEU
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreruntimeCommonSlowPathscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp (243576 => 243577)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp     2019-03-27 23:43:48 UTC (rev 243576)
+++ branches/safari-607-branch/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp        2019-03-27 23:43:52 UTC (rev 243577)
</span><span class="lines">@@ -1257,6 +1257,9 @@
</span><span class="cx">         THROW(createOutOfMemoryError(exec));
</span><span class="cx"> 
</span><span class="cx">     unsigned arraySize = checkedArraySize.unsafeGet();
</span><ins>+    if (UNLIKELY(arraySize >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH))
+        THROW(createOutOfMemoryError(exec));
+
</ins><span class="cx">     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
</span><span class="cx">     Structure* structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>