Changeset 190838 in webkit
- Timestamp:
- Oct 10, 2015 8:27:46 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r190836 r190838 1 2015-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 1 12 2015-10-09 Myles C. Maxfield <mmaxfield@apple.com> 2 13 -
trunk/LayoutTests/fast/storage/serialized-script-value.html
r181458 r190838 6 6 <body> 7 7 <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 11 function dec2hex(n) { 12 var s = n.toString(16); 13 if (s.length < 2) 14 return "0x0" + s; 15 return "0x" + s; 16 } 17 18 function 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 } 13 39 14 40 function testSerialization(obj, values, oldFormat, serializeExceptionValue) { … … 18 44 testSerialization({foo: 'zoo', bar: {baz: 'myNewKey'}}, 19 45 [ 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 30 53 ], 31 54 [ … … 44 67 testSerialization({foo: 'zoo', bar: 'myNewKey'}, 45 68 [ 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 54 75 ], 55 76 [ … … 66 87 testSerialization([], 67 88 [ 68 0x0 5, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,89 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 69 90 0x00, 0xff, 0xff, 0xff, 0xff 70 91 ], … … 75 96 testSerialization({foo: "zoo"}, 76 97 [ 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 81 101 ], 82 102 [ … … 88 108 testSerialization({foo: null}, 89 109 [ 90 0x0 5, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00,91 0x 00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x04,92 0xff , 0xff, 0xff, 0xff110 0x06, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 111 0x80, 0x66, 0x6f, 0x6f, 0x04, 0xff, 0xff, 0xff, 112 0xff 93 113 ], 94 114 [ … … 100 120 testSerialization({}, 101 121 [ 102 0x0 5, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff,122 0x06, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff, 103 123 0xff 104 124 ], … … 110 130 testSerialization(undefined, 111 131 [ 112 0x0 5, 0x00, 0x00, 0x00, 0x03132 0x06, 0x00, 0x00, 0x00, 0x03 113 133 ], 114 134 [ … … 117 137 testSerialization(true, 118 138 [ 119 0x0 5, 0x00, 0x00, 0x00, 0x09139 0x06, 0x00, 0x00, 0x00, 0x09 120 140 ], 121 141 [ … … 124 144 testSerialization(false, 125 145 [ 126 0x0 5, 0x00, 0x00, 0x00, 0x08146 0x06, 0x00, 0x00, 0x00, 0x08 127 147 ], 128 148 [ … … 131 151 testSerialization(new Array(100), 132 152 [ 133 0x0 5, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00,153 0x06, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00, 134 154 0x00, 0xff, 0xff, 0xff, 0xff 135 155 ], … … 140 160 testSerialization(10, 141 161 [ 142 0x0 5, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00,162 0x06, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00, 143 163 0x00 144 164 ], … … 149 169 testSerialization(-10, 150 170 [ 151 0x0 5, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff,171 0x06, 0x00, 0x00, 0x00, 0x05, 0xf6, 0xff, 0xff, 152 172 0xff 153 173 ], … … 158 178 testSerialization(Math.pow(2,30), 159 179 [ 160 0x0 5, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,180 0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 161 181 0x40 162 182 ], … … 167 187 testSerialization(Math.pow(2,55), 168 188 [ 169 0x0 5, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,189 0x06, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 170 190 0x00, 0x00, 0x00, 0x60, 0x43, 171 191 ], … … 176 196 testSerialization(1.23, 177 197 [ 178 0x0 5, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1,198 0x06, 0x00, 0x00, 0x00, 0x0a, 0xae, 0x47, 0xe1, 179 199 0x7a, 0x14, 0xae, 0xf3, 0x3f 180 200 ], … … 185 205 testSerialization("", 186 206 [ 187 0x0 5, 0x00, 0x00, 0x00, 0x11207 0x06, 0x00, 0x00, 0x00, 0x11 188 208 ], 189 209 [ … … 192 212 testSerialization("abc", 193 213 [ 194 0x0 5, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00,195 0x 00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00214 0x06, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00, 215 0x80, 0x61, 0x62, 0x63 196 216 ], 197 217 [ … … 201 221 testSerialization({integer: 123}, 202 222 [ 203 0x0 5, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,204 0x 00, 0x69, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x65,205 0x0 0, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x05,206 0x 7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff223 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 207 227 ], 208 228 [ … … 214 234 testSerialization({string: "str"}, 215 235 [ 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 221 240 ], 222 241 [ … … 229 248 testSerialization({list: [1,2,3]}, 230 249 [ 231 0x0 5, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,232 0x 00, 0x6c, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74,233 0x00, 0x0 1, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,234 0x00, 0x00, 0x0 7, 0x01, 0x00, 0x00, 0x00, 0x05,235 0x02, 0x00, 0x00, 0x00, 0x0 2, 0x00, 0x00, 0x00,236 0x0 5, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,237 0xff , 0xff, 0xff, 0xff, 0xff250 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 238 257 ], 239 258 [ … … 248 267 testSerialization(null, 249 268 [ 250 0x0 5, 0x00, 0x00, 0x00, 0x04269 0x06, 0x00, 0x00, 0x00, 0x04 251 270 ], 252 271 [ … … 255 274 testSerialization(/abc/, 256 275 [ 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 260 278 ], 261 279 [ … … 270 288 testSerialization(outerObject, 271 289 [ 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 282 297 ], 283 298 [ … … 295 310 testSerialization(innerObject, 296 311 [ 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 302 316 ], 303 317 [ … … 312 326 testSerialization(unicodeObject, 313 327 [ 314 0x0 5, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,315 0x 00, 0x61, 0x00, 0x10, 0xfe, 0xff, 0xff, 0xff,316 0x0 0, 0x01, 0x00, 0x00, 0x00, 0x75, 0x00, 0x10,317 0x0 2, 0x00, 0x00, 0x00, 0xb1, 0x03, 0xb2, 0x03,318 0x0 1, 0x00, 0x00, 0x00, 0x64, 0x00, 0x05, 0x2a,319 0x 00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff328 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 320 334 ], 321 335 [ … … 330 344 testSerialization(unicodeObject, 331 345 [ 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 339 352 ], 340 353 [ … … 356 369 testSerialization(arrayObject, 357 370 [ 358 0x0 5, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,371 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 359 372 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, 366 378 0xff, 0xff 367 379 ]); … … 371 383 testSerialization(arrayObject, 372 384 [ 373 0x0 5, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,385 0x06, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 374 386 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, 380 391 0x08, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x05, 0x7b, 381 392 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x01, 382 393 0x05, 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 383 0x 00, 0x04, 0xff, 0xff, 0xff, 0xff394 0x80, 0x04, 0xff, 0xff, 0xff, 0xff 384 395 ]); 385 396 … … 393 404 testSerialization(mapObject, 394 405 [ 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 406 415 ]); 407 416 … … 416 425 testSerialization(setObject, 417 426 [ 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 426 434 ]); 427 435 -
trunk/Source/WebCore/ChangeLog
r190837 r190838 1 2015-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 1 32 2015-10-10 Dan Bernstein <mitz@apple.com> 2 33 -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r190794 r190838 248 248 * Version 4. added support for serializing non-index properties of arrays. 249 249 * Version 5. added support for Map and Set types. 250 * Version 6. added support for 8-bit strings. 250 251 */ 251 static const unsigned CurrentVersion = 5;252 static const unsigned CurrentVersion = 6; 252 253 static const unsigned TerminatorTag = 0xFFFFFFFF; 253 254 static const unsigned StringPoolTag = 0xFFFFFFFE; 254 255 static const unsigned NonIndexPropertiesTag = 0xFFFFFFFD; 256 257 // The high bit of a StringData's length determines the character size. 258 static const unsigned StringDataIs8BitFlag = 0x80000000; 255 259 256 260 /* … … 319 323 * StringData :- 320 324 * StringPoolTag <cpIndex:IndexType> 321 * (not (TerminatorTag | StringPoolTag))< length:uint32_t><characters:UChar{length}> // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed325 * (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 322 326 * 323 327 * File :- … … 455 459 } 456 460 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 470 461 template <> bool writeLittleEndian<uint8_t>(Vector<uint8_t>& buffer, const uint8_t* values, uint32_t length) 471 462 { … … 492 483 } 493 484 writeLittleEndian<uint8_t>(out, StringTag); 485 if (s.is8Bit()) { 486 writeLittleEndian(out, s.length() | StringDataIs8BitFlag); 487 return writeLittleEndian(out, s.characters8(), s.length()); 488 } 494 489 writeLittleEndian(out, s.length()); 495 if (s.is8Bit())496 return writeLittleEndianUInt16(out, s.characters8(), s.length());497 490 return writeLittleEndian(out, s.characters16(), s.length()); 498 491 } … … 994 987 unsigned length = str.length(); 995 988 996 // This condition is unlikely to happen as they would imply an ~8gb997 // string but we should guard against it anyway998 if (length >= StringPoolTag) {999 fail();1000 return;1001 }1002 1003 989 // Guard against overflow 1004 990 if (length > (std::numeric_limits<uint32_t>::max() - sizeof(uint32_t)) / sizeof(UChar)) { … … 1007 993 } 1008 994 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)) 1012 1004 fail(); 1013 1005 return; … … 1478 1470 return String(); 1479 1471 uint32_t length; 1480 if (!readLittleEndian(ptr, end, length) || length >= StringPoolTag)1472 if (!readLittleEndian(ptr, end, length)) 1481 1473 return String(); 1474 bool is8Bit = length & StringDataIs8BitFlag; 1475 length &= ~StringDataIs8BitFlag; 1482 1476 String str; 1483 if (!readString(ptr, end, str, length ))1477 if (!readString(ptr, end, str, length, is8Bit)) 1484 1478 return String(); 1485 return String(str.impl());1479 return str; 1486 1480 } 1487 1481 … … 1663 1657 } 1664 1658 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) 1666 1660 { 1667 1661 if (length >= std::numeric_limits<int32_t>::max() / sizeof(UChar)) 1668 1662 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 } 1669 1671 1670 1672 unsigned size = length * sizeof(UChar); … … 1718 1720 return true; 1719 1721 } 1722 bool is8Bit = length & StringDataIs8BitFlag; 1723 length &= ~StringDataIs8BitFlag; 1720 1724 String str; 1721 if (!readString(m_ptr, m_end, str, length )) {1725 if (!readString(m_ptr, m_end, str, length, is8Bit)) { 1722 1726 fail(); 1723 1727 return false;
Note: See TracChangeset
for help on using the changeset viewer.