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/core/v8/SerializedScriptValueFactory.h" | 5 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptValueSerializer.h" | 8 #include "bindings/core/v8/ScriptValueSerializer.h" |
9 #include "bindings/core/v8/Transferables.h" | 9 #include "bindings/core/v8/Transferables.h" |
10 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" | 10 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 V8ScriptValueDeserializer deserializer(ScriptState::current(isolate), | 48 V8ScriptValueDeserializer deserializer(ScriptState::current(isolate), |
49 value); | 49 value); |
50 deserializer.setTransferredMessagePorts(messagePorts); | 50 deserializer.setTransferredMessagePorts(messagePorts); |
51 deserializer.setBlobInfoArray(blobInfo); | 51 deserializer.setBlobInfoArray(blobInfo); |
52 return deserializer.deserialize(); | 52 return deserializer.deserialize(); |
53 } | 53 } |
54 // deserialize() can run arbitrary script (e.g., setters), which could result | 54 // deserialize() can run arbitrary script (e.g., setters), which could result |
55 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along | 55 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
56 // with our internal data) throughout the operation. | 56 // with our internal data) throughout the operation. |
57 RefPtr<SerializedScriptValue> protect(value); | 57 RefPtr<SerializedScriptValue> protect(value); |
58 String& data = value->data(); | 58 if (!value->dataLengthInBytes()) |
59 if (!data.impl()) | |
60 return v8::Null(isolate); | 59 return v8::Null(isolate); |
61 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, | 60 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, |
62 "BufferValueType should be 2 bytes"); | 61 "BufferValueType should be 2 bytes"); |
63 data.ensure16Bit(); | |
64 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 62 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
65 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 63 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
66 // information stored in m_data isn't even encoded in UTF-16. Instead, | 64 // information stored in m_data isn't even encoded in UTF-16. Instead, |
67 // unicode characters are encoded as UTF-8 with two code units per UChar. | 65 // unicode characters are encoded as UTF-8 with two code units per UChar. |
68 SerializedScriptValueReader reader( | 66 SerializedScriptValueReader reader(value->data(), value->dataLengthInBytes(), |
69 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), | 67 blobInfo, value->blobDataHandles(), |
70 2 * data.length(), blobInfo, value->blobDataHandles(), | 68 ScriptState::current(isolate)); |
71 ScriptState::current(isolate)); | |
72 ScriptValueDeserializer deserializer(reader, messagePorts, | 69 ScriptValueDeserializer deserializer(reader, messagePorts, |
73 value->getArrayBufferContentsArray(), | 70 value->getArrayBufferContentsArray(), |
74 value->getImageBitmapContentsArray()); | 71 value->getImageBitmapContentsArray()); |
75 | 72 |
76 // deserialize() can run arbitrary script (e.g., setters), which could result | 73 // deserialize() can run arbitrary script (e.g., setters), which could result |
77 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along | 74 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
78 // with our internal data) throughout the operation. | 75 // with our internal data) throughout the operation. |
79 return deserializer.deserialize(); | 76 return deserializer.deserialize(); |
80 } | 77 } |
81 | 78 |
82 } // namespace blink | 79 } // namespace blink |
OLD | NEW |