| 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 doWriteWebCoreString(type); | 386 doWriteWebCoreString(type); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void writeFileList(const FileList& fileList) | 389 void writeFileList(const FileList& fileList) |
| 390 { | 390 { |
| 391 append(FileListTag); | 391 append(FileListTag); |
| 392 uint32_t length = fileList.length(); | 392 uint32_t length = fileList.length(); |
| 393 doWriteUint32(length); | 393 doWriteUint32(length); |
| 394 for (unsigned i = 0; i < length; ++i) { | 394 for (unsigned i = 0; i < length; ++i) { |
| 395 doWriteWebCoreString(fileList.item(i)->path()); | 395 doWriteWebCoreString(fileList.item(i)->path()); |
| 396 doWriteWebCoreString(fileList.item(i)->url().string()); | 396 doWriteWebCoreString(fileList.item(i)->uuid()); // TODO: bump versio
n numbers somewhere? |
| 397 doWriteWebCoreString(fileList.item(i)->type()); | 397 doWriteWebCoreString(fileList.item(i)->type()); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 401 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
| 402 { | 402 { |
| 403 append(ArrayBufferTag); | 403 append(ArrayBufferTag); |
| 404 doWriteArrayBuffer(arrayBuffer); | 404 doWriteArrayBuffer(arrayBuffer); |
| 405 } | 405 } |
| 406 | 406 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 public: | 620 public: |
| 621 enum Status { | 621 enum Status { |
| 622 Success, | 622 Success, |
| 623 InputError, | 623 InputError, |
| 624 DataCloneError, | 624 DataCloneError, |
| 625 InvalidStateError, | 625 InvalidStateError, |
| 626 JSException, | 626 JSException, |
| 627 JSFailure | 627 JSFailure |
| 628 }; | 628 }; |
| 629 | 629 |
| 630 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray*
arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch) | 630 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray*
arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch) |
| 631 : m_writer(writer) | 631 : m_writer(writer) |
| 632 , m_tryCatch(tryCatch) | 632 , m_tryCatch(tryCatch) |
| 633 , m_depth(0) | 633 , m_depth(0) |
| 634 , m_execDepth(0) | 634 , m_execDepth(0) |
| 635 , m_status(Success) | 635 , m_status(Success) |
| 636 , m_nextObjectReference(0) | 636 , m_nextObjectReference(0) |
| 637 , m_blobURLs(blobURLs) | 637 , m_blobDataHandles(blobDataHandles) |
| 638 { | 638 { |
| 639 ASSERT(!tryCatch.HasCaught()); | 639 ASSERT(!tryCatch.HasCaught()); |
| 640 if (messagePorts) { | 640 if (messagePorts) { |
| 641 for (size_t i = 0; i < messagePorts->size(); i++) | 641 for (size_t i = 0; i < messagePorts->size(); i++) |
| 642 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get
(), v8::Handle<v8::Object>(), m_writer.getIsolate()), i); | 642 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get
(), v8::Handle<v8::Object>(), m_writer.getIsolate()), i); |
| 643 } | 643 } |
| 644 if (arrayBuffers) { | 644 if (arrayBuffers) { |
| 645 for (size_t i = 0; i < arrayBuffers->size(); i++) { | 645 for (size_t i = 0; i < arrayBuffers->size(); i++) { |
| 646 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->
at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate()); | 646 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->
at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate()); |
| 647 // Coalesce multiple occurences of the same buffer to the first
index. | 647 // Coalesce multiple occurences of the same buffer to the first
index. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 { | 991 { |
| 992 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
>(); | 992 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
>(); |
| 993 m_writer.writeBooleanObject(booleanObject->BooleanValue()); | 993 m_writer.writeBooleanObject(booleanObject->BooleanValue()); |
| 994 } | 994 } |
| 995 | 995 |
| 996 void writeBlob(v8::Handle<v8::Value> value) | 996 void writeBlob(v8::Handle<v8::Value> value) |
| 997 { | 997 { |
| 998 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 998 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); |
| 999 if (!blob) | 999 if (!blob) |
| 1000 return; | 1000 return; |
| 1001 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); | 1001 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); |
| 1002 m_blobURLs.append(blob->url().string()); | 1002 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 #if ENABLE(FILE_SYSTEM) | 1005 #if ENABLE(FILE_SYSTEM) |
| 1006 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1006 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
| 1007 { | 1007 { |
| 1008 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1008 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); |
| 1009 if (!fs) | 1009 if (!fs) |
| 1010 return 0; | 1010 return 0; |
| 1011 if (!fs->clonable()) | 1011 if (!fs->clonable()) |
| 1012 return handleError(DataCloneError, next); | 1012 return handleError(DataCloneError, next); |
| 1013 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); | 1013 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); |
| 1014 return 0; | 1014 return 0; |
| 1015 } | 1015 } |
| 1016 #endif | 1016 #endif |
| 1017 | 1017 |
| 1018 void writeFile(v8::Handle<v8::Value> value) | 1018 void writeFile(v8::Handle<v8::Value> value) |
| 1019 { | 1019 { |
| 1020 File* file = V8File::toNative(value.As<v8::Object>()); | 1020 File* file = V8File::toNative(value.As<v8::Object>()); |
| 1021 if (!file) | 1021 if (!file) |
| 1022 return; | 1022 return; |
| 1023 m_writer.writeFile(file->path(), file->url().string(), file->type()); | 1023 m_writer.writeFile(file->path(), file->uuid(), file->type()); |
| 1024 m_blobURLs.append(file->url().string()); | 1024 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 void writeFileList(v8::Handle<v8::Value> value) | 1027 void writeFileList(v8::Handle<v8::Value> value) |
| 1028 { | 1028 { |
| 1029 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1029 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
| 1030 if (!fileList) | 1030 if (!fileList) |
| 1031 return; | 1031 return; |
| 1032 m_writer.writeFileList(*fileList); | 1032 m_writer.writeFileList(*fileList); |
| 1033 unsigned length = fileList->length(); | 1033 unsigned length = fileList->length(); |
| 1034 for (unsigned i = 0; i < length; ++i) | 1034 for (unsigned i = 0; i < length; ++i) |
| 1035 m_blobURLs.append(fileList->item(i)->url().string()); | 1035 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->
blobDataHandle()); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 void writeImageData(v8::Handle<v8::Value> value) | 1038 void writeImageData(v8::Handle<v8::Value> value) |
| 1039 { | 1039 { |
| 1040 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1040 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); |
| 1041 if (!imageData) | 1041 if (!imageData) |
| 1042 return; | 1042 return; |
| 1043 Uint8ClampedArray* pixelArray = imageData->data(); | 1043 Uint8ClampedArray* pixelArray = imageData->data(); |
| 1044 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); | 1044 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); |
| 1045 } | 1045 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 Writer& m_writer; | 1144 Writer& m_writer; |
| 1145 v8::TryCatch& m_tryCatch; | 1145 v8::TryCatch& m_tryCatch; |
| 1146 int m_depth; | 1146 int m_depth; |
| 1147 int m_execDepth; | 1147 int m_execDepth; |
| 1148 Status m_status; | 1148 Status m_status; |
| 1149 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 1149 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
| 1150 ObjectPool m_objectPool; | 1150 ObjectPool m_objectPool; |
| 1151 ObjectPool m_transferredMessagePorts; | 1151 ObjectPool m_transferredMessagePorts; |
| 1152 ObjectPool m_transferredArrayBuffers; | 1152 ObjectPool m_transferredArrayBuffers; |
| 1153 uint32_t m_nextObjectReference; | 1153 uint32_t m_nextObjectReference; |
| 1154 Vector<String>& m_blobURLs; | 1154 BlobDataHandleMap& m_blobDataHandles; |
| 1155 }; | 1155 }; |
| 1156 | 1156 |
| 1157 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
eBase* next) | 1157 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
eBase* next) |
| 1158 { | 1158 { |
| 1159 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { | 1159 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { |
| 1160 m_writer.writeNull(); | 1160 m_writer.writeNull(); |
| 1161 return 0; | 1161 return 0; |
| 1162 } | 1162 } |
| 1163 m_writer.writeReferenceCount(m_nextObjectReference); | 1163 m_writer.writeReferenceCount(m_nextObjectReference); |
| 1164 uint32_t objectReference; | 1164 uint32_t objectReference; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 virtual bool newObject() = 0; | 1254 virtual bool newObject() = 0; |
| 1255 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*)
= 0; | 1255 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*)
= 0; |
| 1256 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Handle<v8::Value>*) = 0; | 1256 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Handle<v8::Value>*) = 0; |
| 1257 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Handle<v8::Value>*) = 0; | 1257 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Handle<v8::Value>*) = 0; |
| 1258 }; | 1258 }; |
| 1259 | 1259 |
| 1260 // Reader is responsible for deserializing primitive types and | 1260 // Reader is responsible for deserializing primitive types and |
| 1261 // restoring information about saved objects of composite types. | 1261 // restoring information about saved objects of composite types. |
| 1262 class Reader { | 1262 class Reader { |
| 1263 public: | 1263 public: |
| 1264 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate) | 1264 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobDa
taHandleMap& blobDataHandles) |
| 1265 : m_buffer(buffer) | 1265 : m_buffer(buffer) |
| 1266 , m_length(length) | 1266 , m_length(length) |
| 1267 , m_position(0) | 1267 , m_position(0) |
| 1268 , m_version(0) | 1268 , m_version(0) |
| 1269 , m_isolate(isolate) | 1269 , m_isolate(isolate) |
| 1270 , m_blobDataHandles(blobDataHandles) |
| 1270 { | 1271 { |
| 1271 ASSERT(length >= 0); | 1272 ASSERT(length >= 0); |
| 1272 } | 1273 } |
| 1273 | 1274 |
| 1274 bool isEof() const { return m_position >= m_length; } | 1275 bool isEof() const { return m_position >= m_length; } |
| 1275 | 1276 |
| 1276 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) | 1277 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) |
| 1277 { | 1278 { |
| 1278 SerializationTag tag; | 1279 SerializationTag tag; |
| 1279 if (!readTag(&tag)) | 1280 if (!readTag(&tag)) |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 return false; | 1755 return false; |
| 1755 uint32_t flags; | 1756 uint32_t flags; |
| 1756 if (!doReadUint32(&flags)) | 1757 if (!doReadUint32(&flags)) |
| 1757 return false; | 1758 return false; |
| 1758 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx
p::Flags>(flags)); | 1759 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx
p::Flags>(flags)); |
| 1759 return true; | 1760 return true; |
| 1760 } | 1761 } |
| 1761 | 1762 |
| 1762 bool readBlob(v8::Handle<v8::Value>* value) | 1763 bool readBlob(v8::Handle<v8::Value>* value) |
| 1763 { | 1764 { |
| 1764 String url; | 1765 String uuid; |
| 1765 String type; | 1766 String type; |
| 1766 uint64_t size; | 1767 uint64_t size; |
| 1767 if (!readWebCoreString(&url)) | 1768 if (!readWebCoreString(&uuid)) |
| 1768 return false; | 1769 return false; |
| 1769 if (!readWebCoreString(&type)) | 1770 if (!readWebCoreString(&type)) |
| 1770 return false; | 1771 return false; |
| 1771 if (!doReadUint64(&size)) | 1772 if (!doReadUint64(&size)) |
| 1772 return false; | 1773 return false; |
| 1773 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s
ize); | 1774 PassRefPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(uuid, typ
e, size)); |
| 1774 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); | 1775 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); |
| 1775 return true; | 1776 return true; |
| 1776 } | 1777 } |
| 1777 | 1778 |
| 1778 #if ENABLE(FILE_SYSTEM) | 1779 #if ENABLE(FILE_SYSTEM) |
| 1779 bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 1780 bool readDOMFileSystem(v8::Handle<v8::Value>* value) |
| 1780 { | 1781 { |
| 1781 uint32_t type; | 1782 uint32_t type; |
| 1782 String name; | 1783 String name; |
| 1783 String url; | 1784 String url; |
| 1784 if (!doReadUint32(&type)) | 1785 if (!doReadUint32(&type)) |
| 1785 return false; | 1786 return false; |
| 1786 if (!readWebCoreString(&name)) | 1787 if (!readWebCoreString(&name)) |
| 1787 return false; | 1788 return false; |
| 1788 if (!readWebCoreString(&url)) | 1789 if (!readWebCoreString(&url)) |
| 1789 return false; | 1790 return false; |
| 1790 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
l), AsyncFileSystem::create()); | 1791 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
l), AsyncFileSystem::create()); |
| 1791 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 1792 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); |
| 1792 return true; | 1793 return true; |
| 1793 } | 1794 } |
| 1794 #endif | 1795 #endif |
| 1795 | 1796 |
| 1796 bool readFile(v8::Handle<v8::Value>* value) | 1797 bool readFile(v8::Handle<v8::Value>* value) |
| 1797 { | 1798 { |
| 1798 String path; | 1799 String path; |
| 1799 String url; | 1800 String uuid; |
| 1800 String type; | 1801 String type; |
| 1801 if (!readWebCoreString(&path)) | 1802 if (!readWebCoreString(&path)) |
| 1802 return false; | 1803 return false; |
| 1803 if (!readWebCoreString(&url)) | 1804 if (!readWebCoreString(&uuid)) |
| 1804 return false; | 1805 return false; |
| 1805 if (!readWebCoreString(&type)) | 1806 if (!readWebCoreString(&type)) |
| 1806 return false; | 1807 return false; |
| 1807 PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), t
ype); | 1808 PassRefPtr<File> file = File::create(path, getOrCreateBlobDataHandle(uui
d, type)); |
| 1808 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate); | 1809 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate); |
| 1809 return true; | 1810 return true; |
| 1810 } | 1811 } |
| 1811 | 1812 |
| 1812 bool readFileList(v8::Handle<v8::Value>* value) | 1813 bool readFileList(v8::Handle<v8::Value>* value) |
| 1813 { | 1814 { |
| 1814 uint32_t length; | 1815 uint32_t length; |
| 1815 if (!doReadUint32(&length)) | 1816 if (!doReadUint32(&length)) |
| 1816 return false; | 1817 return false; |
| 1817 PassRefPtr<FileList> fileList = FileList::create(); | 1818 PassRefPtr<FileList> fileList = FileList::create(); |
| 1818 for (unsigned i = 0; i < length; ++i) { | 1819 for (unsigned i = 0; i < length; ++i) { |
| 1819 String path; | 1820 String path; |
| 1820 String urlString; | 1821 String uuid; |
| 1821 String type; | 1822 String type; |
| 1822 if (!readWebCoreString(&path)) | 1823 if (!readWebCoreString(&path)) |
| 1823 return false; | 1824 return false; |
| 1824 if (!readWebCoreString(&urlString)) | 1825 if (!readWebCoreString(&uuid)) |
| 1825 return false; | 1826 return false; |
| 1826 if (!readWebCoreString(&type)) | 1827 if (!readWebCoreString(&type)) |
| 1827 return false; | 1828 return false; |
| 1828 fileList->append(File::create(path, KURL(ParsedURLString, urlString)
, type)); | 1829 fileList->append(File::create(path, getOrCreateBlobDataHandle(uuid,
type))); |
| 1829 } | 1830 } |
| 1830 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); | 1831 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); |
| 1831 return true; | 1832 return true; |
| 1832 } | 1833 } |
| 1833 | 1834 |
| 1834 template<class T> | 1835 template<class T> |
| 1835 bool doReadUintHelper(T* value) | 1836 bool doReadUintHelper(T* value) |
| 1836 { | 1837 { |
| 1837 *value = 0; | 1838 *value = 0; |
| 1838 uint8_t currentByte; | 1839 uint8_t currentByte; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1860 bool doReadNumber(double* number) | 1861 bool doReadNumber(double* number) |
| 1861 { | 1862 { |
| 1862 if (m_position + sizeof(double) > m_length) | 1863 if (m_position + sizeof(double) > m_length) |
| 1863 return false; | 1864 return false; |
| 1864 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number); | 1865 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number); |
| 1865 for (unsigned i = 0; i < sizeof(double); ++i) | 1866 for (unsigned i = 0; i < sizeof(double); ++i) |
| 1866 numberAsByteArray[i] = m_buffer[m_position++]; | 1867 numberAsByteArray[i] = m_buffer[m_position++]; |
| 1867 return true; | 1868 return true; |
| 1868 } | 1869 } |
| 1869 | 1870 |
| 1871 PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, con
st String& type, long long size = -1) |
| 1872 { |
| 1873 // The containing ssv may have a BDH for this uuid if this ssv is just b
eing |
| 1874 // passed from main to worker thread (for example). We use those values
when creating the |
| 1875 // new blob instead of cons'ing up a new BDH. |
| 1876 // |
| 1877 // FIXME: Maybe we should require that it work that way where the ssv mu
st have a BDH for any |
| 1878 // blobs it comes across during deserialization. Would require callers t
o explicitly populate |
| 1879 // the collection of BDH's for blobs to work, which would encourage life
times to be considered |
| 1880 // when passing ssv's around cross process. At present, we get 'lucky' i
n some cases because |
| 1881 // the blob in the src process happens to still exists at the time the d
est process is deserializing. |
| 1882 // For example in sharedWorker.postMesssage(...). |
| 1883 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
| 1884 if (it != m_blobDataHandles.end()) |
| 1885 return it->value; |
| 1886 return BlobDataHandle::create(uuid, type, size); |
| 1887 } |
| 1888 |
| 1870 const uint8_t* m_buffer; | 1889 const uint8_t* m_buffer; |
| 1871 const unsigned m_length; | 1890 const unsigned m_length; |
| 1872 unsigned m_position; | 1891 unsigned m_position; |
| 1873 uint32_t m_version; | 1892 uint32_t m_version; |
| 1874 v8::Isolate* m_isolate; | 1893 v8::Isolate* m_isolate; |
| 1894 const BlobDataHandleMap& m_blobDataHandles; |
| 1875 }; | 1895 }; |
| 1876 | 1896 |
| 1877 | 1897 |
| 1878 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 1898 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 1879 | 1899 |
| 1880 class Deserializer : public CompositeCreator { | 1900 class Deserializer : public CompositeCreator { |
| 1881 public: | 1901 public: |
| 1882 explicit Deserializer(Reader& reader, | 1902 explicit Deserializer(Reader& reader, |
| 1883 MessagePortArray* messagePorts, ArrayBufferContentsArr
ay* arrayBufferContents) | 1903 MessagePortArray* messagePorts, ArrayBufferContentsArr
ay* arrayBufferContents) |
| 1884 : m_reader(reader) | 1904 : m_reader(reader) |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2261 MessagePortArray* messagePorts, Arr
ayBufferArray* arrayBuffers, | 2281 MessagePortArray* messagePorts, Arr
ayBufferArray* arrayBuffers, |
| 2262 bool& didThrow, | 2282 bool& didThrow, |
| 2263 v8::Isolate* isolate) | 2283 v8::Isolate* isolate) |
| 2264 : m_externallyAllocatedMemory(0) | 2284 : m_externallyAllocatedMemory(0) |
| 2265 { | 2285 { |
| 2266 didThrow = false; | 2286 didThrow = false; |
| 2267 Writer writer(isolate); | 2287 Writer writer(isolate); |
| 2268 Serializer::Status status; | 2288 Serializer::Status status; |
| 2269 { | 2289 { |
| 2270 v8::TryCatch tryCatch; | 2290 v8::TryCatch tryCatch; |
| 2271 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr
yCatch); | 2291 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand
les, tryCatch); |
| 2272 status = serializer.serialize(value); | 2292 status = serializer.serialize(value); |
| 2273 if (status == Serializer::JSException) { | 2293 if (status == Serializer::JSException) { |
| 2274 // If there was a JS exception thrown, re-throw it. | 2294 // If there was a JS exception thrown, re-throw it. |
| 2275 didThrow = true; | 2295 didThrow = true; |
| 2276 tryCatch.ReThrow(); | 2296 tryCatch.ReThrow(); |
| 2277 return; | 2297 return; |
| 2278 } | 2298 } |
| 2279 } | 2299 } |
| 2280 switch (status) { | 2300 switch (status) { |
| 2281 case Serializer::InputError: | 2301 case Serializer::InputError: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2311 : m_externallyAllocatedMemory(0) | 2331 : m_externallyAllocatedMemory(0) |
| 2312 { | 2332 { |
| 2313 m_data = wireData.isolatedCopy(); | 2333 m_data = wireData.isolatedCopy(); |
| 2314 } | 2334 } |
| 2315 | 2335 |
| 2316 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
gePorts, v8::Isolate* isolate) | 2336 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
gePorts, v8::Isolate* isolate) |
| 2317 { | 2337 { |
| 2318 if (!m_data.impl()) | 2338 if (!m_data.impl()) |
| 2319 return v8NullWithCheck(isolate); | 2339 return v8NullWithCheck(isolate); |
| 2320 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2340 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); |
| 2321 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()),
2 * m_data.length(), isolate); | 2341 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()),
2 * m_data.length(), isolate, m_blobDataHandles); |
| 2322 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); | 2342 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); |
| 2323 return deserializer.deserialize(); | 2343 return deserializer.deserialize(); |
| 2324 } | 2344 } |
| 2325 | 2345 |
| 2326 #if ENABLE(INSPECTOR) | 2346 #if ENABLE(INSPECTOR) |
| 2327 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
ate, v8::Isolate* isolate) | 2347 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
ate, v8::Isolate* isolate) |
| 2328 { | 2348 { |
| 2329 v8::HandleScope handleScope; | 2349 v8::HandleScope handleScope; |
| 2330 v8::Context::Scope contextScope(scriptState->context()); | 2350 v8::Context::Scope contextScope(scriptState->context()); |
| 2331 | 2351 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2346 // If the allocated memory was not registered before, then this class is lik
ely | 2366 // If the allocated memory was not registered before, then this class is lik
ely |
| 2347 // used in a context other then Worker's onmessage environment and the prese
nce of | 2367 // used in a context other then Worker's onmessage environment and the prese
nce of |
| 2348 // current v8 context is not guaranteed. Avoid calling v8 then. | 2368 // current v8 context is not guaranteed. Avoid calling v8 then. |
| 2349 if (m_externallyAllocatedMemory) { | 2369 if (m_externallyAllocatedMemory) { |
| 2350 ASSERT(v8::Isolate::GetCurrent()); | 2370 ASSERT(v8::Isolate::GetCurrent()); |
| 2351 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); | 2371 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); |
| 2352 } | 2372 } |
| 2353 } | 2373 } |
| 2354 | 2374 |
| 2355 } // namespace WebCore | 2375 } // namespace WebCore |
| OLD | NEW |