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 24 matching lines...) Expand all Loading... |
35 v8::Isolate* isolate, | 35 v8::Isolate* isolate, |
36 MessagePortArray* messagePorts, | 36 MessagePortArray* messagePorts, |
37 const WebBlobInfoArray* blobInfo) { | 37 const WebBlobInfoArray* blobInfo) { |
38 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { | 38 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { |
39 V8ScriptValueDeserializerForModules deserializer( | 39 V8ScriptValueDeserializerForModules deserializer( |
40 ScriptState::current(isolate), value); | 40 ScriptState::current(isolate), value); |
41 deserializer.setTransferredMessagePorts(messagePorts); | 41 deserializer.setTransferredMessagePorts(messagePorts); |
42 deserializer.setBlobInfoArray(blobInfo); | 42 deserializer.setBlobInfoArray(blobInfo); |
43 return deserializer.deserialize(); | 43 return deserializer.deserialize(); |
44 } | 44 } |
45 // deserialize() can run arbitrary script (e.g., setters), which could result
in |this| being destroyed. | 45 // deserialize() can run arbitrary script (e.g., setters), which could result |
46 // Holding a RefPtr ensures we are alive (along with our internal data) throug
hout the operation. | 46 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
| 47 // with our internal data) throughout the operation. |
47 RefPtr<SerializedScriptValue> protect(value); | 48 RefPtr<SerializedScriptValue> protect(value); |
48 String& data = value->data(); | 49 String& data = value->data(); |
49 if (!data.impl()) | 50 if (!data.impl()) |
50 return v8::Null(isolate); | 51 return v8::Null(isolate); |
51 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, | 52 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, |
52 "BufferValueType should be 2 bytes"); | 53 "BufferValueType should be 2 bytes"); |
53 data.ensure16Bit(); | 54 data.ensure16Bit(); |
54 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 55 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
55 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 56 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
56 // information stored in m_data isn't even encoded in UTF-16. Instead, | 57 // information stored in m_data isn't even encoded in UTF-16. Instead, |
57 // unicode characters are encoded as UTF-8 with two code units per UChar. | 58 // unicode characters are encoded as UTF-8 with two code units per UChar. |
58 SerializedScriptValueReaderForModules reader( | 59 SerializedScriptValueReaderForModules reader( |
59 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), | 60 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), |
60 2 * data.length(), blobInfo, value->blobDataHandles(), | 61 2 * data.length(), blobInfo, value->blobDataHandles(), |
61 ScriptState::current(isolate)); | 62 ScriptState::current(isolate)); |
62 ScriptValueDeserializerForModules deserializer( | 63 ScriptValueDeserializerForModules deserializer( |
63 reader, messagePorts, value->getArrayBufferContentsArray(), | 64 reader, messagePorts, value->getArrayBufferContentsArray(), |
64 value->getImageBitmapContentsArray()); | 65 value->getImageBitmapContentsArray()); |
65 return deserializer.deserialize(); | 66 return deserializer.deserialize(); |
66 } | 67 } |
67 | 68 |
68 } // namespace blink | 69 } // namespace blink |
OLD | NEW |