Changeset 190838 in webkit


Ignore:
Timestamp:
Oct 10, 2015 8:27:46 AM (9 years ago)
Author:
akling@apple.com
Message:

SerializedScriptValue should use a compact encoding for 8-bit strings.
<https://webkit.org/b/149934>

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 >= 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:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190836 r190838  
     12015-10-10  Andreas Kling  <akling@apple.com>
     2
     3        SerializedScriptValue should use a compact encoding for 8-bit strings.
     4        <https://webkit.org/b/149934>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Update a test to reflect changes to the serialization format.
     9
     10        * fast/storage/serialized-script-value.html:
     11
    1122015-10-09  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/LayoutTests/fast/storage/serialized-script-value.html

    r181458 r190838  
    66    <body>
    77        <script>
    8 /*
    9     See LayoutTests/platform/chromium/fast/storage/serialized-script-value.js,
    10     upon which this test is based, for the corresponding test of the V8
    11     serialization format.
    12 */
     8
     9// Here's a little Q&D helper for future adventurers needing to rebaseline this.
     10
     11function dec2hex(n) {
     12    var s = n.toString(16);
     13    if (s.length < 2)
     14        return "0x0" + s;
     15    return "0x" + s;
     16}
     17
     18function dumpSerialization(obj)
     19{
     20    var serialized = internals.serializeObject(obj);
     21    var bufferView = new Uint8Array(serialized);
     22
     23    var numbers = new Array();
     24    for (var i = 0; i < bufferView.length; ++i) {
     25        numbers.push(dec2hex(bufferView[i]));
     26    }
     27    var str = "";
     28    for (var i = 0; i < numbers.length; ++i) {
     29        if (i % 8 == 0)
     30            str += "\n    ";
     31        else
     32            str += " ";
     33        str += numbers[i];
     34        if (i != numbers.length - 1)
     35            str += ",";
     36    }
     37    debug(str);
     38}
    1339
    1440function testSerialization(obj, values, oldFormat, serializeExceptionValue) {
     
    1844testSerialization({foo: 'zoo', bar: {baz: 'myNewKey'}},
    1945[
    20     0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
    21     0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
    22     0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
    23     0x6f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
    24     0x61, 0x00, 0x72, 0x00, 0x02, 0x03, 0x00, 0x00,
    25     0x00, 0x62, 0x00, 0x61, 0x00, 0x7a, 0x00, 0x10,
    26     0x08, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x79, 0x00,
    27     0x4e, 0x00, 0x65, 0x00, 0x77, 0x00, 0x4b, 0x00,
    28     0x65, 0x00, 0x79, 0x00, 0xff, 0xff, 0xff, 0xff,
    29     0xff, 0xff, 0xff, 0xff
     46    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
     47    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
     48    0x80, 0x7a, 0x6f, 0x6f, 0x03, 0x00, 0x00, 0x80,
     49    0x62, 0x61, 0x72, 0x02, 0x03, 0x00, 0x00, 0x80,
     50    0x62, 0x61, 0x7a, 0x10, 0x08, 0x00, 0x00, 0x80,
     51    0x6d, 0x79, 0x4e, 0x65, 0x77, 0x4b, 0x65, 0x79,
     52    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
    3053],
    3154[
     
    4467testSerialization({foo: 'zoo', bar: 'myNewKey'},
    4568[
    46     0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
    47     0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
    48     0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
    49     0x6f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
    50     0x61, 0x00, 0x72, 0x00, 0x10, 0x08, 0x00, 0x00,
    51     0x00, 0x6d, 0x00, 0x79, 0x00, 0x4e, 0x00, 0x65,
    52     0x00, 0x77, 0x00, 0x4b, 0x00, 0x65, 0x00, 0x79,
    53     0x00, 0xff, 0xff, 0xff, 0xff
     69    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
     70    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
     71    0x80, 0x7a, 0x6f, 0x6f, 0x03, 0x00, 0x00, 0x80,
     72    0x62, 0x61, 0x72, 0x10, 0x08, 0x00, 0x00, 0x80,
     73    0x6d, 0x79, 0x4e, 0x65, 0x77, 0x4b, 0x65, 0x79,
     74    0xff, 0xff, 0xff, 0xff
    5475],
    5576[
     
    6687testSerialization([],
    6788[
    68     0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
     89    0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    6990    0x00, 0xff, 0xff, 0xff, 0xff
    7091],
     
    7596testSerialization({foo: "zoo"},
    7697[
    77     0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
    78     0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10,
    79     0x03, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x6f, 0x00,
    80     0x6f, 0x00, 0xff, 0xff, 0xff, 0xff
     98    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
     99    0x80, 0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00,
     100    0x80, 0x7a, 0x6f, 0x6f, 0xff, 0xff, 0xff, 0xff
    81101],
    82102[
     
    88108testSerialization({foo: null},
    89109[
    90     0x05, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
    91     0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x04,
    92     0xff, 0xff, 0xff, 0xff
     110    0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,
     111    0x80, 0x66, 0x6f, 0x6f, 0x04, 0xff, 0xff, 0xff,
     112    0xff
    93113],
    94114[
     
    100120testSerialization({},
    101121[
    102     0x05, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff,
     122    0x06, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff,
    103123    0xff
    104124],
     
    110130testSerialization(undefined,
    111131[
    112     0x05, 0x00, 0x00, 0x00, 0x03
     132    0x06, 0x00, 0x00, 0x00, 0x03
    113133],
    114134[
     
    117137testSerialization(true,
    118138[
    119     0x05, 0x00, 0x00, 0x00, 0x09
     139    0x06, 0x00, 0x00, 0x00, 0x09
    120140],
    121141[
     
    124144testSerialization(false,
    125145[
    126     0x05, 0x00, 0x00, 0x00, 0x08
     146    0x06, 0x00, 0x00, 0x00, 0x08
    127147],
    128148[
     
    131151testSerialization(new Array(100),
    132152[
    133     0x05, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00,
     153    0x06, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00,
    134154    0x00, 0xff, 0xff, 0xff, 0xff
    135155],
     
    140160testSerialization(10,
    141161[
    142     0x05, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00,
     162    0x06, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00,
    143163    0x00
    144164],
     
    149169testSerialization(-10,
    150170[
    151     0x05, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff,
     171    0x06, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff,
    152172    0xff
    153173],
     
    158178testSerialization(Math.pow(2,30),
    159179[
    160     0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
     180    0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
    161181    0x40
    162182],
     
    167187testSerialization(Math.pow(2,55),
    168188[
    169     0x05, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
     189    0x06, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
    170190    0x00, 0x00, 0x00, 0x60, 0x43,
    171191],
     
    176196testSerialization(1.23,
    177197[
    178     0x05, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1,
     198    0x06, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1,
    179199    0x7a, 0x14, 0xae, 0xf3, 0x3f
    180200],
     
    185205testSerialization("",
    186206[
    187     0x05, 0x00, 0x00, 0x00, 0x11
     207    0x06, 0x00, 0x00, 0x00, 0x11
    188208],
    189209[
     
    192212testSerialization("abc",
    193213[
    194     0x05, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
    195     0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00
     214    0x06, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
     215    0x80, 0x61, 0x62, 0x63
    196216],
    197217[
     
    201221testSerialization({integer: 123},
    202222[
    203     0x05, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,
    204     0x00, 0x69, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x65,
    205     0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x05,
    206     0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
     223    0x06, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,
     224    0x80, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72,
     225    0x05, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
     226    0xff
    207227],
    208228[
     
    214234testSerialization({string: "str"},
    215235[
    216     0x05, 0x00, 0x00, 0x00, 0x02, 0x06, 0x00, 0x00,
    217     0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x69,
    218     0x00, 0x6e, 0x00, 0x67, 0x00, 0x10, 0x03, 0x00,
    219     0x00, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00,
    220     0xff, 0xff, 0xff, 0xff
     236    0x06, 0x00, 0x00, 0x00, 0x02, 0x06, 0x00, 0x00,
     237    0x80, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x10,
     238    0x03, 0x00, 0x00, 0x80, 0x73, 0x74, 0x72, 0xff,
     239    0xff, 0xff, 0xff
    221240],
    222241[
     
    229248testSerialization({list: [1,2,3]},
    230249[
    231     0x05, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
    232     0x00, 0x6c, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74,
    233     0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
    234     0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x05,
    235     0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
    236     0x05, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
    237     0xff, 0xff, 0xff, 0xff, 0xff
     250    0x06, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
     251    0x80, 0x6c, 0x69, 0x73, 0x74, 0x01, 0x03, 0x00,
     252    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01,
     253    0x00, 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00,
     254    0x02, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,
     255    0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     256    0xff
    238257],
    239258[
     
    248267testSerialization(null,
    249268[
    250     0x05, 0x00, 0x00, 0x00, 0x04
     269    0x06, 0x00, 0x00, 0x00, 0x04
    251270],
    252271[
     
    255274testSerialization(/abc/,
    256275[
    257     0x05, 0x00, 0x00, 0x00, 0x12, 0x03, 0x00, 0x00,
    258     0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x00,
    259     0x00, 0x00, 0x00
     276    0x06, 0x00, 0x00, 0x00, 0x12, 0x03, 0x00, 0x00,
     277    0x80, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x80
    260278],
    261279[
     
    270288testSerialization(outerObject,
    271289[
    272     0x05, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
    273     0x00, 0x69, 0x00, 0x6e, 0x00, 0x6e, 0x00, 0x65,
    274     0x00, 0x72, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00,
    275     0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00,
    276     0x6f, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00, 0x74,
    277     0x00, 0x68, 0x00, 0x65, 0x00, 0x72, 0x00, 0x65,
    278     0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00,
    279     0x00, 0x6f, 0x00, 0x75, 0x00, 0x74, 0x00, 0x65,
    280     0x00, 0x72, 0x00, 0x13, 0x01, 0xff, 0xff, 0xff,
    281     0xff
     290    0x06, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
     291    0x80, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x02, 0x05,
     292    0x00, 0x00, 0x80, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
     293    0x10, 0x05, 0x00, 0x00, 0x80, 0x74, 0x68, 0x65,
     294    0x72, 0x65, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00,
     295    0x00, 0x80, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x13,
     296    0x01, 0xff, 0xff, 0xff, 0xff
    282297],
    283298[
     
    295310testSerialization(innerObject,
    296311[
    297     0x05, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
    298     0x00, 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c,
    299     0x00, 0x6f, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00,
    300     0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x72, 0x00,
    301     0x65, 0x00, 0xff, 0xff, 0xff, 0xff
     312    0x06, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
     313    0x80, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x10, 0x05,
     314    0x00, 0x00, 0x80, 0x74, 0x68, 0x65, 0x72, 0x65,
     315    0xff, 0xff, 0xff, 0xff
    302316],
    303317[
     
    312326testSerialization(unicodeObject,
    313327[
    314     0x05, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
    315     0x00, 0x61, 0x00, 0x10, 0xfe, 0xff, 0xff, 0xff,
    316     0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x00, 0x10,
    317     0x02, 0x00, 0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03,
    318     0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x05, 0x2a,
    319     0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
     328    0x06, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
     329    0x80, 0x61, 0x10, 0xfe, 0xff, 0xff, 0xff, 0x00,
     330    0x01, 0x00, 0x00, 0x80, 0x75, 0x10, 0x02, 0x00,
     331    0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03, 0x01, 0x00,
     332    0x00, 0x80, 0x64, 0x05, 0x2a, 0x00, 0x00, 0x00,
     333    0xff, 0xff, 0xff, 0xff
    320334],
    321335[
     
    330344testSerialization(unicodeObject,
    331345[
    332     0x05, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
    333     0x00, 0x61, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00,
    334     0x61, 0x00, 0x62, 0x00, 0x01, 0x00, 0x00, 0x00,
    335     0x75, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00, 0xb1,
    336     0x03, 0xb2, 0x03, 0x01, 0x00, 0x00, 0x00, 0x64,
    337     0x00, 0x05, 0x2a, 0x00, 0x00, 0x00, 0xff, 0xff,
    338     0xff, 0xff
     346    0x06, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
     347    0x80, 0x61, 0x10, 0x02, 0x00, 0x00, 0x80, 0x61,
     348    0x62, 0x01, 0x00, 0x00, 0x80, 0x75, 0x10, 0x02,
     349    0x00, 0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03, 0x01,
     350    0x00, 0x00, 0x80, 0x64, 0x05, 0x2a, 0x00, 0x00,
     351    0x00, 0xff, 0xff, 0xff, 0xff
    339352],
    340353[
     
    356369testSerialization(arrayObject,
    357370[
    358     0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
     371    0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    359372    0x00, 0xfd, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
    360     0x00, 0x61, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00,
    361     0x62, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x66,
    362     0x00, 0x6f, 0x00, 0x6f, 0x00, 0x05, 0x7b, 0x00,
    363     0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
    364     0x61, 0x00, 0x72, 0x00, 0x05, 0xc8, 0x01, 0x00,
    365     0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff, 0xff,
     373    0x80, 0x61, 0x09, 0x01, 0x00, 0x00, 0x80, 0x62,
     374    0x08, 0x03, 0x00, 0x00, 0x80, 0x66, 0x6f, 0x6f,
     375    0x05, 0x7b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
     376    0x80, 0x62, 0x61, 0x72, 0x05, 0xc8, 0x01, 0x00,
     377    0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0xff, 0xff,
    366378    0xff, 0xff
    367379]);
     
    371383testSerialization(arrayObject,
    372384[
    373     0x05, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
     385    0x06, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
    374386    0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00,
    375     0x00, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00,
    376     0x01, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,
    377     0x00, 0x62, 0x00, 0x61, 0x00, 0x72, 0x00, 0xfd,
    378     0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x61,
    379     0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x62, 0x00,
     387    0x00, 0x80, 0x66, 0x6f, 0x6f, 0x01, 0x00, 0x00,
     388    0x00, 0x10, 0x03, 0x00, 0x00, 0x80, 0x62, 0x61,
     389    0x72, 0xfd, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
     390    0x80, 0x61, 0x09, 0x01, 0x00, 0x00, 0x80, 0x62,
    380391    0x08, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x05, 0x7b,
    381392    0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x01,
    382393    0x05, 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
    383     0x00, 0x04, 0xff, 0xff, 0xff, 0xff
     394    0x80, 0x04, 0xff, 0xff, 0xff, 0xff
    384395]);
    385396
     
    393404testSerialization(mapObject,
    394405[
    395     0x05, 0x00, 0x00, 0x00, 0x1e, 0x07, 0x05, 0x02,
    396     0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
    397     0x00, 0x00, 0xf8, 0x3f, 0x02, 0xff, 0xff, 0xff,
    398     0xff, 0x13, 0x00, 0x10, 0x03, 0x00, 0x00, 0x00,
    399     0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x10, 0x03,
    400     0x00, 0x00, 0x00, 0x62, 0x00, 0x61, 0x00, 0x72,
    401     0x00, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x01, 0x1f,
    402     0x07, 0x00, 0x00, 0x00, 0x65, 0x00, 0x78, 0x00,
    403     0x70, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00,
    404     0x6f, 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff,
    405     0xff, 0xff, 0xff
     406    0x06, 0x00, 0x00, 0x00, 0x1e, 0x07, 0x05, 0x02,
     407    0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
     408    0x00, 0x00, 0xf8, 0x3f, 0x02, 0xff, 0xff, 0xff,
     409    0xff, 0x13, 0x00, 0x10, 0x03, 0x00, 0x00, 0x80,
     410    0x66, 0x6f, 0x6f, 0x10, 0x03, 0x00, 0x00, 0x80,
     411    0x62, 0x61, 0x72, 0x1a, 0xfe, 0xff, 0xff, 0xff,
     412    0x01, 0x1f, 0x07, 0x00, 0x00, 0x80, 0x65, 0x78,
     413    0x70, 0x61, 0x6e, 0x64, 0x6f, 0x02, 0xff, 0xff,
     414    0xff, 0xff, 0xff, 0xff, 0xff, 0xff
    406415]);
    407416
     
    416425testSerialization(setObject,
    417426[
    418     0x05, 0x00, 0x00, 0x00, 0x1d, 0x07, 0x0a, 0x00, 0x00,
    419     0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x13, 0x00, 0x10,
    420     0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 0x61, 0x00, 0x72,
    421     0x00, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x20, 0x07,
    422     0x00, 0x00, 0x00, 0x65, 0x00, 0x78, 0x00, 0x70, 0x00,
    423     0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x02,
    424     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
    425 
     427    0x06, 0x00, 0x00, 0x00, 0x1d, 0x07, 0x0a, 0x00,
     428    0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x13,
     429    0x00, 0x10, 0x03, 0x00, 0x00, 0x80, 0x62, 0x61,
     430    0x72, 0x1a, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x20,
     431    0x07, 0x00, 0x00, 0x80, 0x65, 0x78, 0x70, 0x61,
     432    0x6e, 0x64, 0x6f, 0x02, 0xff, 0xff, 0xff, 0xff,
     433    0xff, 0xff, 0xff, 0xff
    426434]);
    427435
  • trunk/Source/WebCore/ChangeLog

    r190837 r190838  
     12015-10-10  Andreas Kling  <akling@apple.com>
     2
     3        SerializedScriptValue should use a compact encoding for 8-bit strings.
     4        <https://webkit.org/b/149934>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        We were encoding known 8-bit strings in a 16-bit format when serializing script values.
     9
     10        Extend the format to support 8-bit strings. The 8-bittiness is encoded in the highest bit
     11        of the string length. This is possible while supporting all older formats due to string
     12        lengths >= 0x7FFFFFFF being disallowed.
     13
     14        This patch knocks ~1 MB off of theverge.com, where some ad or tracker or whatever likes to
     15        do a ton of postMessage() business.
     16
     17        * bindings/js/SerializedScriptValue.cpp:
     18        (WebCore::CurrentVersion): Bump the serialization format version. Also updated the grammar
     19        comment to describe the new format. Artistic license applied in description of bitfield.
     20
     21        (WebCore::writeLittleEndianUInt16): Deleted.
     22
     23        (WebCore::CloneSerializer::serialize):
     24        (WebCore::CloneSerializer::write):
     25        (WebCore::CloneDeserializer::deserializeString):
     26        (WebCore::CloneDeserializer::readString):
     27        (WebCore::CloneDeserializer::readStringData): Support 8-bit strings. I kept the string
     28        length limit at UINT_MAX/sizeof(UChar) since the highest bit of the length is no longer
     29        available. Besides, it seems flimsy to support longer strings if they happen to have all
     30        8-bit characters.
     31
    1322015-10-10  Dan Bernstein  <mitz@apple.com>
    233
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r190794 r190838  
    248248 * Version 4. added support for serializing non-index properties of arrays.
    249249 * Version 5. added support for Map and Set types.
     250 * Version 6. added support for 8-bit strings.
    250251 */
    251 static const unsigned CurrentVersion = 5;
     252static const unsigned CurrentVersion = 6;
    252253static const unsigned TerminatorTag = 0xFFFFFFFF;
    253254static const unsigned StringPoolTag = 0xFFFFFFFE;
    254255static const unsigned NonIndexPropertiesTag = 0xFFFFFFFD;
     256
     257// The high bit of a StringData's length determines the character size.
     258static const unsigned StringDataIs8BitFlag = 0x80000000;
    255259
    256260/*
     
    319323 * StringData :-
    320324 *      StringPoolTag <cpIndex:IndexType>
    321  *      (not (TerminatorTag | StringPoolTag))<length:uint32_t><characters:UChar{length}> // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed
     325 *      (not (TerminatorTag | StringPoolTag))<is8Bit:uint32_t:1><length:uint32_t:31><characters:CharType{length}> // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed
    322326 *
    323327 * File :-
     
    455459}
    456460
    457 static bool writeLittleEndianUInt16(Vector<uint8_t>& buffer, const LChar* values, uint32_t length)
    458 {
    459     if (length > std::numeric_limits<uint32_t>::max() / 2)
    460         return false;
    461 
    462     for (unsigned i = 0; i < length; ++i) {
    463         buffer.append(values[i]);
    464         buffer.append(0);
    465     }
    466 
    467     return true;
    468 }
    469 
    470461template <> bool writeLittleEndian<uint8_t>(Vector<uint8_t>& buffer, const uint8_t* values, uint32_t length)
    471462{
     
    492483        }
    493484        writeLittleEndian<uint8_t>(out, StringTag);
     485        if (s.is8Bit()) {
     486            writeLittleEndian(out, s.length() | StringDataIs8BitFlag);
     487            return writeLittleEndian(out, s.characters8(), s.length());
     488        }
    494489        writeLittleEndian(out, s.length());
    495         if (s.is8Bit())
    496             return writeLittleEndianUInt16(out, s.characters8(), s.length());
    497490        return writeLittleEndian(out, s.characters16(), s.length());
    498491    }
     
    994987        unsigned length = str.length();
    995988
    996         // This condition is unlikely to happen as they would imply an ~8gb
    997         // string but we should guard against it anyway
    998         if (length >= StringPoolTag) {
    999             fail();
    1000             return;
    1001         }
    1002 
    1003989        // Guard against overflow
    1004990        if (length > (std::numeric_limits<uint32_t>::max() - sizeof(uint32_t)) / sizeof(UChar)) {
     
    1007993        }
    1008994
    1009         writeLittleEndian<uint32_t>(m_buffer, length);
    1010         if (!length || str.is8Bit()) {
    1011             if (!writeLittleEndianUInt16(m_buffer, str.characters8(), length))
     995        if (str.is8Bit())
     996            writeLittleEndian<uint32_t>(m_buffer, length | StringDataIs8BitFlag);
     997        else
     998            writeLittleEndian<uint32_t>(m_buffer, length);
     999
     1000        if (!length)
     1001            return;
     1002        if (str.is8Bit()) {
     1003            if (!writeLittleEndian(m_buffer, str.characters8(), length))
    10121004                fail();
    10131005            return;
     
    14781470            return String();
    14791471        uint32_t length;
    1480         if (!readLittleEndian(ptr, end, length) || length >= StringPoolTag)
     1472        if (!readLittleEndian(ptr, end, length))
    14811473            return String();
     1474        bool is8Bit = length & StringDataIs8BitFlag;
     1475        length &= ~StringDataIs8BitFlag;
    14821476        String str;
    1483         if (!readString(ptr, end, str, length))
     1477        if (!readString(ptr, end, str, length, is8Bit))
    14841478            return String();
    1485         return String(str.impl());
     1479        return str;
    14861480    }
    14871481
     
    16631657    }
    16641658
    1665     static bool readString(const uint8_t*& ptr, const uint8_t* end, String& str, unsigned length)
     1659    static bool readString(const uint8_t*& ptr, const uint8_t* end, String& str, unsigned length, bool is8Bit)
    16661660    {
    16671661        if (length >= std::numeric_limits<int32_t>::max() / sizeof(UChar))
    16681662            return false;
     1663
     1664        if (is8Bit) {
     1665            if ((end - ptr) < static_cast<int>(length))
     1666                return false;
     1667            str = String(reinterpret_cast<const LChar*>(ptr), length);
     1668            ptr += length;
     1669            return true;
     1670        }
    16691671
    16701672        unsigned size = length * sizeof(UChar);
     
    17181720            return true;
    17191721        }
     1722        bool is8Bit = length & StringDataIs8BitFlag;
     1723        length &= ~StringDataIs8BitFlag;
    17201724        String str;
    1721         if (!readString(m_ptr, m_end, str, length)) {
     1725        if (!readString(m_ptr, m_end, str, length, is8Bit)) {
    17221726            fail();
    17231727            return false;
Note: See TracChangeset for help on using the changeset viewer.