<!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>[205228] branches/safari-602-branch/Source</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/205228">205228</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-08-31 00:19:59 -0700 (Wed, 31 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/203834">r203834</a>. rdar://problem/27991582</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceJavaScriptCoreChangeLog">branches/safari-602-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWTFChangeLog">branches/safari-602-branch/Source/WTF/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWTFwtftextStringViewh">branches/safari-602-branch/Source/WTF/wtf/text/StringView.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceJavaScriptCoretestsstressstringjoininglongstringsshouldnotcrashjs">branches/safari-602-branch/Source/JavaScriptCore/tests/stress/string-joining-long-strings-should-not-crash.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/JavaScriptCore/ChangeLog (205227 => 205228)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/JavaScriptCore/ChangeLog        2016-08-31 07:19:55 UTC (rev 205227)
+++ branches/safari-602-branch/Source/JavaScriptCore/ChangeLog        2016-08-31 07:19:59 UTC (rev 205228)
</span><span class="lines">@@ -1,5 +1,20 @@
</span><span class="cx"> 2016-08-30  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r203834. rdar://problem/27991582
+
+    2016-07-28  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+            StringView should have an explicit m_is8Bit field.
+            https://bugs.webkit.org/show_bug.cgi?id=160282
+            &lt;rdar://problem/27327943&gt;
+
+            Reviewed by Benjamin Poulain.
+
+            * tests/stress/string-joining-long-strings-should-not-crash.js: Added.
+            (catch):
+
+2016-08-30  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
</ins><span class="cx">         Merge r203802. rdar://problem/27991569
</span><span class="cx"> 
</span><span class="cx">     2016-07-27  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchSourceJavaScriptCoretestsstressstringjoininglongstringsshouldnotcrashjs"></a>
<div class="addfile"><h4>Added: branches/safari-602-branch/Source/JavaScriptCore/tests/stress/string-joining-long-strings-should-not-crash.js (0 => 205228)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/JavaScriptCore/tests/stress/string-joining-long-strings-should-not-crash.js                                (rev 0)
+++ branches/safari-602-branch/Source/JavaScriptCore/tests/stress/string-joining-long-strings-should-not-crash.js        2016-08-31 07:19:59 UTC (rev 205228)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+//@ runDefault
+// This test should not crash.
+
+var error;
+let str = '';
+let arr = [{}, 2, 3];
+try {
+    for (let z = 0; z &lt; 30; z++)
+        str = arr.join(str); // exponentially grow length of string.
+} catch(e) {
+    error = e;
+}
+
+if (!error)
+    throw Error(&quot;Failed&quot;);
</ins></span></pre></div>
<a id="branchessafari602branchSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WTF/ChangeLog (205227 => 205228)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WTF/ChangeLog        2016-08-31 07:19:55 UTC (rev 205227)
+++ branches/safari-602-branch/Source/WTF/ChangeLog        2016-08-31 07:19:59 UTC (rev 205228)
</span><span class="lines">@@ -1,3 +1,52 @@
</span><ins>+2016-08-30  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r203834. rdar://problem/27991582
+
+    2016-07-28  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+            StringView should have an explicit m_is8Bit field.
+            https://bugs.webkit.org/show_bug.cgi?id=160282
+            &lt;rdar://problem/27327943&gt;
+
+            Reviewed by Benjamin Poulain.
+
+            The current implementation reserves 1 bit in the 32-bit m_length field as an
+            is16Bit flag.  As a result, a StringView is incapable of handling strings that
+            have a length of 32-bit in size.  This results in a mismatch with the
+            expectations of String, StringImpl, and JavaScriptCore's JSString which all
+            support a 32-bit unsigned length.
+
+            This patch fixes this issue by introducing an explicit m_is8Bit field, thereby
+            allowing m_length to be a full 32-bit again.
+
+            We also introduced a clear() convenience method to set the fields of StringView
+            to empty values.  Previously, we were duplicating the code for clearing those
+            fields.  We now call clear() in all those places instead.
+
+            Note: in clear(), we set m_is8Bit to true because we want an empty StringView
+            to be 8-bit rather than 16-bit.  This is consistent with what the empty() method
+            returns.
+
+            * wtf/text/StringView.h:
+            (WTF::StringView::setUnderlyingString):
+            (WTF::StringView::StringView):
+            (WTF::StringView::operator=):
+            (WTF::StringView::initialize):
+            (WTF::StringView::clear):
+            (WTF::StringView::empty):
+            (WTF::StringView::length):
+            (WTF::StringView::operator bool):
+            (WTF::StringView::is8Bit):
+            (WTF::StringView::substring):
+            (WTF::StringView::getCharactersWithUpconvert):
+            (WTF::StringView::toString):
+            (WTF::StringView::toAtomicString):
+            (WTF::StringView::toFloat):
+            (WTF::StringView::toInt):
+            (WTF::StringView::toIntStrict):
+            (WTF::StringView::toStringWithoutCopying):
+            (WTF::StringView::find):
+
</ins><span class="cx"> 2016-08-03  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r204074. rdar://problem/25856238
</span></span></pre></div>
<a id="branchessafari602branchSourceWTFwtftextStringViewh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WTF/wtf/text/StringView.h (205227 => 205228)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WTF/wtf/text/StringView.h        2016-08-31 07:19:55 UTC (rev 205227)
+++ branches/safari-602-branch/Source/WTF/wtf/text/StringView.h        2016-08-31 07:19:59 UTC (rev 205228)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-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">@@ -156,11 +156,11 @@
</span><span class="cx">     void setUnderlyingString(const StringImpl*) { }
</span><span class="cx">     void setUnderlyingString(const StringView&amp;) { }
</span><span class="cx"> #endif
</span><ins>+    void clear();
</ins><span class="cx"> 
</span><del>-    static const unsigned is16BitStringFlag = 1u &lt;&lt; 31;
-
</del><span class="cx">     const void* m_characters { nullptr };
</span><span class="cx">     unsigned m_length { 0 };
</span><ins>+    bool m_is8Bit { true };
</ins><span class="cx"> 
</span><span class="cx"> #if CHECK_STRINGVIEW_LIFETIME
</span><span class="cx">     void adoptUnderlyingString(UnderlyingString*);
</span><span class="lines">@@ -210,11 +210,11 @@
</span><span class="cx"> inline StringView::StringView(StringView&amp;&amp; other)
</span><span class="cx">     : m_characters(other.m_characters)
</span><span class="cx">     , m_length(other.m_length)
</span><ins>+    , m_is8Bit(other.m_is8Bit)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(other.underlyingStringIsValid());
</span><span class="cx"> 
</span><del>-    other.m_characters = nullptr;
-    other.m_length = 0;
</del><ins>+    other.clear();
</ins><span class="cx"> 
</span><span class="cx">     setUnderlyingString(other);
</span><span class="cx">     other.setUnderlyingString(nullptr);
</span><span class="lines">@@ -223,6 +223,7 @@
</span><span class="cx"> inline StringView::StringView(const StringView&amp; other)
</span><span class="cx">     : m_characters(other.m_characters)
</span><span class="cx">     , m_length(other.m_length)
</span><ins>+    , m_is8Bit(other.m_is8Bit)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(other.underlyingStringIsValid());
</span><span class="cx"> 
</span><span class="lines">@@ -235,9 +236,9 @@
</span><span class="cx"> 
</span><span class="cx">     m_characters = other.m_characters;
</span><span class="cx">     m_length = other.m_length;
</span><ins>+    m_is8Bit = other.m_is8Bit;
</ins><span class="cx"> 
</span><del>-    other.m_characters = nullptr;
-    other.m_length = 0;
</del><ins>+    other.clear();
</ins><span class="cx"> 
</span><span class="cx">     setUnderlyingString(other);
</span><span class="cx">     other.setUnderlyingString(nullptr);
</span><span class="lines">@@ -251,6 +252,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_characters = other.m_characters;
</span><span class="cx">     m_length = other.m_length;
</span><ins>+    m_is8Bit = other.m_is8Bit;
</ins><span class="cx"> 
</span><span class="cx">     setUnderlyingString(other);
</span><span class="cx"> 
</span><span class="lines">@@ -259,20 +261,16 @@
</span><span class="cx"> 
</span><span class="cx"> inline void StringView::initialize(const LChar* characters, unsigned length)
</span><span class="cx"> {
</span><del>-    // FIXME: We need a better solution here, because there is no guarantee that
-    // the length here won't be too long. Maybe at least a RELEASE_ASSERT?
-    ASSERT(!(length &amp; is16BitStringFlag));
</del><span class="cx">     m_characters = characters;
</span><span class="cx">     m_length = length;
</span><ins>+    m_is8Bit = true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void StringView::initialize(const UChar* characters, unsigned length)
</span><span class="cx"> {
</span><del>-    // FIXME: We need a better solution here, because there is no guarantee that
-    // the length here won't be too long. Maybe at least a RELEASE_ASSERT?
-    ASSERT(!(length &amp; is16BitStringFlag));
</del><span class="cx">     m_characters = characters;
</span><del>-    m_length = is16BitStringFlag | length;
</del><ins>+    m_length = length;
+    m_is8Bit = false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline StringView::StringView(const LChar* characters, unsigned length)
</span><span class="lines">@@ -310,8 +308,7 @@
</span><span class="cx"> {
</span><span class="cx">     setUnderlyingString(string.impl());
</span><span class="cx">     if (!string.impl()) {
</span><del>-        m_characters = nullptr;
-        m_length = 0;
</del><ins>+        clear();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     if (string.is8Bit()) {
</span><span class="lines">@@ -321,6 +318,13 @@
</span><span class="cx">     initialize(string.characters16(), string.length());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void StringView::clear()
+{
+    m_characters = nullptr;
+    m_length = 0;
+    m_is8Bit = true;
+}
+
</ins><span class="cx"> inline StringView StringView::empty()
</span><span class="cx"> {
</span><span class="cx">     return StringView(reinterpret_cast&lt;const LChar*&gt;(&quot;&quot;), 0);
</span><span class="lines">@@ -367,7 +371,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline unsigned StringView::length() const
</span><span class="cx"> {
</span><del>-    return m_length &amp; ~is16BitStringFlag;
</del><ins>+    return m_length;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline StringView::operator bool() const
</span><span class="lines">@@ -377,7 +381,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline bool StringView::is8Bit() const
</span><span class="cx"> {
</span><del>-    return !(m_length &amp; is16BitStringFlag);
</del><ins>+    return m_is8Bit;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline StringView StringView::substring(unsigned start, unsigned length) const
</span><span class="lines">@@ -432,8 +436,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     auto characters16 = this-&gt;characters16();
</span><del>-    unsigned length = this-&gt;length();
-    for (unsigned i = 0; i &lt; length; ++i)
</del><ins>+    for (unsigned i = 0; i &lt; m_length; ++i)
</ins><span class="cx">         destination[i] = characters16[i];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -455,7 +458,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return String(characters8(), m_length);
</span><del>-    return String(characters16(), length());
</del><ins>+    return String(characters16(), m_length);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline AtomicString StringView::toAtomicString() const
</span><span class="lines">@@ -462,7 +465,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return AtomicString(characters8(), m_length);
</span><del>-    return AtomicString(characters16(), length());
</del><ins>+    return AtomicString(characters16(), m_length);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline float StringView::toFloat(bool&amp; isValid) const
</span><span class="lines">@@ -469,7 +472,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return charactersToFloat(characters8(), m_length, &amp;isValid);
</span><del>-    return charactersToFloat(characters16(), length(), &amp;isValid);
</del><ins>+    return charactersToFloat(characters16(), m_length, &amp;isValid);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline int StringView::toInt() const
</span><span class="lines">@@ -482,7 +485,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return charactersToInt(characters8(), m_length, &amp;isValid);
</span><del>-    return charactersToInt(characters16(), length(), &amp;isValid);
</del><ins>+    return charactersToInt(characters16(), m_length, &amp;isValid);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline int StringView::toIntStrict(bool&amp; isValid) const
</span><span class="lines">@@ -489,7 +492,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return charactersToIntStrict(characters8(), m_length, &amp;isValid);
</span><del>-    return charactersToIntStrict(characters16(), length(), &amp;isValid);
</del><ins>+    return charactersToIntStrict(characters16(), m_length, &amp;isValid);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline String StringView::toStringWithoutCopying() const
</span><span class="lines">@@ -496,7 +499,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return StringImpl::createWithoutCopying(characters8(), m_length);
</span><del>-    return StringImpl::createWithoutCopying(characters16(), length());
</del><ins>+    return StringImpl::createWithoutCopying(characters16(), m_length);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline size_t StringView::find(UChar character, unsigned start) const
</span><span class="lines">@@ -503,7 +506,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return WTF::find(characters8(), m_length, character, start);
</span><del>-    return WTF::find(characters16(), length(), character, start);
</del><ins>+    return WTF::find(characters16(), m_length, character, start);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline size_t StringView::find(CharacterMatchFunction matchFunction, unsigned start) const
</span><span class="lines">@@ -510,7 +513,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (is8Bit())
</span><span class="cx">         return WTF::find(characters8(), m_length, matchFunction, start);
</span><del>-    return WTF::find(characters16(), length(), matchFunction, start);
</del><ins>+    return WTF::find(characters16(), m_length, matchFunction, start);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if !CHECK_STRINGVIEW_LIFETIME
</span></span></pre>
</div>
</div>

</body>
</html>