OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/modules/v8/SerializedScriptValueForModulesFactory.h" | 5 #include "bindings/modules/v8/SerializedScriptValueForModulesFactory.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/SerializedScriptValue.h" | 8 #include "bindings/core/v8/SerializedScriptValue.h" |
9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" | 9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" |
10 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules.
h" | 10 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules.
h" |
(...skipping 31 matching lines...) Loading... |
42 V8ScriptValueDeserializerForModules deserializer( | 42 V8ScriptValueDeserializerForModules deserializer( |
43 ScriptState::current(isolate), value); | 43 ScriptState::current(isolate), value); |
44 deserializer.setTransferredMessagePorts(messagePorts); | 44 deserializer.setTransferredMessagePorts(messagePorts); |
45 deserializer.setBlobInfoArray(blobInfo); | 45 deserializer.setBlobInfoArray(blobInfo); |
46 return deserializer.deserialize(); | 46 return deserializer.deserialize(); |
47 } | 47 } |
48 // deserialize() can run arbitrary script (e.g., setters), which could result | 48 // deserialize() can run arbitrary script (e.g., setters), which could result |
49 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along | 49 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
50 // with our internal data) throughout the operation. | 50 // with our internal data) throughout the operation. |
51 RefPtr<SerializedScriptValue> protect(value); | 51 RefPtr<SerializedScriptValue> protect(value); |
52 String& data = value->data(); | 52 if (!value->dataLengthInBytes()) |
53 if (!data.impl()) | |
54 return v8::Null(isolate); | 53 return v8::Null(isolate); |
55 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, | 54 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, |
56 "BufferValueType should be 2 bytes"); | 55 "BufferValueType should be 2 bytes"); |
57 data.ensure16Bit(); | |
58 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 56 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
59 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 57 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
60 // information stored in m_data isn't even encoded in UTF-16. Instead, | 58 // information stored in m_data isn't even encoded in UTF-16. Instead, |
61 // unicode characters are encoded as UTF-8 with two code units per UChar. | 59 // unicode characters are encoded as UTF-8 with two code units per UChar. |
62 SerializedScriptValueReaderForModules reader( | 60 SerializedScriptValueReaderForModules reader( |
63 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), | 61 value->data(), value->dataLengthInBytes(), blobInfo, |
64 2 * data.length(), blobInfo, value->blobDataHandles(), | 62 value->blobDataHandles(), ScriptState::current(isolate)); |
65 ScriptState::current(isolate)); | |
66 ScriptValueDeserializerForModules deserializer( | 63 ScriptValueDeserializerForModules deserializer( |
67 reader, messagePorts, value->getArrayBufferContentsArray(), | 64 reader, messagePorts, value->getArrayBufferContentsArray(), |
68 value->getImageBitmapContentsArray()); | 65 value->getImageBitmapContentsArray()); |
69 return deserializer.deserialize(); | 66 return deserializer.deserialize(); |
70 } | 67 } |
71 | 68 |
72 } // namespace blink | 69 } // namespace blink |
OLD | NEW |