<!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>[212087] branches/safari-603-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/212087">212087</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-02-10 00:15:58 -0800 (Fri, 10 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/212019">r212019</a>. rdar://problem/30128133</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchJSTestsChangeLog">branches/safari-603-branch/JSTests/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCoreChangeLog">branches/safari-603-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorebuiltinsArrayPrototypejs">branches/safari-603-branch/Source/JavaScriptCore/builtins/ArrayPrototype.js</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorebytecodeBytecodeIntrinsicRegistrycpp">branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorebytecodeBytecodeIntrinsicRegistryh">branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCoreruntimeArrayPrototypecpp">branches/safari-603-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCoreruntimeJSArraycpp">branches/safari-603-branch/Source/JavaScriptCore/runtime/JSArray.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari603branchJSTestsstressarrayprototypeconcatoflongsplicedarraysjs">branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays.js</a></li>
<li><a href="#branchessafari603branchJSTestsstressarrayprototypeconcatoflongsplicedarrays2js">branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays2.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/JSTests/ChangeLog (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/ChangeLog        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/JSTests/ChangeLog        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -1,5 +1,20 @@
</span><span class="cx"> 2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r212019. rdar://problem/30128133
+
+    2017-02-09  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+            Fix max length check in ArrayPrototype.js' concatSlowPath().
+            https://bugs.webkit.org/show_bug.cgi?id=167270
+            &lt;rdar://problem/30128133&gt;
+
+            Reviewed by Filip Pizlo.
+
+            * stress/array-prototype-concat-of-long-spliced-arrays.js: Added.
+            * stress/array-prototype-concat-of-long-spliced-arrays2.js: Added.
+
+2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r212009. rdar://problem/29939864
</span><span class="cx"> 
</span><span class="cx">     2017-02-09  Keith Miller  &lt;keith_miller@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari603branchJSTestsstressarrayprototypeconcatoflongsplicedarraysjs"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays.js (0 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays.js                                (rev 0)
+++ branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays.js        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+function shouldEqual(actual, expected) {
+    if (actual != expected) {
+        throw &quot;ERROR: expect &quot; + expected + &quot;, actual &quot; + actual;
+    }
+}
+
+function test() {
+    var exception;
+    try {
+        var a = [];
+        a.length = 0xffffff00;
+
+        var b = a.splice(0, 0x100000); // Undecided array
+
+        var args = [];
+        args.length = 4094;
+        args.fill(b);
+
+        var q = [];
+        q.length = 0x1000;
+        q.fill(7);
+
+        var c = a.splice(0, 0xfffef); //Shorter undecided array
+
+        args[4094] = c;
+        args[4095] = q;
+
+        b.concat.apply(b, args);
+    } catch (e) {
+        exception = e;
+    }
+
+    shouldEqual(exception, &quot;RangeError: Length exceeded the maximum array length&quot;);
+}
+
+test();
</ins></span></pre></div>
<a id="branchessafari603branchJSTestsstressarrayprototypeconcatoflongsplicedarrays2js"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays2.js (0 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays2.js                                (rev 0)
+++ branches/safari-603-branch/JSTests/stress/array-prototype-concat-of-long-spliced-arrays2.js        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+function shouldEqual(actual, expected) {
+    if (actual != expected) {
+        throw &quot;ERROR: expect &quot; + expected + &quot;, actual &quot; + actual;
+    }
+}
+
+function test() {
+    var exception;
+    try {
+        var a = [];
+        a.length = 0xffffff00;
+
+        var b = a.splice(0, 0x100000); // Undecided array
+
+        var args = [];
+        args.length = 4096;
+        args.fill(b);
+
+        b.concat.apply(b, args);
+    } catch (e) {
+        exception = e;
+    }
+    shouldEqual(exception, &quot;RangeError: Length exceeded the maximum array length&quot;);
+}
+
+test();
</ins></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/ChangeLog (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/ChangeLog        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/ChangeLog        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -1,5 +1,53 @@
</span><span class="cx"> 2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r212019. rdar://problem/30128133
+
+    2017-02-09  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+            Fix max length check in ArrayPrototype.js' concatSlowPath().
+            https://bugs.webkit.org/show_bug.cgi?id=167270
+            &lt;rdar://problem/30128133&gt;
+
+            Reviewed by Filip Pizlo.
+
+            1. Fixed concatSlowPath() to ensure that the result array length does not exceed
+               @MAX_ARRAY_INDEX.  The old code was checking against @MAX_SAFE_INTEGER in some
+               cases, but this is overly permissive.
+
+            2. Changed concatSlowPath() to throw a RangeError instead of a TypeError to be
+               consistent with the C++ runtime functions in JSArray.cpp.
+
+            3. Changed the RangeError message in concatSlowPath() and JSArray.cpp to &quot;Length
+               exceeded the maximum array length&quot; when the error is that the result length
+               exceeds MAX_ARRAY_INDEX.  We do this for 2 reasons:
+               a. &quot;Length exceeded the maximum array length&quot; is more informative than
+                  &quot;Invalid array length&quot;.
+               b. We want to use the same string consistently for the same error.
+
+               There are still 2 places in JSArray.cpp that still throws a RangeError with
+               message &quot;Invalid array length&quot;.  In those cases, the error is not necessarily
+               due to the result length exceeding MAX_ARRAY_INDEX, but is due to attempting to
+               set a length value that is not an integer that fits in MAX_ARRAY_INDEX e.g.
+               an attempt to set a fractional length value.  Hence, &quot;Invalid array length&quot; is
+               appropriate for those cases.
+
+            4. Fixed JSArray::appendMemcpy() to handle overflows when computing the result
+               array length.
+
+            * builtins/ArrayPrototype.js:
+            (concatSlowPath):
+            * bytecode/BytecodeIntrinsicRegistry.cpp:
+            (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
+            * bytecode/BytecodeIntrinsicRegistry.h:
+            * runtime/ArrayPrototype.cpp:
+            (JSC::concatAppendOne):
+            (JSC::arrayProtoPrivateFuncAppendMemcpy):
+            * runtime/JSArray.cpp:
+            (JSC::JSArray::appendMemcpy):
+            (JSC::JSArray::push):
+
+2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r212015. rdar://problem/30054759
</span><span class="cx"> 
</span><span class="cx">     2017-02-09  Mark Lam  &lt;mark.lam@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorebuiltinsArrayPrototypejs"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/builtins/ArrayPrototype.js (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/builtins/ArrayPrototype.js        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/builtins/ArrayPrototype.js        2017-02-10 08:15:58 UTC (rev 212087)
</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-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2015 Yusuke Suzuki &lt;utatane.tea@gmail.com&gt;.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -686,12 +686,12 @@
</span><span class="cx">         let spreadable = @isObject(currentElement) &amp;&amp; currentElement.@isConcatSpreadableSymbol;
</span><span class="cx">         if ((spreadable === @undefined &amp;&amp; @isArray(currentElement)) || spreadable) {
</span><span class="cx">             let length = @toLength(currentElement.length);
</span><ins>+            if (length + resultIndex &gt; @MAX_ARRAY_INDEX)
+                @throwRangeError(&quot;Length exceeded the maximum array length&quot;);
</ins><span class="cx">             if (resultIsArray &amp;&amp; @isJSArray(currentElement)) {
</span><span class="cx">                 @appendMemcpy(result, currentElement, resultIndex);
</span><span class="cx">                 resultIndex += length;
</span><span class="cx">             } else {
</span><del>-                if (length + resultIndex &gt; @MAX_SAFE_INTEGER)
-                    @throwTypeError(&quot;length exceeded the maximum safe integer&quot;);
</del><span class="cx">                 for (var i = 0; i &lt; length; i++) {
</span><span class="cx">                     if (i in currentElement)
</span><span class="cx">                         @putByValDirect(result, resultIndex, currentElement[i]);
</span><span class="lines">@@ -699,8 +699,8 @@
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">         } else {
</span><del>-            if (resultIndex &gt;= @MAX_SAFE_INTEGER)
-                @throwTypeError(&quot;length exceeded the maximum safe integer&quot;);
</del><ins>+            if (resultIndex &gt;= @MAX_ARRAY_INDEX)
+                @throwRangeError(&quot;Length exceeded the maximum array length&quot;);
</ins><span class="cx">             @putByValDirect(result, resultIndex++, currentElement);
</span><span class="cx">         }
</span><span class="cx">         currentElement = arguments[argIndex];
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorebytecodeBytecodeIntrinsicRegistrycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2015 Yusuke Suzuki &lt;utatane.tea@gmail.com&gt;.
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 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">@@ -53,6 +53,7 @@
</span><span class="cx">     m_iterationKindKey.set(m_vm, jsNumber(IterateKey));
</span><span class="cx">     m_iterationKindValue.set(m_vm, jsNumber(IterateValue));
</span><span class="cx">     m_iterationKindKeyValue.set(m_vm, jsNumber(IterateKeyValue));
</span><ins>+    m_MAX_ARRAY_INDEX.set(m_vm, jsNumber(MAX_ARRAY_INDEX));
</ins><span class="cx">     m_MAX_STRING_LENGTH.set(m_vm, jsNumber(JSString::MaxLength));
</span><span class="cx">     m_MAX_SAFE_INTEGER.set(m_vm, jsDoubleNumber(maxSafeInteger()));
</span><span class="cx">     m_ModuleFetch.set(m_vm, jsNumber(static_cast&lt;unsigned&gt;(JSModuleLoader::Status::Fetch)));
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorebytecodeBytecodeIntrinsicRegistryh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2015 Yusuke Suzuki &lt;utatane.tea@gmail.com&gt;.
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 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">@@ -64,6 +64,7 @@
</span><span class="cx">     macro(iterationKindKey) \
</span><span class="cx">     macro(iterationKindValue) \
</span><span class="cx">     macro(iterationKindKeyValue) \
</span><ins>+    macro(MAX_ARRAY_INDEX) \
</ins><span class="cx">     macro(MAX_STRING_LENGTH) \
</span><span class="cx">     macro(MAX_SAFE_INTEGER) \
</span><span class="cx">     macro(ModuleFetch) \
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCoreruntimeArrayPrototypecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp        2017-02-10 08:15:58 UTC (rev 212087)
</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, 2007-2009, 2011, 2013, 2015-2016 Apple Inc. All rights reserved.
</del><ins>+ *  Copyright (C) 2003, 2007-2009, 2011, 2013, 2015-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  *  Copyright (C) 2003 Peter Kelly (pmk@post.com)
</span><span class="cx">  *  Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
</span><span class="cx">  *
</span><span class="lines">@@ -1216,8 +1216,10 @@
</span><span class="cx">         return JSValue::encode(throwOutOfMemoryError(exec, scope));
</span><span class="cx"> 
</span><span class="cx">     bool success = result-&gt;appendMemcpy(exec, vm, 0, first);
</span><del>-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
</del><ins>+    ASSERT(!success || !scope.exception());
</ins><span class="cx">     if (!success) {
</span><ins>+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
+
</ins><span class="cx">         bool success = moveElements(exec, vm, result, 0, first, firstArraySize);
</span><span class="cx">         ASSERT(!scope.exception() == success);
</span><span class="cx">         if (UNLIKELY(!success))
</span><span class="lines">@@ -1311,14 +1313,18 @@
</span><span class="cx">     ASSERT(exec-&gt;argumentCount() == 3);
</span><span class="cx"> 
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><ins>+    auto scope = DECLARE_THROW_SCOPE(vm);
</ins><span class="cx">     JSArray* resultArray = jsCast&lt;JSArray*&gt;(exec-&gt;uncheckedArgument(0));
</span><span class="cx">     JSArray* otherArray = jsCast&lt;JSArray*&gt;(exec-&gt;uncheckedArgument(1));
</span><span class="cx">     JSValue startValue = exec-&gt;uncheckedArgument(2);
</span><span class="cx">     ASSERT(startValue.isAnyInt() &amp;&amp; startValue.asAnyInt() &gt;= 0 &amp;&amp; startValue.asAnyInt() &lt;= std::numeric_limits&lt;unsigned&gt;::max());
</span><span class="cx">     unsigned startIndex = static_cast&lt;unsigned&gt;(startValue.asAnyInt());
</span><del>-    if (!resultArray-&gt;appendMemcpy(exec, vm, startIndex, otherArray))
</del><ins>+    bool success = resultArray-&gt;appendMemcpy(exec, vm, startIndex, otherArray);
+    ASSERT(!success || !scope.exception());
+    if (!success) {
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
</ins><span class="cx">         moveElements(exec, vm, resultArray, startIndex, otherArray, otherArray-&gt;length());
</span><del>-
</del><ins>+    }
</ins><span class="cx">     return JSValue::encode(jsUndefined());
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCoreruntimeJSArraycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/runtime/JSArray.cpp (212086 => 212087)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/runtime/JSArray.cpp        2017-02-10 08:15:53 UTC (rev 212086)
+++ branches/safari-603-branch/Source/JavaScriptCore/runtime/JSArray.cpp        2017-02-10 08:15:58 UTC (rev 212087)
</span><span class="lines">@@ -40,6 +40,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><ins>+static const char* const LengthExceededTheMaximumArrayLengthError = &quot;Length exceeded the maximum array length&quot;;
+
</ins><span class="cx"> STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSArray);
</span><span class="cx"> 
</span><span class="cx"> const ClassInfo JSArray::s_info = {&quot;Array&quot;, &amp;JSNonFinalObject::s_info, 0, CREATE_METHOD_TABLE(JSArray)};
</span><span class="lines">@@ -495,7 +497,15 @@
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     unsigned otherLength = otherArray-&gt;length();
</span><del>-    unsigned newLength = startIndex + otherLength;
</del><ins>+    Checked&lt;unsigned, RecordOverflow&gt; checkedNewLength = startIndex;
+    checkedNewLength += otherLength;
+
+    unsigned newLength;
+    if (checkedNewLength.safeGet(newLength) == CheckedState::DidOverflow) {
+        throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError)));
+        return false;
+    }
+
</ins><span class="cx">     if (newLength &gt;= MIN_SPARSE_ARRAY_INDEX)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="lines">@@ -724,7 +734,7 @@
</span><span class="cx">         if (UNLIKELY(length &gt; MAX_ARRAY_INDEX)) {
</span><span class="cx">             methodTable(vm)-&gt;putByIndex(this, exec, length, value, true);
</span><span class="cx">             if (!scope.exception())
</span><del>-                throwException(exec, scope, createRangeError(exec, ASCIILiteral(&quot;Invalid array length&quot;)));
</del><ins>+                throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError)));
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -745,7 +755,7 @@
</span><span class="cx">         if (UNLIKELY(length &gt; MAX_ARRAY_INDEX)) {
</span><span class="cx">             methodTable(vm)-&gt;putByIndex(this, exec, length, value, true);
</span><span class="cx">             if (!scope.exception())
</span><del>-                throwException(exec, scope, createRangeError(exec, ASCIILiteral(&quot;Invalid array length&quot;)));
</del><ins>+                throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError)));
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -780,7 +790,7 @@
</span><span class="cx">         if (UNLIKELY(length &gt; MAX_ARRAY_INDEX)) {
</span><span class="cx">             methodTable(vm)-&gt;putByIndex(this, exec, length, value, true);
</span><span class="cx">             if (!scope.exception())
</span><del>-                throwException(exec, scope, createRangeError(exec, ASCIILiteral(&quot;Invalid array length&quot;)));
</del><ins>+                throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError)));
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -819,7 +829,7 @@
</span><span class="cx">             methodTable(vm)-&gt;putByIndex(this, exec, storage-&gt;length(), value, true);
</span><span class="cx">             // Per ES5.1 15.4.4.7 step 6 &amp; 15.4.5.1 step 3.d.
</span><span class="cx">             if (!scope.exception())
</span><del>-                throwException(exec, scope, createRangeError(exec, ASCIILiteral(&quot;Invalid array length&quot;)));
</del><ins>+                throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError)));
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>