<!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>[190838] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/190838">190838</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2015-10-10 08:27:46 -0700 (Sat, 10 Oct 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>SerializedScriptValue should use a compact encoding for 8-bit strings.
&lt;https://webkit.org/b/149934&gt;

Reviewed by Antti Koivisto.

Source/WebCore:

We were encoding known 8-bit strings in a 16-bit format when serializing script values.

Extend the format to support 8-bit strings. The 8-bittiness is encoded in the highest bit
of the string length. This is possible while supporting all older formats due to string
lengths &gt;= 0x7FFFFFFF being disallowed.

This patch knocks ~1 MB off of theverge.com, where some ad or tracker or whatever likes to
do a ton of postMessage() business.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CurrentVersion): Bump the serialization format version. Also updated the grammar
comment to describe the new format. Artistic license applied in description of bitfield.

(WebCore::writeLittleEndianUInt16): Deleted.

(WebCore::CloneSerializer::serialize):
(WebCore::CloneSerializer::write):
(WebCore::CloneDeserializer::deserializeString):
(WebCore::CloneDeserializer::readString):
(WebCore::CloneDeserializer::readStringData): Support 8-bit strings. I kept the string
length limit at UINT_MAX/sizeof(UChar) since the highest bit of the length is no longer
available. Besides, it seems flimsy to support longer strings if they happen to have all
8-bit characters.

LayoutTests:

Update a test to reflect changes to the serialization format.

* fast/storage/serialized-script-value.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfaststorageserializedscriptvaluehtml">trunk/LayoutTests/fast/storage/serialized-script-value.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValuecpp">trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (190837 => 190838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-10-10 08:40:34 UTC (rev 190837)
+++ trunk/LayoutTests/ChangeLog        2015-10-10 15:27:46 UTC (rev 190838)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-10-10  Andreas Kling  &lt;akling@apple.com&gt;
+
+        SerializedScriptValue should use a compact encoding for 8-bit strings.
+        &lt;https://webkit.org/b/149934&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Update a test to reflect changes to the serialization format.
+
+        * fast/storage/serialized-script-value.html:
+
</ins><span class="cx"> 2015-10-09  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r190689
</span></span></pre></div>
<a id="trunkLayoutTestsfaststorageserializedscriptvaluehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/storage/serialized-script-value.html (190837 => 190838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/storage/serialized-script-value.html        2015-10-10 08:40:34 UTC (rev 190837)
+++ trunk/LayoutTests/fast/storage/serialized-script-value.html        2015-10-10 15:27:46 UTC (rev 190838)
</span><span class="lines">@@ -5,28 +5,51 @@
</span><span class="cx">     &lt;/head&gt;
</span><span class="cx">     &lt;body&gt;
</span><span class="cx">         &lt;script&gt;
</span><del>-/*
-    See LayoutTests/platform/chromium/fast/storage/serialized-script-value.js,
-    upon which this test is based, for the corresponding test of the V8
-    serialization format.
-*/
</del><span class="cx"> 
</span><ins>+// Here's a little Q&amp;D helper for future adventurers needing to rebaseline this.
+
+function dec2hex(n) {
+    var s = n.toString(16);
+    if (s.length &lt; 2)
+        return &quot;0x0&quot; + s;
+    return &quot;0x&quot; + s;
+}
+
+function dumpSerialization(obj)
+{
+    var serialized = internals.serializeObject(obj);
+    var bufferView = new Uint8Array(serialized);
+
+    var numbers = new Array();
+    for (var i = 0; i &lt; bufferView.length; ++i) {
+        numbers.push(dec2hex(bufferView[i]));
+    }
+    var str = &quot;&quot;;
+    for (var i = 0; i &lt; numbers.length; ++i) {
+        if (i % 8 == 0)
+            str += &quot;\n    &quot;;
+        else
+            str += &quot; &quot;;
+        str += numbers[i];
+        if (i != numbers.length - 1)
+            str += &quot;,&quot;;
+    }
+    debug(str);
+}
+
</ins><span class="cx"> function testSerialization(obj, values, oldFormat, serializeExceptionValue) {
</span><span class="cx">     _testSerialization(1, obj, values, oldFormat, serializeExceptionValue);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> testSerialization({foo: 'zoo', bar: {baz: 'myNewKey'}},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
-    0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
-    0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
-    0x6f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
-    0x61, 0x00, 0x72, 0x00, 0x02, 0x03, 0x00, 0x00,
-    0x00, 0x62, 0x00, 0x61, 0x00, 0x7a, 0x00, 0x10,
-    0x08, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x79, 0x00,
-    0x4e, 0x00, 0x65, 0x00, 0x77, 0x00, 0x4b, 0x00,
-    0x65, 0x00, 0x79, 0x00, 0xff, 0xff, 0xff, 0xff,
-    0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
+    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
+    0x80, 0x7a, 0x6f, 0x6f, 0x03, 0x00, 0x00, 0x80,
+    0x62, 0x61, 0x72, 0x02, 0x03, 0x00, 0x00, 0x80,
+    0x62, 0x61, 0x7a, 0x10, 0x08, 0x00, 0x00, 0x80,
+    0x6d, 0x79, 0x4e, 0x65, 0x77, 0x4b, 0x65, 0x79,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -43,14 +66,12 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization({foo: 'zoo', bar: 'myNewKey'},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
-    0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
-    0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
-    0x6f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
-    0x61, 0x00, 0x72, 0x00, 0x10, 0x08, 0x00, 0x00,
-    0x00, 0x6d, 0x00, 0x79, 0x00, 0x4e, 0x00, 0x65,
-    0x00, 0x77, 0x00, 0x4b, 0x00, 0x65, 0x00, 0x79,
-    0x00, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
+    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
+    0x80, 0x7a, 0x6f, 0x6f, 0x03, 0x00, 0x00, 0x80,
+    0x62, 0x61, 0x72, 0x10, 0x08, 0x00, 0x00, 0x80,
+    0x6d, 0x79, 0x4e, 0x65, 0x77, 0x4b, 0x65, 0x79,
+    0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -65,7 +86,7 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization([],
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
</ins><span class="cx">     0x00, 0xff, 0xff, 0xff, 0xff
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -74,10 +95,9 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization({foo: &quot;zoo&quot;},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
-    0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
-    0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
-    0x6f, 0x00, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
+    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
+    0x80, 0x7a, 0x6f, 0x6f, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -87,9 +107,9 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization({foo: null},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
-    0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x04,
-    0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
+    0x80, 0x66, 0x6f, 0x6f, 0x04, 0xff, 0xff, 0xff,
+    0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -99,7 +119,7 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization({},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff,
</ins><span class="cx">     0xff
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -109,28 +129,28 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization(undefined,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x03
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x03
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x03
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(true,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x09
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x09
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x09
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(false,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x08
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x08
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x08
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(new Array(100),
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00,
</ins><span class="cx">     0x00, 0xff, 0xff, 0xff, 0xff
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -139,7 +159,7 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(10,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00,
</ins><span class="cx">     0x00
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -148,7 +168,7 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(-10,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff,
</ins><span class="cx">     0xff
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -157,7 +177,7 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(Math.pow(2,30),
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
</ins><span class="cx">     0x40
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -166,7 +186,7 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(Math.pow(2,55),
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
</ins><span class="cx">     0x00, 0x00, 0x00, 0x60, 0x43,
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -175,7 +195,7 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(1.23,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1,
</ins><span class="cx">     0x7a, 0x14, 0xae, 0xf3, 0x3f
</span><span class="cx"> ],
</span><span class="cx"> [
</span><span class="lines">@@ -184,15 +204,15 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(&quot;&quot;,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x11
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x11
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x11
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(&quot;abc&quot;,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
-    0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
+    0x80, 0x61, 0x62, 0x63
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -200,10 +220,10 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization({integer: 123},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,
-    0x00, 0x69, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x65,
-    0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x05,
-    0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,
+    0x80, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72,
+    0x05, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+    0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,
</span><span class="lines">@@ -213,11 +233,10 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization({string: &quot;str&quot;},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x06, 0x00, 0x00,
-    0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x69,
-    0x00, 0x6e, 0x00, 0x67, 0x00, 0x10, 0x03, 0x00,
-    0x00, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00,
-    0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x06, 0x00, 0x00,
+    0x80, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x10,
+    0x03, 0x00, 0x00, 0x80, 0x73, 0x74, 0x72, 0xff,
+    0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x06, 0x00, 0x00,
</span><span class="lines">@@ -228,13 +247,13 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization({list: [1,2,3]},
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
-    0x00, 0x6c, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74,
-    0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x05,
-    0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-    0x05, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
-    0xff, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
+    0x80, 0x6c, 0x69, 0x73, 0x74, 0x01, 0x03, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01,
+    0x00, 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00,
+    0x02, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,
+    0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
</span><span class="lines">@@ -247,16 +266,15 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(null,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x04
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x04
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x04
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(/abc/,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x12, 0x03, 0x00, 0x00,
-    0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x00,
-    0x00, 0x00, 0x00
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x12, 0x03, 0x00, 0x00,
+    0x80, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x80
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x12, 0x03, 0x00, 0x00,
</span><span class="lines">@@ -269,16 +287,13 @@
</span><span class="cx"> outerObject['outer'] = innerObject;
</span><span class="cx"> testSerialization(outerObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
-    0x00, 0x69, 0x00, 0x6e, 0x00, 0x6e, 0x00, 0x65,
-    0x00, 0x72, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00,
-    0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00,
-    0x6f, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00, 0x74,
-    0x00, 0x68, 0x00, 0x65, 0x00, 0x72, 0x00, 0x65,
-    0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00,
-    0x00, 0x6f, 0x00, 0x75, 0x00, 0x74, 0x00, 0x65,
-    0x00, 0x72, 0x00, 0x13, 0x01, 0xff, 0xff, 0xff,
-    0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
+    0x80, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x02, 0x05,
+    0x00, 0x00, 0x80, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
+    0x10, 0x05, 0x00, 0x00, 0x80, 0x74, 0x68, 0x65,
+    0x72, 0x65, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00,
+    0x00, 0x80, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x13,
+    0x01, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
</span><span class="lines">@@ -294,11 +309,10 @@
</span><span class="cx"> ]);
</span><span class="cx"> testSerialization(innerObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
-    0x00, 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c,
-    0x00, 0x6f, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00,
-    0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x72, 0x00,
-    0x65, 0x00, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
+    0x80, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x10, 0x05,
+    0x00, 0x00, 0x80, 0x74, 0x68, 0x65, 0x72, 0x65,
+    0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
</span><span class="lines">@@ -311,12 +325,12 @@
</span><span class="cx"> var unicodeObject = {a: 'a', u: String.fromCharCode(0x03B1,0x03B2), d: 42};
</span><span class="cx"> testSerialization(unicodeObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
-    0x00, 0x61, 0x00, 0x10, 0xfe, 0xff, 0xff, 0xff,
-    0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x00, 0x10,
-    0x02, 0x00, 0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03,
-    0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x05, 0x2a,
-    0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
+    0x80, 0x61, 0x10, 0xfe, 0xff, 0xff, 0xff, 0x00,
+    0x01, 0x00, 0x00, 0x80, 0x75, 0x10, 0x02, 0x00,
+    0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03, 0x01, 0x00,
+    0x00, 0x80, 0x64, 0x05, 0x2a, 0x00, 0x00, 0x00,
+    0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
</span><span class="lines">@@ -329,13 +343,12 @@
</span><span class="cx"> unicodeObject.a = 'ab';
</span><span class="cx"> testSerialization(unicodeObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
-    0x00, 0x61, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00,
-    0x61, 0x00, 0x62, 0x00, 0x01, 0x00, 0x00, 0x00,
-    0x75, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00, 0xb1,
-    0x03, 0xb2, 0x03, 0x01, 0x00, 0x00, 0x00, 0x64,
-    0x00, 0x05, 0x2a, 0x00, 0x00, 0x00, 0xff, 0xff,
-    0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
+    0x80, 0x61, 0x10, 0x02, 0x00, 0x00, 0x80, 0x61,
+    0x62, 0x01, 0x00, 0x00, 0x80, 0x75, 0x10, 0x02,
+    0x00, 0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03, 0x01,
+    0x00, 0x00, 0x80, 0x64, 0x05, 0x2a, 0x00, 0x00,
+    0x00, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ],
</span><span class="cx"> [
</span><span class="cx">     0x03, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
</span><span class="lines">@@ -355,14 +368,13 @@
</span><span class="cx"> arrayObject[''] = null;
</span><span class="cx"> testSerialization(arrayObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
</ins><span class="cx">     0x00, 0xfd, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
</span><del>-    0x00, 0x61, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00,
-    0x62, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x66,
-    0x00, 0x6f, 0x00, 0x6f, 0x00, 0x05, 0x7b, 0x00,
-    0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
-    0x61, 0x00, 0x72, 0x00, 0x05, 0xc8, 0x01, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff, 0xff,
</del><ins>+    0x80, 0x61, 0x09, 0x01, 0x00, 0x00, 0x80, 0x62,
+    0x08, 0x03, 0x00, 0x00, 0x80, 0x66, 0x6f, 0x6f,
+    0x05, 0x7b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
+    0x80, 0x62, 0x61, 0x72, 0x05, 0xc8, 0x01, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0xff, 0xff,
</ins><span class="cx">     0xff, 0xff
</span><span class="cx"> ]);
</span><span class="cx"> 
</span><span class="lines">@@ -370,17 +382,16 @@
</span><span class="cx"> arrayObject[1] = 'bar';
</span><span class="cx"> testSerialization(arrayObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
</ins><span class="cx">     0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00,
</span><del>-    0x00, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00,
-    0x01, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
-    0x00, 0x62, 0x00, 0x61, 0x00, 0x72, 0x00, 0xfd,
-    0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x61,
-    0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x62, 0x00,
</del><ins>+    0x00, 0x80, 0x66, 0x6f, 0x6f, 0x01, 0x00, 0x00,
+    0x00, 0x10, 0x03, 0x00, 0x00, 0x80, 0x62, 0x61,
+    0x72, 0xfd, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
+    0x80, 0x61, 0x09, 0x01, 0x00, 0x00, 0x80, 0x62,
</ins><span class="cx">     0x08, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x05, 0x7b,
</span><span class="cx">     0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x01,
</span><span class="cx">     0x05, 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
</span><del>-    0x00, 0x04, 0xff, 0xff, 0xff, 0xff
</del><ins>+    0x80, 0x04, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ]);
</span><span class="cx"> 
</span><span class="cx"> var mapObject = new Map;
</span><span class="lines">@@ -392,17 +403,15 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization(mapObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x1e, 0x07, 0x05, 0x02, 
-    0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 
-    0x00, 0x00, 0xf8, 0x3f, 0x02, 0xff, 0xff, 0xff, 
-    0xff, 0x13, 0x00, 0x10, 0x03, 0x00, 0x00, 0x00, 
-    0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10, 0x03, 
-    0x00, 0x00, 0x00, 0x62, 0x00, 0x61, 0x00, 0x72, 
-    0x00, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x01, 0x1f, 
-    0x07, 0x00, 0x00, 0x00, 0x65, 0x00, 0x78, 0x00, 
-    0x70, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 
-    0x6f, 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 
-    0xff, 0xff, 0xff
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x1e, 0x07, 0x05, 0x02,
+    0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0xf8, 0x3f, 0x02, 0xff, 0xff, 0xff,
+    0xff, 0x13, 0x00, 0x10, 0x03, 0x00, 0x00, 0x80,
+    0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00, 0x80,
+    0x62, 0x61, 0x72, 0x1a, 0xfe, 0xff, 0xff, 0xff,
+    0x01, 0x1f, 0x07, 0x00, 0x00, 0x80, 0x65, 0x78,
+    0x70, 0x61, 0x6e, 0x64, 0x6f, 0x02, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ]);
</span><span class="cx"> 
</span><span class="cx"> var setObject = new Set;
</span><span class="lines">@@ -415,14 +424,13 @@
</span><span class="cx"> 
</span><span class="cx"> testSerialization(setObject,
</span><span class="cx"> [
</span><del>-    0x05, 0x00, 0x00, 0x00, 0x1d, 0x07, 0x0a, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x13, 0x00, 0x10,
-    0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 0x61, 0x00, 0x72,
-    0x00, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x20, 0x07,
-    0x00, 0x00, 0x00, 0x65, 0x00, 0x78, 0x00, 0x70, 0x00,
-    0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x02,
-    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
-
</del><ins>+    0x06, 0x00, 0x00, 0x00, 0x1d, 0x07, 0x0a, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x13,
+    0x00, 0x10, 0x03, 0x00, 0x00, 0x80, 0x62, 0x61,
+    0x72, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x20,
+    0x07, 0x00, 0x00, 0x80, 0x65, 0x78, 0x70, 0x61,
+    0x6e, 0x64, 0x6f, 0x02, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff
</ins><span class="cx"> ]);
</span><span class="cx"> 
</span><span class="cx"> testSerialization(function(){}, [], null, DOMException.DATA_CLONE_ERR);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (190837 => 190838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-10-10 08:40:34 UTC (rev 190837)
+++ trunk/Source/WebCore/ChangeLog        2015-10-10 15:27:46 UTC (rev 190838)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2015-10-10  Andreas Kling  &lt;akling@apple.com&gt;
+
+        SerializedScriptValue should use a compact encoding for 8-bit strings.
+        &lt;https://webkit.org/b/149934&gt;
+
+        Reviewed by Antti Koivisto.
+
+        We were encoding known 8-bit strings in a 16-bit format when serializing script values.
+
+        Extend the format to support 8-bit strings. The 8-bittiness is encoded in the highest bit
+        of the string length. This is possible while supporting all older formats due to string
+        lengths &gt;= 0x7FFFFFFF being disallowed.
+
+        This patch knocks ~1 MB off of theverge.com, where some ad or tracker or whatever likes to
+        do a ton of postMessage() business.
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CurrentVersion): Bump the serialization format version. Also updated the grammar
+        comment to describe the new format. Artistic license applied in description of bitfield.
+
+        (WebCore::writeLittleEndianUInt16): Deleted.
+
+        (WebCore::CloneSerializer::serialize):
+        (WebCore::CloneSerializer::write):
+        (WebCore::CloneDeserializer::deserializeString):
+        (WebCore::CloneDeserializer::readString):
+        (WebCore::CloneDeserializer::readStringData): Support 8-bit strings. I kept the string
+        length limit at UINT_MAX/sizeof(UChar) since the highest bit of the length is no longer
+        available. Besides, it seems flimsy to support longer strings if they happen to have all
+        8-bit characters.
+
</ins><span class="cx"> 2015-10-10  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] Remove project support for iOS 8
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (190837 => 190838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2015-10-10 08:40:34 UTC (rev 190837)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2015-10-10 15:27:46 UTC (rev 190838)
</span><span class="lines">@@ -247,12 +247,16 @@
</span><span class="cx">  * and EmptyStringObjectTag for serialization of Boolean, Number and String objects.
</span><span class="cx">  * Version 4. added support for serializing non-index properties of arrays.
</span><span class="cx">  * Version 5. added support for Map and Set types.
</span><ins>+ * Version 6. added support for 8-bit strings.
</ins><span class="cx">  */
</span><del>-static const unsigned CurrentVersion = 5;
</del><ins>+static const unsigned CurrentVersion = 6;
</ins><span class="cx"> static const unsigned TerminatorTag = 0xFFFFFFFF;
</span><span class="cx"> static const unsigned StringPoolTag = 0xFFFFFFFE;
</span><span class="cx"> static const unsigned NonIndexPropertiesTag = 0xFFFFFFFD;
</span><span class="cx"> 
</span><ins>+// The high bit of a StringData's length determines the character size.
+static const unsigned StringDataIs8BitFlag = 0x80000000;
+
</ins><span class="cx"> /*
</span><span class="cx">  * Object serialization is performed according to the following grammar, all tags
</span><span class="cx">  * are recorded as a single uint8_t.
</span><span class="lines">@@ -318,7 +322,7 @@
</span><span class="cx">  *
</span><span class="cx">  * StringData :-
</span><span class="cx">  *      StringPoolTag &lt;cpIndex:IndexType&gt;
</span><del>- *      (not (TerminatorTag | StringPoolTag))&lt;length:uint32_t&gt;&lt;characters:UChar{length}&gt; // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed
</del><ins>+ *      (not (TerminatorTag | StringPoolTag))&lt;is8Bit:uint32_t:1&gt;&lt;length:uint32_t:31&gt;&lt;characters:CharType{length}&gt; // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed
</ins><span class="cx">  *
</span><span class="cx">  * File :-
</span><span class="cx">  *    FileTag FileData
</span><span class="lines">@@ -454,19 +458,6 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool writeLittleEndianUInt16(Vector&lt;uint8_t&gt;&amp; buffer, const LChar* values, uint32_t length)
-{
-    if (length &gt; std::numeric_limits&lt;uint32_t&gt;::max() / 2)
-        return false;
-
-    for (unsigned i = 0; i &lt; length; ++i) {
-        buffer.append(values[i]);
-        buffer.append(0);
-    }
-
-    return true;
-}
-
</del><span class="cx"> template &lt;&gt; bool writeLittleEndian&lt;uint8_t&gt;(Vector&lt;uint8_t&gt;&amp; buffer, const uint8_t* values, uint32_t length)
</span><span class="cx"> {
</span><span class="cx">     buffer.append(values, length);
</span><span class="lines">@@ -491,9 +482,11 @@
</span><span class="cx">             return true;
</span><span class="cx">         }
</span><span class="cx">         writeLittleEndian&lt;uint8_t&gt;(out, StringTag);
</span><ins>+        if (s.is8Bit()) {
+            writeLittleEndian(out, s.length() | StringDataIs8BitFlag);
+            return writeLittleEndian(out, s.characters8(), s.length());
+        }
</ins><span class="cx">         writeLittleEndian(out, s.length());
</span><del>-        if (s.is8Bit())
-            return writeLittleEndianUInt16(out, s.characters8(), s.length());
</del><span class="cx">         return writeLittleEndian(out, s.characters16(), s.length());
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -993,22 +986,21 @@
</span><span class="cx"> 
</span><span class="cx">         unsigned length = str.length();
</span><span class="cx"> 
</span><del>-        // This condition is unlikely to happen as they would imply an ~8gb
-        // string but we should guard against it anyway
-        if (length &gt;= StringPoolTag) {
-            fail();
-            return;
-        }
-
</del><span class="cx">         // Guard against overflow
</span><span class="cx">         if (length &gt; (std::numeric_limits&lt;uint32_t&gt;::max() - sizeof(uint32_t)) / sizeof(UChar)) {
</span><span class="cx">             fail();
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        writeLittleEndian&lt;uint32_t&gt;(m_buffer, length);
-        if (!length || str.is8Bit()) {
-            if (!writeLittleEndianUInt16(m_buffer, str.characters8(), length))
</del><ins>+        if (str.is8Bit())
+            writeLittleEndian&lt;uint32_t&gt;(m_buffer, length | StringDataIs8BitFlag);
+        else
+            writeLittleEndian&lt;uint32_t&gt;(m_buffer, length);
+
+        if (!length)
+            return;
+        if (str.is8Bit()) {
+            if (!writeLittleEndian(m_buffer, str.characters8(), length))
</ins><span class="cx">                 fail();
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="lines">@@ -1477,12 +1469,14 @@
</span><span class="cx">         if (!readLittleEndian(ptr, end, tag) || tag != StringTag)
</span><span class="cx">             return String();
</span><span class="cx">         uint32_t length;
</span><del>-        if (!readLittleEndian(ptr, end, length) || length &gt;= StringPoolTag)
</del><ins>+        if (!readLittleEndian(ptr, end, length))
</ins><span class="cx">             return String();
</span><ins>+        bool is8Bit = length &amp; StringDataIs8BitFlag;
+        length &amp;= ~StringDataIs8BitFlag;
</ins><span class="cx">         String str;
</span><del>-        if (!readString(ptr, end, str, length))
</del><ins>+        if (!readString(ptr, end, str, length, is8Bit))
</ins><span class="cx">             return String();
</span><del>-        return String(str.impl());
</del><ins>+        return str;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     static DeserializationResult deserialize(ExecState* exec, JSGlobalObject* globalObject,
</span><span class="lines">@@ -1662,11 +1656,19 @@
</span><span class="cx">         return read(i);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    static bool readString(const uint8_t*&amp; ptr, const uint8_t* end, String&amp; str, unsigned length)
</del><ins>+    static bool readString(const uint8_t*&amp; ptr, const uint8_t* end, String&amp; str, unsigned length, bool is8Bit)
</ins><span class="cx">     {
</span><span class="cx">         if (length &gt;= std::numeric_limits&lt;int32_t&gt;::max() / sizeof(UChar))
</span><span class="cx">             return false;
</span><span class="cx"> 
</span><ins>+        if (is8Bit) {
+            if ((end - ptr) &lt; static_cast&lt;int&gt;(length))
+                return false;
+            str = String(reinterpret_cast&lt;const LChar*&gt;(ptr), length);
+            ptr += length;
+            return true;
+        }
+
</ins><span class="cx">         unsigned size = length * sizeof(UChar);
</span><span class="cx">         if ((end - ptr) &lt; static_cast&lt;int&gt;(size))
</span><span class="cx">             return false;
</span><span class="lines">@@ -1717,8 +1719,10 @@
</span><span class="cx">             cachedString = CachedStringRef(&amp;m_constantPool, index);
</span><span class="cx">             return true;
</span><span class="cx">         }
</span><ins>+        bool is8Bit = length &amp; StringDataIs8BitFlag;
+        length &amp;= ~StringDataIs8BitFlag;
</ins><span class="cx">         String str;
</span><del>-        if (!readString(m_ptr, m_end, str, length)) {
</del><ins>+        if (!readString(m_ptr, m_end, str, length, is8Bit)) {
</ins><span class="cx">             fail();
</span><span class="cx">             return false;
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>