OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 append(NumberTag); | 388 append(NumberTag); |
389 doWriteNumber(number); | 389 doWriteNumber(number); |
390 } | 390 } |
391 | 391 |
392 void writeNumberObject(double number) | 392 void writeNumberObject(double number) |
393 { | 393 { |
394 append(NumberObjectTag); | 394 append(NumberObjectTag); |
395 doWriteNumber(number); | 395 doWriteNumber(number); |
396 } | 396 } |
397 | 397 |
398 void writeBlob(const String& url, const String& type, unsigned long long siz e) | 398 void writeBlob(const String& uuid, const String& type, unsigned long long si ze) |
399 { | 399 { |
400 append(BlobTag); | 400 append(BlobTag); |
401 doWriteWebCoreString(url); | 401 doWriteWebCoreString(uuid); |
402 doWriteWebCoreString(type); | 402 doWriteWebCoreString(type); |
403 doWriteUint64(size); | 403 doWriteUint64(size); |
404 } | 404 } |
405 | 405 |
406 void writeDOMFileSystem(int type, const String& name, const String& url) | 406 void writeDOMFileSystem(int type, const String& name, const String& url) |
407 { | 407 { |
408 append(DOMFileSystemTag); | 408 append(DOMFileSystemTag); |
409 doWriteUint32(type); | 409 doWriteUint32(type); |
410 doWriteWebCoreString(name); | 410 doWriteWebCoreString(name); |
411 doWriteWebCoreString(url); | 411 doWriteWebCoreString(url); |
412 } | 412 } |
413 | 413 |
414 void writeFile(const String& path, const String& url, const String& type) | 414 void writeFile(const File& file) |
415 { | 415 { |
416 append(FileTag); | 416 append(FileTag); |
417 doWriteWebCoreString(path); | 417 doWriteFile(file); |
418 doWriteWebCoreString(url); | |
419 doWriteWebCoreString(type); | |
420 } | 418 } |
421 | 419 |
422 void writeFileList(const FileList& fileList) | 420 void writeFileList(const FileList& fileList) |
423 { | 421 { |
424 append(FileListTag); | 422 append(FileListTag); |
425 uint32_t length = fileList.length(); | 423 uint32_t length = fileList.length(); |
426 doWriteUint32(length); | 424 doWriteUint32(length); |
427 for (unsigned i = 0; i < length; ++i) { | 425 for (unsigned i = 0; i < length; ++i) |
428 doWriteWebCoreString(fileList.item(i)->path()); | 426 doWriteFile(*fileList.item(i)); |
429 doWriteWebCoreString(fileList.item(i)->url().string()); | |
430 doWriteWebCoreString(fileList.item(i)->type()); | |
431 } | |
432 } | 427 } |
433 | 428 |
434 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 429 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
435 { | 430 { |
436 append(ArrayBufferTag); | 431 append(ArrayBufferTag); |
437 doWriteArrayBuffer(arrayBuffer); | 432 doWriteArrayBuffer(arrayBuffer); |
438 } | 433 } |
439 | 434 |
440 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 435 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) |
441 { | 436 { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 | 551 |
557 void writeGenerateFreshDenseArray(uint32_t length) | 552 void writeGenerateFreshDenseArray(uint32_t length) |
558 { | 553 { |
559 append(GenerateFreshDenseArrayTag); | 554 append(GenerateFreshDenseArrayTag); |
560 doWriteUint32(length); | 555 doWriteUint32(length); |
561 } | 556 } |
562 | 557 |
563 v8::Isolate* getIsolate() { return m_isolate; } | 558 v8::Isolate* getIsolate() { return m_isolate; } |
564 | 559 |
565 private: | 560 private: |
561 void doWriteFile(const File& file) | |
562 { | |
563 doWriteWebCoreString(file.path()); | |
564 doWriteWebCoreString(file.uuid()); | |
565 doWriteWebCoreString(file.type()); | |
566 } | |
567 | |
566 void doWriteArrayBuffer(const ArrayBuffer& arrayBuffer) | 568 void doWriteArrayBuffer(const ArrayBuffer& arrayBuffer) |
567 { | 569 { |
568 uint32_t byteLength = arrayBuffer.byteLength(); | 570 uint32_t byteLength = arrayBuffer.byteLength(); |
569 doWriteUint32(byteLength); | 571 doWriteUint32(byteLength); |
570 append(static_cast<const uint8_t*>(arrayBuffer.data()), byteLength); | 572 append(static_cast<const uint8_t*>(arrayBuffer.data()), byteLength); |
571 } | 573 } |
572 | 574 |
573 void doWriteString(const char* data, int length) | 575 void doWriteString(const char* data, int length) |
574 { | 576 { |
575 doWriteUint32(static_cast<uint32_t>(length)); | 577 doWriteUint32(static_cast<uint32_t>(length)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 public: | 697 public: |
696 enum Status { | 698 enum Status { |
697 Success, | 699 Success, |
698 InputError, | 700 InputError, |
699 DataCloneError, | 701 DataCloneError, |
700 InvalidStateError, | 702 InvalidStateError, |
701 JSException, | 703 JSException, |
702 JSFailure | 704 JSFailure |
703 }; | 705 }; |
704 | 706 |
705 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch, v8::Isolate* is olate) | 707 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, v8::I solate* isolate) |
706 : m_writer(writer) | 708 : m_writer(writer) |
707 , m_tryCatch(tryCatch) | 709 , m_tryCatch(tryCatch) |
708 , m_depth(0) | 710 , m_depth(0) |
709 , m_execDepth(0) | 711 , m_execDepth(0) |
710 , m_status(Success) | 712 , m_status(Success) |
711 , m_nextObjectReference(0) | 713 , m_nextObjectReference(0) |
712 , m_blobURLs(blobURLs) | 714 , m_blobDataHandles(blobDataHandles) |
713 , m_isolate(isolate) | 715 , m_isolate(isolate) |
714 { | 716 { |
715 ASSERT(!tryCatch.HasCaught()); | 717 ASSERT(!tryCatch.HasCaught()); |
716 if (messagePorts) { | 718 if (messagePorts) { |
717 for (size_t i = 0; i < messagePorts->size(); i++) | 719 for (size_t i = 0; i < messagePorts->size(); i++) |
718 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), m_writer.getIsolate()), i); | 720 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), m_writer.getIsolate()), i); |
719 } | 721 } |
720 if (arrayBuffers) { | 722 if (arrayBuffers) { |
721 for (size_t i = 0; i < arrayBuffers->size(); i++) { | 723 for (size_t i = 0; i < arrayBuffers->size(); i++) { |
722 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers-> at(i).get(), m_writer.getIsolate()); | 724 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers-> at(i).get(), m_writer.getIsolate()); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 { | 1072 { |
1071 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >(); | 1073 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >(); |
1072 m_writer.writeBooleanObject(booleanObject->BooleanValue()); | 1074 m_writer.writeBooleanObject(booleanObject->BooleanValue()); |
1073 } | 1075 } |
1074 | 1076 |
1075 void writeBlob(v8::Handle<v8::Value> value) | 1077 void writeBlob(v8::Handle<v8::Value> value) |
1076 { | 1078 { |
1077 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1079 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); |
1078 if (!blob) | 1080 if (!blob) |
1079 return; | 1081 return; |
1080 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); | 1082 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); |
1081 m_blobURLs.append(blob->url().string()); | 1083 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); |
1082 } | 1084 } |
1083 | 1085 |
1084 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1086 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
1085 { | 1087 { |
1086 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1088 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); |
1087 if (!fs) | 1089 if (!fs) |
1088 return 0; | 1090 return 0; |
1089 if (!fs->clonable()) | 1091 if (!fs->clonable()) |
1090 return handleError(DataCloneError, next); | 1092 return handleError(DataCloneError, next); |
1091 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); | 1093 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); |
1092 return 0; | 1094 return 0; |
1093 } | 1095 } |
1094 | 1096 |
1095 void writeFile(v8::Handle<v8::Value> value) | 1097 void writeFile(v8::Handle<v8::Value> value) |
1096 { | 1098 { |
1097 File* file = V8File::toNative(value.As<v8::Object>()); | 1099 File* file = V8File::toNative(value.As<v8::Object>()); |
1098 if (!file) | 1100 if (!file) |
1099 return; | 1101 return; |
1100 m_writer.writeFile(file->path(), file->url().string(), file->type()); | 1102 m_writer.writeFile(*file); |
1101 m_blobURLs.append(file->url().string()); | 1103 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); |
1102 } | 1104 } |
1103 | 1105 |
1104 void writeFileList(v8::Handle<v8::Value> value) | 1106 void writeFileList(v8::Handle<v8::Value> value) |
1105 { | 1107 { |
1106 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1108 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
1107 if (!fileList) | 1109 if (!fileList) |
1108 return; | 1110 return; |
1109 m_writer.writeFileList(*fileList); | 1111 m_writer.writeFileList(*fileList); |
1110 unsigned length = fileList->length(); | 1112 unsigned length = fileList->length(); |
1111 for (unsigned i = 0; i < length; ++i) | 1113 for (unsigned i = 0; i < length; ++i) |
1112 m_blobURLs.append(fileList->item(i)->url().string()); | 1114 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)-> blobDataHandle()); |
1113 } | 1115 } |
1114 | 1116 |
1115 void writeImageData(v8::Handle<v8::Value> value) | 1117 void writeImageData(v8::Handle<v8::Value> value) |
1116 { | 1118 { |
1117 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1119 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); |
1118 if (!imageData) | 1120 if (!imageData) |
1119 return; | 1121 return; |
1120 Uint8ClampedArray* pixelArray = imageData->data(); | 1122 Uint8ClampedArray* pixelArray = imageData->data(); |
1121 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); | 1123 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); |
1122 } | 1124 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1221 Writer& m_writer; | 1223 Writer& m_writer; |
1222 v8::TryCatch& m_tryCatch; | 1224 v8::TryCatch& m_tryCatch; |
1223 int m_depth; | 1225 int m_depth; |
1224 int m_execDepth; | 1226 int m_execDepth; |
1225 Status m_status; | 1227 Status m_status; |
1226 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 1228 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
1227 ObjectPool m_objectPool; | 1229 ObjectPool m_objectPool; |
1228 ObjectPool m_transferredMessagePorts; | 1230 ObjectPool m_transferredMessagePorts; |
1229 ObjectPool m_transferredArrayBuffers; | 1231 ObjectPool m_transferredArrayBuffers; |
1230 uint32_t m_nextObjectReference; | 1232 uint32_t m_nextObjectReference; |
1231 Vector<String>& m_blobURLs; | 1233 BlobDataHandleMap& m_blobDataHandles; |
1232 v8::Isolate* m_isolate; | 1234 v8::Isolate* m_isolate; |
1233 }; | 1235 }; |
1234 | 1236 |
1235 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next) | 1237 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next) |
1236 { | 1238 { |
1237 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { | 1239 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { |
1238 m_writer.writeNull(); | 1240 m_writer.writeNull(); |
1239 return 0; | 1241 return 0; |
1240 } | 1242 } |
1241 m_writer.writeReferenceCount(m_nextObjectReference); | 1243 m_writer.writeReferenceCount(m_nextObjectReference); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 virtual bool newObject() = 0; | 1333 virtual bool newObject() = 0; |
1332 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; | 1334 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; |
1333 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0; | 1335 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0; |
1334 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; | 1336 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; |
1335 }; | 1337 }; |
1336 | 1338 |
1337 // Reader is responsible for deserializing primitive types and | 1339 // Reader is responsible for deserializing primitive types and |
1338 // restoring information about saved objects of composite types. | 1340 // restoring information about saved objects of composite types. |
1339 class Reader { | 1341 class Reader { |
1340 public: | 1342 public: |
1341 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate) | 1343 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobD ataHandleMap& blobDataHandles) |
1342 : m_buffer(buffer) | 1344 : m_buffer(buffer) |
1343 , m_length(length) | 1345 , m_length(length) |
1344 , m_position(0) | 1346 , m_position(0) |
1345 , m_version(0) | 1347 , m_version(0) |
1346 , m_isolate(isolate) | 1348 , m_isolate(isolate) |
1349 , m_blobDataHandles(blobDataHandles) | |
1347 { | 1350 { |
1348 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); | 1351 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); |
1349 ASSERT(length >= 0); | 1352 ASSERT(length >= 0); |
1350 } | 1353 } |
1351 | 1354 |
1352 bool isEof() const { return m_position >= m_length; } | 1355 bool isEof() const { return m_position >= m_length; } |
1353 | 1356 |
1354 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) | 1357 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) |
1355 { | 1358 { |
1356 SerializationTag tag; | 1359 SerializationTag tag; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1846 return false; | 1849 return false; |
1847 uint32_t flags; | 1850 uint32_t flags; |
1848 if (!doReadUint32(&flags)) | 1851 if (!doReadUint32(&flags)) |
1849 return false; | 1852 return false; |
1850 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); | 1853 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); |
1851 return true; | 1854 return true; |
1852 } | 1855 } |
1853 | 1856 |
1854 bool readBlob(v8::Handle<v8::Value>* value) | 1857 bool readBlob(v8::Handle<v8::Value>* value) |
1855 { | 1858 { |
1856 String url; | 1859 if (m_version < 3) |
1860 return false; | |
1861 String uuid; | |
1857 String type; | 1862 String type; |
1858 uint64_t size; | 1863 uint64_t size; |
1859 if (!readWebCoreString(&url)) | 1864 if (!readWebCoreString(&uuid)) |
1860 return false; | 1865 return false; |
1861 if (!readWebCoreString(&type)) | 1866 if (!readWebCoreString(&type)) |
1862 return false; | 1867 return false; |
1863 if (!doReadUint64(&size)) | 1868 if (!doReadUint64(&size)) |
1864 return false; | 1869 return false; |
1865 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s ize); | 1870 RefPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(uuid, type, s ize)); |
1866 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); | 1871 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); |
1867 return true; | 1872 return true; |
1868 } | 1873 } |
1869 | 1874 |
1870 bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 1875 bool readDOMFileSystem(v8::Handle<v8::Value>* value) |
1871 { | 1876 { |
1872 uint32_t type; | 1877 uint32_t type; |
1873 String name; | 1878 String name; |
1874 String url; | 1879 String url; |
1875 if (!doReadUint32(&type)) | 1880 if (!doReadUint32(&type)) |
1876 return false; | 1881 return false; |
1877 if (!readWebCoreString(&name)) | 1882 if (!readWebCoreString(&name)) |
1878 return false; | 1883 return false; |
1879 if (!readWebCoreString(&url)) | 1884 if (!readWebCoreString(&url)) |
1880 return false; | 1885 return false; |
1881 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur l)); | 1886 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur l)); |
1882 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 1887 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); |
1883 return true; | 1888 return true; |
1884 } | 1889 } |
1885 | 1890 |
1886 bool readFile(v8::Handle<v8::Value>* value) | 1891 bool readFile(v8::Handle<v8::Value>* value) |
1887 { | 1892 { |
1888 String path; | 1893 RefPtr<File> file = doReadFileHelper(); |
1889 String url; | 1894 if (!file) |
1890 String type; | |
1891 if (!readWebCoreString(&path)) | |
1892 return false; | 1895 return false; |
1893 if (!readWebCoreString(&url)) | 1896 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); |
1894 return false; | |
1895 if (!readWebCoreString(&type)) | |
1896 return false; | |
1897 PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), t ype); | |
1898 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate); | |
1899 return true; | 1897 return true; |
1900 } | 1898 } |
1901 | 1899 |
1902 bool readFileList(v8::Handle<v8::Value>* value) | 1900 bool readFileList(v8::Handle<v8::Value>* value) |
1903 { | 1901 { |
1902 if (m_version < 3) | |
1903 return false; | |
1904 uint32_t length; | 1904 uint32_t length; |
1905 if (!doReadUint32(&length)) | 1905 if (!doReadUint32(&length)) |
1906 return false; | 1906 return false; |
1907 PassRefPtr<FileList> fileList = FileList::create(); | 1907 RefPtr<FileList> fileList = FileList::create(); |
1908 for (unsigned i = 0; i < length; ++i) { | 1908 for (unsigned i = 0; i < length; ++i) |
1909 String path; | 1909 fileList->append(doReadFileHelper()); |
jsbell
2013/10/02 22:24:41
If doReadFileHelper() returns 0, should this retur
michaeln
2013/10/03 00:22:24
Ooops... thnx... done!
| |
1910 String urlString; | 1910 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
1911 String type; | |
1912 if (!readWebCoreString(&path)) | |
1913 return false; | |
1914 if (!readWebCoreString(&urlString)) | |
1915 return false; | |
1916 if (!readWebCoreString(&type)) | |
1917 return false; | |
1918 fileList->append(File::create(path, KURL(ParsedURLString, urlString) , type)); | |
1919 } | |
1920 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); | |
1921 return true; | 1911 return true; |
1922 } | 1912 } |
1923 | 1913 |
1914 PassRefPtr<File> doReadFileHelper() | |
1915 { | |
1916 if (m_version < 3) | |
1917 return 0; | |
1918 String path; | |
1919 String uuid; | |
1920 String type; | |
1921 if (!readWebCoreString(&path)) | |
1922 return 0; | |
1923 if (!readWebCoreString(&uuid)) | |
1924 return 0; | |
1925 if (!readWebCoreString(&type)) | |
1926 return 0; | |
1927 return File::create(path, getOrCreateBlobDataHandle(uuid, type)); | |
1928 } | |
1929 | |
1924 template<class T> | 1930 template<class T> |
1925 bool doReadUintHelper(T* value) | 1931 bool doReadUintHelper(T* value) |
1926 { | 1932 { |
1927 *value = 0; | 1933 *value = 0; |
1928 uint8_t currentByte; | 1934 uint8_t currentByte; |
1929 int shift = 0; | 1935 int shift = 0; |
1930 do { | 1936 do { |
1931 if (m_position >= m_length) | 1937 if (m_position >= m_length) |
1932 return false; | 1938 return false; |
1933 currentByte = m_buffer[m_position++]; | 1939 currentByte = m_buffer[m_position++]; |
(...skipping 16 matching lines...) Expand all Loading... | |
1950 bool doReadNumber(double* number) | 1956 bool doReadNumber(double* number) |
1951 { | 1957 { |
1952 if (m_position + sizeof(double) > m_length) | 1958 if (m_position + sizeof(double) > m_length) |
1953 return false; | 1959 return false; |
1954 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number); | 1960 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number); |
1955 for (unsigned i = 0; i < sizeof(double); ++i) | 1961 for (unsigned i = 0; i < sizeof(double); ++i) |
1956 numberAsByteArray[i] = m_buffer[m_position++]; | 1962 numberAsByteArray[i] = m_buffer[m_position++]; |
1957 return true; | 1963 return true; |
1958 } | 1964 } |
1959 | 1965 |
1966 PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, con st String& type, long long size = -1) | |
1967 { | |
1968 // The containing ssv may have a BDH for this uuid if this ssv is just b eing | |
1969 // passed from main to worker thread (for example). We use those values when creating | |
1970 // the new blob instead of cons'ing up a new BDH. | |
1971 // | |
1972 // FIXME: Maybe we should require that it work that way where the ssv mu st have a BDH for any | |
jsbell
2013/10/02 22:24:41
+1 to this.
Do any of our current tests rely on t
michaeln
2013/10/03 00:22:24
I pretty sure they do. Any test that involves send
| |
1973 // blobs it comes across during deserialization. Would require callers t o explicitly populate | |
1974 // the collection of BDH's for blobs to work, which would encourage life times to be considered | |
1975 // when passing ssv's around cross process. At present, we get 'lucky' i n some cases because | |
1976 // the blob in the src process happens to still exist at the time the de st process is deserializing. | |
1977 // For example in sharedWorker.postMesssage(...). | |
1978 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | |
1979 if (it != m_blobDataHandles.end()) { | |
1980 // make assertions about type and size? | |
1981 return it->value; | |
1982 } | |
1983 return BlobDataHandle::create(uuid, type, size); | |
1984 } | |
1985 | |
1960 const uint8_t* m_buffer; | 1986 const uint8_t* m_buffer; |
1961 const unsigned m_length; | 1987 const unsigned m_length; |
1962 unsigned m_position; | 1988 unsigned m_position; |
1963 uint32_t m_version; | 1989 uint32_t m_version; |
1964 v8::Isolate* m_isolate; | 1990 v8::Isolate* m_isolate; |
1991 const BlobDataHandleMap& m_blobDataHandles; | |
1965 }; | 1992 }; |
1966 | 1993 |
1967 | 1994 |
1968 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 1995 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
1969 | 1996 |
1970 class Deserializer : public CompositeCreator { | 1997 class Deserializer : public CompositeCreator { |
1971 public: | 1998 public: |
1972 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) | 1999 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) |
1973 : m_reader(reader) | 2000 : m_reader(reader) |
1974 , m_transferredMessagePorts(messagePorts) | 2001 , m_transferredMessagePorts(messagePorts) |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2423 } | 2450 } |
2424 | 2451 |
2425 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is olate* isolate, ExceptionPolicy policy) | 2452 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is olate* isolate, ExceptionPolicy policy) |
2426 : m_externallyAllocatedMemory(0) | 2453 : m_externallyAllocatedMemory(0) |
2427 { | 2454 { |
2428 didThrow = false; | 2455 didThrow = false; |
2429 Writer writer(isolate); | 2456 Writer writer(isolate); |
2430 Serializer::Status status; | 2457 Serializer::Status status; |
2431 { | 2458 { |
2432 v8::TryCatch tryCatch; | 2459 v8::TryCatch tryCatch; |
2433 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr yCatch, isolate); | 2460 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand les, tryCatch, isolate); |
2434 status = serializer.serialize(value); | 2461 status = serializer.serialize(value); |
2435 if (status == Serializer::JSException) { | 2462 if (status == Serializer::JSException) { |
2436 didThrow = true; | 2463 didThrow = true; |
2437 // If there was a JS exception thrown, re-throw it. | 2464 // If there was a JS exception thrown, re-throw it. |
2438 if (policy == ThrowExceptions) | 2465 if (policy == ThrowExceptions) |
2439 tryCatch.ReThrow(); | 2466 tryCatch.ReThrow(); |
2440 return; | 2467 return; |
2441 } | 2468 } |
2442 } | 2469 } |
2443 switch (status) { | 2470 switch (status) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2487 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts) | 2514 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts) |
2488 { | 2515 { |
2489 if (!m_data.impl()) | 2516 if (!m_data.impl()) |
2490 return v8NullWithCheck(isolate); | 2517 return v8NullWithCheck(isolate); |
2491 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2518 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); |
2492 m_data.ensure16Bit(); | 2519 m_data.ensure16Bit(); |
2493 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 2520 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
2494 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 2521 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
2495 // information stored in m_data isn't even encoded in UTF-16. Instead, | 2522 // information stored in m_data isn't even encoded in UTF-16. Instead, |
2496 // unicode characters are encoded as UTF-8 with two code units per UChar. | 2523 // unicode characters are encoded as UTF-8 with two code units per UChar. |
2497 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate); | 2524 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate, m_blobDataHandles); |
2498 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); | 2525 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); |
2499 | 2526 |
2500 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. | 2527 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. |
2501 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. | 2528 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. |
2502 RefPtr<SerializedScriptValue> protect(this); | 2529 RefPtr<SerializedScriptValue> protect(this); |
2503 return deserializer.deserialize(); | 2530 return deserializer.deserialize(); |
2504 } | 2531 } |
2505 | 2532 |
2506 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt ate) | 2533 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt ate) |
2507 { | 2534 { |
(...skipping 17 matching lines...) Expand all Loading... | |
2525 // If the allocated memory was not registered before, then this class is lik ely | 2552 // If the allocated memory was not registered before, then this class is lik ely |
2526 // used in a context other then Worker's onmessage environment and the prese nce of | 2553 // used in a context other then Worker's onmessage environment and the prese nce of |
2527 // current v8 context is not guaranteed. Avoid calling v8 then. | 2554 // current v8 context is not guaranteed. Avoid calling v8 then. |
2528 if (m_externallyAllocatedMemory) { | 2555 if (m_externallyAllocatedMemory) { |
2529 ASSERT(v8::Isolate::GetCurrent()); | 2556 ASSERT(v8::Isolate::GetCurrent()); |
2530 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry); | 2557 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry); |
2531 } | 2558 } |
2532 } | 2559 } |
2533 | 2560 |
2534 } // namespace WebCore | 2561 } // namespace WebCore |
OLD | NEW |